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.

0

filed read function error

By
huongcute
on 8/14/14, 12:26 AM 861 views

Hi all ! I defined a function. but when I used it , the message error  is : TypeError: _read() takes at least 6 arguments (4 given). 

I dont know i have an error. I need some your help.

This is my code  .py

 

 def _read(self, cr, uid, ids, field_name ,arg, context = None):
        res = {}
        obj = self.pool.get('danh.sach.nv').browse(cr, uid, ma_nv, context = context)
        ma_nvs = self.search(cr, uid, [('obj','=',ma_nv)], context=context)
        res = self.read(cr, uid, ma_nvs , ['ten_bp', 'ten_cd'])
        return { ' value' : res}

    _columns = {
                
                'ma_nv':fields.many2one('danh.sach.nv', 'Mã NV'),
                'ten_nv':fields.char( 'Tên nhân viên', size = 30),
                'ngay_sinh':fields.date('Ngày sinh'),
                'ten_bp':fields.char('Bộ phận', size = 30),
                
                'ten_cd':fields.char( 'Chức danh', size = 30),
               
                'ly_do_huy': fields.char('Lý do hủy hợp đồng', size = 100),
                'ngay_huy':fields.date('Ngày hủy'),
                
                }
    _defaults = {
                 'ten_bp': _read,
                 'ten_cd' : _read
                 }

 

 

I need  your help. 

Thanks all

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 8/14/14, 1:01 AM

Hi,

Just change the name of the function and write down as like below.

def _default_bp(self, cr, uid, context = None):   

    .... your code for bp ....

    return 'any string'

def _default_cd(self, cr, uid, context = None):    

    .... your code for cd ....

    return 'any string'

_columns = {

                'ma_nv':fields.many2one('danh.sach.nv', 'Mã NV'),
                'ten_nv':fields.char( 'Tên nhân viên', size = 30),
                'ngay_sinh':fields.date('Ngày sinh'),
                'ten_bp':fields.char('Bộ phận', size = 30),
                
                'ten_cd':fields.char( 'Chức danh', size = 30),
               
                'ly_do_huy': fields.char('Lý do hủy hợp đồng', size = 100),
                'ngay_huy':fields.date('Ngày hủy'),
                
                }
    _defaults = {
                 'ten_bp': _default_bp,
                 'ten_cd' : _default_cd
                 }

0

René Schuster

--René Schuster--
1560
| 5 5 8
Weinheim, Germany
--René Schuster--

Challenge Everything!

René Schuster
On 8/14/14, 5:09 AM

You are mixing up function fields, on_change methods and default methods.

What you try to do is setting default values with a function. The syntax for that is the one that chirag pointed out. Use it!

Further it looks like ten_bp should default to a value that has something to do with  danh.sach.nv (ma_nv), but you must not forget, that the default values will be calculated on the creation of a record. Thus there is no related ma_nv assigned to the new object yet. You can not browse a record that has not yet been created. 

0
huongcute
On 8/14/14, 4:32 AM

Thanks Chirag. But I tried it. my code .py

    def _get_bp(self, cr, uid, *args):
        try:
            proxy = self.pool.get('danh.sach.nv').browse(cr, uid, ids).ma_nv
            md = self.browse(cr, uid, ids).ma_nv
            if proxy==md :
                res['ten_bp'] = proxy.ten_bp
            return {'value': res}
        except Exception, ex:
            return False 

 

 

But it did not work. I dont know I have error. Can you help me?

hi, You have to take following things in mind. 1) In this kind of function you did not get ids. You have to fetch details without ids. 2) You have to return 'string' not Dictionary. (In your case). Can you write down your objective over here ?

Emipro Technologies Pvt. Ltd.
on 8/14/14, 5:13 AM

hi. Thanks your help. I want the value fields in class danh.sach.sv which will fill to field in class : huy.hd when two records has value to equal of value fields : ma_nv. I want to ask you a question : when I use on_change method which limit number field to load??? because when I creat 3 field then server report a error : overload???I dont understand?

huongcute
on 8/14/14, 6:08 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: 8/14/14, 12:26 AM
Seen: 861 times
Last updated: 3/16/15, 8:10 AM