← Back to team overview

openerp-india team mailing list archive

[Bug 921543] Re: function and related fields do not store man2one value in db on create()

 

[Expired for OpenERP Server because there has been no activity for 60
days.]

** Changed in: openobject-server
       Status: Incomplete => Expired

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

Title:
  function and related fields do not store man2one value in db on
  create()

Status in OpenERP Server:
  Expired

Bug description:
  Hi folks,

  in a custom module's class I declare a function or a related field of
  type many2one, and set it to store with update instructions as

  class custom_object(osv.osv):

  [...]
  _columns = {

      'parent_object_id': fields.many2one('parent_object', 'Parent
  Object'),

      'parent_object_child_id': fields.related('parent_object_id','child_id', type="many2one", relation="parent_object.child", string="Related Parent child", store = {
                  'parent_object': (get_records_related_to_parent_object, ['child_id'], 10),
              }),

  when creating a new record of custom_object, the field
  parent_object_child_id is displayed correctly in the interface since
  the relation is always computed at read() time. But the database
  record shows that parent_object_child_id was not stored !

  if modifying the child_id in the parent_object the value of
  parent_object_child_id is updated AND stored in the database.

  I was expecting that the computed id of my parent_object_child_id
  would be stored at create() time.

  As a workaround, the only way to get it stored when creating a new
  record is to add a trigger on another local field (a required one
  insures integrity) such that my field declaration looks like this:

      'parent_object_child_id': fields.related('parent_object_id','child_id', type="many2one", relation="parent_object.child", string="Related Field", store = {
                  'custom_object': (lambda self, cr, uid, ids, c={}: ids, ['some_other_required_field'],10),
                  'parent_object': (get_records_related_to_parent_object, ['parent_field_id'], 10),
              }),

  By doing so, the computation of the related field is triggered AND
  stored at create() time (likely in a later step).

  IMHO this behavior is not correct since without this additional
  trigger, it can create a situation where a record displays correctly
  in the interface, but if you perform a search on the value of
  parent_object_child_id, no records are found because the value is not
  stored and the search executes on database records. And  I dont see
  myself writing a specific fnct_search on each and every related field
  since a project can contain many ...

  The interface displays the correct related value because it ALWAYS computes the value, no matter what is stored and that relates to this bug :
  https://bugs.launchpad.net/openobject-server/+bug/821583

  I think the correct behavior would be to trigger computation of
  related records automatically after create(). Same about functions.

  This does not seem to happen with related fields of type integer or strings.
  This behavior is the same for function fields with many2one fields.
  I did not test this with other types of relational fields like many2many, one2many, property nor with simple store=True.

  Could some experts chime in with more explanations  ?
  Tx for your time folks,
  Nicolas

  working on openerp server 6.0.3 rev 3571
  pgsql 8.4 & 9.1
  linux & mac platform

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


References