我使用One2many字段扩展了'account.analytic.account'模型,该字段引用了具有One2many字段的第二个模型.
当我尝试从compute方法迭代第二个One2many字段时,它只列出刚刚添加的记录.在保存父记录之前,先前的记录(在界面上可见)在使用"自我"上下文的代码中不可见.
例:
for line in self.One2manyField:
#only gets here for records I add during current session, or all records if parent is saved
#how can I see previously saved records?
Run Code Online (Sandbox Code Playgroud)
这是代码:
1.)扩展'account.analytic.account'模型
class account_analytic_account(models.Model):
_inherit = ['account.analytic.account']
service_location_ids = fields.One2many(comodel_name='contract.service.location', inverse_name='contract_id', copy=True)
Run Code Online (Sandbox Code Playgroud)
2.)首先引用One2many模型:
class Contract_Service_Location(models.Model):
_name = 'contract.service.location'
_description = 'Service Location Record'
#problem is here!
#compute method for subtotal field
@api.one
@api.depends('recurring_line_ids','recurring_line_ids.price_subtotal')
def _compute_subtotal(self):
total = 0.0
#I tried to get previously saved ids, but returns nothing, until …Run Code Online (Sandbox Code Playgroud)