From 2c702108b815014c9bbb0c910280a4aeea15abc7 Mon Sep 17 00:00:00 2001 From: Goffin Simon Date: Tue, 2 Apr 2019 14:50:55 +0000 Subject: [PATCH] [FIX] purchase_stock: Wrong journal entry created from vendor bill MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Steps to reproduce: - Create a storable product P with a vendor V and a purchase price = 100€ - Set the category of the prodcut to automated and AVCO and set a price diff account on it - Create PO for V with 10 P with a price_unit = 110€ - Confirm the PO and deliver 7 P with no backorder - Change the ordered quantity of P to 9 on PO (and the unit_price will be set to 100€) - Go on the delivery order and deliver 2 remainig P - Create the invoice and validate it Bug: The amount due on the invoice was 900.02€ instead of 900.00€ PS: The debit and credit of an aml are computed with the price (defined in function _anglo_saxon_purchase_move_lines) with the function _convert_prepared_anglosaxon_line defined on model account.invoice. So rounding the price unit after the computation of the price allows to keep the same total as the one computed for the PO. opw:1951465 closes odoo/odoo#32345 Signed-off-by: Simon Goffin (sig) --- addons/purchase_stock/models/account_invoice.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/addons/purchase_stock/models/account_invoice.py b/addons/purchase_stock/models/account_invoice.py index 54c9bdc19fb..efb494777cd 100644 --- a/addons/purchase_stock/models/account_invoice.py +++ b/addons/purchase_stock/models/account_invoice.py @@ -123,7 +123,7 @@ class AccountInvoice(models.Model): diff_line = { 'type': 'src', 'name': i_line.name[:64], - 'price_unit': inv.currency_id.round(price_unit_val_dif), + 'price_unit': price_unit_val_dif, 'quantity': line_quantity, 'price': inv.currency_id.round(price_val_dif), 'account_id': acc, @@ -133,8 +133,9 @@ class AccountInvoice(models.Model): 'tax_ids': tax_ids, } # We update the original line accordingly - line['price_unit'] = inv.currency_id.round(line['price_unit'] - diff_line['price_unit']) + line['price_unit'] = line['price_unit'] - diff_line['price_unit'] line['price'] = inv.currency_id.round(line['quantity'] * line['price_unit']) + line['price_unit'] = inv.currency_id.round(line['price_unit']) diff_res.append(diff_line) return diff_res return []