2
votes

I'd like to ask, if is there any way to "disable" onchange decorator, when product is already created.

I have a field (X), which value depends, what will be in the 3 another fields (Y). I've used "api.onchange". When product is created, i want to make, that one of Y fields, will not change a value of X anymore.

I tryed to check, if "self" is existing in database, like exists(), but even new record is marked as "existing". I tryed to get access to self.id, but it's impossible. I thought about create additional field with Boolean type, but it's the last resort.

1

1 Answers

0
votes

NEW API

First picture i added an onchange event to the name of product.template i used debug mode to stop the program and see if i have an acces to self._origin clearly i have access to it

enter image description here

Second picture it shows when I updated a product the ID value is passed

enter image description here

Now Third picture shows when i'm creating a new Product the value of the id in self._origin is False

enter image description here

so can you post the code that use used please i want to understand why you don't have acccess to self._origin

OLD API

when using old api self._origin is not access but you have the list of ids in edit mode the list will not be empty .

def onchange_name(self, cr, uid, ids, name, context=None):
        # when updating a record ids will not be empty
        # in my case will be ids=[55]
        # in create mode the ids is empty
        # id = []
        if not ids :
             # here you are in create mode you put your logic here