← Back to team overview

openerp-india team mailing list archive

[Bug 1204478] [NEW] Browse on one2many_v_id_xxx in onchange fails

 

Public bug reported:

I attached a demo module showing the error.

Content of the module:
The demo module is a drastically simplified version from what we're using. It changes the kanban view of subcontacts in a res.partner form to a tree. It also makes these subcontacts visible all the time (even for non-companies).
The result of this change is that you can define a deeper hierarchy: contacts can be linked to other contacts, which can be linked to other contacts, and so on. Thus, when creating a contact, you can immediately add subcontacts, which can have other subcontacts, ...

To reproduce:
1) Install the attached module
2) Start creating a new contact, let's call him 'Root contact'. (Don't save!)
3) Now, under the tab 'Contacts', click on 'Add an item', this opens another contact form.
4) Enter 'Sub contact' as a name, and click 'Save & Close'. (Don't save the 'Root contact' yet!)
5) Now from the 'Root contact' form, open the 'Sub contact' form again.
6) On the 'Sub contact' form, under the tab 'Contacts', click on 'Add an item'.

This results in the following error:
...
  File "C:\...\openerp\addons\base\res\res_partner.py", line 367, in onchange_address
    result['value'] = dict((key, value_or_id(parent[key])) for key in address_fields)
  File "C:\...\openerp\addons\base\res\res_partner.py", line 367, in <genexpr>
    result['value'] = dict((key, value_or_id(parent[key])) for key in address_fields)
  File "C:\...\openerp\addons\base\res\res_partner.py", line 354, in value_or_id
    return val if isinstance(val, (bool, int, long, float, basestring)) else val.id
AttributeError: 'NoneType' object has no attribute 'id'

As far as I can see, the following is happening:
1) When clicking 'Save & Close' to save the 'Sub Contact' (step 4), the active_id / id of the 'Sub Contact' is saved as 'one2many_v_id_xxx' on the client-side.
2) After re-opening the 'Sub Contact' and clicking on 'Add an item' (step 6), the form that opens is prefilled with some values, defined in the context of the field "child_ids" from the 'Sub Contact'. One of these values is "'parent_id': active_id". As I pointed out in the previous point, this active_id is at this point 'one2many_v_id_xxx'.
3) When prefilling the 'parent_id' value in the form, the onchange method of that field is called, which is onchange_address.
4) In the onchange method, a self.browse() is called on the parent_id. Since it's not a real id but a virtual id, this returns None. Thus, when trying to get one of the fields of the parent (from the browse object), the above exception is thrown, since obviously, the None object doesn't have the attributes we want.

OpenERP version used: 7.0-20130526-231028

** Affects: openobject-addons
     Importance: Undecided
         Status: New

** Attachment added: "test_virtual_id.zip"
   https://bugs.launchpad.net/bugs/1204478/+attachment/3747623/+files/test_virtual_id.zip

-- 
You received this bug notification because you are a member of OpenERP
Indian Team, which is subscribed to OpenERP Addons.
https://bugs.launchpad.net/bugs/1204478

Title:
  Browse on one2many_v_id_xxx in onchange fails

Status in OpenERP Addons (modules):
  New

Bug description:
  I attached a demo module showing the error.

  Content of the module:
  The demo module is a drastically simplified version from what we're using. It changes the kanban view of subcontacts in a res.partner form to a tree. It also makes these subcontacts visible all the time (even for non-companies).
  The result of this change is that you can define a deeper hierarchy: contacts can be linked to other contacts, which can be linked to other contacts, and so on. Thus, when creating a contact, you can immediately add subcontacts, which can have other subcontacts, ...

  To reproduce:
  1) Install the attached module
  2) Start creating a new contact, let's call him 'Root contact'. (Don't save!)
  3) Now, under the tab 'Contacts', click on 'Add an item', this opens another contact form.
  4) Enter 'Sub contact' as a name, and click 'Save & Close'. (Don't save the 'Root contact' yet!)
  5) Now from the 'Root contact' form, open the 'Sub contact' form again.
  6) On the 'Sub contact' form, under the tab 'Contacts', click on 'Add an item'.

  This results in the following error:
  ...
    File "C:\...\openerp\addons\base\res\res_partner.py", line 367, in onchange_address
      result['value'] = dict((key, value_or_id(parent[key])) for key in address_fields)
    File "C:\...\openerp\addons\base\res\res_partner.py", line 367, in <genexpr>
      result['value'] = dict((key, value_or_id(parent[key])) for key in address_fields)
    File "C:\...\openerp\addons\base\res\res_partner.py", line 354, in value_or_id
      return val if isinstance(val, (bool, int, long, float, basestring)) else val.id
  AttributeError: 'NoneType' object has no attribute 'id'

  As far as I can see, the following is happening:
  1) When clicking 'Save & Close' to save the 'Sub Contact' (step 4), the active_id / id of the 'Sub Contact' is saved as 'one2many_v_id_xxx' on the client-side.
  2) After re-opening the 'Sub Contact' and clicking on 'Add an item' (step 6), the form that opens is prefilled with some values, defined in the context of the field "child_ids" from the 'Sub Contact'. One of these values is "'parent_id': active_id". As I pointed out in the previous point, this active_id is at this point 'one2many_v_id_xxx'.
  3) When prefilling the 'parent_id' value in the form, the onchange method of that field is called, which is onchange_address.
  4) In the onchange method, a self.browse() is called on the parent_id. Since it's not a real id but a virtual id, this returns None. Thus, when trying to get one of the fields of the parent (from the browse object), the above exception is thrown, since obviously, the None object doesn't have the attributes we want.

  OpenERP version used: 7.0-20130526-231028

To manage notifications about this bug go to:
https://bugs.launchpad.net/openobject-addons/+bug/1204478/+subscriptions


Follow ups

References