Skip to content
Permalink
Browse files

Rename variables

  • Loading branch information...
kebeclibre committed Apr 15, 2019
1 parent 2a656bb commit c7c38ede5512dedd9961cb0ffdcfee7d6d5431a4
Showing with 12 additions and 9 deletions.
  1. +12 −9 addons/purchase/models/account_invoice.py
@@ -142,6 +142,7 @@ def _anglo_saxon_purchase_move_lines(self, i_line, res):
"""
inv = i_line.invoice_id
company_currency = inv.company_id.currency_id
invoice_currency = inv.currency_id
if i_line.product_id and i_line.product_id.valuation == 'real_time' and i_line.product_id.type == 'product':
# get the fiscal position
fpos = i_line.invoice_id.fiscal_position_id
@@ -189,41 +190,43 @@ def _anglo_saxon_purchase_move_lines(self, i_line, res):
currency_valuation_price_unit = i_line.purchase_line_id.order_id.currency_id

# Put the valuation price unit in the invoice currency
if inv.currency_id != currency_valuation_price_unit:
valuation_price_unit = (
if invoice_currency != currency_valuation_price_unit:
valuation_price_unit_invoice_currency = (
currency_valuation_price_unit
.with_context(date=inv.date_invoice)
.compute(valuation_price_unit, inv.currency_id, round=False)
.compute(valuation_price_unit, invoice_currency, round=False)
)
else:
valuation_price_unit_invoice_currency = valuation_price_unit

# Valuation price unit and i_line.price_unit in invoice currency
# A safe assumption is that line['price_unit'] and i_line.price_unit both in the currency of the invoice, foreign or not
if (
acc and
float_compare(line['price_unit'], i_line.price_unit, precision_rounding=i_line.currency_id.rounding) == 0 and
float_compare(valuation_price_unit, i_line.price_unit, precision_rounding=i_line.currency_id.rounding) != 0
float_compare(line['price_unit'], i_line.price_unit, precision_rounding=invoice_currency.rounding) == 0 and
float_compare(valuation_price_unit_invoice_currency, i_line.price_unit, precision_rounding=invoice_currency.rounding) != 0
):
# price with discount and without tax included
price_unit = i_line.price_unit * (1 - (i_line.discount or 0.0) / 100.0)
tax_ids = []
if line['tax_ids']:
#line['tax_ids'] is like [(4, tax_id, None), (4, tax_id2, None)...]
taxes = self.env['account.tax'].browse([x[1] for x in line['tax_ids']])
price_unit = taxes.compute_all(price_unit, currency=inv.currency_id, quantity=1.0)['total_excluded']
price_unit = taxes.compute_all(price_unit, currency=invoice_currency, quantity=1.0)['total_excluded']
for tax in taxes:
tax_ids.append((4, tax.id, None))
for child in tax.children_tax_ids:
if child.type_tax_use != 'none':
tax_ids.append((4, child.id, None))

price_before = line.get('price', 0.0)
line.update({'price': inv.currency_id.round(valuation_price_unit * line['quantity'])})
line.update({'price': invoice_currency.round(valuation_price_unit_invoice_currency * line['quantity'])})
diff_res.append({
'type': 'src',
'name': i_line.name[:64],
'price_unit': inv.currency_id.round(price_unit - valuation_price_unit),
'price_unit': invoice_currency.round(price_unit - valuation_price_unit_invoice_currency),
'quantity': line['quantity'],
'price': inv.currency_id.round(price_before - line.get('price', 0.0)),
'price': invoice_currency.round(price_before - line.get('price', 0.0)),
'account_id': acc,
'product_id': line['product_id'],
'uom_id': line['uom_id'],

0 comments on commit c7c38ed

Please sign in to comment.
You can’t perform that action at this time.