Skip to content

Commit

Permalink
[9.0] [MIG] sale_order_price_recalculation module
Browse files Browse the repository at this point in the history
  • Loading branch information
cubells committed Dec 16, 2016
1 parent 1b5e00a commit 66b6118
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 59 deletions.
19 changes: 10 additions & 9 deletions sale_order_price_recalculation/README.rst
@@ -1,10 +1,11 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3

===================================================
Recalculation of sales order lines prices on demand
===================================================

.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:alt: License: AGPL-3

This module add 2 buttons on sale orders (below sale order lines) that:

* recalculates the prices of the order lines that contain a product in them.
Expand All @@ -28,7 +29,7 @@ loosing custom descriptions.

.. 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
:target: https://runbot.odoo-community.org/runbot/167/9.0

Known issues / Roadmap
======================
Expand All @@ -40,11 +41,10 @@ Known issues / Roadmap
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_order_price_recalculation%0Aversion:%208.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

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.

Credits
=======
Expand All @@ -56,6 +56,7 @@ Contributors
* Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
* Oihane Crucelaegui <oihanecrucelaegi@avanzosc.es>
* Pierre Verkest <pverkest@anybox.fr>
* Vicent Cubells <vicent.cubells@tecnativa.com>

Maintainer
----------
Expand Down
4 changes: 4 additions & 0 deletions sale_order_price_recalculation/__init__.py
@@ -1,4 +1,8 @@
# -*- coding: utf-8 -*-
# Copyright 2014 Carlos Sánchez Cifuentes <csanchez@grupovermon.com>
# Copyright 2015 Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
# Copyright 2015 Oihane Crucelaegui <oihanecrucelaegi@avanzosc.es>
# Copyright 2016 Vicent Cubells <vicent.cubells@tecnativa.com>
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from . import models
25 changes: 14 additions & 11 deletions sale_order_price_recalculation/__openerp__.py
@@ -1,24 +1,27 @@
# -*- coding: utf-8 -*-
# (c) 2014 Carlos Sánchez Cifuentes <csanchez@grupovermon.com>
# (c) 2015 Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
# (c) 2015 Oihane Crucelaegui <oihanecrucelaegi@avanzosc.es>
# Copyright 2014 Carlos Sánchez Cifuentes <csanchez@grupovermon.com>
# Copyright 2015 Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
# Copyright 2015 Oihane Crucelaegui <oihanecrucelaegi@avanzosc.es>
# Copyright 2016 Vicent Cubells <vicent.cubells@tecnativa.com>
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

{
"name": "Price recalculation in sales orders",
"version": "8.0.1.0.0",
"depends": [
"sale",
],
'license': 'AGPL-3',
"version": "9.0.1.0.0",
"category": "Sales Management",
"website": "http://github.com/OCA/sale-workflow",
"author": "AvanzOSC,"
"Serv. Tecnol. Avanzados - Pedro M. Baeza,"
"Grupo Vermon,"
"Tecnativa,"
"Odoo Community Association (OCA)",
"category": "Sales Management",
"website": "http://github.com/OCA/sale-workflow",
"license": "AGPL-3",
"application": False,
"installable": True,
"depends": [
"sale",
],
"data": [
"views/sale_order_view.xml",
],
'installable': False,
}
4 changes: 4 additions & 0 deletions sale_order_price_recalculation/models/__init__.py
@@ -1,4 +1,8 @@
# -*- coding: utf-8 -*-
# Copyright 2014 Carlos Sánchez Cifuentes <csanchez@grupovermon.com>
# Copyright 2015 Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
# Copyright 2015 Oihane Crucelaegui <oihanecrucelaegi@avanzosc.es>
# Copyright 2016 Vicent Cubells <vicent.cubells@tecnativa.com>
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from . import sale_order
37 changes: 11 additions & 26 deletions sale_order_price_recalculation/models/sale_order.py
@@ -1,7 +1,8 @@
# -*- coding: utf-8 -*-
# (c) 2014 Carlos Sánchez Cifuentes <csanchez@grupovermon.com>
# (c) 2015 Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
# (c) 2015 Oihane Crucelaegui <oihanecrucelaegi@avanzosc.es>
# Copyright 2014 Carlos Sánchez Cifuentes <csanchez@grupovermon.com>
# Copyright 2015 Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
# Copyright 2015 Oihane Crucelaegui <oihanecrucelaegi@avanzosc.es>
# Copyright 2016 Vicent Cubells <vicent.cubells@tecnativa.com>
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from openerp import models, api
Expand All @@ -12,31 +13,15 @@ class SaleOrder(models.Model):

@api.multi
def recalculate_prices(self):
return self.reset_lines(price=True)
for line in self.mapped('order_line'):
line.product_uom_change()
return True

@api.multi
def recalculate_names(self):
return self.reset_lines(price=False)

@api.multi
def reset_lines(self, price=False):
"""
Reset lines according informations on products and price list
:param price: boolean to indicate if we are resetting price or
descriptions
"""
for line in self.mapped('order_line'):
order = line.order_id
res = line.product_id_change(
order.pricelist_id.id, line.product_id.id,
qty=line.product_uom_qty, uom=line.product_uom.id,
qty_uos=line.product_uos_qty, uos=line.product_uos.id,
name=line.name, partner_id=order.partner_id.id, lang=False,
update_tax=True, date_order=order.date_order, packaging=False,
fiscal_position=order.fiscal_position.id, flag=price)
if price:
line.write(res['value'])
else:
if 'name' in res['value']:
line.write({'name': res['value']['name']})
name = line.product_id.name_get()[0][1]
if line.product_id.description_sale:
name += '\n' + line.product_id.description_sale
line.name = name
return True
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
# (c) 2015 Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
# Copyright 2015 Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
# Copyright 2016 Vicent Cubells <vicent.cubells@tecnativa.com>
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

import openerp.tests.common as common
Expand All @@ -13,19 +14,18 @@ def setUp(self):
self.sale_order_line_model = self.env['sale.order.line']
self.partner = self.env.ref('base.res_partner_3')
self.product = self.env.ref('product.product_product_4')
order_vals = self.sale_order_model.onchange_partner_id(
self.partner.id)['value']
order_vals['partner_id'] = self.partner.id
self.sale_order = self.sale_order_model.create(order_vals)
self.sale_order = self.sale_order_model.create({
'partner_id': self.partner.id,
'partner_invoice_id': self.partner.id,
'partner_shipping_id': self.partner.id,
'pricelist_id': self.env.ref('product.list0').id,
})
self.product.uos_id = self.env.ref('product.product_uom_kgm')
self.product.uos_coeff = 12.0
line_vals = {
'product_id': self.product.id,
'name': self.product.name,
'product_uom_qty': 1.0,
'product_uom': self.product.uom_id.id,
'product_uos_qty': 12.0,
'product_uos': self.product.uos_id.id,
'price_unit': self.product.lst_price,
'order_id': self.sale_order.id,
}
Expand All @@ -45,7 +45,6 @@ def test_price_recalculation(self):
self.sale_order_line.price_unit, self.product.lst_price)
# Check if quantities have changed
self.assertEqual(self.sale_order_line.product_uom_qty, 1.0)
self.assertEqual(self.sale_order_line.product_uos_qty, 12.0)
# Check the description still unchanged
self.assertEqual(self.sale_order_line.name, u"My product description")

Expand Down
6 changes: 2 additions & 4 deletions sale_order_price_recalculation/views/sale_order_view.xml
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<odoo>

<record id="sorp_view_order_form" model="ir.ui.view">
<field name="name">sale.order.form</field>
Expand All @@ -20,5 +19,4 @@
</field>
</record>

</data>
</openerp>
</odoo>

0 comments on commit 66b6118

Please sign in to comment.