From bd4da1b7499a27f1460bd67bf83e697a18753b5b Mon Sep 17 00:00:00 2001 From: qdp-odoo Date: Thu, 8 Jun 2017 17:40:21 +0200 Subject: [PATCH] [FIX] sale, sale_expense, stock_landed_costs: fix nightly build. stock_landed_costs: on nightly, the localization installed may not have stock properties accounts defined. If it's not, we create them on the fly with a random account sale, sale_expense: fix broken tests due to mismatch currency: On 10.0-nightly, the currency of the company is not the same that the product.list0 that leads to assertion errors. --- addons/account/tests/account_test_classes.py | 27 +++++++++++++++++++ addons/sale/tests/test_sale_order.py | 3 +++ .../sale_expense/tests/test_sale_expense.py | 3 +++ addons/stock_landed_costs/tests/common.py | 3 +++ 4 files changed, 36 insertions(+) diff --git a/addons/account/tests/account_test_classes.py b/addons/account/tests/account_test_classes.py index cf37e2493ef..8477f4109d9 100644 --- a/addons/account/tests/account_test_classes.py +++ b/addons/account/tests/account_test_classes.py @@ -28,3 +28,30 @@ class AccountingTestCase(HttpCase): if theorical_lines: raise ValidationError('Remaining theorical line (not found). %s)' % ([(aml[0], aml[1], aml[2]) for aml in theorical_lines])) return True + + def ensure_account_property(self, property_name): + '''Ensure the ir.property targetting an account.account passed as parameter exists. + In case it's not: create it with a random account. This is useful when testing with + partially defined localization (missing stock properties for example) + + :param property_name: The name of the property. + ''' + company_id = self.env.user.company_id + field_id = self.env['ir.model.fields'].search( + [('model', '=', 'product.template'), ('name', '=', property_name)], limit=1) + property_id = self.env['ir.property'].search([ + ('company_id', '=', company_id.id), + ('name', '=', property_name), + ('res_id', '=', None), + ('fields_id', '=', field_id.id)], limit=1) + account_id = self.env['account.account'].search([('company_id', '=', company_id.id)], limit=1) + value_reference = 'account.account,%d' % account_id.id + if property_id and not property_id.value_reference: + property_id.value_reference = value_reference + else: + self.env['ir.property'].create({ + 'name': property_name, + 'company_id': company_id.id, + 'fields_id': field_id.id, + 'value_reference': value_reference, + }) diff --git a/addons/sale/tests/test_sale_order.py b/addons/sale/tests/test_sale_order.py index c7e40df04db..2e97137277d 100644 --- a/addons/sale/tests/test_sale_order.py +++ b/addons/sale/tests/test_sale_order.py @@ -104,6 +104,9 @@ class TestSaleOrder(TestSale): def test_cost_invoicing(self): """ Test confirming a vendor invoice to reinvoice cost on the so """ + # force the pricelist to have the same currency as the company + self.env.ref('product.list0').currency_id = self.env.ref('base.main_company').currency_id + serv_cost = self.env.ref('product.service_cost_01') prod_gap = self.env.ref('product.product_product_1') so = self.env['sale.order'].create({ diff --git a/addons/sale_expense/tests/test_sale_expense.py b/addons/sale_expense/tests/test_sale_expense.py index fdc1317cf57..e2893a2e2de 100644 --- a/addons/sale_expense/tests/test_sale_expense.py +++ b/addons/sale_expense/tests/test_sale_expense.py @@ -7,6 +7,9 @@ from odoo.addons.sale.tests.test_sale_common import TestSale class TestSaleExpense(TestSale): def test_sale_expense(self): """ Test the behaviour of sales orders when managing expenses """ + # force the pricelist to have the same currency as the company + self.env.ref('product.list0').currency_id = self.env.ref('base.main_company').currency_id + # create a so with a product invoiced on delivery prod = self.env.ref('product.product_product_1') so = self.env['sale.order'].create({ diff --git a/addons/stock_landed_costs/tests/common.py b/addons/stock_landed_costs/tests/common.py index cdd99228dab..205d2171853 100644 --- a/addons/stock_landed_costs/tests/common.py +++ b/addons/stock_landed_costs/tests/common.py @@ -59,6 +59,9 @@ class TestStockLandedCostsCommon(AccountingTestCase): self.brokerage_quantity = self._create_services('Brokerage Cost') self.transportation_weight = self._create_services('Transportation Cost') self.packaging_volume = self._create_services('Packaging Cost') + # Ensure the account properties exists. + self.ensure_account_property('property_stock_account_input') + self.ensure_account_property('property_stock_account_output') def _create_services(self, name): return self.Product.create({