← Back to team overview

c2c-oerpscenario team mailing list archive

[Bug 821583] Re: function field type many2one and store=True doesn't work

 

Hello Rifakat.
In my opinion when a function field with many2one have the option store=True, the orm should read the id from the database and after link it to the object related. And if the option store=False is set it should always read it from the function.
Moreover In my case I also use the inv_fnc to set the value. 
Indeed depending of the context my field is in readonly or not, and so the user can filled the field manually so I have to read it from the database because I can not compute it as it was set manually.

You can check the code where I used it http://bazaar.launchpad.net/~akretion-team/openobject-addons/base_external_ref_error_managment/revision/5485
in the file sale

Extract of the code :

    def _get_referential_id(self, cr, uid, ids, name, args, context=None):
        res = {}
        for shop in self.browse(cr, uid, ids, context=context):
            if shop.shop_group_id:
                res[shop.id] = shop.shop_group_id.referential_id.id
            else:
                #path to fix orm bug indeed even if function field are store, the value is never read for many2one fields
                cr.execute('select referential_id from sale_shop where id=%s', (shop.id,))
                result = cr.fetchone()
                res[shop.id] = result[0]
        return res
                
    def _set_referential_id(self, cr, uid, id, name, value, arg, context=None):
        shop = self.browse(cr, uid, id, context=context)
        if shop.shop_group_id:
            raise osv.except_osv(_("User Error"), _("You can not change the referential of this shop, please change the referential of the shop group!"))
        else:
            if value == False:
                cr.execute('update sale_shop set referential_id = NULL where id=%s', (id,))
            else:
                cr.execute('update sale_shop set referential_id = %s where id=%s', (value, id))
        return True

    def _get_shop_id(self, cr, uid, ids, context=None):
        shop_ids=[]
        for group in self.pool.get('external.shop.group').browse(cr, uid, ids, context=context):
            shop_ids.append([shop.id for shop in group.shop_ids])
        return shop_ids
        

        'referential_id': fields.function(_get_referential_id, fnct_inv = _set_referential_id, type='many2one',
                relation='external.referential', string='External Referential', method=True,
                store={
                    'external.shop.group': (_get_shop_id, ['referential_id'], 10),
                 }),

As you can see I had an ugly patch to force to read into the database the value of the id when the function is call.
In the case that fnct_inv is used with store=True, we don't have the choice the orm have to read it the value from the database because the value can not be computed.

Hope my explication can help you.

Best Regards

-- 
You received this bug notification because you are a member of C2C
OERPScenario, which is subscribed to the OpenERP Project Group.
https://bugs.launchpad.net/bugs/821583

Title:
  function field type many2one and store=True doesn't work

Status in OpenERP Server:
  Triaged

Bug description:
  Hi
  I am migrating my customer from v5 to v6
  I make some imporvement for is V6 and I have a problem with the function field

  I try to create a function fields with the type many2one and the
  option store=True. The problem is that the field is still read from
  the function and never from the database. It look like the option
  store=True is never use in reading.

  exemple add this field to sale_shop

      def _get_test_id(self, cr, uid, ids, name, args, context=None):
          print 'get test'
          res={}
          for id in ids:
              res[id] = 1
          return res

          'test': fields.function(_get_test_id, type='many2one',
                  relation='product.product', string='Product', method=True,
                  store=True),

  And open the sale shop. You will see that each time the sale_shop is
  open the field test is read from the function "_get_test_id" and not
  directly from the database.

  I have this bug with the last version of openerp 6.0

  I also send a mail to the support team.
  Best Regard

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


References