从字段 odoo 10 的同一记录中检索值

retrieve values from the same record from a field odoo 10

我想从所选字段中检索不同的值。让我解释: 我有这个 class:

class SchoolWebServices(models.Model):

    _name = 'ecole.webservices'

    name = fields.Char(string='Nom')
    code_produit = fields.Char(string='Produit')
    code_CDG = fields.Char(string='Centre de Gestion')
    code_Catalog = fields.Char(string='Catalogue Produits')

我还有这个 class:

class ResPartner_school(models.Model):

    _name = 'ecole.partner.school'
    _order = 'id desc'

    half_pension_name = fields.Many2one(comodel_name="ecole.webservices",
                                    string="Lieu")

我有一个函数在 class 中:ecole.partner.school

    @api.multi
    def create_compte_cantine(self):

        print "Inscription réussie"

        get_halfpension_name = self.half_pension_name.id


        if get_halfpension_name:

            code_Catalog = self.env['ecole.webservices'].code_Catalog

我在我的变量 get_halfpension_name 中得到了 half_pension_name 的 ID,但我也希望恢复同一录音的 code_Catalog。怎么办?

您只需要使用点符号来检索值:

@api.multi
def create_compte_cantine(self):
    self.ensure_one()
    if self.half_pension_name:
        code_Catalog = self.half_pension_name.code_Catalog

尽量留在 Odoo guideline 的 "rules"。例如 Many2one 关系字段应该以 _id -> half_pension_id = fields.Many2one(comodel_name="ecole.webservices", string="Lieu")

结尾