如何根据odoo 9中的关系提取名称,地址,mobile_no等所有字段

时间:2016-09-03 10:22:38

标签: odoo-9

     class Company(models.Model):
        _name="account.company.name"
        name=fields.Char(string="Company Name")
        address=fields.Text(string="Address")
        mobile_no=fields.Char(string="Mobile Number", size=10)

     and another model :

    class New(models.Model):
      _inherit ='sale.order'
      company = fields.Many2one("account.company.name")

如何在New类

中提取名称,地址,mobile_no等所有字段

2 个答案:

答案 0 :(得分:0)

如果您在新课程中选择公司作为记录,则应使用所选公司的相关字段填充其他字段。

class New(models.Model):
    _inherit ='sale.order'
    company = fields.Many2one("account.company.name")
    name=fields.Char(related='company.name',string="Company Name")
    address=fields.Text(related='company.address',string="Address")
    mobile_no=fields.Char(related='company.mobile_no',string="Mobile Number", size=10)

答案 1 :(得分:0)

(未测试的)

class NewModel(models.Model):
    _name="account.company.name"
    name=fields.Char()

class InheritedModel(models.Model):
    _inherit="sale.order"
    company_id=fields.Many2one('account.company.name")
    company_id_name=fields.Char(related='company_id.name',string="Company Name")
    company_id_name2=fields.Char(related=['company_id','name'],string="Company Name")