Skip to content

Commit

Permalink
[ADD] sale_order_recalculate_prices: Module to allow to recalculate o…
Browse files Browse the repository at this point in the history
…n demand sale order line prices

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

This module adds a button on sale orders below pricelist that recalculates the
prices of the order lines that contain a product in them.

It is launched manually as a button to get the user decide if he/she wants to
recalculate prices when pricelist is changed.

Usage
=====

Inside a sale order, you can click in any moment a button called
"(Recalculate prices)", that is next to the pricelist selection, to launch
a recalculation of all the prices of the lines, losing previous custom prices.

Known issues / Roadmap
======================

* In a sale order with lot of lines, the recalculation may slow down, because
  sale general data (amount untaxed, amount taxed...) are recalculated for
  each line.
  • Loading branch information
pedrobaeza committed Aug 28, 2015
1 parent 4a8563c commit 8046370
Show file tree
Hide file tree
Showing 11 changed files with 230 additions and 0 deletions.
63 changes: 63 additions & 0 deletions sale_order_price_recalculation/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
===================================================
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 adds a button on sale orders below pricelist that recalculates the
prices of the order lines that contain a product in them.

It is launched manually as a button to get the user decide if he/she wants to
recalculate prices when pricelist is changed.

Usage
=====

Inside a sale order, you can click in any moment a button called
"(Recalculate prices)", that is next to the pricelist selection, to launch
a recalculation of all the prices of the lines, losing previous custom prices.

.. 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

Known issues / Roadmap
======================

* In a sale order with lot of lines, the recalculation may slow down, because
sale general data (amount untaxed, amount taxed...) are recalculated for
each line.

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**>`_.


Credits
=======

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

* Firstname Lastname <email.address@example.org>
* Second Person <second.person@example.org>

Maintainer
----------

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://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.
4 changes: 4 additions & 0 deletions sale_order_price_recalculation/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from . import models
24 changes: 24 additions & 0 deletions sale_order_price_recalculation/__openerp__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*- 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>
# 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',
"author": "AvanzOSC,"
"Serv. Tecnol. Avanzados - Pedro M. Baeza,"
"Grupo Vermon,"
"Odoo Community Association (OCA)",
"category": "Sales Management",
"website": "http://www.odoomrp.com",
"data": [
"views/sale_order_view.xml",
],
"installable": True,
}
21 changes: 21 additions & 0 deletions sale_order_price_recalculation/i18n/es.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Translation of OpenERP Server.
# This file contains the translation of the following modules:
# * sale_order_price_recalculation
#
msgid ""
msgstr ""
"Project-Id-Version: OpenERP Server 7.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2014-08-05 13:14+0000\n"
"PO-Revision-Date: 2014-08-05 13:14+0000\n"
"Last-Translator: Carlos Sánchez Cifuentes <csanchez@grupovermon.com>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: \n"

#. module: sale_order_price_recalculation
#: view:sale.order:0
msgid "(Recalculate prices)"
msgstr "(Recalcular precios)"
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Translation of OpenERP Server.
# This file contains the translation of the following modules:
# * sale_order_price_recalculation
#
msgid ""
msgstr ""
"Project-Id-Version: OpenERP Server 7.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2014-08-05 13:14+0000\n"
"PO-Revision-Date: 2014-08-05 13:14+0000\n"
"Last-Translator: Carlos Sánchez Cifuentes <csanchez@grupovermon.com>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: \n"

#. module: sale_order_price_recalculation
#: view:sale.order:0
msgid "(Recalculate prices)"
msgstr ""
4 changes: 4 additions & 0 deletions sale_order_price_recalculation/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from . import sale_order
25 changes: 25 additions & 0 deletions sale_order_price_recalculation/models/sale_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# -*- 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>
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from openerp import models, api


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

@api.multi
def recalculate_prices(self):
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=False)
line.write(res['value'])
return True
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions sale_order_price_recalculation/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from . import test_sale_order_price_recalculation
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# -*- coding: utf-8 -*-
# (c) 2015 Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

import openerp.tests.common as common


class TestSaleOrderPriceRecalculation(common.TransactionCase):

def setUp(self):
super(TestSaleOrderPriceRecalculation, self).setUp()
self.sale_order_model = self.env['sale.order']
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.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,
}
self.sale_order_line = self.sale_order_line_model.create(line_vals)

def test_price_recalculation(self):
# Check current price
self.assertEqual(
self.sale_order_line.price_unit, self.product.lst_price)
# Change price
self.product.lst_price = 500
# Launch recalculation
self.sale_order.recalculate_prices()
# Check if the price has been updated
self.assertEqual(
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)
17 changes: 17 additions & 0 deletions sale_order_price_recalculation/views/sale_order_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>

<record id="sorp_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">
<field name="pricelist_id" position="after">
<button name="recalculate_prices" string="(Recalculate prices)" type="object" colspan="4" class="oe_link"/>
</field>
</field>
</record>

</data>
</openerp>

0 comments on commit 8046370

Please sign in to comment.