[FIX] lunch: bring back the favorites lunch products
It was no longer possible to favorite a product and the already favorited products were not showing. closes odoo/odoo#81692 Taskid: 2704569 X-original-commit: 328e0384cc2cff34fc5c4131014d94efb5747cb5 Signed-off-by: Kevin Baptiste <kba@odoo.com>
This commit is contained in:
@@ -32,7 +32,7 @@ class LunchProduct(models.Model):
|
||||
is_new = fields.Boolean(compute='_compute_is_new')
|
||||
|
||||
favorite_user_ids = fields.Many2many('res.users', 'lunch_product_favorite_user_rel', 'product_id', 'user_id', check_company=True)
|
||||
is_favorite = fields.Boolean(compute='_compute_is_favorite')
|
||||
is_favorite = fields.Boolean(compute='_compute_is_favorite', inverse='_inverse_is_favorite')
|
||||
|
||||
last_order_date = fields.Date(compute='_compute_last_order_date')
|
||||
|
||||
@@ -58,7 +58,7 @@ class LunchProduct(models.Model):
|
||||
@api.depends('favorite_user_ids')
|
||||
def _compute_is_favorite(self):
|
||||
for product in self:
|
||||
product.is_favorite = self.env.user in self.favorite_user_ids
|
||||
product.is_favorite = self.env.user in product.favorite_user_ids
|
||||
|
||||
@api.depends_context('uid')
|
||||
def _compute_last_order_date(self):
|
||||
@@ -110,13 +110,20 @@ class LunchProduct(models.Model):
|
||||
raise UserError(_("The following suppliers are archived. You should either unarchive the suppliers or change the supplier of the product.\n%s", '\n'.join(invalid_products.supplier_id.mapped('name'))))
|
||||
return super().toggle_active()
|
||||
|
||||
def write(self, values):
|
||||
if 'is_favorite' in values:
|
||||
if values['is_favorite']:
|
||||
def _inverse_is_favorite(self):
|
||||
""" Handled in the write() """
|
||||
return
|
||||
|
||||
def write(self, vals):
|
||||
if 'is_favorite' in vals:
|
||||
if vals.pop('is_favorite'):
|
||||
commands = [(4, product.id) for product in self]
|
||||
else:
|
||||
commands = [(3, product.id) for product in self]
|
||||
self.env.user.write({
|
||||
'favorite_lunch_product_ids': commands,
|
||||
})
|
||||
return super().write(values)
|
||||
|
||||
if not vals:
|
||||
return True
|
||||
return super().write(vals)
|
||||
|
||||
Reference in New Issue
Block a user