Odoo合并2个整数字段

2024-09-28 05:24:50 发布

您现在位置:Python中文网/ 问答频道 /正文

如何将字段中的两个整数合并到一个字段中

Ex

work1_name = fields.Many2one('work1.model',string='Work1 Name')
field1 = fields.Integer(related='work1_name.work1_id',string='Work1 ID')

work2_name = fields.Many2one('work2.model',string='Work2 Name')
field2 = fields.Integer(related='work2_name.work2_id',string='Work2 ID')

需要获取field3=field1&;的值;字段2

如果字段1=12和字段2=20,则字段3=1220


尝试了此操作,但出现错误:

    @api.depends("field1","field2")
    def _comp_bondid(self):
        self.bondid = (self.field1 or "")+" "+(self.field2 or "")

    bondid = fields.Char(compute="_comp_bondid", store=True)  

感谢您的帮助<;三,


Tags: nameselffieldsstringmodelintegerrelatedfield2
1条回答
网友
1楼 · 发布于 2024-09-28 05:24:50

更新修复

旧的

@api.depends("field1","field2")
def _comp_bondid(self):
    self.bondid = (self.field1 or "")+" "+(self.field2 or "")

bondid = fields.Char(compute="_comp_bondid", store=True)  

新建:(在self.fields之前添加str)

 @api.depends("field1","field2")
 def _comp_bondid(self):
     self.bondid = str(self.field1 or "")+" "+str(self.field2 or "")
    
 bondid = fields.Char(compute="_comp_bondid", store=True)  

相关问题 更多 >

    热门问题