[FIX] product: only activate pricelists when enabling pricelists

Following 83c52575d0 we activated or created pricelists as soon as a
currency was activated/created/deleted, for every company that might already have another
pricelist setup done, which was quite confusing.

With this fix, we ensure this will only happen:
- at company creation
- when enabling the pricelist feature
- when enabling the multi-currency setting (only the first time, unless the pricelists were
disabled manually afterward)

closes odoo/odoo#120039

X-original-commit: 4c0146d939e40e9433794802388cf06147e716f2
Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com>
Signed-off-by: Morgane Demesmaeker <edm@odoo.com>
This commit is contained in:
Demesmaeker
2023-04-28 09:53:12 +02:00
parent 4dbab115e2
commit 4c701ab1fc
2 changed files with 7 additions and 5 deletions
+3 -2
View File
@@ -67,7 +67,8 @@ class ResConfigSettings(models.TransientModel):
pl = self.env['product.pricelist'].search([('discount_policy', '=', 'without_discount')])
pl.write({'discount_policy': 'with_discount'})
if self.group_product_pricelist:
had_group_pl = self.default_get(['group_product_pricelist'])['group_product_pricelist']
if self.group_product_pricelist and not had_group_pl:
self.env['res.company']._activate_or_create_pricelists()
else:
elif not self.group_product_pricelist:
self.env['product.pricelist'].sudo().search([]).action_archive()
+4 -3
View File
@@ -10,6 +10,7 @@ class ResCurrency(models.Model):
def _activate_group_multi_currency(self):
# for Sale/ POS - Multi currency flows require pricelists
super()._activate_group_multi_currency()
group_user = self.env.ref('base.group_user').sudo()
group_user._apply_group(self.env.ref('product.group_product_pricelist'))
self.env['res.company']._activate_or_create_pricelists()
if not self.user_has_groups('product.group_product_pricelist'):
group_user = self.env.ref('base.group_user').sudo()
group_user._apply_group(self.env.ref('product.group_product_pricelist'))
self.env['res.company']._activate_or_create_pricelists()