[FIX] purchase: correct average cost tests

Correctly forward-port baf1580be4 by
backporting 38eb5346c7.
This commit is contained in:
Nicolas Martinelli
2019-07-04 19:45:25 +02:00
committed by Christophe Simonis
parent 1debaa89f1
commit 6cf09b9a3c
+14 -8
View File
@@ -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,