Odoo Help

Welcome!

This community 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.

1

How to set default value on a field?

By
Anirudh Lou
on 2/23/15, 10:24 PM 1,449 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

Emipro Technologies Pvt. Ltd.

--Emipro Technologies Pvt. Ltd.--
Tiny ERP Pvt Ltd
http://www.odoo.com
5975
| 6 7 8
Rajkot, India
--Emipro Technologies Pvt. Ltd.--

Being an emerging leader in IT market since 2011, Emipro Technologies Pvt. Ltd. has been providing a wide range of business solutions in Odoo & Magento. We are pleased to have a large pool of contented customers with our meticulous work in the domain of ERP & e-Commerce. A ray of relief & satisfaction to  our customers heart by our successful deployment in their organization, purely represents our success in Odoo platform. Hence, we take pride for being an Odoo partner with a vision of expanding our strategic alliances with our customers to offer them high value-added, trustworthy & cost effective solutions.

 

Since establishment, our business has span across 11 countries of the world. Our customers are companies of all sizes ranging from start-ups to large enterprises, who realize that they need a professional business solutions to generate revenue streams, establish proper communication channels or streamline business operations. Standing with strong determination of customer satisfaction, observing each minute detail of their business processes, providing proper guidance and moving forth to develop product accordingly adds our value and reliability among our customers. 

 

We are blessed with efficient, passionate & eclectic young developers who have come across almost all kinds of business profiles, working with full dedication, applying creativity & new features in existing modules and completing customer's projects successfully on predefined target. Our in-depth knowledge while giving business solutions in Odoo allows us to offer following services to our customers :

 

  • Consulting
  • Installation, Configuration & Customization
  • Training & Support
  • Maintenance
  • Upgradation
  • Documentation
  • Crafting community modules
  • Drafting videos on demand
  • Smart Apps development

We will be :) to welcome you @ www.emiprotechnologies.com to solve any kind of your business needs around Odoo. However we are just an inch away from you by email info@emiprotechnologies.com or a tweet to @EmiproTech

Emipro Technologies Pvt. Ltd.
On 2/23/15, 11:19 PM

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

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

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