Odoo Help
Odoo is the world's easiest all-in-one management software. It includes hundreds of business apps:
CRM
|
e-Commerce
|
Accounting
|
Inventory
|
PoS
|
Project management
|
MRP
|
etc.
string indices must be integers , many2one
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
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...
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.
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.
RegisterOdoo Training Center
Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.
Test it nowQuestion tools
Stats
Asked: 9/4/14, 11:32 PM |
Seen: 1990 times |
Last updated: 3/16/15, 8:10 AM |
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
Sorry other class's(dieu_chinh) field name