Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
3 ตอบกลับ
15494 มุมมอง

I am trying to create one field that can be accesses thru many odoo models,  Here is the model code!


# -*- coding: utf-8 -*-

from odoo import models, fields

class code_adi(models.Model):

    _inherit=['res.currency','res.partner','product.product']

     _order='adi_code asc'

    adi_code = fields.Char(string='Code')

    _sql_constraints = [

         ('name_uniq_code', 'UNIQUE (adi_code)', 'Code must be unique.')

]

when i upgrade my module with an xml file that is empty it works for me, and i am able to see the added field in all inherited models, but once i start inheriting views and trying to access my field ('adi_code'), i get an error saying that my field does not exist. 

Thanks

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

This code is not right , You must inherit any class alone and add this field or write this field in new class and link these three classes with many2one relation with this new class

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

I'm not sure, but I guess you have to add attribute '_name'.

See this : http://www.odoo.com/documentation/9.0/reference/orm.html#inheritance-and-extension


Because class code_adi need to have own table when the class inherit from multiple classes.

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

I have no idea how to do this.

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
3
เม.ย. 20
3886
4
ก.ย. 19
4883
multiple models inherited in a class แก้ไขแล้ว
5
มิ.ย. 21
17776
Override the field from another module แก้ไขแล้ว
1
พ.ย. 19
3614
Calling two models in one model แก้ไขแล้ว
3
ธ.ค. 22
4503