Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
2 Antwoorden
6429 Weergaven

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

Avatar
Annuleer

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

Auteur

Thanks for your answer Manish, But no need else condition

Beste antwoord

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)


Avatar
Annuleer
Auteur

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'])]}"

Gerelateerde posts Antwoorden Weergaven Activiteit
1
okt. 23
1925
2
okt. 23
2142
2
aug. 23
4124
4
aug. 23
20444
3
okt. 22
10916