Odoo Help


1 Answer

Axel Mendoza คิวบา

--Axel Mendoza--
| 8 8 10
Camaguey, คิวบา
--Axel Mendoza--

DevOps - Full stack - Software Architect - Developer - Technology Integrator

I could help you to develop anything and solve complex problems based on technologies, integrations and tricky stuffs mostly in Python with OpenERP/Odoo, Zato, Django and many others frameworks programming languages and technologies.

I offers consulting services to anyone with an unanswered questions or needs for customizations. Think about it, maybe it's better to have an expert to solve your issues and projects than having a full-time employee trying to understand what to do and how

Reach me at aekroft@gmail.com

Axel Mendoza คิวบา
27/11/16 07:26

Hi Temur

You could do it using the "new" method like this:

invoice_id = self.env['account.invoice'].new(vals)
invoice_vals = invoice_id._convert_to_write(invoice_id._cache)

Where vals is a normal dict of vals for the virtual record and invoice_vals will have the resulting virtual record modifications made by the onchange call. If you don't have the vals and you need to pass all the vals from a record you could use the method copy_data to get it by it's id like:

#from a recordset one record
vals = self.copy_data()
#from a record by id
vals = self.browse(id).copy_data()

also the copy_data method accept an optional dict argument with the default data for the result dict

UPDATE (Temur):

before calling "new" method,

if type(vals) == list:
vals = vals[0]

-see comment below.

4 ความคิดเห็น
Temur จอร์เจีย
2/12/16 08:47

Thanks Axel for your reply. I tried it and a code "vals = self.copy_data()" followed by "self.env['some.model'].new(vals)" gave me an error. I'll investigate the error deeper as soon as I'll have some spare time. I forgot to mention in my question that server used is a v9, should it work in v9 as well? Or you were referring to a different version?

Axel Mendoza คิวบา
2/12/16 14:00

That is the way of the new api, no matter what version you are using, v8, v9, v10 or master.

Temur จอร์เจีย
6/12/16 03:13

It seems `new` method expects a dictionary, whereas `copy_data` method returns a list of dictionaries. I fixed the error by using `vals = self.copy_data()[0]` instead of `vals = self.copy_data()` and so I was able to get a virtual record.

Axel Mendoza คิวบา
6/12/16 03:41


Ask a Question
Keep Informed
2 ผู้ติดตาม
About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now