1
votes

I want in res.partner model make onchange event on field parent_id. this field already have onchange event by old api, so i changed it`s value on XML to on_change=1 and added .py code

def onchange_parent_id(self):
    self.category_id = self.parent_id.category_id
    super(res_partner, self).onchange_parent_id(self)

after update, then i open contact form and changing parent_id, everything works as i want, but when i press save error occurrs

TypeError: cannot convert dictionary update sequence element #0 to a sequence

as i understand it occurrs becouse on create other method (_fields_sync) also calls this onchange_parent_id methot by 'old style'.

Maybe someone can advice me how to fix this.

Thanks in advance

1

1 Answers

0
votes

It seems that _fields_sync calls onchange_parent_id with context=[partner.id] and this is the raison of the conversion error (api.py line 756).

ODOO LOG:
WARNING ...: partner: res.partner(93,)
api:756:context=[93]

Python test:

>>> from openerp.tools import frozendict
>>> context = [93]
>>> frozendict(context)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>

TypeError: cannot convert dictionary update sequence element #0 to a sequence

You can remove the old onchange event and create a new one (onchange_parent_id_new) without overriding onchange_parent_id method.

Python:

@api.model
@api.onchange('parent_id')
def onchange_parent_id_new(self):
  old_res = super(res_partner, self).onchange_parent_id(self.parent_id.id)
  if type(old_res) is dict and 'value' in old_res:
    for field, value in old_res.get('value').items():
      if hasattr(self, field):
        setattr(self, field, value)

  if self.parent_id:
      self.category_id = self.parent_id.category_id

XML:

<record id="view_partner_form_inherit" model="ir.ui.view">
    <field name="name">view.partner.form.inherit</field>
    <field name="model">res.partner</field>
    <field name="inherit_id" ref="base.view_partner_form"/>
    <field name="arch" type="xml">
    <field name="parent_id" position="replace">
        <field name="parent_id"/>
    </field>
    </field>
</record>