diff --git a/addons/stock/models/stock_warehouse.py b/addons/stock/models/stock_warehouse.py index b255eede23dde..f907abee72722 100644 --- a/addons/stock/models/stock_warehouse.py +++ b/addons/stock/models/stock_warehouse.py @@ -6,6 +6,7 @@ from odoo import _, _lt, api, fields, models from odoo.exceptions import UserError +from odoo.tools.misc import clean_context _logger = logging.getLogger(__name__) @@ -125,7 +126,7 @@ def create(self, vals): # actually create WH warehouse = super(Warehouse, self).create(vals) # create sequences and operation types - new_vals = warehouse._create_or_update_sequences_and_picking_types() + new_vals = warehouse.with_context(clean_context(self.env.context))._create_or_update_sequences_and_picking_types() warehouse.write(new_vals) # TDE FIXME: use super ? # create routes and push/stock rules route_vals = warehouse._create_or_update_route() diff --git a/addons/stock/tests/__init__.py b/addons/stock/tests/__init__.py index f8001befaffe5..03be45c834bb6 100644 --- a/addons/stock/tests/__init__.py +++ b/addons/stock/tests/__init__.py @@ -19,4 +19,5 @@ from . import test_report from . import test_report_stock_quantity from . import test_report_tours +from . import test_res_company from . import test_stock_return_picking diff --git a/addons/stock/tests/test_res_company.py b/addons/stock/tests/test_res_company.py new file mode 100644 index 0000000000000..a0058d628926f --- /dev/null +++ b/addons/stock/tests/test_res_company.py @@ -0,0 +1,13 @@ +from odoo.tests.common import TransactionCase + + +class TestResCompany(TransactionCase): + def test_create_warehouse_default_code(self): + code = 'TEST' + company = self.env['res.company'].with_context(default_code=code).create({ + 'name': 'name', + }) + warehouse = self.env['stock.warehouse'].search([('company_id', '=', company.id)]) + self.assertEqual(code, warehouse.code) + sequences = self.env['ir.sequence'].search([('company_id', '=', company.id), ('code', '=', code)]) + self.assertEqual([], list(sequences), 'warehouse default_code should not overwrite sequence codes')