Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADD] sale_order_price_recalculation: Module to allow to recalculate on demand sale order line prices #54

Merged
merged 1 commit into from
Sep 1, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions sale_order_price_recalculation/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
===================================================
Recalculation of sales order lines prices on demand
===================================================

Copy link
Sponsor Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add the licence badge. IMO, we should move the licence badge under the module title otherwise it's not displayed on the app store since when the file is converted to html the badge is outside a section element. I'll propose a PR on the template in maintainer-tools to move the badge under the module title.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added it, although it looks weird...

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pedrobaeza Usually we put the license image on top of the file you just need to swap it with the title

https://github.com/pedrobaeza/sale-workflow/blob/8.0-sale_order_recalculate_prices/sale_order_price_recalculation/README.rst

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is because the previous comment of @lmignon. See https://github.com/OCA/sale-workflow/pull/54/files#r38179222

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed it looks weird ...

We could try with a

|Licence|

.. |Licence| image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
   :alt: License: AGPL-3
   :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope it doesn't work :-/

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have we already tried to put it after the title? Is there an example we can see on apps?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I'm afraid not

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/OCA/stock-logistics-transport/blob/8.0/stock_shipment_management/README.rst
https://www.odoo.com/apps/modules/8.0/stock_shipment_management/
I added a logo after title and one before title using http instead of https

And in odoo it is well displayed. Don't they use the same lib in odoo and on apps?

I sent a message to apps@odoo.com the issue is clearly on their side

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can see that the page is up to date on apps.odoo.com as there are empty balises for the logo
I guess they don't support svg files ...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, let's move then with this module in any position you want, and wait for the answer and decide on maintainer-tools about the other topic, OK?

Copy link
Sponsor Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


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

* Carlos Sánchez Cifuentes <csanchez@grupovermon.com>
* Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
* Oihane Crucelaegui <oihanecrucelaegi@avanzosc.es>

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": [
Copy link
Sponsor Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the licence miss

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(fixed below)

"sale",
],
'license': 'AGPL-3',
"author": "AvanzOSC,"
"Serv. Tecnol. Avanzados - Pedro M. Baeza,"
"Grupo Vermon,"
"Odoo Community Association (OCA)",
"category": "Sales Management",
"website": "http://github.com/OCA/sale-workflow",
"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,
Copy link
Sponsor Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, you should also provide the packaging from the line even if it's not used by default but if the method is redefined by others modules, the params is part of the api..

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But this will add an unneeded dependency to sale_stock module. Are you sure this is needed?

Copy link
Sponsor Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pedrobaeza sorry for the noise. You are right. The filed packaging is not defined on the sale.order.line in this module. Strange to see a parameter for a field defined in an optional module...

fiscal_position=order.fiscal_position.id, flag=False)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm concerned about setting uom and uos to False here, because I think product_id_change will reset these to the default product's uom and uos (not sure, and that method is complex enough for the outcome to be uncertain).

I'd feel much reassured if you could update the automated test to have a non default unit for on the sale.order.line and check that the quantity + unit are not affected by recalculate_prices.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is exactly what Odoo does in its onchange: https://github.com/odoo/odoo/blob/8.0/addons/sale/sale_view.xml#L128

That's why I have copied as is. I don't think it's a problem, because that arguments are for conversions, but I'm passing qty and qty_uos

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just tested this on the runbot and I confirm it does not work

Steps to reproduce:

  1. activate "manage UoM" in sales settings
  2. create a sale order
  3. add a sale order line for 2 dozens TONER
  4. click "recalculate prices"

Expected result:

  • nothing changes

Actual result:

  • the sale order is updated to a sale of 2 Unites TONER

==> needs fixing.

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>