From ecc8308f5e3d849598250b7a0aa54a0c0d323bd2 Mon Sep 17 00:00:00 2001 From: Adam Heinz Date: Wed, 5 Nov 2025 09:22:32 -0500 Subject: [PATCH] [FIX] OO-1216 Prevent OCA product_cost_security from breaking tests. --- addons/account/tests/common.py | 5 +++++ addons/sale/tests/test_sale_prices.py | 7 +++++++ addons/sale_stock/tests/test_anglo_saxon_valuation.py | 6 ++++++ addons/sale_stock/tests/test_sale_stock.py | 7 +++++++ addons/sales_team/tests/common.py | 8 ++++++++ addons/stock_account/tests/test_lot_valuation.py | 7 +++++++ addons/stock_account/tests/test_stockvaluation.py | 6 ++++++ 7 files changed, 46 insertions(+) diff --git a/addons/account/tests/common.py b/addons/account/tests/common.py index 4abcb2a1318f94..0437936c799742 100644 --- a/addons/account/tests/common.py +++ b/addons/account/tests/common.py @@ -272,6 +272,11 @@ def _create_product(cls, **create_values): @classmethod def get_default_groups(cls): groups = super().get_default_groups() + + if cls.env['ir.module.module'].search([('name', '=', 'product_cost_security')]).state == 'installed': + # OO-1216 Restore permissions reduced by product_cost_security for testing + groups |= cls.env.ref('product_cost_security.group_product_edit_cost') + return groups | cls.env.ref('account.group_account_manager') | cls.env.ref('account.group_account_user') \ | cls.env.ref('account.group_validate_bank_account') diff --git a/addons/sale/tests/test_sale_prices.py b/addons/sale/tests/test_sale_prices.py index 91607340ba4a60..f6d8f01c722e41 100644 --- a/addons/sale/tests/test_sale_prices.py +++ b/addons/sale/tests/test_sale_prices.py @@ -429,6 +429,13 @@ def test_multi_currency_discount(self): 'name': 'E.T', 'login': 'hohoho', }) + + if self.env['ir.module.module'].search([('name', '=', 'product_cost_security')]).state == 'installed': + # OO-1216 Restore permissions reduced by product_cost_security for testing + user_in_other_company.write({ + 'groups_id': [Command.link(self.env.ref('product_cost_security.group_product_edit_cost').id)], + }) + with mute_logger('odoo.models.unlink'): self.env['res.currency.rate'].search([]).unlink() self.env['res.currency.rate'].create({ diff --git a/addons/sale_stock/tests/test_anglo_saxon_valuation.py b/addons/sale_stock/tests/test_anglo_saxon_valuation.py index cd966993158aba..a62da3df4e1024 100644 --- a/addons/sale_stock/tests/test_anglo_saxon_valuation.py +++ b/addons/sale_stock/tests/test_anglo_saxon_valuation.py @@ -1629,6 +1629,12 @@ def test_fifo_reverse_and_create_new_invoice(self): 'groups_id': [(6, 0, self.env.ref('account.group_account_invoice').ids)], }) + if self.env['ir.module.module'].search([('name', '=', 'product_cost_security')]).state == 'installed': + # OO-1216 Restore permissions reduced by product_cost_security for testing + accountman.write({ + 'groups_id': [Command.link(self.env.ref('product_cost_security.group_product_edit_cost').id)], + }) + in_moves = self.env['stock.move'].create([{ 'name': 'IN move @%s' % p, 'product_id': self.product.id, diff --git a/addons/sale_stock/tests/test_sale_stock.py b/addons/sale_stock/tests/test_sale_stock.py index 6b3b03fb0b5963..19372de42d8038 100644 --- a/addons/sale_stock/tests/test_sale_stock.py +++ b/addons/sale_stock/tests/test_sale_stock.py @@ -1724,6 +1724,13 @@ def test_inventory_admin_no_backorder_not_own_sale_order(self): self.ref('stock.group_stock_manager'), self.ref('sales_team.group_sale_salesman')])] }) + + if self.env['ir.module.module'].search([('name', '=', 'product_cost_security')]).state == 'installed': + # OO-1216 Restore permissions reduced by product_cost_security for testing + inventory_admin_user.write({ + 'groups_id': [Command.link(self.env.ref('product_cost_security.group_product_edit_cost').id)], + }) + pick.with_user(inventory_admin_user).move_ids.write( {'quantity': 1, 'picked': True}) Form.from_action(self.env(user=inventory_admin_user), pick.button_validate())\ diff --git a/addons/sales_team/tests/common.py b/addons/sales_team/tests/common.py index 50f1e5f5f1e284..eb7d5f74449634 100644 --- a/addons/sales_team/tests/common.py +++ b/addons/sales_team/tests/common.py @@ -5,6 +5,7 @@ from odoo.addons.base.tests.common import BaseCommon from odoo.addons.mail.tests.common import mail_new_test_user +from odoo import Command class SalesTeamCommon(BaseCommon): @@ -34,6 +35,13 @@ def setUpClass(cls): 'notification_type': 'email', 'groups_id': [(6, 0, cls.group_sale_manager.ids)], }) + + if cls.env['ir.module.module'].search([('name', '=', 'product_cost_security')]).state == 'installed': + # OO-1216 Restore permissions reduced by product_cost_security for testing + cls.sale_manager.write({ + 'groups_id': [Command.link(cls.env.ref('product_cost_security.group_product_edit_cost').id)], + }) + cls.sale_team = cls.env['crm.team'].create({ 'name': 'Test Sales Team', }) diff --git a/addons/stock_account/tests/test_lot_valuation.py b/addons/stock_account/tests/test_lot_valuation.py index 02636faca3fcbf..de9a8905d2a5fd 100644 --- a/addons/stock_account/tests/test_lot_valuation.py +++ b/addons/stock_account/tests/test_lot_valuation.py @@ -774,6 +774,13 @@ def test_deliveries_with_minimal_access_rights(self): 'email': 'inventory_user@gmail.com', 'groups_id': [Command.set(self.env.ref('stock.group_stock_user').ids)], }) + + if self.env['ir.module.module'].search([('name', '=', 'product_cost_security')]).state == 'installed': + # OO-1216 Restore permissions reduced by product_cost_security for testing + inventory_user.write({ + 'groups_id': [Command.link(self.env.ref('product_cost_security.group_product_edit_cost').id)], + }) + customer = self.env['res.partner'].create({ 'name': 'Lovely customer' }) diff --git a/addons/stock_account/tests/test_stockvaluation.py b/addons/stock_account/tests/test_stockvaluation.py index 56ba06ff5dc92d..458f3b8189ee05 100644 --- a/addons/stock_account/tests/test_stockvaluation.py +++ b/addons/stock_account/tests/test_stockvaluation.py @@ -77,6 +77,12 @@ def setUpClass(cls): 'groups_id': [(6, 0, [cls.env.ref('stock.group_stock_user').id])] }) + if cls.env['ir.module.module'].search([('name', '=', 'product_cost_security')]).state == 'installed': + # OO-1216 Restore permissions reduced by product_cost_security for testing + cls.inventory_user.write({ + 'groups_id': [Command.link(cls.env.ref('product_cost_security.group_product_edit_cost').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.categ_id.write({ 'property_stock_account_input_categ_id': cls.stock_input_account.id,