Merge lp:~alejandrosantana/ocb-addons/7.0-ocb-addons-fix-bug-1089229 into lp:ocb-addons

Proposed by Alejandro Santana
Status: Work in progress
Proposed branch: lp:~alejandrosantana/ocb-addons/7.0-ocb-addons-fix-bug-1089229
Merge into: lp:ocb-addons
Diff against target: 22 lines (+2/-2)
1 file modified
sale/report/sale_order.rml (+2/-2)
To merge this branch: bzr merge lp:~alejandrosantana/ocb-addons/7.0-ocb-addons-fix-bug-1089229
Reviewer Review Type Date Requested Status
Alejandro Santana (community) Needs Information
Holger Brunn (Therp) code review Needs Fixing
Review via email: mp+202233@code.launchpad.net

Commit message

[FIX] Fixes the sales order report to show correctly the unit price if UoS is definied.

Description of the change

[FIX] Fixes the sales order report to show correctly the unit price if UoS is definied.
Before, it showed the price of UoM, even if a UoS was defined, thus resulting in an invoice with wrong lines, which may be considered illegal.

To post a comment you must log in.
Revision history for this message
Holger Brunn (Therp) (hbrunn) wrote :

8: I think you should be using product_id.uos_coeff

16: don't you also have to do something with price_subtotal? If so, I'd better change _amount_line in sale.py. Otherwise, please avoid whitespace only changes.

review: Needs Fixing (code review)
Revision history for this message
Alejandro Santana (alejandrosantana) wrote :

8: OK, this can be changed, yes.
Yet, this comment on code puzzles me:
http://bazaar.launchpad.net/~openerp/openobject-addons/trunk/view/head:/sale/sale.py#L827

16: Mathematically shouldn't have to (if I am not wrong):
subtotalA = uom_qty * unit_price[for UoM] (<-- Usual calculation, isn't it?)

subtotalB = uos_qty * unit_price[for UoS] =
          = (uom_qty * uos_coeff) * (unit_price[for UoM] / uos_coeff) =
          = uom_qty * unit_price[for UoM] * (uos_coeff / uos_coeff) =
          = uom_qty * unit_price[for UoM] * 1 =
          = subtotalA
So no need for further calculations and rounding errors.

If any other calculation should be done, it should be done not at report level, but in a sales or product level, I think.
And this other comment in code seems the way to go to correct it definetely, not only in report, which was my aim:
http://bazaar.launchpad.net/~openerp/openobject-addons/trunk/view/head:/sale/sale.py#L632
(Same comments since, at least 6.1, but never implemented)

Revision history for this message
Alejandro Santana (alejandrosantana) wrote :

OK, despite the pure mathematics, I set myself as 'Needs fixing', because rounding calculations make mandatory to compute subtotal as shown in the report:
product_uos_qty (dp as "UoM") * price_unit_uos (dp as "Product Price") = subtotal (dp as "Account")
dp = decimal precision

A case of use:
Description VAT Quantity Unit Disc.(%) Price Price
Handful of peanuts ITAX S 10.000 g 20.00 0.00 200.00 €
Handful of peanuts (big) ITAX S 30.000 g 8.33 0.00 250.00 € <-- This should be: 30.000*8.33=249.90

In this simple case we see how rounding methods can easily make a 0.10€ difference.

So to correctly fix this it may be necessary to create the product.template.list_price_uos, as pointed in those code comments I told about. Would it be acceptable in OCB? (It adds a column)
Or should I create a new module that fixes this and make a MP into community branches?
Not sure, because it's a bug for me (as an incomplete feature), but it modifies the module.

review: Needs Information
Revision history for this message
Holger Brunn (Therp) (hbrunn) wrote :

I see no problem with a new column if it's necessary.

But in this case, isn't the actual problem that we want the product's unit price being calculated with taking it's uos into account? Then I think you should have a look at http://bazaar.launchpad.net/~openerp/openobject-addons/trunk/view/head:/sale/sale.py#L861 and make it fill in the correct price in the first place, then the rest should just follow from that.

Meanwhile, I set you two MPs to 'work in progress'

Unmerged revisions

9855. By Alejandro Santana

[FIX] Fixes the sales order report to show correctly the unit price if UoS is definied.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'sale/report/sale_order.rml'
2--- sale/report/sale_order.rml 2013-08-15 07:54:23 +0000
3+++ sale/report/sale_order.rml 2014-01-20 00:52:38 +0000
4@@ -275,13 +275,13 @@
5 <para style="terp_default_Right_9">[[ formatLang(line.product_uos and line.product_uos_qty or line.product_uom_qty) ]] [[ line.product_uos and line.product_uos.name or line.product_uom.name ]]</para>
6 </td>
7 <td>
8- <para style="terp_default_Right_9">[[ formatLang(line.price_unit , digits=get_digits(dp='Product Price'))]]</para>
9+ <para style="terp_default_Right_9">[[ formatLang(line.product_uos and (line.price_unit * line.product_uom_qty / line.product_uos_qty) or line.price_unit , digits=get_digits(dp='Product Price')) ]]</para>
10 </td>
11 <td>
12 <para style="terp_default_Centre_9">[[show_discount(user.id) and formatLang(line.discount, digits=get_digits(dp='Discount')) or '']]</para>
13 </td>
14 <td>
15- <para style="terp_default_Right_9">[[ formatLang(line.price_subtotal, digits=get_digits(dp='Account'), currency_obj=o.pricelist_id.currency_id) ]] </para>
16+ <para style="terp_default_Right_9">[[ formatLang(line.price_subtotal, digits=get_digits(dp='Account'), currency_obj=o.pricelist_id.currency_id) ]]</para>
17 </td>
18 </tr>
19 </blockTable>
20
21=== modified file 'sale/report/sale_order.sxw'
22Binary files sale/report/sale_order.sxw 2013-09-20 09:39:47 +0000 and sale/report/sale_order.sxw 2014-01-20 00:52:38 +0000 differ