[FIX] account_anglo_savon: round prices according to account precision to avoid getting unbalanced move
The standard move_line_get from account.invoice returns prices rounded (price_subtotal field as account precision) while the anglo-saxon module could return dict with non-rounded prices. With amounts with bigger precision, we could get a difference of a few cents when comparing the debit/credits and then not be able to balance the invoice (opw 597208).
This commit is contained in:
parent
d31faceb67
commit
1d826a6051
|
@ -22,6 +22,7 @@
|
|||
##############################################################################
|
||||
|
||||
from openerp.osv import osv
|
||||
from openerp.tools.float_utils import float_round as round
|
||||
|
||||
class account_invoice_line(osv.osv):
|
||||
_inherit = "account.invoice.line"
|
||||
|
@ -32,11 +33,12 @@ class account_invoice_line(osv.osv):
|
|||
company_currency = inv.company_id.currency_id.id
|
||||
def get_price(cr, uid, inv, company_currency,i_line):
|
||||
cur_obj = self.pool.get('res.currency')
|
||||
decimal_precision = self.pool.get('decimal.precision')
|
||||
if inv.currency_id.id != company_currency:
|
||||
price = cur_obj.compute(cr, uid, company_currency, inv.currency_id.id, i_line.product_id.standard_price * i_line.quantity, context={'date': inv.date_invoice})
|
||||
else:
|
||||
price = i_line.product_id.standard_price * i_line.quantity
|
||||
return price
|
||||
return round(price, decimal_precision.precision_get(cr, uid, 'Account'))
|
||||
|
||||
if inv.type in ('out_invoice','out_refund'):
|
||||
for i_line in inv.invoice_line:
|
||||
|
@ -113,6 +115,8 @@ class account_invoice_line(osv.osv):
|
|||
fpos = i_line.invoice_id.fiscal_position or False
|
||||
a = self.pool.get('account.fiscal.position').map_account(cr, uid, fpos, oa)
|
||||
diff_res = []
|
||||
decimal_precision = self.pool.get('decimal.precision')
|
||||
account_prec = decimal_precision.precision_get(cr, uid, 'Account')
|
||||
# calculate and write down the possible price difference between invoice price and product price
|
||||
for line in res:
|
||||
if a == line['account_id'] and i_line.product_id.id == line['product_id']:
|
||||
|
@ -121,14 +125,14 @@ class account_invoice_line(osv.osv):
|
|||
if inv.currency_id.id != company_currency:
|
||||
standard_price = self.pool.get('res.currency').compute(cr, uid, company_currency, inv.currency_id.id, standard_price, context={'date': inv.date_invoice})
|
||||
if standard_price != i_line.price_unit and line['price_unit'] == i_line.price_unit and acc:
|
||||
price_diff = i_line.price_unit - standard_price
|
||||
line.update({'price':standard_price * line['quantity']})
|
||||
price_diff = round(i_line.price_unit - standard_price, account_prec)
|
||||
line.update({'price': round(standard_price * line['quantity'], account_prec)})
|
||||
diff_res.append({
|
||||
'type':'src',
|
||||
'name': i_line.name[:64],
|
||||
'price_unit':price_diff,
|
||||
'quantity':line['quantity'],
|
||||
'price': price_diff * line['quantity'],
|
||||
'price': round(price_diff * line['quantity'], account_prec),
|
||||
'account_id':acc,
|
||||
'product_id':line['product_id'],
|
||||
'uos_id':line['uos_id'],
|
||||
|
|
Loading…
Reference in New Issue