Odoo Help

Welcome!

This community 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.

2

How does the resolve_2many_commands method work?

By
Moin
on 6/3/13, 2:33 PM 2,815 views

This method is defined at def resolve_2many_commands Found at: openerp.osv.orm

I'm especially confused about the "commands" parameter, I know 0 = Create and 1 = Write but not sure about others. Documentation gives an usage example

values = self.resolve_2many_commands(cr, uid, 'my_o2m', my_o2m_values, ['price', 'tax'], context)

my_o2m is the o2m field that the onchange method is applied to, what is my_o2m_values?

1

Felipe

--Felipe--
962
| 5 3 8
Bogotá, Colombia
--Felipe--
Informatics engineer Industrial engineer
Felipe
On 12/27/13, 6:08 PM

That method will format the on_change parameter that you receive from the x2many field of the form

the meaning of options 0,1,2,3,4,5,6 are found in openerp docs field methods

Example on xml: <field name="list_ids" onchange="onchange_list(list_ids, context)"/>

let say our one2many field is 'list_ids' and inside it we have the fields 'amount'(float) and 'analytic_account_id' (many2one)

when we create a line inside the list_ids variable will be like this:

[[0, False, {'analytic_account_id': 33, 'amount': 800}]]

after you format it with values = self.resolve_2many_commands(cr, uid, 'list_ids', list_ids, ['amount', 'analytic_account_id'], context) it will look like this:

[{'analytic_account_id': 33, 'amount': 800}]

but if you are editing a one2many field it will only bring, the field you are editing: if you only change the amount field, it will look like this

[[1, 201981, {'amount': 500}]]

but you will probably need the other fields, so you format it with resolve_2many_commands again, and get:

[{'analytic_account_id': (33, u'ANALYTIC ACCOUNT NAME'), 'amount': 500}]

now you have the many2one in the form of an object, it is different when you change the one2many in the form because then it will be show as an integer id.

this way is easier to construct your on_change_methods, because you will always get the fields you need, no matter if they where changed inside the form or not.

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

Asked: 6/3/13, 2:33 PM
Seen: 2815 times
Last updated: 3/16/15, 8:10 AM