Odoo is the world's easiest all-in-one management software. It includes hundreds of business apps:
CRM | e-Commerce | Accounting | Inventory | PoS | Project management | MRP | etc.
As described here onchange methods are called with virtual recordset by Odoo, if a corresponding field is changed. Say I have the following onchange method:
when Odoo calls this method internally, the "self" is a virtual recordset. However, I have a scenario where I would like to call this method manually, from the another object method, where I do NOT have virtual recordset, but a normal recordset instead, so if I call the onchange method like this:
it gets called with ordinary recordset instead of virtual recordset (consequently the final result is as expected, except of huge difference in performance).
In order to avoid the performance penalty, I would like to get somehow virtual recordset from the ordinary "self" recordset I have for the moment and than call the onchange function using it. i.e. something like:
rec = get virtual recordset from self
it comes down to the question: How to get a virtual record/recordset from an ordinary record/recordset?
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
before calling "new" method,
if type(vals) == list:
vals = vals
-see comment below.
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.Register
Odoo Training Center
Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.Test it now
|Asked: 11/25/16, 9:20 AM|
|Seen: 819 times|
|Last updated: 12/6/16, 3:17 AM|