Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
37 changed files
with
1,676 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# -*- coding: utf-8 -*- | ||
############################################################################## | ||
# | ||
# Copyright (C) 2014 Agile Business Group sagl (<http://www.agilebg.com>) | ||
# | ||
# 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 product | ||
from . import sale_order_line |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# -*- coding: utf-8 -*- | ||
############################################################################## | ||
# | ||
# Copyright (C) 2014 Agile Business Group sagl | ||
# (<http://www.agilebg.com>) | ||
# @author Lorenzo Battistini <lorenzo.battistini@agilebg.com> | ||
# @author Alex Comba <alex.comba@agilebg.com> | ||
# | ||
# 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': "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 <lorenzo.battistini@agilebg.com> | ||
- Alex Comba <alex.comba@agilebg.com> | ||
""", | ||
'author': 'Agile Business Group', | ||
'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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# -*- coding: utf-8 -*- | ||
############################################################################## | ||
# | ||
# Copyright (C) 2014 Agile Business Group sagl | ||
# (<http://www.agilebg.com>) | ||
# | ||
# 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 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<openerp> | ||
<data> | ||
<record model="product.product" id="product.product_product_7"> | ||
<field name="price_formula_id" ref="sale_properties_easy_creation.area_formula"></field> | ||
</record> | ||
</data> | ||
</openerp> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<openerp> | ||
<data> | ||
<record id="product_normal_form_formula_view" model="ir.ui.view"> | ||
<field name="name">product.normal.formula.form</field> | ||
<field name="model">product.product</field> | ||
<field name="inherit_id" ref="product.product_normal_form_view"></field> | ||
<field name="arch" type="xml"> | ||
<field name="list_price" position="after"> | ||
<field name="price_formula_id"></field> | ||
</field> | ||
</field> | ||
</record> | ||
</data> | ||
</openerp> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# -*- coding: utf-8 -*- | ||
############################################################################## | ||
# | ||
# Copyright (C) 2014 Agile Business Group sagl | ||
# (<http://www.agilebg.com>) | ||
# | ||
# 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 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<openerp> | ||
<data> | ||
|
||
<record id="view_order_form_inherit" model="ir.ui.view"> | ||
<field name="name">sale.order.form</field> | ||
<field name="model">sale.order</field> | ||
<field name="inherit_id" ref="sale_stock.view_order_form_inherit"/> | ||
<field name="arch" type="xml"> | ||
<xpath expr="//field[@name='order_line']/form[@string='Sales Order Lines']/group/group/field[@name='product_id']" position="attributes"> | ||
<attribute name="context_properties">{'property_ids': property_ids}</attribute> | ||
</xpath> | ||
<xpath expr="//field[@name='order_line']/form[@string='Sales Order Lines']/group/group/div/field[@name='product_uom_qty']" position="attributes"> | ||
<attribute name="context_properties">{'property_ids': property_ids}</attribute> | ||
</xpath> | ||
<field name="property_ids" position="attributes"> | ||
<attribute name="on_change">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)</attribute> | ||
<attribute name="context_properties">{'property_ids': property_ids}</attribute> | ||
</field> | ||
</field> | ||
</record> | ||
|
||
<record id="view_order_form" model="ir.ui.view"> | ||
<field name="name">sale.order.form</field> | ||
<field name="model">sale.order</field> | ||
<field name="inherit_id" ref="sale.view_order_form"/> | ||
<field name="arch" type="xml"> | ||
<xpath expr="//field[@name='order_line']/form/group/group/div/field[@name='product_uom']" position="attributes"> | ||
<attribute name="context_properties">{'property_ids': property_ids}</attribute> | ||
</xpath> | ||
</field> | ||
</record> | ||
|
||
</data> | ||
</openerp> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'] |
Oops, something went wrong.