This question has been flagged
2 Replies
1708 Views

Hi,

We have a computed field called x_monthsdue.  to calculate it, we do,  record['x_monthsdue'] = self.credit / self.x_monthly .

We wish to introduce a condition such that IF credit is greater than zero, then we compute  record['x_monthsdue'] = self.credit / self.x_monthly   ELSE the field x_monthdue will be represented as OK.


The field x_monthlydue is type float and read only.


Regards,

Michael

Avatar
Discard
Best Answer

Hi,

You can define a compute function for field x_monthsdue as below.

@api.depends('credit', 'x_monthly')
def _compute_x_monthsdue(self):
    for rec in self:
        if rec.credit > 0:
            rec.x_monthsdue = rec.credit / rec.x_monthly
        else:
            rec.x_monthsdue = 'OK'

Regards

Avatar
Discard
Author Best Answer

Brilliant. Thank you. 

Avatar
Discard