[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) <jcb@odoo.com>
This commit is contained in:
Paweł Fertyk
2024-04-12 09:53:18 +00:00
parent e5f2b9d164
commit 1bca12c443
2 changed files with 9 additions and 1 deletions
+1 -1
View File
@@ -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))
@@ -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,
})