Skip to content

Commit

Permalink
Merge dacf1c0 into 5242f90
Browse files Browse the repository at this point in the history
  • Loading branch information
tafaRU committed Jun 16, 2016
2 parents 5242f90 + dacf1c0 commit e668eda
Show file tree
Hide file tree
Showing 11 changed files with 400 additions and 0 deletions.
61 changes: 61 additions & 0 deletions sale_line_price_properties_based/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
.. 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 formulas to compute the sale order line
price.

You can configure the 'Price formula' on the product form using python code.

Formula example:

.. 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 <https://github.com/OCA/sale-workflow/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 <https://github.com/OCA/sale-workflow/issues/new?body=module:%20sale_line_price_properties_based%0Aversion:%208.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Credits
=======

Contributors
------------

* Lorenzo Battistini <lorenzo.battistini@agilebg.com>
* Alex Comba <alex.comba@agilebg.com>

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.
21 changes: 21 additions & 0 deletions sale_line_price_properties_based/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (C) 2014-15 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
44 changes: 44 additions & 0 deletions sale_line_price_properties_based/__openerp__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (C) 2014-15 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': "Sale line price properties based",
'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',
"depends": [
'sale_properties_dynamic_fields',
],
"data": [
'product_view.xml',
'sale_order_view.xml',
],
"demo": [
'product_demo.xml',
],
"test": [
'test/sale_order.yml',
],
"installable": True
}
63 changes: 63 additions & 0 deletions sale_line_price_properties_based/i18n/it.po
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}"

75 changes: 75 additions & 0 deletions sale_line_price_properties_based/product.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (C) 2014-15 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
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"),
}


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(ProductTemplate, self)._price_get(
cr, uid, products, ptype=ptype, context=context)
if 'properties' in context:
for product in products:
res = super(ProductTemplate, self)._price_get(
cr, uid, products, ptype=ptype, context=context)
if product.price_formula_id:
localdict = {
'self': self,
'cr': cr,
'uid': uid,
'ptype': ptype,
'product_id': product.id,
'uos_id': context['uos_id'],
'properties': context['properties'],
}
try:
res[product.id] = product.price_formula_id.\
compute_formula(localdict)
except ValueError as e:
_logger.warning(
"Formula evaluation error: '%s'" % e.message)
continue
return res
8 changes: 8 additions & 0 deletions sale_line_price_properties_based/product_demo.xml
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>
15 changes: 15 additions & 0 deletions sale_line_price_properties_based/product_view.xml
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="lst_price" position="after">
<field name="price_formula_id"></field>
</field>
</field>
</record>
</data>
</openerp>
81 changes: 81 additions & 0 deletions sale_line_price_properties_based/sale_order_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (C) 2014-15 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 import models, api
from openerp.tools.translate import _
from openerp.exceptions import except_orm


class SaleOrderLine(models.Model):
_inherit = 'sale.order.line'

@api.onchange('property_ids', 'product_uos')
def price_property_ids_changed(self):
prop_dict = {}
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(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
ctx.update({
'uos_id': self.product_uos.id,
'uom': self.product_uom.id,
'date': self.order_id.date_order,
'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,
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
19 changes: 19 additions & 0 deletions sale_line_price_properties_based/sale_order_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>

<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="//page[@string='Order Lines']/field[@name='order_line']/form[@string='Sales Order Lines']/group/group/div/field[@name='product_uom_qty']" position="replace">
<field
context="{'partner_id':parent.partner_id, 'quantity':product_uom_qty, 'pricelist':parent.pricelist_id, 'uom':product_uom}"
name="product_uom_qty" class="oe_inline"/>
</xpath>
</field>
</record>

</data>
</openerp>
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e668eda

Please sign in to comment.