Merge lp:~camptocamp/openerp-swiss-localization/7.0-add-l10n_ch_add_invoice_rounding into lp:~camptocamp/openerp-swiss-localization/7.0

Proposed by Yannick Vaucher @ Camptocamp
Status: Superseded
Proposed branch: lp:~camptocamp/openerp-swiss-localization/7.0-add-l10n_ch_add_invoice_rounding
Merge into: lp:~camptocamp/openerp-swiss-localization/7.0
Diff against target: 452 lines (+419/-0)
6 files modified
l10n_ch_invoice_rounding/__init__.py (+23/-0)
l10n_ch_invoice_rounding/__openerp__.py (+48/-0)
l10n_ch_invoice_rounding/account.py (+237/-0)
l10n_ch_invoice_rounding/company.py (+36/-0)
l10n_ch_invoice_rounding/res_config.py (+49/-0)
l10n_ch_invoice_rounding/res_config_view.xml (+26/-0)
To merge this branch: bzr merge lp:~camptocamp/openerp-swiss-localization/7.0-add-l10n_ch_add_invoice_rounding
Reviewer Review Type Date Requested Status
Yannick Vaucher @ Camptocamp Needs Information
Nicolas Bessi - Camptocamp (community) Needs Information
Review via email: mp+171359@code.launchpad.net

This proposal has been superseded by a proposal from 2014-01-14.

To post a comment you must log in.
179. By Yannick Vaucher @ Camptocamp

[FIX] l10n_ch_invoice_rounding - comparison to avoid write of added rounding invoice line

180. By Yannick Vaucher @ Camptocamp

[FIX] l10n_ch_invoice_rounding - add missing call to onchange on invoice tax line amount

181. By Yannick Vaucher @ Camptocamp

[FIX] l10n_ch_invoice_rounding - using multiple taxes the adjustment need to be made only once all taxes are computed

182. By Vincent Renaville@camptocamp

[IMP] l10n_ch_invoice_rounding - do not apply rounding for supplier invoices

183. By Vincent Renaville@camptocamp

[ADD] l10n_ch_invoice_rounding - documentation

Revision history for this message
Nicolas Bessi - Camptocamp (nbessi-c2c-deactivatedaccount) wrote :

Hello,

Should we put this addons in account-financial-tools + a configuration addons in l10n_ch

review: Needs Information
Revision history for this message
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote :

It would make sense if in other countries you also have a unit different than a base of 10. Likes we do in Switzerland as our lowest unit is 5 cts.

Otherwise, if in other countries you are allowed / want to give a rounded tax amount to round your total on an other base that 10.

I couldn't found such information about this need for other countries.

review: Needs Information
Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote :

> It would make sense if in other countries you also have a unit different than
> a base of 10. Likes we do in Switzerland as our lowest unit is 5 cts.
>
> Otherwise, if in other countries you are allowed / want to give a rounded tax
> amount to round your total on an other base that 10.
>
> I couldn't found such information about this need for other countries.

Here is an interesting link: http://en.wikipedia.org/wiki/Swedish_rounding, it may be useful for other countries with 5 øre intervals. (the 25 øre is no longer used).

Revision history for this message
Frederic Clementi - Camptocamp (frederic-clementi) wrote :

> Hello,
>
> Should we put this addons in account-financial-tools + a configuration addons
> in l10n_ch

Guewen link shows that this module is generic -> yes let's put this into account-financial-tools + a module in l10n_ch

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

Go for this one, more appropriate: https://launchpad.net/account-invoicing

Unmerged revisions

183. By Vincent Renaville@camptocamp

[ADD] l10n_ch_invoice_rounding - documentation

182. By Vincent Renaville@camptocamp

[IMP] l10n_ch_invoice_rounding - do not apply rounding for supplier invoices

181. By Yannick Vaucher @ Camptocamp

[FIX] l10n_ch_invoice_rounding - using multiple taxes the adjustment need to be made only once all taxes are computed

180. By Yannick Vaucher @ Camptocamp

[FIX] l10n_ch_invoice_rounding - add missing call to onchange on invoice tax line amount

179. By Yannick Vaucher @ Camptocamp

[FIX] l10n_ch_invoice_rounding - comparison to avoid write of added rounding invoice line

178. By Yannick Vaucher @ Camptocamp

[ADD] l10n_ch_invoice_rounding - add global precision on tax computation

177. By Yannick Vaucher @ Camptocamp

[IMP] l10n_ch_invoice_rounding - module description

176. By Yannick Vaucher @ Camptocamp

[ADD] module l10n_ch_invoice_rounding

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'l10n_ch_invoice_rounding'
2=== added file 'l10n_ch_invoice_rounding/__init__.py'
3--- l10n_ch_invoice_rounding/__init__.py 1970-01-01 00:00:00 +0000
4+++ l10n_ch_invoice_rounding/__init__.py 2013-07-16 09:34:25 +0000
5@@ -0,0 +1,23 @@
6+# -*- coding: utf-8 -*-
7+##############################################################################
8+#
9+# Author: Yannick Vaucher
10+# Copyright 2013 Camptocamp SA
11+#
12+# This program is free software: you can redistribute it and/or modify
13+# it under the terms of the GNU Affero General Public License as
14+# published by the Free Software Foundation, either version 3 of the
15+# License, or (at your option) any later version.
16+#
17+# This program is distributed in the hope that it will be useful,
18+# but WITHOUT ANY WARRANTY; without even the implied warranty of
19+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+# GNU Affero General Public License for more details.
21+#
22+# You should have received a copy of the GNU Affero General Public License
23+# along with this program. If not, see <http://www.gnu.org/licenses/>.
24+#
25+##############################################################################
26+from . import company
27+from . import res_config
28+from . import account
29
30=== added file 'l10n_ch_invoice_rounding/__openerp__.py'
31--- l10n_ch_invoice_rounding/__openerp__.py 1970-01-01 00:00:00 +0000
32+++ l10n_ch_invoice_rounding/__openerp__.py 2013-07-16 09:34:25 +0000
33@@ -0,0 +1,48 @@
34+# -*- coding: utf-8 -*-
35+##############################################################################
36+#
37+# Author: Yannick Vaucher
38+# Copyright 2013 Camptocamp SA
39+#
40+# This program is free software: you can redistribute it and/or modify
41+# it under the terms of the GNU Affero General Public License as
42+# published by the Free Software Foundation, either version 3 of the
43+# License, or (at your option) any later version.
44+#
45+# This program is distributed in the hope that it will be useful,
46+# but WITHOUT ANY WARRANTY; without even the implied warranty of
47+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
48+# GNU Affero General Public License for more details.
49+#
50+# You should have received a copy of the GNU Affero General Public License
51+# along with this program. If not, see <http://www.gnu.org/licenses/>.
52+#
53+##############################################################################
54+{'name' : 'Unit rounded invoice',
55+ 'version' : '1.0',
56+ 'category': 'Accounting',
57+ 'description':
58+"""
59+Add a parameter to give a unit for rounding such as CHF 0.05 for Swiss invoices
60+
61+In Settings -> Configuration -> Accounting you will find 2 new types of rounding
62+`Swiss Round globally`
63+To round your invoice total amount, this option will do the adjustment in the
64+the most important tax line of your invoice.
65+
66+`Swiss Round by adding an invoice line`
67+To round your invoice total amount, this option create a invoice line without
68+taxes on it. This invoice line is tagged as `is_rounding`
69+
70+You can choose the account on which the invoice line will be written
71+""",
72+ 'author' : 'Camptocamp',
73+ 'maintainer': 'Camptocamp',
74+ 'website': 'http://www.camptocamp.com/',
75+ 'depends' : ['account'],
76+ 'data': ['res_config_view.xml'],
77+ 'test': [],
78+ 'installable': True,
79+ 'auto_install': False,
80+ 'application': True,
81+ }
82
83=== added file 'l10n_ch_invoice_rounding/account.py'
84--- l10n_ch_invoice_rounding/account.py 1970-01-01 00:00:00 +0000
85+++ l10n_ch_invoice_rounding/account.py 2013-07-16 09:34:25 +0000
86@@ -0,0 +1,237 @@
87+# -*- coding: utf-8 -*-
88+##############################################################################
89+#
90+# Author: Yannick Vaucher
91+# Copyright 2013 Camptocamp SA
92+#
93+# This program is free software: you can redistribute it and/or modify
94+# it under the terms of the GNU Affero General Public License as
95+# published by the Free Software Foundation, either version 3 of the
96+# License, or (at your option) any later version.
97+#
98+# This program is distributed in the hope that it will be useful,
99+# but WITHOUT ANY WARRANTY; without even the implied warranty of
100+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
101+# GNU Affero General Public License for more details.
102+#
103+# You should have received a copy of the GNU Affero General Public License
104+# along with this program. If not, see <http://www.gnu.org/licenses/>.
105+#
106+##############################################################################
107+
108+from openerp.osv import orm, fields
109+from openerp.tools.float_utils import float_round, float_compare
110+from openerp.tools.translate import _
111+
112+import openerp.addons.decimal_precision as dp
113+
114+def _all_invoice_tax_line_computed(invoice):
115+ tax_ids = set()
116+ for line in invoice.invoice_line:
117+ # invoice_line_tax_id is a many2many if you wonder about it
118+ for tax in line.invoice_line_tax_id:
119+ if not tax.price_include:
120+ tax_ids.add(tax.id)
121+ computed_tax_ids = [tax.id for tax in invoice.tax_line]
122+ return len(tax_ids) == len(computed_tax_ids)
123+class AccountInvoice(orm.Model):
124+ _inherit = "account.invoice"
125+
126+
127+ def _l10n_ch_add_invoice_line(self, cr, uid, invoice, amounts, rounded_total, delta, context=None):
128+ """Create a invoice_line with the diff of rounding"""
129+ invoice_line_obj = self.pool.get('account.invoice.line')
130+ obj_precision = self.pool.get('decimal.precision')
131+ prec = obj_precision.precision_get(cr, uid, 'Account')
132+
133+ company = invoice.company_id
134+ if not invoice.global_round_line_id:
135+ new_invoice_line = {
136+ 'name': _('Rounding'),
137+ 'price_unit': -delta,
138+ 'account_id': company.tax_calculation_rounding_account_id.id,
139+ 'invoice_id': invoice.id,
140+ 'is_rounding': True,
141+ }
142+ round_line_id = invoice_line_obj.create(cr, uid, new_invoice_line, context=context)
143+ elif float_compare(invoice.global_round_line_id.price_unit, -delta, precision_digits=prec) != 0:
144+ invoice_line_obj.write(cr, uid, invoice.global_round_line_id.id, {'price_unit': -delta}, context=context)
145+
146+ amount_untaxed = float_round(amounts['amount_untaxed'] - delta, precision_digits=prec)
147+ return {'amount_total': rounded_total,
148+ 'amount_untaxed': amount_untaxed}
149+
150+
151+ def _l10n_ch_round_globally(self, cr, uid, invoice, amounts, rounded_total, delta, context=None):
152+ """Add the diff to the biggest tax line
153+
154+ This ajustment must be done only after all tax are computed
155+ """
156+ # Here we identify that all taxe lines have been computed
157+ if not _all_invoice_tax_line_computed(invoice):
158+ return {}
159+
160+ obj_precision = self.pool.get('decimal.precision')
161+ prec = obj_precision.precision_get(cr, uid, 'Account')
162+ inv_tax_obj = self.pool.get('account.invoice.tax')
163+
164+ ajust_line = None
165+ for tax_line in invoice.tax_line:
166+ if not ajust_line or tax_line.amount > ajust_line.amount:
167+ ajust_line = tax_line
168+ if ajust_line:
169+ amount = ajust_line.amount - delta
170+ vals = inv_tax_obj.amount_change(cr, uid, [ajust_line.id],
171+ amount,
172+ currency_id=invoice.currency_id.id,
173+ company_id=invoice.company_id.id,
174+ date_invoice=invoice.date_invoice)['value']
175+ ajust_line.write({'amount': amount, 'tax_amount': vals['tax_amount']}, context=context)
176+
177+ amount_tax = float_round(amounts['amount_tax'] - delta, precision_digits=prec)
178+ return {'amount_total': rounded_total,
179+ 'amount_tax': amount_tax}
180+ return {}
181+
182+
183+ def _compute_l10n_rounding(self, cr, uid, invoice, amounts, context=None):
184+ """
185+ Depending on the method defined, we add an invoice line or adapt the tax lines
186+ to have a rounded total amount on the invoice
187+
188+ :param invoice: invoice browse record
189+ :param amounts: unrounded computed totals for the invoice
190+ :return dict: updated values for _amount_all
191+ """
192+
193+ obj_precision = self.pool.get('decimal.precision')
194+
195+ # avoid recusivity
196+ if 'l10n_write' in context:
197+ return {}
198+
199+ company = invoice.company_id
200+ round_method = company.tax_calculation_rounding_method
201+
202+ if round_method[:7] != 'l10n_ch':
203+ return {}
204+
205+ prec = obj_precision.precision_get(cr, uid, 'Account')
206+ rounding_prec = company.tax_calculation_rounding
207+ rounded_total = float_round(amounts['amount_total'], precision_rounding=rounding_prec)
208+
209+ if float_compare(rounded_total, amounts['amount_total'], precision_digits=prec) == 0:
210+ return {}
211+
212+ # To avoid recursivity as we need to write on invoice or
213+ # on objects triggering computation of _amount_all
214+ ctx = context.copy()
215+ ctx['l10n_write'] = True
216+
217+ delta = float_round(amounts['amount_total'] - rounded_total, precision_digits=prec)
218+
219+ if round_method == 'l10n_ch_add_invoice_line':
220+ return self._l10n_ch_add_invoice_line(cr, uid, invoice, amounts, rounded_total, delta, context=ctx)
221+ elif round_method == 'l10n_ch_round_globally':
222+ return self._l10n_ch_round_globally(cr, uid, invoice, amounts, rounded_total, delta, context=ctx)
223+ return {}
224+
225+
226+ def _amount_all(self, cr, uid, ids, name, args, context=None):
227+ """
228+ Add l10n computing and make sure invoice line for rounding is not computed in totals
229+ """
230+ res = super(AccountInvoice, self)._amount_all(cr, uid, ids, name, args, context=context)
231+
232+ for invoice in self.browse(cr, uid, ids, context=context):
233+ if invoice.type in ('out_invoice','out_refund'):
234+ if invoice.global_round_line_id:
235+ res[invoice.id]['amount_untaxed'] -= invoice.global_round_line_id.price_subtotal
236+
237+ amount_total = res[invoice.id]['amount_tax'] + res[invoice.id]['amount_untaxed']
238+ res[invoice.id]['amount_total'] = amount_total
239+
240+ l10n_rounding = self._compute_l10n_rounding(cr, uid, invoice, res[invoice.id], context=context)
241+ res[invoice.id].update(l10n_rounding)
242+ return res
243+
244+
245+ def _get_rounding_invoice_line_id(self, cr, uid, ids, name, args, context=None):
246+ """
247+ :return dict: {invoice id: global_rounding_line_id}
248+ """
249+ line_obj = self.pool.get('account.invoice.line')
250+ res = {}
251+ for invoice_id in ids:
252+ line_ids = line_obj.search(cr, uid,
253+ [('invoice_id', '=', invoice_id),
254+ ('is_rounding', '=', True)], context=context)
255+ res[invoice_id] = line_ids and line_ids[0] or False
256+ return res
257+
258+
259+ def _get_invoice_line(self, cr, uid, ids, context=None):
260+ """Use super's trigger"""
261+ return super(AccountInvoice, self.pool.get('account.invoice'))._get_invoice_line(cr, uid, ids, context=context)
262+
263+ def _get_invoice_tax(self, cr, uid, ids, context=None):
264+ """Use super's trigger"""
265+ return super(AccountInvoice, self.pool.get('account.invoice'))._get_invoice_tax(cr, uid, ids, context=context)
266+
267+ _columns = {
268+ 'global_round_line_id': fields.function(_get_rounding_invoice_line_id, type='many2one', relation='account.invoice.line', string='Invoice Line for total rounding', readonly=True),
269+ 'amount_untaxed': fields.function(_amount_all, digits_compute=dp.get_precision('Account'), string='Subtotal', track_visibility='always',
270+ store={
271+ 'account.invoice': (lambda self, cr, uid, ids, c={}: ids, ['invoice_line'], 20),
272+ 'account.invoice.tax': (_get_invoice_tax, None, 20),
273+ 'account.invoice.line': (_get_invoice_line, ['price_unit','invoice_line_tax_id','quantity','discount','invoice_id'], 20),
274+ },
275+ multi='all'),
276+ 'amount_tax': fields.function(_amount_all, digits_compute=dp.get_precision('Account'), string='Tax',
277+ store={
278+ 'account.invoice': (lambda self, cr, uid, ids, c={}: ids, ['invoice_line'], 20),
279+ 'account.invoice.tax': (_get_invoice_tax, None, 20),
280+ 'account.invoice.line': (_get_invoice_line, ['price_unit','invoice_line_tax_id','quantity','discount','invoice_id'], 20),
281+ },
282+ multi='all'),
283+ 'amount_total': fields.function(_amount_all, digits_compute=dp.get_precision('Account'), string='Total',
284+ store={
285+ 'account.invoice': (lambda self, cr, uid, ids, c={}: ids, ['invoice_line'], 20),
286+ 'account.invoice.tax': (_get_invoice_tax, None, 20),
287+ 'account.invoice.line': (_get_invoice_line, ['price_unit','invoice_line_tax_id','quantity','discount','invoice_id'], 20),
288+ },
289+ multi='all'),
290+ }
291+
292+
293+class AccountInvoiceLine(orm.Model):
294+ _inherit = 'account.invoice.line'
295+
296+ _columns = {
297+ 'is_rounding': fields.boolean('Rounding Line')
298+ }
299+
300+class AccountTax(orm.Model):
301+ _inherit = 'account.tax'
302+
303+ def compute_inv(self, cr, uid, taxes, price_unit, quantity, product=None, partner=None, precision=None):
304+ """
305+ Using l10n_ch rounding we want to keep standard global precision
306+ so we add precision to do global computation
307+ """
308+ if taxes and taxes[0].company_id.tax_calculation_rounding_method[:7] == 'l10n_ch':
309+ if not precision:
310+ precision = self.pool.get('decimal.precision').precision_get(cr, uid, 'Account')
311+ precision += 5
312+ return super(AccountTax, self).compute_inv(cr, uid, taxes, price_unit, quantity, product=product, partner=partner, precision=precision)
313+
314+ def _compute(self, cr, uid, taxes, price_unit, quantity, product=None, partner=None, precision=None):
315+ """
316+ Using l10n_ch rounding we want to keep standard global precision
317+ so we add precision to do global computation
318+ """
319+ if taxes and taxes[0].company_id.tax_calculation_rounding_method[:7] == 'l10n_ch':
320+ if not precision:
321+ precision = self.pool.get('decimal.precision').precision_get(cr, uid, 'Account')
322+ precision += 5
323+ return super(AccountTax, self)._compute(cr, uid, taxes, price_unit, quantity, product=product, partner=partner, precision=precision)
324
325=== added file 'l10n_ch_invoice_rounding/company.py'
326--- l10n_ch_invoice_rounding/company.py 1970-01-01 00:00:00 +0000
327+++ l10n_ch_invoice_rounding/company.py 2013-07-16 09:34:25 +0000
328@@ -0,0 +1,36 @@
329+# -*- coding: utf-8 -*-
330+##############################################################################
331+#
332+# Author: Yannick Vaucher
333+# Copyright 2013 Camptocamp SA
334+#
335+# This program is free software: you can redistribute it and/or modify
336+# it under the terms of the GNU Affero General Public License as
337+# published by the Free Software Foundation, either version 3 of the
338+# License, or (at your option) any later version.
339+#
340+# This program is distributed in the hope that it will be useful,
341+# but WITHOUT ANY WARRANTY; without even the implied warranty of
342+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
343+# GNU Affero General Public License for more details.
344+#
345+# You should have received a copy of the GNU Affero General Public License
346+# along with this program. If not, see <http://www.gnu.org/licenses/>.
347+#
348+##############################################################################
349+from openerp.osv import orm, fields
350+
351+class ResCompany(orm.Model):
352+ _inherit = "res.company"
353+
354+ _columns = {
355+ 'tax_calculation_rounding': fields.float('Tax Rounding unit'),
356+ 'tax_calculation_rounding_method': fields.selection([
357+ ('round_per_line', 'Round per Line'),
358+ ('round_globally', 'Round Globally'),
359+ ('l10n_ch_round_globally', 'Swiss Round globally'),
360+ ('l10n_ch_add_invoice_line', 'Swiss Round by adding a line'),
361+ ], 'Tax Calculation Rounding Method',
362+ help="If you select 'Round per Line' : for each tax, the tax amount will first be computed and rounded for each PO/SO/invoice line and then these rounded amounts will be summed, leading to the total amount for that tax. If you select 'Round Globally': for each tax, the tax amount will be computed for each PO/SO/invoice line, then these amounts will be summed and eventually this total tax amount will be rounded. If you sell with tax included, you should choose 'Round per line' because you certainly want the sum of your tax-included line subtotals to be equal to the total amount with taxes."),
363+ 'tax_calculation_rounding_account_id': fields.many2one('account.account', 'Tax Rounding Account', domain=[('type', '<>', 'view')]),
364+ }
365
366=== added directory 'l10n_ch_invoice_rounding/documentation'
367=== added file 'l10n_ch_invoice_rounding/documentation/DOC_l10n_ch_5cts_roundings.ods'
368Binary files l10n_ch_invoice_rounding/documentation/DOC_l10n_ch_5cts_roundings.ods 1970-01-01 00:00:00 +0000 and l10n_ch_invoice_rounding/documentation/DOC_l10n_ch_5cts_roundings.ods 2013-07-16 09:34:25 +0000 differ
369=== added file 'l10n_ch_invoice_rounding/res_config.py'
370--- l10n_ch_invoice_rounding/res_config.py 1970-01-01 00:00:00 +0000
371+++ l10n_ch_invoice_rounding/res_config.py 2013-07-16 09:34:25 +0000
372@@ -0,0 +1,49 @@
373+# -*- coding: utf-8 -*-
374+##############################################################################
375+#
376+# Author: Yannick Vaucher
377+# Copyright 2013 Camptocamp SA
378+#
379+# This program is free software: you can redistribute it and/or modify
380+# it under the terms of the GNU Affero General Public License as
381+# published by the Free Software Foundation, either version 3 of the
382+# License, or (at your option) any later version.
383+#
384+# This program is distributed in the hope that it will be useful,
385+# but WITHOUT ANY WARRANTY; without even the implied warranty of
386+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
387+# GNU Affero General Public License for more details.
388+#
389+# You should have received a copy of the GNU Affero General Public License
390+# along with this program. If not, see <http://www.gnu.org/licenses/>.
391+#
392+##############################################################################
393+from openerp.osv import orm, fields
394+
395+class AccountConfigSettings(orm.TransientModel):
396+ _inherit = 'account.config.settings'
397+
398+ _columns = {
399+ 'tax_calculation_rounding_method': fields.related('company_id',
400+ 'tax_calculation_rounding_method', type='selection', selection=[
401+ ('round_per_line', 'Round per line'),
402+ ('round_globally', 'Round globally'),
403+ ('l10n_ch_round_globally', 'Swiss Round globally'),
404+ ('l10n_ch_add_invoice_line', 'Swiss Round by adding an invoice line'),
405+ ], string='Tax calculation rounding method',
406+ help="If you select 'Round per line' : for each tax, the tax amount will first be computed and rounded for each PO/SO/invoice line and then these rounded amounts will be summed, leading to the total amount for that tax. If you select 'Round globally': for each tax, the tax amount will be computed for each PO/SO/invoice line, then these amounts will be summed and eventually this total tax amount will be rounded. If you sell with tax included, you should choose 'Round per line' because you certainly want the sum of your tax-included line subtotals to be equal to the total amount with taxes."),
407+ 'tax_calculation_rounding': fields.related('company_id', 'tax_calculation_rounding', type='float', string='Tax Rounding unit'),
408+ 'tax_calculation_rounding_account_id': fields.related('company_id', 'tax_calculation_rounding_account_id', type='many2one', relation='account.account', string='Tax Rounding account',
409+ domain=[('type', '<>', 'view')]),
410+ }
411+
412+ _defaults = {
413+ 'tax_calculation_rounding': 0.05
414+ }
415+
416+ def onchange_company_id(self, cr, uid, ids, company_id, context=None):
417+ res = super(AccountConfigSettings, self).onchange_company_id(cr, uid, ids, company_id, context=context)
418+ company = self.pool.get('res.company').browse(cr, uid, company_id, context=context)
419+ res['value']['tax_calculation_rounding'] = company.tax_calculation_rounding
420+ res['value']['tax_calculation_rounding_account_id'] = company.tax_calculation_rounding_account_id.id
421+ return res
422
423=== added file 'l10n_ch_invoice_rounding/res_config_view.xml'
424--- l10n_ch_invoice_rounding/res_config_view.xml 1970-01-01 00:00:00 +0000
425+++ l10n_ch_invoice_rounding/res_config_view.xml 2013-07-16 09:34:25 +0000
426@@ -0,0 +1,26 @@
427+<?xml version="1.0" encoding="utf-8"?>
428+<openerp>
429+ <data>
430+
431+ <record id="view_account_config_settings" model="ir.ui.view">
432+ <field name="name">account settings.add.rounding</field>
433+ <field name="model">account.config.settings</field>
434+ <field name="inherit_id" ref="account.view_account_config_settings"/>
435+ <field name="arch" type="xml">
436+ <xpath expr="//field[@name='tax_calculation_rounding_method']/ancestor::div[1]" position="after">
437+ <div attrs="{'invisible': [('tax_calculation_rounding_method', 'not in', ['l10n_ch_round_globally', 'l10n_ch_add_invoice_line'])]}">
438+ <label for="tax_calculation_rounding"/>
439+ <field name="tax_calculation_rounding" class="oe_inline"/>
440+ </div>
441+ <div attrs="{'invisible': [('tax_calculation_rounding_method', '&lt;&gt;', 'l10n_ch_add_invoice_line')]}">
442+ <label for="tax_calculation_rounding_account_id"/>
443+ <field name="tax_calculation_rounding_account_id"
444+ domain="[('type', '&lt;&gt;', 'view')]"
445+ attrs="{'required': [('tax_calculation_rounding_method', '=', 'l10n_ch_add_invoice_line')]}" class="oe_inline"/>
446+ </div>
447+ </xpath>
448+ </field>
449+ </record>
450+
451+ </data>
452+</openerp>

Subscribers

People subscribed via source and target branches

to all changes: