From 1bca12c44327ed0ad6c763c468134f3248067240 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Fertyk?= Date: Wed, 10 Apr 2024 14:19:00 +0200 Subject: [PATCH] [FIX] point_of_sale: fix product creation for non-sales users After `_check_combo_inclusion` was added, it broke product creation for users without sales rights (e.g. stock managers). This commit fixes the issue by using `sudo().search`. closes odoo/odoo#161313 Signed-off-by: Joseph Caburnay (jcb) --- addons/point_of_sale/models/product.py | 2 +- addons/point_of_sale/tests/test_pos_stock_account.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/addons/point_of_sale/models/product.py b/addons/point_of_sale/models/product.py index 82af00add11..963e9da3bce 100644 --- a/addons/point_of_sale/models/product.py +++ b/addons/point_of_sale/models/product.py @@ -41,7 +41,7 @@ class ProductTemplate(models.Model): def _check_combo_inclusions(self): for product in self: if not product.available_in_pos: - combo_name = self.env['pos.combo.line'].search([('product_id', 'in', product.product_variant_ids.ids)], limit=1).combo_id.name + combo_name = self.env['pos.combo.line'].sudo().search([('product_id', 'in', product.product_variant_ids.ids)], limit=1).combo_id.name if combo_name: raise UserError(_('You must first remove this product from the %s combo', combo_name)) diff --git a/addons/point_of_sale/tests/test_pos_stock_account.py b/addons/point_of_sale/tests/test_pos_stock_account.py index 7611fb996a0..45483a30f54 100644 --- a/addons/point_of_sale/tests/test_pos_stock_account.py +++ b/addons/point_of_sale/tests/test_pos_stock_account.py @@ -267,3 +267,11 @@ class TestPoSStock(TestPoSCommon): self.pos_session.action_pos_session_validate() expense_account_move_line = self.env['account.move.line'].search([('account_id', '=', self.expense_account.id)]) self.assertEqual(expense_account_move_line.balance, 0.0, "Expense account should be 0.0") + + def test_stock_user_without_pos_permissions_can_create_product(self): + stock_manager = odoo.tests.common.new_test_user( + self.env, 'temp_stock_manager', 'stock.group_stock_manager', + ) + self.env['product.product'].with_user(stock_manager).create({ + 'name': 'temp', 'type': 'product', 'available_in_pos': False, + })