[IMP] stock_landed_costs: Remove dependency to AccountTestCommon

l10n runbot builds are all failing when running at least one test depending of AccountTestCommon because it:
- doesn't create a sandboxed testing environnement to manage the multi-currency, multi-company, the default company's currency, the exchange rates...
- doesn't setup a testing user then all tests are done using the superuser.
- doesn't provide a fully setup chart of accounts: exchange difference journal is not set, accounts have bad types, etc...
- is run sometimes at-install.

--task: 2301180
This commit is contained in:
Laurent Smet
2020-07-31 07:11:33 +00:00
parent 0d8ee78fa5
commit 8a9392c1b2
5 changed files with 110 additions and 61 deletions
+9 -8
View File
@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-
from odoo.addons.account.tests.common import AccountTestInvoicingCommon
from odoo.addons.stock_account.tests.test_anglo_saxon_valuation_reconciliation_common import ValuationReconciliationTestCommon
class TestStockLandedCostsCommon(AccountTestInvoicingCommon):
class TestStockLandedCostsCommon(ValuationReconciliationTestCommon):
@classmethod
def setUpClass(cls, chart_template_ref=None):
@@ -16,13 +16,18 @@ class TestStockLandedCostsCommon(AccountTestInvoicingCommon):
cls.LandedCost = cls.env['stock.landed.cost']
cls.CostLine = cls.env['stock.landed.cost.lines']
# References
cls.warehouse = cls.env['stock.warehouse'].search([('company_id', '=', cls.env.company.id)], limit=1)
cls.warehouse = cls.company_data['default_warehouse']
cls.supplier_id = cls.env['res.partner'].create({'name': 'My Test Supplier'}).id
cls.customer_id = cls.env['res.partner'].create({'name': 'My Test Customer'}).id
cls.supplier_location_id = cls.env.ref('stock.stock_location_suppliers').id
cls.customer_location_id = cls.env.ref('stock.stock_location_customers').id
cls.categ_all = cls.env.ref('product.product_category_all')
cls.categ_all = cls.stock_account_product_categ
cls.expenses_journal = cls.company_data['default_journal_purchase']
cls.stock_journal = cls.env['account.journal'].create({
'name': 'Stock Journal',
'code': 'STJTEST',
'type': 'general',
})
# Create product refrigerator & oven
cls.product_refrigerator = cls.Product.create({
'name': 'Refrigerator',
@@ -31,8 +36,6 @@ class TestStockLandedCostsCommon(AccountTestInvoicingCommon):
'weight': 10,
'volume': 1,
'categ_id': cls.categ_all.id})
cls.product_refrigerator.categ_id.property_cost_method = 'fifo'
cls.product_refrigerator.categ_id.property_valuation = 'real_time'
cls.product_oven = cls.Product.create({
'name': 'Microwave Oven',
'type': 'product',
@@ -40,8 +43,6 @@ class TestStockLandedCostsCommon(AccountTestInvoicingCommon):
'weight': 20,
'volume': 1.5,
'categ_id': cls.categ_all.id})
cls.product_oven.categ_id.property_cost_method = 'fifo'
cls.product_oven.categ_id.property_valuation = 'real_time'
# Create service type product 1.Labour 2.Brokerage 3.Transportation 4.Packaging
cls.landed_cost = cls.Product.create({'name': 'Landed Cost', 'type': 'service'})
cls.brokerage_quantity = cls.Product.create({'name': 'Brokerage Cost', 'type': 'service'})
@@ -19,19 +19,15 @@ class TestStockLandedCosts(TestStockLandedCostsCommon):
'name': "LC product 1",
'weight': 10,
'volume': 1,
'categ_id': self.stock_account_product_categ.id,
})
product_landed_cost_1.product_tmpl_id.categ_id.property_cost_method = 'fifo'
product_landed_cost_1.product_tmpl_id.categ_id.property_stock_account_input_categ_id = self.company_data['default_account_expense']
product_landed_cost_1.product_tmpl_id.categ_id.property_stock_account_output_categ_id = self.company_data['default_account_revenue']
product_landed_cost_2 = self.env['product.product'].create({
'name': "LC product 2",
'weight': 20,
'volume': 1.5,
'categ_id': self.stock_account_product_categ.id,
})
product_landed_cost_2.product_tmpl_id.categ_id.property_cost_method = 'fifo'
product_landed_cost_2.product_tmpl_id.categ_id.property_stock_account_input_categ_id = self.company_data['default_account_expense']
product_landed_cost_2.product_tmpl_id.categ_id.property_stock_account_output_categ_id = self.company_data['default_account_revenue']
self.assertEqual(product_landed_cost_1.value_svl, 0)
self.assertEqual(product_landed_cost_1.quantity_svl, 0)
@@ -97,7 +93,10 @@ class TestStockLandedCosts(TestStockLandedCostsCommon):
# I create a landed cost for those 2 pickings
default_vals = self.env['stock.landed.cost'].default_get(list(self.env['stock.landed.cost'].fields_get()))
virtual_home_staging = self.env['product.product'].create({'name': 'Virtual Home Staging'})
virtual_home_staging = self.env['product.product'].create({
'name': 'Virtual Home Staging',
'categ_id': self.stock_account_product_categ.id,
})
default_vals.update({
'picking_ids': [picking_landed_cost_1.id, picking_landed_cost_2.id],
'account_journal_id': self.expenses_journal,
@@ -49,13 +49,6 @@ class TestLandedCosts(TestStockLandedCostsCommon):
'picking_id': self.picking_out.id,
'location_id': self.warehouse.lot_stock_id.id,
'location_dest_id': self.customer_location_id})
self.stock_input_account, self.stock_output_account, self.stock_valuation_account, self.expense_account, self.stock_journal = _create_accounting_data(self.env)
self.categ_all.write({
'property_stock_account_input_categ_id': self.stock_input_account.id,
'property_stock_account_output_categ_id': self.stock_output_account.id,
'property_stock_valuation_account_id': self.stock_valuation_account.id,
'property_stock_journal': self.stock_journal.id,
})
def test_00_landed_costs_on_incoming_shipment(self):
""" Test landed cost on incoming shipment """
@@ -334,7 +327,7 @@ class TestLandedCostsWithPurchaseAndInv(TestStockValuationLCCommon):
# Check SVL and AML
svl = self.env['stock.valuation.layer'].search([('stock_move_id', '=', receipt.move_lines.id)])
self.assertAlmostEqual(svl.value, 455)
aml = self.env['account.move.line'].search([('account_id', '=', self.stock_valuation_account.id)])
aml = self.env['account.move.line'].search([('account_id', '=', self.company_data['default_account_stock_valuation'].id)])
self.assertAlmostEqual(aml.debit, 455)
# Create and validate LC
@@ -357,7 +350,7 @@ class TestLandedCostsWithPurchaseAndInv(TestStockValuationLCCommon):
self.assertAlmostEqual(lc.valuation_adjustment_lines.final_cost, 554)
svl = self.env['stock.valuation.layer'].search([('stock_move_id', '=', receipt.move_lines.id)], order='id desc', limit=1)
self.assertAlmostEqual(svl.value, 99)
aml = self.env['account.move.line'].search([('account_id', '=', self.stock_valuation_account.id)], order='id desc', limit=1)
aml = self.env['account.move.line'].search([('account_id', '=', self.company_data['default_account_stock_valuation'].id)], order='id desc', limit=1)
self.assertAlmostEqual(aml.debit, 99)
# Create an invoice with the same price
@@ -2,12 +2,11 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo.addons.stock_landed_costs.tests.common import TestStockLandedCostsCommon
from odoo.addons.account.tests.common import AccountTestCommon
from odoo.tests import tagged
@tagged('post_install', '-at_install')
class TestStockLandedCostsRounding(TestStockLandedCostsCommon, AccountTestCommon):
class TestStockLandedCostsRounding(TestStockLandedCostsCommon):
def test_stock_landed_costs_rounding(self):
# In order to test the rounding in landed costs feature of stock, I create 2 landed cost
@@ -4,64 +4,53 @@
""" Implementation of "INVENTORY VALUATION TESTS (With valuation layers)" spreadsheet. """
from odoo.tests import Form, tagged
from odoo.addons.stock_account.tests.test_stockvaluationlayer import TestStockValuationCommon
from odoo.addons.stock_account.tests.test_stockvaluation import _create_accounting_data
from odoo.addons.account.tests.common import AccountTestCommon
from odoo.addons.stock_landed_costs.tests.common import TestStockLandedCostsCommon
class TestStockValuationLCCommon(TestStockValuationCommon, AccountTestCommon):
class TestStockValuationLCCommon(TestStockLandedCostsCommon):
@classmethod
def setUpClass(cls):
super(TestStockValuationLCCommon, cls).setUpClass()
def setUpClass(cls, chart_template_ref=None):
super().setUpClass(chart_template_ref=chart_template_ref)
cls.product1 = cls.env['product.product'].create({
'name': 'product1',
'type': 'product',
'categ_id': cls.stock_account_product_categ.id,
})
cls.productlc1 = cls.env['product.product'].create({
'name': 'product1',
'type': 'service',
'categ_id': cls.env.ref('product.product_category_all').id,
})
cls.stock_input_account, cls.stock_output_account, cls.stock_valuation_account, cls.expense_account, cls.stock_journal = _create_accounting_data(cls.env)
cls.product1.write({
'property_account_expense_id': cls.expense_account.id,
})
cls.productlc1.write({
'property_account_expense_id': cls.expense_account.id,
})
cls.product1.categ_id.write({
'property_stock_account_input_categ_id': cls.stock_input_account.id,
'property_stock_account_output_categ_id': cls.stock_output_account.id,
'property_stock_valuation_account_id': cls.stock_valuation_account.id,
'property_stock_journal': cls.stock_journal.id,
})
cls.payable_account = cls.env['account.account'].create({
'name': 'payable',
'code': 'payable',
'user_type_id': cls.env.ref('account.data_account_type_payable').id,
'reconcile': True,
'categ_id': cls.stock_account_product_categ.id,
})
def setUp(self):
super().setUp()
self.days = 0
def _get_stock_input_move_lines(self):
return self.env['account.move.line'].search([
('account_id', '=', self.stock_input_account.id),
('account_id', '=', self.company_data['default_account_stock_in'].id),
], order='id')
def _get_stock_output_move_lines(self):
return self.env['account.move.line'].search([
('account_id', '=', self.stock_output_account.id),
('account_id', '=', self.company_data['default_account_stock_out'].id),
], order='id')
def _get_stock_valuation_move_lines(self):
return self.env['account.move.line'].search([
('account_id', '=', self.stock_valuation_account.id),
('account_id', '=', self.company_data['default_account_stock_valuation'].id),
], order='id')
def _get_payable_move_lines(self):
return self.env['account.move.line'].search([
('account_id', '=', self.payable_account.id),
('account_id', '=', self.company_data['default_account_payable'].id),
], order='id')
def _get_expense_move_lines(self):
return self.env['account.move.line'].search([
('account_id', '=', self.expense_account.id),
('account_id', '=', self.company_data['default_account_expense'].id),
], order='id')
def _make_lc(self, move, amount):
@@ -76,6 +65,74 @@ class TestStockValuationLCCommon(TestStockValuationCommon, AccountTestCommon):
lc.compute_landed_cost()
lc.button_validate()
return lc
def _make_in_move(self, product, quantity, unit_cost=None, create_picking=False):
""" Helper to create and validate a receipt move.
"""
unit_cost = unit_cost or product.standard_price
in_move = self.env['stock.move'].create({
'name': 'in %s units @ %s per unit' % (str(quantity), str(unit_cost)),
'product_id': product.id,
'location_id': self.env.ref('stock.stock_location_suppliers').id,
'location_dest_id': self.company_data['default_warehouse'].lot_stock_id.id,
'product_uom': self.env.ref('uom.product_uom_unit').id,
'product_uom_qty': quantity,
'price_unit': unit_cost,
'picking_type_id': self.company_data['default_warehouse'].in_type_id.id,
})
if create_picking:
picking = self.env['stock.picking'].create({
'picking_type_id': in_move.picking_type_id.id,
'location_id': in_move.location_id.id,
'location_dest_id': in_move.location_dest_id.id,
})
in_move.write({'picking_id': picking.id})
in_move._action_confirm()
in_move._action_assign()
in_move.move_line_ids.qty_done = quantity
in_move._action_done()
self.days += 1
return in_move.with_context(svl=True)
def _make_out_move(self, product, quantity, force_assign=None, create_picking=False):
""" Helper to create and validate a delivery move.
"""
out_move = self.env['stock.move'].create({
'name': 'out %s units' % str(quantity),
'product_id': product.id,
'location_id': self.company_data['default_warehouse'].lot_stock_id.id,
'location_dest_id': self.env.ref('stock.stock_location_customers').id,
'product_uom': self.env.ref('uom.product_uom_unit').id,
'product_uom_qty': quantity,
'picking_type_id': self.company_data['default_warehouse'].out_type_id.id,
})
if create_picking:
picking = self.env['stock.picking'].create({
'picking_type_id': out_move.picking_type_id.id,
'location_id': out_move.location_id.id,
'location_dest_id': out_move.location_dest_id.id,
})
out_move.write({'picking_id': picking.id})
out_move._action_confirm()
out_move._action_assign()
if force_assign:
self.env['stock.move.line'].create({
'move_id': out_move.id,
'product_id': out_move.product_id.id,
'product_uom_id': out_move.product_uom.id,
'location_id': out_move.location_id.id,
'location_dest_id': out_move.location_dest_id.id,
})
out_move.move_line_ids.qty_done = quantity
out_move._action_done()
self.days += 1
return out_move.with_context(svl=True)
@tagged('-at_install', 'post_install')
@@ -243,9 +300,9 @@ class TestStockValuationLCFIFOVB(TestStockValuationLCCommon):
def setUpClass(cls):
super(TestStockValuationLCFIFOVB, cls).setUpClass()
cls.vendor1 = cls.env['res.partner'].create({'name': 'vendor1'})
cls.vendor1.property_account_payable_id = cls.payable_account
cls.vendor1.property_account_payable_id = cls.company_data['default_account_payable']
cls.vendor2 = cls.env['res.partner'].create({'name': 'vendor2'})
cls.vendor2.property_account_payable_id = cls.payable_account
cls.vendor2.property_account_payable_id = cls.company_data['default_account_payable']
cls.product1.product_tmpl_id.categ_id.property_cost_method = 'fifo'
cls.product1.product_tmpl_id.categ_id.property_valuation = 'real_time'
@@ -330,7 +387,7 @@ class TestStockValuationLCFIFOVB(TestStockValuationLCCommon):
self.assertEqual(valuation_aml.credit, 0)
# Check reconciliation of input aml of lc
lc_input_aml = lc.account_move_id.line_ids.filtered(lambda aml: aml.account_id == self.stock_input_account)
lc_input_aml = lc.account_move_id.line_ids.filtered(lambda aml: aml.account_id == self.company_data['default_account_stock_in'])
self.assertTrue(len(lc_input_aml.full_reconcile_id), 1)
self.assertEqual(self.product1.quantity_svl, 10)
@@ -386,7 +443,7 @@ class TestStockValuationLCFIFOVB(TestStockValuationLCCommon):
lc.button_validate()
# Check reconciliation of input aml of lc
lc_input_aml = lc.account_move_id.line_ids.filtered(lambda aml: aml.account_id == self.stock_input_account)
lc_input_aml = lc.account_move_id.line_ids.filtered(lambda aml: aml.account_id == self.company_data['default_account_stock_in'])
self.assertTrue(len(lc_input_aml.full_reconcile_id), 1)
def test_vendor_bill_flow_continental_1(self):