From 91efa25bb78859121a7a0887e95c63aa7f7a6bc0 Mon Sep 17 00:00:00 2001 From: Joel Grand-Guillaume Date: Tue, 3 Nov 2009 08:08:58 +0100 Subject: [PATCH 1/2] [FIX] Residual amount into invoice is now correct in every case and avoid rounding trouble even if rating has changed bzr revid: joel.grandguillaume@camptocamp.com-20091103070858-86gtu8tzvztjuyt4 --- addons/account/invoice.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/addons/account/invoice.py b/addons/account/invoice.py index 606b42ee926..ca8b36fbdfe 100644 --- a/addons/account/invoice.py +++ b/addons/account/invoice.py @@ -107,19 +107,29 @@ class account_invoice(osv.osv): for inv in data_inv: debit = credit = 0.0 context.update({'date':inv.date_invoice}) + context_unreconciled=context.copy() for lines in inv.move_lines: + debit_tmp = lines.debit + credit_tmp = lines.credit # If currency conversion needed if inv.company_id.currency_id.id <> inv.currency_id.id: # If invoice paid, compute currency amount according to invoice date # otherwise, take the line date if not inv.reconciled: context.update({'date':lines.date}) - # Compute amount in currency - debit += cur_obj.compute(cr, uid, inv.company_id.currency_id.id, inv.currency_id.id, lines.debit, round=False,context=context) - credit += cur_obj.compute(cr, uid, inv.company_id.currency_id.id, inv.currency_id.id, lines.credit, round=False,context=context) + context_unreconciled.update({'date':lines.date}) + # If amount currency setted, compute for debit and credit in company currency + if lines.amount_currency < 0: + credit_tmp=abs(cur_obj.compute(cr, uid, lines.currency_id.id, inv.company_id.currency_id.id, lines.amount_currency, round=False,context=context_unreconciled)) + elif lines.amount_currency > 0: + debit_tmp=abs(cur_obj.compute(cr, uid, lines.currency_id.id, inv.company_id.currency_id.id, lines.amount_currency, round=False,context=context_unreconciled)) + # Then, recomput into invoice currency to avoid rounding trouble ! + debit += cur_obj.compute(cr, uid, inv.company_id.currency_id.id, inv.currency_id.id, debit_tmp, round=False,context=context) + credit += cur_obj.compute(cr, uid, inv.company_id.currency_id.id, inv.currency_id.id, credit_tmp, round=False,context=context) else: - debit += lines.debit - credit += lines.credit + debit+=debit_tmp + credit+=credit_tmp + if not inv.amount_total: result = 0.0 elif inv.type in ('out_invoice','in_refund'): @@ -128,7 +138,9 @@ class account_invoice(osv.osv): else: amount = debit-credit result = inv.amount_total - amount - res[inv.id] = result + # Use is_zero function to avoid rounding trouble => should be fixed into ORM + res[inv.id] = not self.pool.get('res.currency').is_zero(cr, uid, inv.company_id.currency_id,result) and result or 0.0 + return res def _get_lines(self, cr, uid, ids, name, arg, context=None): From 675d14e54fb5fe674d0e678e5444abe37ba9f2d9 Mon Sep 17 00:00:00 2001 From: Joel Grand-Guillaume Date: Tue, 3 Nov 2009 08:30:04 +0100 Subject: [PATCH 2/2] [FIX] Use price_accuracy to verify balanced entry insteed of fixed '0,0001'. Add price_accuracy on debit and credit move lines lp bug: https://launchpad.net/bugs/452854 fixed bzr revid: joel.grandguillaume@camptocamp.com-20091103073004-7vjpq2t4uqwpgi0j --- addons/account/account.py | 2 +- addons/account/account_move_line.py | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/addons/account/account.py b/addons/account/account.py index ff344b0256b..3ed4ebc600c 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -988,7 +988,7 @@ class account_move(osv.osv): if line.account_id.currency_id.id != line.currency_id.id and (line.account_id.currency_id.id != line.account_id.company_id.currency_id.id or line.currency_id): raise osv.except_osv(_('Error'), _("""Couldn't create move with currency different from the secondary currency of the account "%s - %s". Clear the secondary currency field of the account definition if you want to accept all currencies.""" % (line.account_id.code, line.account_id.name))) - if abs(amount) < 0.0001: + if abs(amount) < config['price_accuracy']: if not len(line_draft_ids): continue self.pool.get('account.move.line').write(cr, uid, line_draft_ids, { diff --git a/addons/account/account_move_line.py b/addons/account/account_move_line.py index f31fca91a44..26d45ab7395 100644 --- a/addons/account/account_move_line.py +++ b/addons/account/account_move_line.py @@ -341,8 +341,8 @@ class account_move_line(osv.osv): 'quantity': fields.float('Quantity', digits=(16,2), help="The optional quantity expressed by this line, eg: number of product sold. The quantity is not a legal requirement but is very usefull for some reports."), 'product_uom_id': fields.many2one('product.uom', 'UoM'), 'product_id': fields.many2one('product.product', 'Product'), - 'debit': fields.float('Debit', digits=(16,2)), - 'credit': fields.float('Credit', digits=(16,2)), + 'debit': fields.float('Debit', digits=(16,int(tools.config['price_accuracy']))), + 'credit': fields.float('Credit', digits=(16,int(tools.config['price_accuracy']))), 'account_id': fields.many2one('account.account', 'Account', required=True, ondelete="cascade", domain=[('type','<>','view'), ('type', '<>', 'closed')], select=2), 'move_id': fields.many2one('account.move', 'Move', ondelete="cascade", states={'valid':[('readonly',True)]}, help="The move of this entry line.", select=2), @@ -350,7 +350,7 @@ class account_move_line(osv.osv): 'statement_id': fields.many2one('account.bank.statement', 'Statement', help="The bank statement used for bank reconciliation", select=1), 'reconcile_id': fields.many2one('account.move.reconcile', 'Reconcile', readonly=True, ondelete='set null', select=2), 'reconcile_partial_id': fields.many2one('account.move.reconcile', 'Partial Reconcile', readonly=True, ondelete='set null', select=2), - 'amount_currency': fields.float('Amount Currency', help="The amount expressed in an optional other currency if it is a multi-currency entry."), + 'amount_currency': fields.float('Amount Currency', help="The amount expressed in an optional other currency if it is a multi-currency entry.", digits=(16,int(tools.config['price_accuracy']))), 'currency_id': fields.many2one('res.currency', 'Currency', help="The optional other currency if it is a multi-currency entry."), 'period_id': fields.many2one('account.period', 'Period', required=True, select=2), @@ -369,14 +369,14 @@ class account_move_line(osv.osv): 'balance': fields.function(_balance, method=True, string='Balance'), 'state': fields.selection([('draft','Draft'), ('valid','Valid')], 'Status', readonly=True), 'tax_code_id': fields.many2one('account.tax.code', 'Tax Account', help="The Account can either be a base tax code or tax code account."), - 'tax_amount': fields.float('Tax/Base Amount', digits=(16,2), select=True, help="If the Tax account is tax code account, this field will contain the taxed amount.If the tax account is base tax code,\ + 'tax_amount': fields.float('Tax/Base Amount', digits=(16,int(tools.config['price_accuracy'])), select=True, help="If the Tax account is tax code account, this field will contain the taxed amount.If the tax account is base tax code,\ this field will contain the basic amount(without tax)."), 'invoice': fields.function(_invoice, method=True, string='Invoice', type='many2one', relation='account.invoice', fnct_search=_invoice_search), 'account_tax_id':fields.many2one('account.tax', 'Tax'), 'analytic_account_id' : fields.many2one('account.analytic.account', 'Analytic Account'), #TODO: remove this - 'amount_taxed':fields.float("Taxed Amount",digits=(16,2)), + 'amount_taxed':fields.float("Taxed Amount",digits=(16,int(tools.config['price_accuracy']))), }