Merge lp:~therp-nl/openobject-addons/lp1107889_supplier_invoice_rounding into lp:openobject-addons

Proposed by Ronald Portier (Therp)
Status: Needs review
Proposed branch: lp:~therp-nl/openobject-addons/lp1107889_supplier_invoice_rounding
Merge into: lp:openobject-addons
Diff against target: 210 lines (+76/-12)
4 files modified
account/__init__.py (+1/-1)
account/account.py (+8/-3)
account/account_invoice.py (+63/-8)
account/account_invoice_view.xml (+4/-0)
To merge this branch: bzr merge lp:~therp-nl/openobject-addons/lp1107889_supplier_invoice_rounding
Reviewer Review Type Date Requested Status
OpenERP Core Team Pending
Review via email: mp+147374@code.launchpad.net

This proposal supersedes a proposal from 2013-01-29.

Description of the change

Fixes lp1107889.

Also stores tax rounding method used with the invoice, so guaranteeing full accountability of the amounts computed, even for sales invoices. Because the company default rounding method might change over time..

To post a comment you must log in.

Unmerged revisions

8523. By Ronald Portier (Therp)

[FIX] Change order of files in __init__.py to prevent problems on
      update of databases that do not already have the field
      tax_calculation_rounding_method in res_company.

8522. By Ronald Portier (Therp)

[FIX] lp1107889 Add needed choice of rounding method to supplier invoice.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'account/__init__.py'
2--- account/__init__.py 2012-11-29 22:26:45 +0000
3+++ account/__init__.py 2013-02-08 14:32:28 +0000
4@@ -23,6 +23,7 @@
5 import account
6 import installer
7 import project
8+import company
9 import account_invoice
10 import account_bank_statement
11 import account_bank
12@@ -34,7 +35,6 @@
13 import report
14 import product
15 import ir_sequence
16-import company
17 import res_currency
18 import edi
19 import res_config
20
21=== modified file 'account/account.py'
22--- account/account.py 2013-01-29 13:34:27 +0000
23+++ account/account.py 2013-02-08 14:32:28 +0000
24@@ -2066,7 +2066,9 @@
25 cur_price_unit+=amount2
26 return res
27
28- def compute_all(self, cr, uid, taxes, price_unit, quantity, product=None, partner=None, force_excluded=False):
29+ def compute_all(
30+ self, cr, uid, taxes, price_unit, quantity, product=None,
31+ partner=None, force_excluded=False, context=None):
32 """
33 :param force_excluded: boolean used to say that we don't want to consider the value of field price_include of
34 tax. It's used in encoding by line where you don't matter if you encoded a tax with that boolean to True or
35@@ -2077,7 +2079,6 @@
36 'taxes': [] # List of taxes, see compute for the format
37 }
38 """
39-
40 # By default, for each tax, tax amount will first be computed
41 # and rounded at the 'Account' decimal precision for each
42 # PO/SO/invoice line and then these rounded amounts will be
43@@ -2089,7 +2090,11 @@
44 # rounding after the sum of the tax amounts of each line
45 precision = self.pool.get('decimal.precision').precision_get(cr, uid, 'Account')
46 tax_compute_precision = precision
47- if taxes and taxes[0].company_id.tax_calculation_rounding_method == 'round_globally':
48+ rounding_method = (
49+ (context and context.get('tax_calculation_rounding_method'))
50+ or (taxes and taxes[0].company_id.tax_calculation_rounding_method)
51+ or 'round_per_line')
52+ if rounding_method == 'round_globally':
53 tax_compute_precision += 5
54 totalin = totalex = float_round(price_unit * quantity, precision)
55 tin = []
56
57=== modified file 'account/account_invoice.py'
58--- account/account_invoice.py 2013-01-05 23:29:19 +0000
59+++ account/account_invoice.py 2013-02-08 14:32:28 +0000
60@@ -286,8 +286,40 @@
61 'payment_ids': fields.function(_compute_lines, relation='account.move.line', type="many2many", string='Payments'),
62 'move_name': fields.char('Journal Entry', size=64, readonly=True, states={'draft':[('readonly',False)]}),
63 'user_id': fields.many2one('res.users', 'Salesperson', readonly=True, track_visibility='onchange', states={'draft':[('readonly',False)]}),
64- 'fiscal_position': fields.many2one('account.fiscal.position', 'Fiscal Position', readonly=True, states={'draft':[('readonly',False)]})
65- }
66+ 'fiscal_position': fields.many2one('account.fiscal.position',
67+ 'Fiscal Position', readonly=True,
68+ states={'draft':[('readonly',False)]}),
69+ 'tax_calculation_rounding_method': fields.selection([
70+ ('round_per_line', 'Round per line'),
71+ ('round_globally', 'Round globally'),
72+ ], 'Tax calculation rounding method',
73+ help='''If you select 'Round per line' : for each tax, the tax
74+amount will first be computed and rounded for each PO/SO/invoice line and then
75+these rounded amounts will be summed, leading to the total amount for that tax.
76+If you select 'Round globally': for each tax, the tax amount will be computed
77+for each PO/SO/invoice line, then these amounts will be summed and eventually
78+this total tax amount will be rounded. If you sell with tax included, you
79+should choose 'Round per line' because you certainly want the sum of your
80+tax-included line subtotals to be equal to the total amount with taxes.'''),
81+ }
82+
83+ def _get_company_rounding(self, cr, uid, company_id, context=None):
84+ res = 'round_per_line'
85+ if company_id:
86+ company_model = self.pool.get('res.company')
87+ company_obj = company_model.browse(
88+ cr, uid, company_id, context=context)
89+ if company_obj and company_obj['tax_calculation_rounding_method']:
90+ res = company_obj['tax_calculation_rounding_method']
91+ return res
92+
93+ def _get_default_rounding_method(self, cr, uid, context=None):
94+ # default rounding depends on company. We start with default company
95+ company_model = self.pool.get('res.company')
96+ company_id = company_model._company_default_get(
97+ cr, uid, 'account.invoice', context=context)
98+ return self._get_company_rounding(cr, uid, company_id, context)
99+
100 _defaults = {
101 'type': _get_type,
102 'state': 'draft',
103@@ -299,6 +331,7 @@
104 'internal_number': False,
105 'user_id': lambda s, cr, u, c: u,
106 'sent': False,
107+ 'tax_calculation_rounding_method': _get_default_rounding_method,
108 }
109 _sql_constraints = [
110 ('number_uniq', 'unique(number, company_id, journal_id, type)', 'Invoice Number must be unique per Company!'),
111@@ -566,6 +599,9 @@
112 obj_journal = self.pool.get('account.journal')
113 account_obj = self.pool.get('account.account')
114 inv_line_obj = self.pool.get('account.invoice.line')
115+ if company_id:
116+ val['tax_calculation_rounding_method'] = (
117+ self._get_company_rounding(cr, uid, company_id))
118 if company_id and part_id and type:
119 acc_id = False
120 partner_obj = self.pool.get('res.partner').browse(cr,uid,part_id)
121@@ -1342,9 +1378,16 @@
122 res = {}
123 tax_obj = self.pool.get('account.tax')
124 cur_obj = self.pool.get('res.currency')
125+ local_context = {}
126 for line in self.browse(cr, uid, ids):
127- price = line.price_unit * (1-(line.discount or 0.0)/100.0)
128- 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)
129+ local_context['tax_calculation_rounding_method'] = (
130+ line.invoice_id.tax_calculation_rounding_method)
131+ price = line.price_unit * (1 - (line.discount or 0.0) / 100.0)
132+ taxes = tax_obj.compute_all(
133+ cr, uid, line.invoice_line_tax_id, price, line.quantity,
134+ product=line.product_id,
135+ partner=line.invoice_id.partner_id,
136+ context=local_context)
137 res[line.id] = taxes['total']
138 if line.invoice_id:
139 cur = line.invoice_id.currency_id
140@@ -1521,16 +1564,19 @@
141 inv = self.pool.get('account.invoice').browse(cr, uid, invoice_id, context=context)
142 company_currency = inv.company_id.currency_id.id
143
144+ local_context = {}
145 for line in inv.invoice_line:
146+ local_context['tax_calculation_rounding_method'] = (
147+ line.invoice_id.tax_calculation_rounding_method)
148 mres = self.move_line_get_item(cr, uid, line, context)
149 if not mres:
150 continue
151 res.append(mres)
152 tax_code_found= False
153 for tax in tax_obj.compute_all(cr, uid, line.invoice_line_tax_id,
154- (line.price_unit * (1.0 - (line['discount'] or 0.0) / 100.0)),
155- line.quantity, line.product_id,
156- inv.partner_id)['taxes']:
157+ (line.price_unit * (1.0 - (line['discount'] or 0.0) / 100.0)),
158+ line.quantity, line.product_id, inv.partner_id,
159+ context=local_context)['taxes']:
160
161 if inv.type in ('out_invoice', 'in_invoice'):
162 tax_code_id = tax['base_code_id']
163@@ -1659,6 +1705,7 @@
164 'base_amount': 0.0,
165 'tax_amount': 0.0,
166 }
167+
168 def compute(self, cr, uid, invoice_id, context=None):
169 tax_grouped = {}
170 tax_obj = self.pool.get('account.tax')
171@@ -1667,8 +1714,16 @@
172 cur = inv.currency_id
173 company_currency = inv.company_id.currency_id.id
174
175+ local_context = {}
176 for line in inv.invoice_line:
177- 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']:
178+ local_context['tax_calculation_rounding_method'] = (
179+ line.invoice_id.tax_calculation_rounding_method)
180+ for tax in tax_obj.compute_all(
181+ cr, uid, line.invoice_line_tax_id,
182+ (line.price_unit * (1 - (line.discount or 0.0) / 100.0)),
183+ line.quantity, line.product_id, inv.partner_id,
184+ context=local_context)['taxes']:
185+
186 val={}
187 val['invoice_id'] = inv.id
188 val['name'] = tax['name']
189
190=== modified file 'account/account_invoice_view.xml'
191--- account/account_invoice_view.xml 2013-02-05 13:38:55 +0000
192+++ account/account_invoice_view.xml 2013-02-08 14:32:28 +0000
193@@ -180,6 +180,7 @@
194 <group>
195 <field name="date_invoice"/>
196 <field name="date_due"/>
197+ <field name="tax_calculation_rounding_method"/>
198 <field domain="[('company_id', '=', company_id), ('type', '=', 'payable')]"
199 name="account_id" groups="account.group_account_user"/>
200 <field name="journal_id" groups="account.group_account_user"
201@@ -343,6 +344,9 @@
202 </group>
203 </group>
204 <field name="sent" invisible="1"/>
205+ <field
206+ name="tax_calculation_rounding_method"
207+ invisible="1" />
208 <notebook colspan="4">
209 <page string="Invoice Lines">
210 <field name="invoice_line" nolabel="1" widget="one2many_list" context="{'type': type}">

Subscribers

People subscribed via source and target branches

to all changes: