Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
2 Odpowiedzi
6442 Widoki

Hi !

I have write the an @api.onchange method in some Float field and the @api.onchange is calculation is working fine.

The problem is that when I click on save the system doesn't pick up the change and it all Float fields append to zero.

Does anybody knows how to do write() function of the model for @api.onchange function?

Below,i have mentioned the code

Thank you !

class LabTest(models.Model):
    _name = 'lab.test.line'
 
    line_id = fields.Many2one('quality.alert', string='perameter type')
    labtest_type_id=fields.Many2one('labtest.type', string='Test Name')   
    sample_value_per = fields.Float(string='Sample Value in Percentage')
    sample_value = fields.Float(string='Input Sample Value')


    @api.onchange('labtest_type_id','labtest_type_id.code','sample_value','sample_value_per')
    def onchange_value(self):
        for line in self:
            if line.labtest_type_id and line.labtest_type_id.code == 'ip' and line.sample_value:
                line.sample_value_per = float(line.sample_value/line.sample_value) * 100
            elif line.labtest_type_id and line.labtest_type_id.code == 'pp':
                ip_value = 1
                lp_lines = line.line_id.labtest_type_line.filtered(lambda r: r.labtest_type_id.code == 'ip')
                for ipln in lp_lines:
                    ip_value = ipln.sample_value
                line.sample_value_per = float(line.sample_value/ip_value) * 100
            elif line.labtest_type_id and line.labtest_type_id.code == 'ss':
                ip_value = 1
                lp_lines = line.line_id.labtest_type_line.filtered(lambda r: r.labtest_type_id.code == 'ip')
                for ipln in lp_lines:
                    ip_value = ipln.sample_value
                line.sample_value_per = float(line.sample_value/ip_value) * 100

Awatar
Odrzuć

I think else loop is missing in your condition and can you update your code after added else condition?

Autor

Thanks for your answer Manish, But no need else condition

Najlepsza odpowiedź

use store= True in python end or force_save = "1" in xml end to save the field value.

  sample_value_per = fields.Float(string='Sample Value in Percentage', store=True)


Awatar
Odrzuć
Autor

Thanks for answer..

its working well but i facing one problem invisible is not working after put force_save = "1"

<field name="sample_value_per" force_save = "1" attrs="{'invisible': [('state', '=', 'draft')]}"/>

try this attrs="{'invisible': [('state', 'in', ['draft'])]}"

Powiązane posty Odpowiedzi Widoki Czynność
1
paź 23
1946
2
paź 23
2152
2
sie 23
4156
4
sie 23
20474
3
paź 22
10944