Merge lp:~akretion-team/openobject-addons/trunk_addons_ref_unit_price into lp:openobject-addons

Proposed by Benoit Guillot - http://www.akretion.com
Status: Needs review
Proposed branch: lp:~akretion-team/openobject-addons/trunk_addons_ref_unit_price
Merge into: lp:openobject-addons
Diff against target: 78 lines (+16/-5)
2 files modified
account/account_invoice.py (+9/-3)
sale/sale.py (+7/-2)
To merge this branch: bzr merge lp:~akretion-team/openobject-addons/trunk_addons_ref_unit_price
Reviewer Review Type Date Requested Status
Victor Tabuenca (OpenERP) (community) Needs Fixing
Review via email: mp+138190@code.launchpad.net

Description of the change

Hello,

This merge adds a method : _unit_price_with_discount() in the class sale_order_line and account_invoice_line.
This method calculate the unit price with the discount

It allows us to override this method in order to customize the unit price.
For instance to round the unit price with discount in order to fix rounding issues.

Best regards,

To post a comment you must log in.
Revision history for this message
Victor Tabuenca (OpenERP) (vta-openerp) wrote :

I'm not able to see whatever you've done. Please fix it.

review: Needs Fixing
Revision history for this message
Benoit Guillot - http://www.akretion.com (benoit-guillot-z) wrote :

It took time to upload the branch, it is done now.

Revision history for this message
Victor Tabuenca (OpenERP) (vta-openerp) wrote :

Ok, thanks.

Revision history for this message
Joël Grand-Guillaume @ camptocamp (jgrandguillaume-c2c) wrote :

Any news on this one, I've got another merge that is waiting on this : https://code.launchpad.net/~akretion-team/sale-wkfl/sale-wkfl_discount_per_unit/+merge/138192

Thanks for the update !

Revision history for this message
Joël Grand-Guillaume @ camptocamp (jgrandguillaume-c2c) wrote :

Still no news ?

Unmerged revisions

8213. By Benoit Guillot - http://www.akretion.com

[REF] add a method to calculate the unti price with the discount in sale order and account invoice.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'account/account_invoice.py'
2--- account/account_invoice.py 2012-12-05 11:28:53 +0000
3+++ account/account_invoice.py 2012-12-05 15:12:37 +0000
4@@ -1354,7 +1354,7 @@
5 tax_obj = self.pool.get('account.tax')
6 cur_obj = self.pool.get('res.currency')
7 for line in self.browse(cr, uid, ids):
8- price = line.price_unit * (1-(line.discount or 0.0)/100.0)
9+ price = self._unit_price_with_discount(cr, uid, line, context=unknow_dict)
10 taxes = tax_obj.compute_all(cr, uid, line.invoice_line_tax_id, price, line.quantity, product=line.product_id, partner=line.invoice_id.partner_id)
11 res[line.id] = taxes['total']
12 if line.invoice_id:
13@@ -1414,6 +1414,10 @@
14 'price_unit': _price_unit_default,
15 'account_id': _default_account_id,
16 }
17+
18+ def _unit_price_with_discount(self, cr, uid, line, context=None):
19+ price = line.price_unit * (1 - (line.discount or 0.0) / 100.0)
20+ return price
21
22 def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
23 if context is None:
24@@ -1539,8 +1543,9 @@
25 continue
26 res.append(mres)
27 tax_code_found= False
28+ price = self._unit_price_with_discount(cr, uid, line, context=context)
29 for tax in tax_obj.compute_all(cr, uid, line.invoice_line_tax_id,
30- (line.price_unit * (1.0 - (line['discount'] or 0.0) / 100.0)),
31+ price,
32 line.quantity, line.product_id,
33 inv.partner_id)['taxes']:
34
35@@ -1680,7 +1685,8 @@
36 company_currency = inv.company_id.currency_id.id
37
38 for line in inv.invoice_line:
39- for tax in tax_obj.compute_all(cr, uid, line.invoice_line_tax_id, (line.price_unit* (1-(line.discount or 0.0)/100.0)), line.quantity, line.product_id, inv.partner_id)['taxes']:
40+ price = self.pool.get('account.invoice.line')._unit_price_with_discount(cr, uid, line, context=context)
41+ for tax in tax_obj.compute_all(cr, uid, line.invoice_line_tax_id, price, line.quantity, line.product_id, inv.partner_id)['taxes']:
42 val={}
43 val['invoice_id'] = inv.id
44 val['name'] = tax['name']
45
46=== modified file 'sale/sale.py'
47--- sale/sale.py 2012-12-04 14:46:49 +0000
48+++ sale/sale.py 2012-12-05 15:12:37 +0000
49@@ -73,7 +73,8 @@
50
51 def _amount_line_tax(self, cr, uid, line, context=None):
52 val = 0.0
53- for c in self.pool.get('account.tax').compute_all(cr, uid, line.tax_id, line.price_unit * (1-(line.discount or 0.0)/100.0), line.product_uom_qty, line.product_id, line.order_id.partner_id)['taxes']:
54+ price = self.pool.get('sale.order.line')._unit_price_with_discount(cr, uid, line, context=context)
55+ for c in self.pool.get('account.tax').compute_all(cr, uid, line.tax_id, price, line.product_uom_qty, line.product_id, line.order_id.partner_id)['taxes']:
56 val += c.get('amount', 0.0)
57 return val
58
59@@ -682,7 +683,7 @@
60 if context is None:
61 context = {}
62 for line in self.browse(cr, uid, ids, context=context):
63- price = line.price_unit * (1 - (line.discount or 0.0) / 100.0)
64+ price = self._unit_price_with_discount(cr, uid, line, context=context)
65 taxes = tax_obj.compute_all(cr, uid, line.tax_id, price, line.product_uom_qty, line.product_id, line.order_id.partner_id)
66 cur = line.order_id.pricelist_id.currency_id
67 res[line.id] = cur_obj.round(cr, uid, cur, taxes['total'])
68@@ -753,6 +754,10 @@
69 'type': 'make_to_stock',
70 'price_unit': 0.0,
71 }
72+
73+ def _unit_price_with_discount(self, cr, uid, line, context=None):
74+ price = line.price_unit * (1 - (line.discount or 0.0) / 100.0)
75+ return price
76
77 def _get_line_qty(self, cr, uid, line, context=None):
78 if (line.order_id.invoice_quantity=='order'):

Subscribers

People subscribed via source and target branches

to all changes: