Skip to Content
Menu
This question has been flagged
2 Replies
3277 Views

I have a function for filling in many fields automatically with an api.onchange() decorator.

@api.onchange('nursery_morning', 'nursery_evening', 'responsible_partner')
def retrieve_responsible_nursery(self):
    if self.nursery_morning or self.nursery_evening:
        if self.responsible_partner:
            if not self.resp_civility1 and not self.resp_name1 and not self.resp_cp1 and not self.resp_num1 \
                    and not self.resp_address1 and not self.resp_town1 \
                    and not self.resp_phone1 and not self.resp_phonemobile1:
                self.resp_civility1 = self.responsible_partner.title.name
                self.resp_name1 = self.responsible_partner.name
                self.resp_cp1 = self.responsible_partner.zip_id.name
                self.resp_num1 = self.responsible_partner.street_number_id.name
                self.resp_address1 = self.responsible_partner.street_id.name
                self.resp_town1 = self.responsible_partner.city_id.name
                self.resp_phone1 = self.responsible_partner.phone
                self.resp_phonemobile1 = self.responsible_partner.mobile

This function works, but I do not want the fields to change until the fields are saved in the database and not before.

Currently, the fields do not change once one of the fields listed are filled but not saved in database

Avatar
Discard
Best Answer

Hi,

if you want to apply changes only after save to a database, use 'inverse' instead of 'onchange'.

UPDATE

You should add to each field the attribute 'inverse' and define a method. E.g.:

@api.multi
def _inverse_my_fields(self):
    for record in self:
        record.field_1 = record.source_field_1
        record.field_2 = record.source_field_2
        ...
field_1 = fields.Char(inverse=_inverse_my_fields)
field_2 = fields.Float(inverse=_inverse_my_fields)


Avatar
Discard
Author Best Answer

Hi,

Thank you for your response. You have an example for how to use inverse ? 

@api.inverse('nursery_morning', 'nursery_evening', 'responsible_partner'):
...

It's good ?
Avatar
Discard

I updated my initial answer

Related Posts Replies Views Activity
3
Apr 24
1013
0
May 24
46
1
Apr 24
1824
4
Sep 23
3084
2
Sep 23
5592