Skip to Content
मेन्यू
This question has been flagged
2 Replies
3186 Views

Hello,

I have a form for "Test". In that form i have two fields, "test_category(such as "written","interview","medical")" and "total_marks". I compute total marks from other fields. As you know when we compute a field using "compute" then it becomes readonly. Now i want that when my "test_category" is "written" only then "total_marks" field should be readonly or computed, otherwise it should be editable.

help please,

Thank you 

Avatar
Discard
Best Answer

Hi,

You can make a compute field editable by writing its inverse function by declaring

total_marks = fields.Float(compute='_compute_total_marks', inverse='_inverse_total_marks')

Here '_inverse_total_marks' is the inverse function of the field total_marks(in inverse function just write the inverse of the compute function).

After making the field editable follow the below steps

in .py

def _compute_total_marks(self):
if self.test_category == 'written':
"""Write steps for computing the total marks"""

in .xml

<field name="total_marks" attrs="{'readonly': [('test_category', '=', 'written')]}"/>

Hope it helps

Avatar
Discard
Best Answer


try this one.

one = fields.Float()

two = fields.Float()

total = fields.Float(compute='_get_sum')


    @api.depends('one', 'two')

    def _get_sum(self):

        for rec in self:

           rec.update({

                'total': rec.one+rec.two,

            })


Avatar
Discard