Odoo Help

1

How to set default value on a field?

By
Anirudh Lou
on 2/23/15, 10:24 PM 1,991 views

Hello everyone, does anyone can help! The case is this, in purchase.requisition i add a fields w/c is m2o on sale.shop and on purchase.requisition.line i also add field on it w/c is m2o to sale.shop also. What i am trying to do is that whenever i am going to add on line_ids i want to set it's shop_id base on purchase.requisition. Here is the chunck of my code.

class purchase_requisition_line(osv.osv):

.... 

def _get_shop(self,cr,uid,ids,context=None):
       p_id = []
       s_id = []
       data = {}
       data['form'] = self.read(cr,uid,ids,['requisition_id'])
       for rec in data['form']:
           if rec['requisition_id']:
               p_id = rec['requisition_id']
               pp_id = self.pool.get('purchase.requisition').browse(cr,uid,p_id,context=context)
               s_id = pp_id.shop_id or False
       return s_id

_defaults={

'shop_id' : _get_shop

}

Here is the error:

File "/opt/openerp/server-7/openerp/osv/orm.py", line 1581, in default_get
   defaults[f] = self._defaults[f](self, cr, uid, context)
 File "/opt/openerp/biz1_server70_addons/biz1_pcci/purchase_order.py", line 149, in _get_shop
   data['form'] = self.read(cr,uid,ids,['requisition_id'])
 File "/opt/openerp/server-7/openerp/osv/orm.py", line 3604, in read
   result = self._read_flat(cr, user, select, fields, context, load)
 File "/opt/openerp/server-7/openerp/osv/orm.py", line 3656, in _read_flat
   cr.execute(query, [tuple(sub_ids)] + rule_params)
 File "/opt/openerp/server-7/openerp/sql_db.py", line 161, in wrapper
   return f(self, *args, **kwargs)
 File "/opt/openerp/server-7/openerp/sql_db.py", line 226, in execute
   res = self._obj.execute(query, params)
DataError: invalid input syntax for integer: "lang"
LINE 1: ...tion_line" WHERE purchase_requisition_line.id IN ('lang', 't..

Any help is much appreciated.

 

1

Hi,

You just need to do one change thats it.

def _get_shop(self,cr,uid,ids,context=None):
       p_id = []
       s_id = []
       data = {}
       data['form'] = self.read(cr,uid,ids,['requisition_id'])
       for rec in data['form']:
           if rec['requisition_id']:
               p_id = rec['requisition_id']
               pp_id = self.pool.get('purchase.requisition').browse(cr,uid,p_id,context=context)
               s_id = pp_id.shop_id and pp_id.shop_id.id or False
       return s_id

I hope you will get as you want.

Edit :

In this function you will not get "ids" argument. So, you have to manage without it as like below.

def _get_shop(self,cr,uid,context=None):
       p_id = []
       s_id = []
       data = {}
       ids = context and context.get('active_ids',[])

      if ids:

       data['form'] = self.read(cr,uid,ids,['requisition_id'])
       for rec in data['form']:
           if rec['requisition_id']:
               p_id = rec['requisition_id']
               pp_id = self.pool.get('purchase.requisition').browse(cr,uid,p_id,context=context)
               s_id = pp_id.shop_id and pp_id.shop_id.id or False
       return s_id

Thanks sir for the response, i have tried your suggestion but it still point to DataError

Anirudh Lou
on 2/24/15, 12:15 AM

can you post your error log ? It is useful to resolve it.

Emipro Technologies Pvt. Ltd.
on 2/24/15, 1:42 AM

Hello I have edited my answer please have a look on that.

Emipro Technologies Pvt. Ltd.
on 2/24/15, 1:50 AM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 2/23/15, 10:24 PM
Seen: 1991 times
Last updated: 3/16/15, 8:10 AM