Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
4 Răspunsuri
7730 Vizualizări

I try to get current id in onchange method before saving this contact using

self.id ==> output is <odoo.models.NewId object at 0x7f72aff2b290>

self._origin.id==>False

self.env.context.get('active_ids')==>None

I know that I have to use self._origin.id in onchange method for saved contact.

How can I get current id before saving?

Here is my code

@api.multi

@api.onchange("mobile")

def onchange_mobile(self):

logging.info("self id")

logging.info(self.id)

logging.info(self._origin)

logging.info(self.env.context.get('active_ids'))

mobile_id=self.search([('mobile','=',self.mobile),('id','!=',self.id)])

if mobile_id:

raise ValidationError(_("similar mobile number are found"))

else:

raise ValidationError(_('No Similar Mobile'))

Imagine profil
Abandonează

Would you please specify what you want to do with current ID?

Autor

I don't know yet.I just want to know to get current id.If there is no way,it is ok.

It's a wrong need, you actually need an orange before planting. Change your logic

You will not have current id in onchange until you save the record.

Cel mai bun răspuns

Hi,

Checking your code seems that you are trying to check whether the same mobile number already exists or not.


For that, you can update this line  like this,

mobile_id=self.search([('mobile','=',self.mobile)]) 


Thanks

Imagine profil
Abandonează
Autor

Thank you. But I want to get current id for another code in onchange model.

Related Posts Răspunsuri Vizualizări Activitate
2
iul. 24
2715
1
iun. 24
5174
1
oct. 23
10903
1
oct. 23
98
1
aug. 23
2194