Help

欢迎!

该社区面向专业人士和我们产品和服务的爱好者。
分享和讨论最好的内容和新的营销理念,建立您的专业形象,一起成为更好的营销人员。


0

write() method not working

Avatar
odoo
2 Comments
Avatar
Discard
Avatar
odoo
-

Hello,
I think you need to change the field name.

Reason: Odoo already external id field in import and export data.
Thanks.

Avatar
odoo
-

Already tried another field name, but same results

2 Answers
0
Avatar
odoo
Best Answer

After further analysis, I noticed that Postgres was receiving a ROLLBACK query every time the sync_with_external method was being called. So the problem wasn´t the write() method.

Finally the culprit was a line of code at the end of the custom method:

raise exceptions.Warning(_("Customer synced successfully"))

I thought raising a Warning was innocent enough to be used just to display a success message to the user. Little I knew this was going to cost me several days of rethinking my life choices and almost falling into insanity.

I hope this helps anyone that may fall into this same issue.

Avatar
Discard
0
Avatar
odoo
Best Answer

Why don't you use

self.external_id = res['id']

Instead of 

self.write({"external_id": res["id"]})

Are you also certain that the method sync_with_external is being executed and that res['id'] is not None. I hope this helps.

3 Comments
Avatar
Discard
Avatar
odoo
-

1. Using self.external_id = res['id'] does change the instance property value. Even I tested it using odoo shell. But in the database doesn't the field remains empty.

2. The method is manually executed by a button in the form view.

Thanks

Avatar
odoo
-

But what does print(res['id']) output? If the API doesn't return anything it can't be saved.

Did you do a module upgrade/odoo restart?

Avatar
odoo
-

Oh sorry, res["id"] returns the correct value every time.
Also I did a module upgrade, odoo restart, even a database wipeout and fresh install, testing it out on docker container instead of the repo build. And all have the same results.