From baec557b60a300a9f675b9ad5036386b4b6ea303 Mon Sep 17 00:00:00 2001 From: Alex Comba Date: Tue, 5 May 2015 11:25:45 +0200 Subject: [PATCH 01/18] Add code using by 'git checkout origin/7.0 -- sale_line_price_properties_based --- sale_line_price_properties_based/__init__.py | 21 +++++ .../__openerp__.py | 71 ++++++++++++++++ sale_line_price_properties_based/i18n/it.po | 63 ++++++++++++++ sale_line_price_properties_based/product.py | 82 +++++++++++++++++++ .../product_demo.xml | 8 ++ .../product_view.xml | 15 ++++ .../sale_order_line.py | 69 ++++++++++++++++ .../sale_order_view.xml | 35 ++++++++ .../test/sale_order.yml | 13 +++ 9 files changed, 377 insertions(+) create mode 100644 sale_line_price_properties_based/__init__.py create mode 100644 sale_line_price_properties_based/__openerp__.py create mode 100644 sale_line_price_properties_based/i18n/it.po create mode 100644 sale_line_price_properties_based/product.py create mode 100644 sale_line_price_properties_based/product_demo.xml create mode 100644 sale_line_price_properties_based/product_view.xml create mode 100644 sale_line_price_properties_based/sale_order_line.py create mode 100644 sale_line_price_properties_based/sale_order_view.xml create mode 100644 sale_line_price_properties_based/test/sale_order.yml diff --git a/sale_line_price_properties_based/__init__.py b/sale_line_price_properties_based/__init__.py new file mode 100644 index 00000000000..df5cc4ec4a5 --- /dev/null +++ b/sale_line_price_properties_based/__init__.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Copyright (C) 2014 Agile Business Group sagl () +# +# 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 . +# +############################################################################## +from . import product +from . import sale_order_line diff --git a/sale_line_price_properties_based/__openerp__.py b/sale_line_price_properties_based/__openerp__.py new file mode 100644 index 00000000000..8544c4d237b --- /dev/null +++ b/sale_line_price_properties_based/__openerp__.py @@ -0,0 +1,71 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Copyright (C) 2014 Agile Business Group sagl +# () +# @author Lorenzo Battistini +# @author Alex Comba +# +# 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 . +# +############################################################################## +{ + 'name': "Product price properties based", + 'version': '0.1', + 'category': '', + 'description': """ +This module allows to use python formaulas to compute the sale order line +price. + +You can configure the 'Price formula' on the product form using python code. + +Formula example: +``` +area = float(properties['Width']) * float(properties['Length']) +result = area / 2.0 +if 'Painting' in properties: + result = result + 5 +``` + +When changing properties on sale order line, the system will automatically +compute the line price unit. + + +Contributors +------------ + + - Lorenzo Battistini + - Alex Comba + +""", + 'author': "Agile Business Group,Odoo Community Association (OCA)", + 'website': 'http://www.agilebg.com', + 'license': 'AGPL-3', + "depends": [ + 'sale_properties_easy_creation', + 'web_context_tunnel', + ], + "data": [ + 'sale_order_view.xml', + 'product_view.xml', + ], + "demo": [ + 'product_demo.xml', + ], + "test": [ + 'test/sale_order.yml', + ], + "active": False, + "installable": True +} diff --git a/sale_line_price_properties_based/i18n/it.po b/sale_line_price_properties_based/i18n/it.po new file mode 100644 index 00000000000..d438bef49a4 --- /dev/null +++ b/sale_line_price_properties_based/i18n/it.po @@ -0,0 +1,63 @@ +# Translation of OpenERP Server. +# This file contains the translation of the following modules: +# * sale_line_price_properties_based +# +msgid "" +msgstr "" +"Project-Id-Version: OpenERP Server 7.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2014-08-19 09:46+0000\n" +"PO-Revision-Date: 2014-08-19 09:46+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: sale_line_price_properties_based +#: field:product.product,price_formula_id:0 +msgid "Price formula" +msgstr "Formula prezzo" + +#. module: sale_line_price_properties_based +#: code:_description:0 +#: model:ir.model,name:sale_line_price_properties_based.model_product_product +#, python-format +msgid "Product" +msgstr "Prodotto" + +#. module: sale_line_price_properties_based +#: code:_description:0 +#: model:ir.model,name:sale_line_price_properties_based.model_sale_order_line +#, python-format +msgid "Sales Order Line" +msgstr "Linea d'ordine di vendita" + +#. module: sale_line_price_properties_based +#: help:product.product,price_formula_id:0 +msgid "You can use the variables\n" +" - self\n" +" - cr\n" +" - uid\n" +" - ptype\n" +" - properties (dictionary of properties)\n" +"You have to put the result in the 'result' variable" +msgstr "E' possibile usare le variabili\n" +" - self\n" +" - cr\n" +" - uid\n" +" - ptype\n" +" - properties (dizionario di proprietà)\n" +"Bisogna mettere il risultato nella variabile 'result'" + +#. module: sale_line_price_properties_based +#: view:sale.order:0 +msgid "product_id_change(parent.pricelist_id,product_id,product_uom_qty,product_uom,False,False,False,parent.partner_id, False, False, parent.date_order, False, False, False, context)" +msgstr "product_id_change(parent.pricelist_id,product_id,product_uom_qty,product_uom,False,False,False,parent.partner_id, False, False, parent.date_order, False, False, False, context)" + +#. module: sale_line_price_properties_based +#: view:sale.order:0 +msgid "{'property_ids': property_ids}" +msgstr "{'property_ids': property_ids}" + diff --git a/sale_line_price_properties_based/product.py b/sale_line_price_properties_based/product.py new file mode 100644 index 00000000000..8ebd0ca7e84 --- /dev/null +++ b/sale_line_price_properties_based/product.py @@ -0,0 +1,82 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Copyright (C) 2014 Agile Business Group sagl +# () +# +# 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 . +# +############################################################################## + +from openerp.osv import orm, fields +from openerp import SUPERUSER_ID +from openerp.tools.translate import _ +import logging + +_logger = logging.getLogger(__name__) + + +class ProductProduct(orm.Model): + _inherit = "product.product" + + _columns = { + 'price_formula_id': fields.many2one( + 'mrp.property.formula', 'Price formula', + help="You can use the variables\n" + " - self\n" + " - cr\n" + " - uid\n" + " - ptype\n" + " - product_id\n" + " - properties (dictionary of properties)\n" + "You have to put the result in the 'result' variable"), + } + + def price_get(self, cr, uid, ids, ptype='list_price', context=None): + if context is None: + context = {} + if 'properties' in context: + res = {} + for product in self.browse(cr, SUPERUSER_ID, ids, context=context): + res[product.id] = super(ProductProduct, self).price_get( + cr, uid, [product.id], ptype=ptype, context=context + )[product.id] + if product.price_formula_id: + localdict = { + 'self': self, + 'cr': cr, + 'uid': uid, + 'ptype': ptype, + 'product_id': product.id, + 'properties': context['properties'], + } + try: + exec product.price_formula_id.formula_text in localdict + except KeyError: + _logger.warning( + "KeyError for formula '%s' and prop_dict '%s'" + % (product.price_formula_id.formula_text, + context['properties'])) + continue + try: + amount = localdict['result'] + except KeyError: + raise orm.except_orm( + _('Error'), + _("Formula must contain 'result' variable")) + res[product.id] = amount + else: + res = super(ProductProduct, self).price_get( + cr, uid, ids, ptype=ptype, context=context) + return res diff --git a/sale_line_price_properties_based/product_demo.xml b/sale_line_price_properties_based/product_demo.xml new file mode 100644 index 00000000000..18355c7499e --- /dev/null +++ b/sale_line_price_properties_based/product_demo.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/sale_line_price_properties_based/product_view.xml b/sale_line_price_properties_based/product_view.xml new file mode 100644 index 00000000000..6ed760be834 --- /dev/null +++ b/sale_line_price_properties_based/product_view.xml @@ -0,0 +1,15 @@ + + + + + product.normal.formula.form + product.product + + + + + + + + + diff --git a/sale_line_price_properties_based/sale_order_line.py b/sale_line_price_properties_based/sale_order_line.py new file mode 100644 index 00000000000..588a71a8899 --- /dev/null +++ b/sale_line_price_properties_based/sale_order_line.py @@ -0,0 +1,69 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Copyright (C) 2014 Agile Business Group sagl +# () +# +# 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 . +# +############################################################################## + +from openerp.osv import orm +from openerp.tools.translate import _ + + +class SaleOrderLine(orm.Model): + _inherit = 'sale.order.line' + + def product_id_change( + self, cr, uid, ids, pricelist, product, qty=0, + uom=False, qty_uos=0, uos=False, name='', partner_id=False, + lang=False, update_tax=True, date_order=False, packaging=False, + fiscal_position=False, flag=False, context=None + ): + res = super(SaleOrderLine, self).product_id_change( + cr, uid, ids, pricelist, product, qty=qty, + uom=uom, qty_uos=qty_uos, uos=uos, + name=name, partner_id=partner_id, + lang=lang, update_tax=update_tax, + date_order=date_order, packaging=packaging, + fiscal_position=fiscal_position, flag=flag, context=context) + if context is None: + context = {} + properties = context.get('property_ids') + prop_ctx = context.copy() + if 'lang' in prop_ctx: + del prop_ctx['lang'] + if properties and product: + prop_dict = {} + prop_pool = self.pool['mrp.property'] + for m2m_tup in properties: + for prop in prop_pool.browse( + cr, uid, m2m_tup[2], context=prop_ctx + ): + if prop.group_id.name in prop_dict: + raise orm.except_orm( + _('Error'), + _('Property of group %s already present') + % prop.group_id.name) + prop_dict[prop.group_id.name] = prop.value + price = self.pool.get('product.pricelist').price_get( + cr, uid, [pricelist], + product, qty or 1.0, partner_id, { + 'uom': uom or res.get('product_uom'), + 'date': date_order, + 'properties': prop_dict, + })[pricelist] + res['value']['price_unit'] = price + return res diff --git a/sale_line_price_properties_based/sale_order_view.xml b/sale_line_price_properties_based/sale_order_view.xml new file mode 100644 index 00000000000..d14fa8904d7 --- /dev/null +++ b/sale_line_price_properties_based/sale_order_view.xml @@ -0,0 +1,35 @@ + + + + + + sale.order.form + sale.order + + + + {'property_ids': property_ids} + + + {'property_ids': property_ids} + + + product_id_change(parent.pricelist_id,product_id,product_uom_qty,product_uom,product_uos_qty,False,False,parent.partner_id, False, False, parent.date_order, False, False, True, context) + {'property_ids': property_ids} + + + + + + sale.order.form + sale.order + + + + {'property_ids': property_ids} + + + + + + diff --git a/sale_line_price_properties_based/test/sale_order.yml b/sale_line_price_properties_based/test/sale_order.yml new file mode 100644 index 00000000000..3ea14d9df36 --- /dev/null +++ b/sale_line_price_properties_based/test/sale_order.yml @@ -0,0 +1,13 @@ +- + I check the on_change +- + !python {model: sale.order.line}: | + if context is None: + context = {} + context['property_ids'] = [(6, False, [ + ref('sale_properties_easy_creation.length_5'), + ref('sale_properties_easy_creation.width_1'), + ])] + res = self.product_id_change(cr, uid, [], ref('product.list0'), ref('product.product_product_7'), qty=8, + partner_id=ref('base.res_partner_2'), context=context) + assert res['value']['price_unit'] == 2.5, "Price unit must be 2.5, %s found" % res['value']['price_unit'] From 9a3512365aaf98563d40cc4267731a53c2bb4add Mon Sep 17 00:00:00 2001 From: Alex Comba Date: Tue, 5 May 2015 11:33:37 +0200 Subject: [PATCH 02/18] Use template istead of product --- sale_line_price_properties_based/product.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/sale_line_price_properties_based/product.py b/sale_line_price_properties_based/product.py index 8ebd0ca7e84..29fca21d5dc 100644 --- a/sale_line_price_properties_based/product.py +++ b/sale_line_price_properties_based/product.py @@ -20,7 +20,6 @@ ############################################################################## from openerp.osv import orm, fields -from openerp import SUPERUSER_ID from openerp.tools.translate import _ import logging @@ -43,15 +42,20 @@ class ProductProduct(orm.Model): "You have to put the result in the 'result' variable"), } - def price_get(self, cr, uid, ids, ptype='list_price', context=None): + +class product_template(orm.Model): + _inherit = "product.template" + + def _price_get(self, cr, uid, products, ptype='list_price', context=None): if context is None: context = {} + + res = super(product_template, self)._price_get( + cr, uid, products, ptype=ptype, context=context) if 'properties' in context: - res = {} - for product in self.browse(cr, SUPERUSER_ID, ids, context=context): - res[product.id] = super(ProductProduct, self).price_get( - cr, uid, [product.id], ptype=ptype, context=context - )[product.id] + for product in products: + res = super(product_template, self)._price_get( + cr, uid, products, ptype=ptype, context=context) if product.price_formula_id: localdict = { 'self': self, @@ -76,7 +80,4 @@ def price_get(self, cr, uid, ids, ptype='list_price', context=None): _('Error'), _("Formula must contain 'result' variable")) res[product.id] = amount - else: - res = super(ProductProduct, self).price_get( - cr, uid, ids, ptype=ptype, context=context) return res From c9e86e71e753b7981a16072851624e1b13db5d1e Mon Sep 17 00:00:00 2001 From: Alex Comba Date: Tue, 5 May 2015 11:34:14 +0200 Subject: [PATCH 03/18] Fix field name, changed in V8 --- sale_line_price_properties_based/product_view.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sale_line_price_properties_based/product_view.xml b/sale_line_price_properties_based/product_view.xml index 6ed760be834..47aee067ccc 100644 --- a/sale_line_price_properties_based/product_view.xml +++ b/sale_line_price_properties_based/product_view.xml @@ -6,7 +6,7 @@ product.product - + From 2a7ff96629fbea9e553f4cac44e02f58a2dffdb5 Mon Sep 17 00:00:00 2001 From: Alex Comba Date: Tue, 5 May 2015 11:37:33 +0200 Subject: [PATCH 04/18] Inherit views from sale_mrp instead of sale_stock --- .../sale_order_view.xml | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/sale_line_price_properties_based/sale_order_view.xml b/sale_line_price_properties_based/sale_order_view.xml index d14fa8904d7..9e59934d8dd 100644 --- a/sale_line_price_properties_based/sale_order_view.xml +++ b/sale_line_price_properties_based/sale_order_view.xml @@ -5,7 +5,7 @@ sale.order.form sale.order - + {'property_ids': property_ids} @@ -13,7 +13,19 @@ {'property_ids': property_ids} - + + product_id_change(parent.pricelist_id,product_id,product_uom_qty,product_uom,product_uos_qty,False,False,parent.partner_id, False, False, parent.date_order, False, False, True, context) + {'property_ids': property_ids} + + + + + + sale.order.form + sale.order + + + product_id_change(parent.pricelist_id,product_id,product_uom_qty,product_uom,product_uos_qty,False,False,parent.partner_id, False, False, parent.date_order, False, False, True, context) {'property_ids': property_ids} From 791501a6d7724bd8bee8b791f78fe53ceb027182 Mon Sep 17 00:00:00 2001 From: Alex Comba Date: Tue, 5 May 2015 11:40:23 +0200 Subject: [PATCH 05/18] Update copyright year --- sale_line_price_properties_based/__init__.py | 2 +- sale_line_price_properties_based/__openerp__.py | 2 +- sale_line_price_properties_based/product.py | 2 +- sale_line_price_properties_based/sale_order_line.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sale_line_price_properties_based/__init__.py b/sale_line_price_properties_based/__init__.py index df5cc4ec4a5..6b8a5884927 100644 --- a/sale_line_price_properties_based/__init__.py +++ b/sale_line_price_properties_based/__init__.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- ############################################################################## # -# Copyright (C) 2014 Agile Business Group sagl () +# Copyright (C) 2014-15 Agile Business Group sagl () # # 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 diff --git a/sale_line_price_properties_based/__openerp__.py b/sale_line_price_properties_based/__openerp__.py index 8544c4d237b..3ee50530896 100644 --- a/sale_line_price_properties_based/__openerp__.py +++ b/sale_line_price_properties_based/__openerp__.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- ############################################################################## # -# Copyright (C) 2014 Agile Business Group sagl +# Copyright (C) 2014-15 Agile Business Group sagl # () # @author Lorenzo Battistini # @author Alex Comba diff --git a/sale_line_price_properties_based/product.py b/sale_line_price_properties_based/product.py index 29fca21d5dc..b1b0647c249 100644 --- a/sale_line_price_properties_based/product.py +++ b/sale_line_price_properties_based/product.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- ############################################################################## # -# Copyright (C) 2014 Agile Business Group sagl +# Copyright (C) 2014-15 Agile Business Group sagl # () # # This program is free software: you can redistribute it and/or modify diff --git a/sale_line_price_properties_based/sale_order_line.py b/sale_line_price_properties_based/sale_order_line.py index 588a71a8899..0c3bcf3c44e 100644 --- a/sale_line_price_properties_based/sale_order_line.py +++ b/sale_line_price_properties_based/sale_order_line.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- ############################################################################## # -# Copyright (C) 2014 Agile Business Group sagl +# Copyright (C) 2014-15 Agile Business Group sagl # () # # This program is free software: you can redistribute it and/or modify From 70a3dd9f2ca8cecd3e5064b22e43f026effe826f Mon Sep 17 00:00:00 2001 From: Alex Comba Date: Tue, 5 May 2015 11:43:27 +0200 Subject: [PATCH 06/18] Extract the description in README.rst --- sale_line_price_properties_based/README.rst | 45 +++++++++++++++++++ .../__openerp__.py | 27 +---------- 2 files changed, 46 insertions(+), 26 deletions(-) create mode 100644 sale_line_price_properties_based/README.rst diff --git a/sale_line_price_properties_based/README.rst b/sale_line_price_properties_based/README.rst new file mode 100644 index 00000000000..64d15032e47 --- /dev/null +++ b/sale_line_price_properties_based/README.rst @@ -0,0 +1,45 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :alt: License: AGPL-3 + +Sale line price properties based +================================ + +This module allows to use python formaulas to compute the sale order line +price. + +You can configure the 'Price formula' on the product form using python code. + +Formula example: +``` +area = float(properties['Width']) * float(properties['Length']) +result = area / 2.0 +if 'Painting' in properties: + result = result + 5 +``` + +When changing properties on sale order line, the system will automatically +compute the line price unit. + +Credits +======= + +Contributors +------------ + +* Lorenzo Battistini +* Alex Comba + +Maintainer +---------- + +.. image:: http://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: http://odoo-community.org + +This module is maintained by the OCA. + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +To contribute to this module, please visit http://odoo-community.org. diff --git a/sale_line_price_properties_based/__openerp__.py b/sale_line_price_properties_based/__openerp__.py index 3ee50530896..e30cda6c3f0 100644 --- a/sale_line_price_properties_based/__openerp__.py +++ b/sale_line_price_properties_based/__openerp__.py @@ -21,34 +21,9 @@ # ############################################################################## { - 'name': "Product price properties based", + 'name': "Sale line price properties based", 'version': '0.1', 'category': '', - 'description': """ -This module allows to use python formaulas to compute the sale order line -price. - -You can configure the 'Price formula' on the product form using python code. - -Formula example: -``` -area = float(properties['Width']) * float(properties['Length']) -result = area / 2.0 -if 'Painting' in properties: - result = result + 5 -``` - -When changing properties on sale order line, the system will automatically -compute the line price unit. - - -Contributors ------------- - - - Lorenzo Battistini - - Alex Comba - -""", 'author': "Agile Business Group,Odoo Community Association (OCA)", 'website': 'http://www.agilebg.com', 'license': 'AGPL-3', From bf2501199f69250c8c513f2076d5027ddd053afc Mon Sep 17 00:00:00 2001 From: Alex Comba Date: Tue, 5 May 2015 11:44:16 +0200 Subject: [PATCH 07/18] Change version and remove deprecated key as active --- sale_line_price_properties_based/__openerp__.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sale_line_price_properties_based/__openerp__.py b/sale_line_price_properties_based/__openerp__.py index e30cda6c3f0..c7d2fbebb62 100644 --- a/sale_line_price_properties_based/__openerp__.py +++ b/sale_line_price_properties_based/__openerp__.py @@ -22,7 +22,7 @@ ############################################################################## { 'name': "Sale line price properties based", - 'version': '0.1', + 'version': '1.0', 'category': '', 'author': "Agile Business Group,Odoo Community Association (OCA)", 'website': 'http://www.agilebg.com', @@ -41,6 +41,5 @@ "test": [ 'test/sale_order.yml', ], - "active": False, "installable": True } From 071be152adbd393b1dafe7b58ee37447c745aa5b Mon Sep 17 00:00:00 2001 From: Alex Comba Date: Tue, 5 May 2015 11:45:05 +0200 Subject: [PATCH 08/18] Use CamelCase notation for model --- sale_line_price_properties_based/product.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sale_line_price_properties_based/product.py b/sale_line_price_properties_based/product.py index b1b0647c249..1fb5278d2c8 100644 --- a/sale_line_price_properties_based/product.py +++ b/sale_line_price_properties_based/product.py @@ -43,18 +43,18 @@ class ProductProduct(orm.Model): } -class product_template(orm.Model): +class ProductTemplate(orm.Model): _inherit = "product.template" def _price_get(self, cr, uid, products, ptype='list_price', context=None): if context is None: context = {} - res = super(product_template, self)._price_get( + res = super(ProductTemplate, self)._price_get( cr, uid, products, ptype=ptype, context=context) if 'properties' in context: for product in products: - res = super(product_template, self)._price_get( + res = super(ProductTemplate, self)._price_get( cr, uid, products, ptype=ptype, context=context) if product.price_formula_id: localdict = { From 03249a83e5b508841164b8e760f513770b368c46 Mon Sep 17 00:00:00 2001 From: Alex Comba Date: Tue, 5 May 2015 11:46:06 +0200 Subject: [PATCH 09/18] Add OCA icon --- .../static/description/icon.png | Bin 0 -> 9455 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 sale_line_price_properties_based/static/description/icon.png diff --git a/sale_line_price_properties_based/static/description/icon.png b/sale_line_price_properties_based/static/description/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..3a0328b516c4980e8e44cdb63fd945757ddd132d GIT binary patch literal 9455 zcmW++2RxMjAAjx~&dlBk9S+%}OXg)AGE&Cb*&}d0jUxM@u(PQx^-s)697TX`ehR4?GS^qbkof1cslKgkU)h65qZ9Oc=ml_0temigYLJfnz{IDzUf>bGs4N!v3=Z3jMq&A#7%rM5eQ#dc?k~! zVpnB`o+K7|Al`Q_U;eD$B zfJtP*jH`siUq~{KE)`jP2|#TUEFGRryE2`i0**z#*^6~AI|YzIWy$Cu#CSLW3q=GA z6`?GZymC;dCPk~rBS%eCb`5OLr;RUZ;D`}um=H)BfVIq%7VhiMr)_#G0N#zrNH|__ zc+blN2UAB0=617@>_u;MPHN;P;N#YoE=)R#i$k_`UAA>WWCcEVMh~L_ zj--gtp&|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^t$+QP?#mov zGVC@I*lBVrOU-%2y!7%)fAKjpEFsgQc4{amtiHb95KQEwvf<(3T<9-Zm$xIew#P22 zc2Ix|App^>v6(3L_MCU0d3W##AB0M~3D00EWoKZqsJYT(#@w$Y_H7G22M~ApVFTRHMI_3be)Lkn#0F*V8Pq zc}`Cjy$bE;FJ6H7p=0y#R>`}-m4(0F>%@P|?7fx{=R^uFdISRnZ2W_xQhD{YuR3t< z{6yxu=4~JkeA;|(J6_nv#>Nvs&FuLA&PW^he@t(UwFFE8)|a!R{`E`K`i^ZnyE4$k z;(749Ix|oi$c3QbEJ3b~D_kQsPz~fIUKym($a_7dJ?o+40*OLl^{=&oq$<#Q(yyrp z{J-FAniyAw9tPbe&IhQ|a`DqFTVQGQ&Gq3!C2==4x{6EJwiPZ8zub-iXoUtkJiG{} zPaR&}_fn8_z~(=;5lD-aPWD3z8PZS@AaUiomF!G8I}Mf>e~0g#BelA-5#`cj;O5>N Xviia!U7SGha1wx#SCgwmn*{w2TRX*I literal 0 HcmV?d00001 From 85b502b546532a320fec82e46b89eef992a6116c Mon Sep 17 00:00:00 2001 From: Alex Comba Date: Thu, 11 Jun 2015 16:04:54 +0200 Subject: [PATCH 10/18] Remove redundant record: this assignment is already done in 'view_order_form_inherit' --- sale_line_price_properties_based/sale_order_view.xml | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/sale_line_price_properties_based/sale_order_view.xml b/sale_line_price_properties_based/sale_order_view.xml index 9e59934d8dd..fc137bbb70b 100644 --- a/sale_line_price_properties_based/sale_order_view.xml +++ b/sale_line_price_properties_based/sale_order_view.xml @@ -20,18 +20,6 @@ - - sale.order.form - sale.order - - - - product_id_change(parent.pricelist_id,product_id,product_uom_qty,product_uom,product_uos_qty,False,False,parent.partner_id, False, False, parent.date_order, False, False, True, context) - {'property_ids': property_ids} - - - - sale.order.form sale.order From c2af0c90fe0f9999c8d36c6074f330b6485184a6 Mon Sep 17 00:00:00 2001 From: Lorenzo Battistini Date: Mon, 15 Jun 2015 14:41:02 +0200 Subject: [PATCH 11/18] [FIX] using new API for property_ids onchange --- .../__openerp__.py | 2 - .../sale_order_line.py | 67 +++++++------------ .../sale_order_view.xml | 35 ---------- 3 files changed, 26 insertions(+), 78 deletions(-) delete mode 100644 sale_line_price_properties_based/sale_order_view.xml diff --git a/sale_line_price_properties_based/__openerp__.py b/sale_line_price_properties_based/__openerp__.py index c7d2fbebb62..40911c15ac1 100644 --- a/sale_line_price_properties_based/__openerp__.py +++ b/sale_line_price_properties_based/__openerp__.py @@ -29,10 +29,8 @@ 'license': 'AGPL-3', "depends": [ 'sale_properties_easy_creation', - 'web_context_tunnel', ], "data": [ - 'sale_order_view.xml', 'product_view.xml', ], "demo": [ diff --git a/sale_line_price_properties_based/sale_order_line.py b/sale_line_price_properties_based/sale_order_line.py index 0c3bcf3c44e..d68114b903c 100644 --- a/sale_line_price_properties_based/sale_order_line.py +++ b/sale_line_price_properties_based/sale_order_line.py @@ -19,51 +19,36 @@ # ############################################################################## -from openerp.osv import orm +from openerp import models, api from openerp.tools.translate import _ +from openerp.exceptions import except_orm -class SaleOrderLine(orm.Model): +class SaleOrderLine(models.Model): _inherit = 'sale.order.line' - def product_id_change( - self, cr, uid, ids, pricelist, product, qty=0, - uom=False, qty_uos=0, uos=False, name='', partner_id=False, - lang=False, update_tax=True, date_order=False, packaging=False, - fiscal_position=False, flag=False, context=None - ): - res = super(SaleOrderLine, self).product_id_change( - cr, uid, ids, pricelist, product, qty=qty, - uom=uom, qty_uos=qty_uos, uos=uos, - name=name, partner_id=partner_id, - lang=lang, update_tax=update_tax, - date_order=date_order, packaging=packaging, - fiscal_position=fiscal_position, flag=flag, context=context) - if context is None: - context = {} - properties = context.get('property_ids') - prop_ctx = context.copy() + @api.onchange( + 'property_ids', 'product_id', 'product_uom_qty', 'product_uom' + ) + def property_ids_changed(self): + prop_dict = {} + prop_ctx = self.env.context.copy() if 'lang' in prop_ctx: del prop_ctx['lang'] - if properties and product: - prop_dict = {} - prop_pool = self.pool['mrp.property'] - for m2m_tup in properties: - for prop in prop_pool.browse( - cr, uid, m2m_tup[2], context=prop_ctx - ): - if prop.group_id.name in prop_dict: - raise orm.except_orm( - _('Error'), - _('Property of group %s already present') - % prop.group_id.name) - prop_dict[prop.group_id.name] = prop.value - price = self.pool.get('product.pricelist').price_get( - cr, uid, [pricelist], - product, qty or 1.0, partner_id, { - 'uom': uom or res.get('product_uom'), - 'date': date_order, - 'properties': prop_dict, - })[pricelist] - res['value']['price_unit'] = price - return res + for prop in self.env['mrp.property'].with_context(prop_ctx).browse( + [p.id for p in self.property_ids] + ): + if prop.group_id.name in prop_dict: + raise except_orm( + _('Error'), + _('Property of group %s already present') + % prop.group_id.name) + prop_dict[prop.group_id.name] = prop.value + self.price_unit = self.pool.get('product.pricelist').price_get( + self._cr, self._uid, [self.order_id.pricelist_id.id], + self.product_id.id, self.product_uom_qty or 1.0, + self.order_id.partner_id.id, { + 'uom': self.product_uom.id, + 'date': self.order_id.date_order, + 'properties': prop_dict, + })[self.order_id.pricelist_id.id] diff --git a/sale_line_price_properties_based/sale_order_view.xml b/sale_line_price_properties_based/sale_order_view.xml deleted file mode 100644 index fc137bbb70b..00000000000 --- a/sale_line_price_properties_based/sale_order_view.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - sale.order.form - sale.order - - - - {'property_ids': property_ids} - - - {'property_ids': property_ids} - - - product_id_change(parent.pricelist_id,product_id,product_uom_qty,product_uom,product_uos_qty,False,False,parent.partner_id, False, False, parent.date_order, False, False, True, context) - {'property_ids': property_ids} - - - - - - sale.order.form - sale.order - - - - {'property_ids': property_ids} - - - - - - From 83b8a58bb67991012e50a6289b76b7f45d8b613b Mon Sep 17 00:00:00 2001 From: Alex Comba Date: Wed, 17 Jun 2015 20:10:21 +0200 Subject: [PATCH 12/18] Fix onchange method name and add check on product_id --- .../sale_order_line.py | 37 ++++++++++--------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/sale_line_price_properties_based/sale_order_line.py b/sale_line_price_properties_based/sale_order_line.py index d68114b903c..b86aa65b906 100644 --- a/sale_line_price_properties_based/sale_order_line.py +++ b/sale_line_price_properties_based/sale_order_line.py @@ -30,25 +30,26 @@ class SaleOrderLine(models.Model): @api.onchange( 'property_ids', 'product_id', 'product_uom_qty', 'product_uom' ) - def property_ids_changed(self): + def price_property_ids_changed(self): prop_dict = {} prop_ctx = self.env.context.copy() if 'lang' in prop_ctx: del prop_ctx['lang'] - for prop in self.env['mrp.property'].with_context(prop_ctx).browse( - [p.id for p in self.property_ids] - ): - if prop.group_id.name in prop_dict: - raise except_orm( - _('Error'), - _('Property of group %s already present') - % prop.group_id.name) - prop_dict[prop.group_id.name] = prop.value - self.price_unit = self.pool.get('product.pricelist').price_get( - self._cr, self._uid, [self.order_id.pricelist_id.id], - self.product_id.id, self.product_uom_qty or 1.0, - self.order_id.partner_id.id, { - 'uom': self.product_uom.id, - 'date': self.order_id.date_order, - 'properties': prop_dict, - })[self.order_id.pricelist_id.id] + if self.product_id: + for prop in self.env['mrp.property'].with_context(prop_ctx).browse( + [p.id for p in self.property_ids] + ): + if prop.group_id.name in prop_dict: + raise except_orm( + _('Error'), + _('Property of group %s already present') + % prop.group_id.name) + prop_dict[prop.group_id.name] = prop.value + self.price_unit = self.pool.get('product.pricelist').price_get( + self._cr, self._uid, [self.order_id.pricelist_id.id], + self.product_id.id, self.product_uom_qty or 1.0, + self.order_id.partner_id.id, { + 'uom': self.product_uom.id, + 'date': self.order_id.date_order, + 'properties': prop_dict, + })[self.order_id.pricelist_id.id] From 9d3f556b38cac46dcc5128f2d20ba3b9d3a08a0b Mon Sep 17 00:00:00 2001 From: Alex Comba Date: Tue, 30 Jun 2015 16:46:00 +0200 Subject: [PATCH 13/18] Fix wrong interoperability among onchange (v8) and on_change (v7). To do this I apply the following changes: - depends from sale_properties_dynamic_fields instead of sale_properties_easy_creation - onchange (v8) only depends by property_ids - get empty properties and get empty properties dynamic fields in on_change (v7) --- .../__openerp__.py | 2 +- .../sale_order_line.py | 30 +++++++++++++++++-- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/sale_line_price_properties_based/__openerp__.py b/sale_line_price_properties_based/__openerp__.py index 40911c15ac1..60abd739d0d 100644 --- a/sale_line_price_properties_based/__openerp__.py +++ b/sale_line_price_properties_based/__openerp__.py @@ -28,7 +28,7 @@ 'website': 'http://www.agilebg.com', 'license': 'AGPL-3', "depends": [ - 'sale_properties_easy_creation', + 'sale_properties_dynamic_fields', ], "data": [ 'product_view.xml', diff --git a/sale_line_price_properties_based/sale_order_line.py b/sale_line_price_properties_based/sale_order_line.py index b86aa65b906..492f6e58b9a 100644 --- a/sale_line_price_properties_based/sale_order_line.py +++ b/sale_line_price_properties_based/sale_order_line.py @@ -27,9 +27,7 @@ class SaleOrderLine(models.Model): _inherit = 'sale.order.line' - @api.onchange( - 'property_ids', 'product_id', 'product_uom_qty', 'product_uom' - ) + @api.onchange('property_ids') def price_property_ids_changed(self): prop_dict = {} prop_ctx = self.env.context.copy() @@ -53,3 +51,29 @@ def price_property_ids_changed(self): 'date': self.order_id.date_order, 'properties': prop_dict, })[self.order_id.pricelist_id.id] + + def product_id_change( + self, cr, uid, ids, pricelist, product_id, qty=0, + uom=False, qty_uos=0, uos=False, name='', partner_id=False, + lang=False, update_tax=True, date_order=False, packaging=False, + fiscal_position=False, flag=False, context=None + ): + res = super(SaleOrderLine, self).product_id_change( + cr, uid, ids, pricelist, product_id, qty=qty, + uom=uom, qty_uos=qty_uos, uos=uos, + name=name, partner_id=partner_id, + lang=lang, update_tax=update_tax, + date_order=date_order, packaging=packaging, + fiscal_position=fiscal_position, flag=flag, context=context) + if 'value' in res: + # get empty properties + res['value']['property_ids'] = [] + # get empty properties dynamic fields + property_group_pool = self.pool['mrp.property.group'] + group_to_empty_ids = property_group_pool.search( + cr, uid, [('draw_dynamically', '=', True)], context=context) + for group in property_group_pool.browse( + cr, uid, group_to_empty_ids, context=context + ): + res['value'][group.field_id.name] = None + return res From 082c40e6e441802f6d82effe727eed81306e55b8 Mon Sep 17 00:00:00 2001 From: Alex Comba Date: Tue, 30 Jun 2015 16:47:59 +0200 Subject: [PATCH 14/18] Add sale_order_view.xml to remove on_change on product_uom_qty --- .../__openerp__.py | 1 + .../sale_order_view.xml | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 sale_line_price_properties_based/sale_order_view.xml diff --git a/sale_line_price_properties_based/__openerp__.py b/sale_line_price_properties_based/__openerp__.py index 60abd739d0d..85e91a0b548 100644 --- a/sale_line_price_properties_based/__openerp__.py +++ b/sale_line_price_properties_based/__openerp__.py @@ -32,6 +32,7 @@ ], "data": [ 'product_view.xml', + 'sale_order_view.xml', ], "demo": [ 'product_demo.xml', diff --git a/sale_line_price_properties_based/sale_order_view.xml b/sale_line_price_properties_based/sale_order_view.xml new file mode 100644 index 00000000000..d35018e529b --- /dev/null +++ b/sale_line_price_properties_based/sale_order_view.xml @@ -0,0 +1,19 @@ + + + + + + sale.order.form + sale.order + + + + + + + + + + From 6cd7ace1f824fc591e3c1b94ad94ef3c8ad12cff Mon Sep 17 00:00:00 2001 From: Alex Comba Date: Mon, 16 Nov 2015 12:32:05 +0100 Subject: [PATCH 15/18] Calculate price by using compute_formula method --- sale_line_price_properties_based/product.py | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/sale_line_price_properties_based/product.py b/sale_line_price_properties_based/product.py index 1fb5278d2c8..bd8c8975e11 100644 --- a/sale_line_price_properties_based/product.py +++ b/sale_line_price_properties_based/product.py @@ -66,18 +66,10 @@ def _price_get(self, cr, uid, products, ptype='list_price', context=None): 'properties': context['properties'], } try: - exec product.price_formula_id.formula_text in localdict - except KeyError: + res[product.id] = product.price_formula_id.\ + compute_formula(localdict) + except ValueError as e: _logger.warning( - "KeyError for formula '%s' and prop_dict '%s'" - % (product.price_formula_id.formula_text, - context['properties'])) + "Formula evaluation error: '%s'" % e.message) continue - try: - amount = localdict['result'] - except KeyError: - raise orm.except_orm( - _('Error'), - _("Formula must contain 'result' variable")) - res[product.id] = amount return res From 37c9b25d28f485975bc706441f8486c24f9c3f54 Mon Sep 17 00:00:00 2001 From: Alex Comba Date: Mon, 16 Nov 2015 12:35:29 +0100 Subject: [PATCH 16/18] Improve README and update module version according to last OCA conventions --- sale_line_price_properties_based/README.rst | 30 ++++++++++++++----- .../__openerp__.py | 4 +-- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/sale_line_price_properties_based/README.rst b/sale_line_price_properties_based/README.rst index 64d15032e47..7b543598c51 100644 --- a/sale_line_price_properties_based/README.rst +++ b/sale_line_price_properties_based/README.rst @@ -1,25 +1,41 @@ .. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg :alt: License: AGPL-3 +================================ Sale line price properties based ================================ -This module allows to use python formaulas to compute the sale order line +This module allows to use python formulas to compute the sale order line price. You can configure the 'Price formula' on the product form using python code. Formula example: -``` -area = float(properties['Width']) * float(properties['Length']) -result = area / 2.0 -if 'Painting' in properties: - result = result + 5 -``` + +.. code:: + + area = float(properties['Width']) * float(properties['Length']) + result = area / 2.0 + if 'Painting' in properties: + result = result + 5 When changing properties on sale order line, the system will automatically compute the line price unit. +Usage +===== + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/167/8.0 + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed feedback `here `_. + Credits ======= diff --git a/sale_line_price_properties_based/__openerp__.py b/sale_line_price_properties_based/__openerp__.py index 85e91a0b548..3ee59b37577 100644 --- a/sale_line_price_properties_based/__openerp__.py +++ b/sale_line_price_properties_based/__openerp__.py @@ -22,8 +22,8 @@ ############################################################################## { 'name': "Sale line price properties based", - 'version': '1.0', - 'category': '', + 'version': '8.0.1.0.0', + 'category': 'Sales Management', 'author': "Agile Business Group,Odoo Community Association (OCA)", 'website': 'http://www.agilebg.com', 'license': 'AGPL-3', From e952c484b2ae467fba4d8206263d510185b7d91f Mon Sep 17 00:00:00 2001 From: Alex Comba Date: Thu, 16 Jun 2016 12:10:26 +0200 Subject: [PATCH 17/18] Add uos_id to localdict --- sale_line_price_properties_based/product.py | 2 +- .../sale_order_line.py | 22 ++++++++++--------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/sale_line_price_properties_based/product.py b/sale_line_price_properties_based/product.py index bd8c8975e11..a83e447cc36 100644 --- a/sale_line_price_properties_based/product.py +++ b/sale_line_price_properties_based/product.py @@ -20,7 +20,6 @@ ############################################################################## from openerp.osv import orm, fields -from openerp.tools.translate import _ import logging _logger = logging.getLogger(__name__) @@ -63,6 +62,7 @@ def _price_get(self, cr, uid, products, ptype='list_price', context=None): 'uid': uid, 'ptype': ptype, 'product_id': product.id, + 'uos_id': context['uos_id'], 'properties': context['properties'], } try: diff --git a/sale_line_price_properties_based/sale_order_line.py b/sale_line_price_properties_based/sale_order_line.py index 492f6e58b9a..3f61662043c 100644 --- a/sale_line_price_properties_based/sale_order_line.py +++ b/sale_line_price_properties_based/sale_order_line.py @@ -30,11 +30,11 @@ class SaleOrderLine(models.Model): @api.onchange('property_ids') def price_property_ids_changed(self): prop_dict = {} - prop_ctx = self.env.context.copy() - if 'lang' in prop_ctx: - del prop_ctx['lang'] + ctx = self.env.context.copy() + if 'lang' in ctx: + del ctx['lang'] if self.product_id: - for prop in self.env['mrp.property'].with_context(prop_ctx).browse( + for prop in self.env['mrp.property'].with_context(ctx).browse( [p.id for p in self.property_ids] ): if prop.group_id.name in prop_dict: @@ -43,14 +43,16 @@ def price_property_ids_changed(self): _('Property of group %s already present') % prop.group_id.name) prop_dict[prop.group_id.name] = prop.value - self.price_unit = self.pool.get('product.pricelist').price_get( - self._cr, self._uid, [self.order_id.pricelist_id.id], - self.product_id.id, self.product_uom_qty or 1.0, - self.order_id.partner_id.id, { + ctx.update({ + 'uos_id': self.product_uos.id, 'uom': self.product_uom.id, 'date': self.order_id.date_order, - 'properties': prop_dict, - })[self.order_id.pricelist_id.id] + 'properties': prop_dict}) + self.price_unit = self.env['product.pricelist'].with_context( + ctx).price_get( + self.product_id.id, + self.product_uom_qty or 1.0, + self.order_id.partner_id.id)[self.order_id.pricelist_id.id] def product_id_change( self, cr, uid, ids, pricelist, product_id, qty=0, From dacf1c0752374b9f452748e979aba11aacd38a08 Mon Sep 17 00:00:00 2001 From: Alex Comba Date: Thu, 16 Jun 2016 12:13:00 +0200 Subject: [PATCH 18/18] Trigger price_property_ids_changed also for product_uos --- sale_line_price_properties_based/sale_order_line.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sale_line_price_properties_based/sale_order_line.py b/sale_line_price_properties_based/sale_order_line.py index 3f61662043c..0396c409a10 100644 --- a/sale_line_price_properties_based/sale_order_line.py +++ b/sale_line_price_properties_based/sale_order_line.py @@ -27,7 +27,7 @@ class SaleOrderLine(models.Model): _inherit = 'sale.order.line' - @api.onchange('property_ids') + @api.onchange('property_ids', 'product_uos') def price_property_ids_changed(self): prop_dict = {} ctx = self.env.context.copy()