Odoo Help

0

string indices must be integers , many2one

By
huongcute
on 9/4/14, 11:32 PM 1,870 views

Hi everybody, I want to ask you a question. I have an error :TypeError: string indices must be integers

code .py

class danh_sach_nv(osv.Model):
    _name = 'danh.sach.nv'
    _rec_name = 'ma_nv'
    

            
    _columns = {
                       'ma_nv':fields.char('Mã NV',size=30),

                       'luong_dc':fields.related('ma_nv', 'luong_dc', type='many2one', relation='dieu.chinh', store=True, string='Lương điều chỉnh', readonly = 'True'),

                  }

class dieu_chinh(osv.Model):
    _name = 'dieu.chinh'

 _columns = {
                    'state': fields.selection([('draft', 'Draft'),('cancel', 'Cancel'),('done', 'Confirmed') ],                                       'Status',readonly=True,track_visibility='onchange'),
                   'image_nv':fields.related('ma_nv', 'image_nv',readonly = 'True', type ='binary', string = 'Ảnh đại diện'),
                   'ma_nv':fields.many2one('danh.sach.nv', 'Mã NV'),

                   'luong_dc':fields.integer('Lương điều chỉnh'),

}

 

 

Can you help me?I dont understan I have why I have an error?

Thank all

Hi huongcute you must change this line: 'luong_dc':fields.related('ma_nv', 'luong_dc', type='many2one', relation='dieu.chinh', store=True, string='Lương điều chỉnh', readonly = 'True'), instead of ma_nv you must give the class name(many2one).Thats why the error occured...Thank u

vadivel
on 9/5/14, 12:53 AM

Sorry other class's(dieu_chinh) field name

vadivel
on 9/5/14, 12:55 AM
0

Anil R. Kesariya

--Anil R. Kesariya--
5396
| 6 5 8
Rajkot, India
--Anil R. Kesariya--

Odoo Techno Functional Expert

* Engaged with odoo since May - 2012.

* Customise existing module or develop new module base on customer requirement.

* Played key developer role in many past and running projects.

* Expert in requirement gathering of business and transforming requirement into odoo platform.

* Major expertise in core modules, database, report development and theme development.

* Integration expert.


Linkedin  : https://in.linkedin.com/in/anil-kesariya-97b20a66


Anil R. Kesariya
On 9/5/14, 1:52 AM

Here you go!
You have used related field luong_dc from dieu.chinh model which is defined as integer inside, but in danh.sach.nv model as you have use as relational field you have given many2one. but field type must be same. if you are realting each other.

Hope this will helps you.

Anil.

0
--deep--

Techno-Functional Associate with 6+ years of experience in Odoo (formerly known as OpenERP).

deep
On 9/8/14, 4:21 AM

Before creating a related fields, one should have many2one field ... only then a related relation can be establised..

For example:

              'partner_id': fields.many2one('res.partner', 'Partner')

               'partner_email': fields.related('partner_id', 'email', ....)

As you can see, I have establised a relation to partner object first, then i can establish related for the same....

and also data type/property for the related field should be of target objects' column's data type...

 

0

Sudhir Arya (ERP Harbor Consulting Services)

--Sudhir Arya (ERP Harbor Consulting Services)--
11166
| 6 8 8
Ahmedabad, India
--Sudhir Arya (ERP Harbor Consulting Services)--

• Co-Founder & Co-Owner at ERP Harbor Consulting Services

• ERP Consultant / ERP Customization / TechnoFunctional Expert

• Sound knowledge in Python, Odoo (Open ERP), XML, PostgreSQL

• Domain knowledge of Sale Management, Purchase Management, Warehouse Management, Manufacturing, Multi Company Configuration & Management, HR Management, Medical Management, Construction Management, Education Management, Point of Sale, Third Party Integrations

• Positive attitude and quick Learner

• Good analytical skill, quick bug and issue tracing and find the solution

• Good knowledge and experience in payment gateway integration with Odoo

• Ready to accept new challenges

Top 10 Odoo contributor On Stackoverflow 

LinkedIn

Blog

Stackoverflow

Sudhir Arya
ERP Harbor Consulting Services
skype: 
sudhir@erpharbor.com 
Sudhir Arya (ERP Harbor Consulting Services)
On 9/5/14, 2:44 PM

In short you should define related field like this:

 'luong_dc':fields.related('ma_nv', 'luong_dc', type='integer, store=True, string='Lương điều chỉnh', readonly=True),

One more thing, readonly value should not be in string form (readonly='True'). It should be readonly=True.

You can get more idea about Related field.

0

Emipro Technologies Pvt. Ltd.

--Emipro Technologies Pvt. Ltd.--
6174
| 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 9/5/14, 12:58 AM

Hi,

There is wrong defination of the fields.related.

 _columns = {
                       'ma_nv':fields.char('Mã NV',size=30),

                       'luong_dc':fields.related('ma_nv', 'luong_dc', type='many2one', relation='dieu.chinh', store=True, string='Lương điều chỉnh', readonly = 'True'),

                  }

In the above columns you have define 'ma_nv' is 'fields.char' and then you have define 'luong_dc' as 'fields.relate' to the relation with 'ma_nv'. This is wrong, you can only relate any field with 'many2one' field. So, you have to take 'ma_nv' of 'may2one' type or you have to remove 'luong_dc' from 'fields.related' and make it 'fields.many2one'.

 

 

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

2 follower(s)

Stats

Asked: 9/4/14, 11:32 PM
Seen: 1870 times
Last updated: 3/16/15, 8:10 AM