Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
8910 Lượt xem

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?

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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.

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 3 15
6266
0
thg 3 15
4490
0
thg 3 15
4004
0
thg 3 15
5003
0
thg 3 25
1447