Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
553 Vistas

I have an inherited crm_lead model as follows:

class CrmLead(models.Model):

    _inherit = 'crm.lead'

​linked_user_ids = fields.One2many('crm.deal.value', 'lead_id', string='Consultants', index=True, tracking=True)

​total_value = fields.Monetary(string='Total Value', currency_field='company_currency', compute='_compute_total_value', store=True, tracking=True)


    @api.depends('linked_user_ids', 'linked_user_ids.value')

    def _compute_total_value(self):

        for lead in self:

            lead.total_value = sum(user.value or 0.0 for user in lead.linked_user_ids) or 0.0


​@api.constrains('total_value','expected_revenue')

​    def _check_total_value(self):

​        for lead in self:

​            if lead.total_value != lead.expected_revenue:

​                raise ValidationError("Total contribution value should be equal to the opportunity's expected revenue.")

I have the following deal_value model

class DealValue(models.Model):

    _name='crm.deal.value'

    _inherit = ['mail.thread', 'mail.activity.mixin']


​lead_id = fields.Many2one('crm.lead', string='Lead', ondelete='cascade', readonly=True)

​value = fields.Monetary('Contribution Value', currency_field = 'currency_id', tracking=True)

​currency_id = fields.Many2one('res.currency', string='Currency', readonly=True, required=True, default= lambda self: self.env.company.currency_id)

  • When I delete a deal value record and modify other deal value records associated with the lead such that total_value = expected_revenue, I get a validation error saying that these values are not equal. Why does this happen?
  • Currently, the only workaround is first setting the deal value to 0, save the changes, and then delete the deal value record.
  • The compute method works correctly.

[Odoo 18 community edition]

Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
2
ago 25
1145
1
jun 25
1096
0
may 25
650
4
jul 25
4774
3
mar 25
2007