【问题标题】:Retrieve the value of a field from another class Odoo 10从另一个类 Odoo 10 中检索字段的值
【发布时间】:2018-08-16 12:20:41
【问题描述】:

编辑:我想检索 Odoo 的 res.partner 类中的字段的值。如何通过函数get_importid_SmartBambi恢复这个值?

res_partner 中的字段:

importid_SmartBambi = fields.Char(string="Import_id_SmartBambi", compute='get_importid_SmartBambi', copy=False)

函数类 res.partner :

@api.one
def get_importid_SmartBambi(self):
    id_partner = self.id
    id_smart = self.env["ir.model.data"].sudo().search([('res_id', '=', id_partner), ('module', '=', 'horanet_tpa_smartbambi')])
    self.importid_SmartBambi = id_smart.name

其他类中的函数:

def create_compte_cantine(self):

    print "Inscription réussie"
    idUsager = self.env['res.partner'].get_importid_SmartBambi

    return idUsager

编辑:

我想使用已经在 res.partner 类中完成的函数get_importid_SmartBambi(self) 获得这个数字。

函数create_compte_cantine(self)在其他类中 谢谢你!

【问题讨论】:

  • 我修改了我的广告。
  • 是的,我会再编辑一些代码
  • res.partner 模型中不存在“importid_SmartBambi”字段
  • id 正在恢复,但 res.partner 模板中没有写入。将 store = True 放在这里就足够了: importid_SmartBambi = fields.Char(string="Import_id_SmartBambi", compute='get_importid_SmartBambi', copy=False, store=True)
  • 我建议你先描述你想要达到的目标,然后再描述问题?

标签: python odoo


【解决方案1】:

在您的方法create_compte_cantine 中,有一些问题需要修复。

首先,您需要使用所需的importid_SmartBambi 检索res.partner 的记录。目前,您的代码使用self.env['res.partner'],它只为您提供模型,而不是特定记录。要检索记录,请使用

the_partners = self.env['res.partner'].search(... some suitable domain...)
the_partner = the_partners[0] if len(the_partners) > 0 else None

获得所需记录后,您可以使用您定义的字段名称访问该值:

the_partner.importid_SmartBambi

【讨论】:

    猜你喜欢
    • 2019-02-28
    • 1970-01-01
    • 1970-01-01
    • 2011-07-13
    • 1970-01-01
    • 1970-01-01
    • 2022-08-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多