openerp-community-reviewer team mailing list archive
-
openerp-community-reviewer team
-
Mailing list archive
-
Message #07797
[Merge] lp:~sylvain-legal/openerp-pos/7.0_fix_pos_change_pricelist into lp:openerp-pos
Sylvain LE GAL (GRAP) has proposed merging lp:~sylvain-legal/openerp-pos/7.0_fix_pos_change_pricelist into lp:openerp-pos.
Commit message:
[ADD] Add new module to manage correctly changes of pricelist in Point Of Sale
Requested reviews:
OpenERP Community Reviewer/Maintainer (openerp-community-reviewer)
For more details, see:
https://code.launchpad.net/~sylvain-legal/openerp-pos/7.0_fix_pos_change_pricelist/+merge/228833
Add a "fix module" to manage correctly the changes of pricelist in a POS Order.
Without:
- when the user change the pricelist (or the customer), it's not possible to apply the new pricelist, and there isn't a warning to inform that there is a problem. (not as in Sale module).
With that module:
- There is the same warning as in 'sale' module, when the user realizes a quotation;
- There is a button to "recompute with pricelist" with pos order is in draft state;
Note:
- Flake8 OK;
- demo data updated;
- feature and non regression covered by python tests;
Thanks for your reviews.
Regards.
--
https://code.launchpad.net/~sylvain-legal/openerp-pos/7.0_fix_pos_change_pricelist/+merge/228833
Your team OpenERP Community Reviewer/Maintainer is requested to review the proposed merge of lp:~sylvain-legal/openerp-pos/7.0_fix_pos_change_pricelist into lp:openerp-pos.
=== added directory 'fix_pos_change_pricelist'
=== added file 'fix_pos_change_pricelist/__init__.py'
--- fix_pos_change_pricelist/__init__.py 1970-01-01 00:00:00 +0000
+++ fix_pos_change_pricelist/__init__.py 2014-07-30 11:57:14 +0000
@@ -0,0 +1,23 @@
+# -*- encoding: utf-8 -*-
+##############################################################################
+#
+# Fix - Point Of Sale Change Pricelist for Odoo
+# Copyright (C) 2014 GRAP (http://www.grap.coop)
+# @author Sylvain LE GAL (https://twitter.com/legalsylvain)
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+
+from . import model
=== added file 'fix_pos_change_pricelist/__openerp__.py'
--- fix_pos_change_pricelist/__openerp__.py 1970-01-01 00:00:00 +0000
+++ fix_pos_change_pricelist/__openerp__.py 2014-07-30 11:57:14 +0000
@@ -0,0 +1,57 @@
+# -*- encoding: utf-8 -*-
+##############################################################################
+#
+# Fix - Point Of Sale Change Pricelist for Odoo
+# Copyright (C) 2014 GRAP (http://www.grap.coop)
+# @author Sylvain LE GAL (https://twitter.com/legalsylvain)
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+{
+ 'name': 'Fix - Point Of Sale Change Pricelist',
+ 'summary': """Fix an incorrect behaviour when changing pricelist on"""
+ """ pos order""",
+ 'version': '1.0',
+ 'category': 'bugfix',
+ 'description': """
+Fix an incorrect behaviour when pricelist on pos order
+======================================================
+
+Features:
+---------
+ * On a POS order, when changing a pricelist, warn the user as in sale"""
+ """ module, when doing a quotation;
+ * On a POS order, provide a 'Recompute With pricelist' button to update"""
+ """ when pricelist has changed;
+
+Copyright, Authors and Licence:
+-------------------------------
+ * Copyright: 2014, GRAP: Groupement Régional Alimentaire de Proximité;
+ * Author:
+ * Sylvain LE GAL (https://twitter.com/legalsylvain);
+ * Licence: AGPL-3 (http://www.gnu.org/licenses/);""",
+ 'author': 'GRAP',
+ 'website': 'http://www.grap.coop',
+ 'license': 'AGPL-3',
+ 'depends': [
+ 'point_of_sale',
+ ],
+ 'data': [
+ 'view/view.xml',
+ ],
+ 'demo': [
+ 'demo/demo.xml',
+ ],
+}
=== added directory 'fix_pos_change_pricelist/demo'
=== added file 'fix_pos_change_pricelist/demo/demo.xml'
--- fix_pos_change_pricelist/demo/demo.xml 1970-01-01 00:00:00 +0000
+++ fix_pos_change_pricelist/demo/demo.xml 2014-07-30 11:57:14 +0000
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+ <data noupdate="1">
+
+ <!-- Price List -->
+ <record id="pricelist_surcharge" model="product.pricelist">
+ <field name="name">Surcharge Pricelist</field>
+ <field name="type">sale</field>
+ </record>
+ <record id="pricelist_version_surcharge" model="product.pricelist.version">
+ <field name="pricelist_id" ref="pricelist_surcharge"/>
+ <field name="name">Surcharge Pricelist Version</field>
+ </record>
+ <record id="pricelist_item_surcharge" model="product.pricelist.item">
+ <field name="price_version_id" ref="pricelist_version_surcharge"/>
+ <field name="base" ref="product.list_price"/>
+ <field name="price_surcharge">10</field>
+ <field name="name">Surcharge Pricelist Line</field>
+ </record>
+
+ <!-- Partner -->
+ <record id="partner_surcharge" model="res.partner">
+ <field name="name">Surcharge Customer</field>
+ <field name="customer" eval="True" />
+ <field name="property_product_pricelist" eval="ref('pricelist_surcharge')" />
+ </record>
+
+ </data>
+</openerp>
=== added directory 'fix_pos_change_pricelist/i18n'
=== added file 'fix_pos_change_pricelist/i18n/fr.po'
--- fix_pos_change_pricelist/i18n/fr.po 1970-01-01 00:00:00 +0000
+++ fix_pos_change_pricelist/i18n/fr.po 2014-07-30 11:57:14 +0000
@@ -0,0 +1,33 @@
+# Translation of OpenERP Server.
+# This file contains the translation of the following modules:
+# * fix_pos_change_pricelist
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: OpenERP Server 7.0\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2014-07-16 13:01+0000\n"
+"PO-Revision-Date: 2014-07-16 13:01+0000\n"
+"Last-Translator: <>\n"
+"Language-Team: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: \n"
+"Plural-Forms: \n"
+
+#. module: fix_pos_change_pricelist
+#: code:addons/fix_pos_change_pricelist/model/pos_order.py:47
+#, python-format
+msgid "If you change the pricelist of this order, prices of existing order lines will not be updated. Please click on the 'Recompute With Pricelist'."
+msgstr "Si vous changez la liste de prix de cette vente, les prix des lignes existantes ne seront pas mis à jour. Merci de cliquer sur le bouton 'Recalculer avec la liste de prix."
+
+#. module: fix_pos_change_pricelist
+#: code:addons/fix_pos_change_pricelist/model/pos_order.py:46
+#, python-format
+msgid "Pricelist Warning!"
+msgstr "Attention à la liste de Prix !"
+
+#. module: fix_pos_change_pricelist
+#: view:pos.order:0
+msgid "Recompute With Pricelist"
+msgstr "Recalculer avec la Liste de Prix"
=== added directory 'fix_pos_change_pricelist/model'
=== added file 'fix_pos_change_pricelist/model/__init__.py'
--- fix_pos_change_pricelist/model/__init__.py 1970-01-01 00:00:00 +0000
+++ fix_pos_change_pricelist/model/__init__.py 2014-07-30 11:57:14 +0000
@@ -0,0 +1,23 @@
+# -*- encoding: utf-8 -*-
+##############################################################################
+#
+# Fix - Point Of Sale Change Pricelist for Odoo
+# Copyright (C) 2014 GRAP (http://www.grap.coop)
+# @author Sylvain LE GAL (https://twitter.com/legalsylvain)
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+
+from . import pos_order
=== added file 'fix_pos_change_pricelist/model/pos_order.py'
--- fix_pos_change_pricelist/model/pos_order.py 1970-01-01 00:00:00 +0000
+++ fix_pos_change_pricelist/model/pos_order.py 2014-07-30 11:57:14 +0000
@@ -0,0 +1,52 @@
+# -*- encoding: utf-8 -*-
+##############################################################################
+#
+# Fix - Point Of Sale Change Pricelist for Odoo
+# Copyright (C) 2014 GRAP (http://www.grap.coop)
+# @author Sylvain LE GAL (https://twitter.com/legalsylvain)
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+
+from openerp.osv.orm import Model
+from openerp.tools.translate import _
+
+
+class pos_order(Model):
+ _inherit = 'pos.order'
+
+ def action_recompute_pricelist(self, cr, uid, ids, context=None):
+ pol_obj = self.pool.get('pos.order.line')
+ for po in self.browse(cr, uid, ids, context=context):
+ for pol in po.lines:
+ res = pol_obj.onchange_product_id(
+ cr, uid, [pol.id], po.pricelist_id.id, pol.product_id.id,
+ pol.qty, po.partner_id.id)
+ if res['value']['price_unit'] != pol.price_unit:
+ pol_obj.write(
+ cr, uid, [pol.id], res['value'], context=context)
+
+ def onchange_pricelist_id(
+ self, cr, uid, ids, pricelist_id, lines, context=None):
+ if not pricelist_id or not lines:
+ return {}
+ warning = {
+ 'title': _('Pricelist Warning!'),
+ 'message': _(
+ """If you change the pricelist of this order,"""
+ """ prices of existing order lines will not be updated."""
+ """ Please click on the 'Recompute With Pricelist'.""")
+ }
+ return {'warning': warning}
=== added directory 'fix_pos_change_pricelist/static'
=== added directory 'fix_pos_change_pricelist/static/src'
=== added directory 'fix_pos_change_pricelist/static/src/img'
=== added file 'fix_pos_change_pricelist/static/src/img/icon.png'
Binary files fix_pos_change_pricelist/static/src/img/icon.png 1970-01-01 00:00:00 +0000 and fix_pos_change_pricelist/static/src/img/icon.png 2014-07-30 11:57:14 +0000 differ
=== added directory 'fix_pos_change_pricelist/tests'
=== added file 'fix_pos_change_pricelist/tests/__init__.py'
--- fix_pos_change_pricelist/tests/__init__.py 1970-01-01 00:00:00 +0000
+++ fix_pos_change_pricelist/tests/__init__.py 2014-07-30 11:57:14 +0000
@@ -0,0 +1,23 @@
+# -*- encoding: utf-8 -*-
+##############################################################################
+#
+# Fix - Point Of Sale Change pricelist for Odoo
+# Copyright (C) 2013-2014 GRAP (http://www.grap.coop)
+# @author Sylvain LE GAL (https://twitter.com/legalsylvain)
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+
+from . import test_fix_pos_change_pricelist
=== added file 'fix_pos_change_pricelist/tests/test_fix_pos_change_pricelist.py'
--- fix_pos_change_pricelist/tests/test_fix_pos_change_pricelist.py 1970-01-01 00:00:00 +0000
+++ fix_pos_change_pricelist/tests/test_fix_pos_change_pricelist.py 2014-07-30 11:57:14 +0000
@@ -0,0 +1,188 @@
+# -*- encoding: utf-8 -*-
+##############################################################################
+#
+# Fix - Point Of Sale Change pricelist for Odoo
+# Copyright (C) 2014 GRAP (http://www.grap.coop)
+# @author Sylvain LE GAL (https://twitter.com/legalsylvain)
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+
+from openerp.tests.common import TransactionCase
+
+
+class TestFixPosChangePricelist(TransactionCase):
+ """Tests for Fix POS Change Pricelist Module"""
+
+ def setUp(self):
+ super(TestFixPosChangePricelist, self).setUp()
+ self.imd_obj = self.registry('ir.model.data')
+ self.pp_obj = self.registry('product.product')
+ self.ppl_obj = self.registry('product.pricelist')
+ self.po_obj = self.registry('pos.order')
+ self.pol_obj = self.registry('pos.order.line')
+ self.pc_obj = self.registry('pos.config')
+ self.ps_obj = self.registry('pos.session')
+
+ # Test Section
+ def test_01_default_price_list(self):
+ """[Regression Test] Sale with default Pricelist"""
+ cr, uid = self.cr, self.uid
+ # Getting object
+ pc_id = self.imd_obj.get_object_reference(
+ cr, uid, 'point_of_sale', 'pos_config_main')[1]
+ rp_c2c_id = self.imd_obj.get_object_reference(
+ cr, uid, 'base', 'res_partner_12')[1]
+ ppl_c2c_id = self.imd_obj.get_object_reference(
+ cr, uid, 'product', 'list0')[1]
+ pp_usb_id = self.imd_obj.get_object_reference(
+ cr, uid, 'product', 'product_product_48')[1]
+
+ # Opening Session
+ self.ps_obj.create(cr, uid, {
+ 'config_id': pc_id,
+ })
+
+ # create Pos Order
+ po_id = self.po_obj.create(cr, uid, {
+ 'partner_id': rp_c2c_id,
+ 'pricelist_id': ppl_c2c_id,
+ 'lines': [[0, False, {
+ 'product_id': pp_usb_id,
+ 'qty': 1,
+ }]],
+ })
+ pp_usb = self.pp_obj.browse(cr, uid, pp_usb_id)
+ po = self.po_obj.browse(cr, uid, po_id)
+
+ res = self.pol_obj.onchange_product_id(
+ cr, uid, po.lines[0].id, po.pricelist_id.id,
+ po.lines[0].product_id.id, po.lines[0].qty)
+
+ self.assertEquals(
+ res['value']['price_subtotal'], pp_usb.list_price,
+ "Incorrect price for default pricelist!")
+
+ def test_02_partner_with_price_list_before(self):
+ """[Regression Test] Sale with specific Pricelist"""
+ cr, uid = self.cr, self.uid
+ # Getting object
+ pc_id = self.imd_obj.get_object_reference(
+ cr, uid, 'point_of_sale', 'pos_config_main')[1]
+ rp_spe_id = self.imd_obj.get_object_reference(
+ cr, uid, 'fix_pos_change_pricelist', 'partner_surcharge')[1]
+ ppl_spe_id = self.imd_obj.get_object_reference(
+ cr, uid, 'fix_pos_change_pricelist', 'pricelist_surcharge')[1]
+ pp_usb_id = self.imd_obj.get_object_reference(
+ cr, uid, 'product', 'product_product_48')[1]
+
+ # Opening Session
+ self.ps_obj.create(cr, uid, {
+ 'config_id': pc_id,
+ })
+
+ # create Pos Order
+ po_id = self.po_obj.create(cr, uid, {
+ 'partner_id': rp_spe_id,
+ 'pricelist_id': ppl_spe_id,
+ 'lines': [[0, False, {
+ 'product_id': pp_usb_id,
+ 'qty': 1,
+ }]],
+ })
+ pp_usb = self.pp_obj.browse(cr, uid, pp_usb_id)
+ po = self.po_obj.browse(cr, uid, po_id)
+
+ res = self.pol_obj.onchange_product_id(
+ cr, uid, po.lines[0].id, po.pricelist_id.id,
+ po.lines[0].product_id.id, po.lines[0].qty)
+ self.assertEquals(
+ res['value']['price_subtotal'], pp_usb.list_price + 10,
+ "Incorrect price for specific pricelist!")
+
+ def test_03_partner_with_price_list_after(self):
+ """[Functional Test] Change pricelist after have set lines."""
+ cr, uid = self.cr, self.uid
+ # Getting object
+ pc_id = self.imd_obj.get_object_reference(
+ cr, uid, 'point_of_sale', 'pos_config_main')[1]
+ ppl_spe_id = self.imd_obj.get_object_reference(
+ cr, uid, 'fix_pos_change_pricelist', 'pricelist_surcharge')[1]
+ ppl_c2c_id = self.imd_obj.get_object_reference(
+ cr, uid, 'product', 'list0')[1]
+ pp_usb_id = self.imd_obj.get_object_reference(
+ cr, uid, 'product', 'product_product_48')[1]
+
+ # Opening Session
+ self.ps_obj.create(cr, uid, {
+ 'config_id': pc_id,
+ })
+
+ # create Pos Order
+ po_id = self.po_obj.create(cr, uid, {
+ 'pricelist_id': ppl_c2c_id,
+ 'lines': [[0, False, {
+ 'product_id': pp_usb_id,
+ 'qty': 1,
+ }]],
+ })
+ po = self.po_obj.browse(cr, uid, po_id)
+
+ res = self.po_obj.onchange_pricelist_id(
+ cr, uid, po.id, ppl_spe_id, po.lines)
+ self.assertNotEquals(
+ res.get('warning', False), False,
+ "Need warning!")
+ pp_usb = self.pp_obj.browse(cr, uid, pp_usb_id)
+
+ # Change now pricelist
+ self.po_obj.write(cr, uid, [po_id], {'pricelist_id': ppl_spe_id})
+ self.po_obj.action_recompute_pricelist(cr, uid, [po.id])
+ po = self.po_obj.browse(cr, uid, po_id)
+ self.assertEquals(
+ po.amount_total, pp_usb.list_price + 10,
+ "Recompute with pricelist error")
+
+ def test_04_partner_without_price_list_after(self):
+ """[Functional Test] Unset pricelist after have set lines."""
+ cr, uid = self.cr, self.uid
+ # Getting object
+ pc_id = self.imd_obj.get_object_reference(
+ cr, uid, 'point_of_sale', 'pos_config_main')[1]
+ pp_usb_id = self.imd_obj.get_object_reference(
+ cr, uid, 'product', 'product_product_48')[1]
+ ppl_c2c_id = self.imd_obj.get_object_reference(
+ cr, uid, 'product', 'list0')[1]
+
+ # Opening Session
+ self.ps_obj.create(cr, uid, {
+ 'config_id': pc_id,
+ })
+
+ # create Pos Order
+ po_id = self.po_obj.create(cr, uid, {
+ 'pricelist_id': ppl_c2c_id,
+ 'lines': [[0, False, {
+ 'product_id': pp_usb_id,
+ 'qty': 1,
+ }]],
+ })
+ po = self.po_obj.browse(cr, uid, po_id)
+
+ res = self.po_obj.onchange_pricelist_id(
+ cr, uid, po.id, False, po.lines)
+ self.assertEquals(
+ res.get('warning', False), False,
+ "Doesn't need warning!")
=== added directory 'fix_pos_change_pricelist/view'
=== added file 'fix_pos_change_pricelist/view/view.xml'
--- fix_pos_change_pricelist/view/view.xml 1970-01-01 00:00:00 +0000
+++ fix_pos_change_pricelist/view/view.xml 2014-07-30 11:57:14 +0000
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- ********************************************************************** -->
+<!--Fix - Point Of Sale Change Pricelist for Odoo -->
+<!--Copyright (C) 2014 GRAP (http://www.grap.coop) -->
+<!--@author Sylvain LE GAL (https://twitter.com/legalsylvain) -->
+
+<!--This program is free software: you can redistribute it and/or modify -->
+<!--it under the terms of the GNU Affero General Public License as -->
+<!--published by the Free Software Foundation, either version 3 of the -->
+<!--License, or (at your option) any later version. -->
+
+<!--This program is distributed in the hope that it will be useful, -->
+<!--but WITHOUT ANY WARRANTY; without even the implied warranty of -->
+<!--MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -->
+<!--GNU Affero General Public License for more details. -->
+
+<!--You should have received a copy of the GNU Affero General Public License-->
+<!--along with this program. If not, see <http://www.gnu.org/licenses/>. -->
+<!-- ********************************************************************** -->
+<openerp>
+ <data>
+ <!-- View : pos.order -->
+ <record id="view_pos_order_form" model="ir.ui.view">
+ <field name="name">pos.order.form</field>
+ <field name="model">pos.order</field>
+ <field name="inherit_id" ref="point_of_sale.view_pos_pos_form" />
+ <field name="arch" type="xml">
+ <header position="inside">
+ <button name="action_recompute_pricelist" string="Recompute With Pricelist" type="object" states="draft"/>
+ </header>
+ <field name="pricelist_id" position="attributes">
+ <attribute name="on_change">onchange_pricelist_id(pricelist_id, lines)</attribute>
+ </field>
+ </field>
+ </record>
+
+ </data>
+</openerp>
Follow ups