From 6cf09b9a3c06d6212c8e14668e034fc7f851e902 Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Fri, 28 Jun 2019 11:55:50 +0000 Subject: [PATCH] [FIX] purchase: correct average cost tests Correctly forward-port baf1580be44eab39f901d153f73546d4a4709588 by backporting 38eb5346c75fb97f215d59d208978cbc27a82b6e. --- addons/purchase/tests/test_stockvaluation.py | 22 +++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/addons/purchase/tests/test_stockvaluation.py b/addons/purchase/tests/test_stockvaluation.py index 8eeedf1353f..da97af804d1 100644 --- a/addons/purchase/tests/test_stockvaluation.py +++ b/addons/purchase/tests/test_stockvaluation.py @@ -812,7 +812,7 @@ class TestStockValuationWithCOA(AccountingTestCase): .write({'quantity_done': 1.0})) picking.button_validate() - # 1 Units received at rate 0.7 = 42.86 + # 1 Unit received at rate 0.7 = 42.86 self.assertAlmostEqual(product_avg.standard_price, 42.86) today = date_invoice @@ -898,7 +898,7 @@ class TestStockValuationWithCOA(AccountingTestCase): 'purchase_method': 'purchase', 'cost_method': 'average', 'name': 'AVG', - 'standard_price': 60, + 'standard_price': 0, 'property_account_creditor_price_difference': self.price_diff_account.id }).product_variant_id product_avg.invoice_policy = 'order' @@ -945,13 +945,12 @@ class TestStockValuationWithCOA(AccountingTestCase): 'company_id': company.id, }) - # To allow testing validation of PO + # To allow testing validation of PO and Delivery + today = date_po def _today(*args, **kwargs): - return date_po - # To allow testing validation of Delivery - delivery_now = date_delivery + return today def _now(*args, **kwargs): - return delivery_now + ' 01:00:00' + return today + ' 01:00:00' patchers = [ patch('odoo.fields.Date.context_today', _today), @@ -980,6 +979,7 @@ class TestStockValuationWithCOA(AccountingTestCase): line_product_avg = po.order_line.filtered(lambda l: l.product_id == product_avg) + today = date_delivery picking = po.picking_ids (picking.move_lines .filtered(lambda l: l.purchase_line_id == line_product_avg) @@ -987,7 +987,10 @@ class TestStockValuationWithCOA(AccountingTestCase): picking.button_validate() picking.action_done() # Create Backorder + # 5 Units received at rate 0.7 = 42.86 + self.assertAlmostEqual(product_avg.standard_price, 42.86) + today = date_invoice inv = self.env['account.invoice'].create({ 'type': 'in_invoice', 'date_invoice': date_invoice, @@ -1010,13 +1013,16 @@ class TestStockValuationWithCOA(AccountingTestCase): inv.action_invoice_open() + today = date_delivery1 backorder_picking = self.env['stock.picking'].search([('backorder_id', '=', picking.id)]) - delivery_now = date_delivery1 (backorder_picking.move_lines .filtered(lambda l: l.purchase_line_id == line_product_avg) .write({'quantity_done': 5.0})) backorder_picking.button_validate() + # 5 Units received at rate 0.7 (42.86) + 5 Units received at rate 0.8 (37.50) = 40.18 + self.assertAlmostEqual(product_avg.standard_price, 40.18) + today = date_invoice1 inv1 = self.env['account.invoice'].create({ 'type': 'in_invoice', 'date_invoice': date_invoice1,