我想创建一个虚拟 Many2many
字段,仅供参考。是否可以在不存储生成的虚拟记录的情况下计算和填充Many2many
字段?
答案 0 :(得分:0)
是,可以创建Virtual Many2many字段以供参考。请参阅以下示例代码
@api.one
@api.depends(
'move_id.line_id.account_id',
'move_id.line_id.reconcile_id.line_id',
'move_id.line_id.reconcile_partial_id.line_partial_ids',
)
def _compute_move_lines(self):
# Give Journal Items related to the payment reconciled to this invoice.
# Return partial and total payments related to the selected invoice.
self.move_lines = self.env['account.move.line']
if not self.move_id:
return
data_lines = self.move_id.line_id.filtered(lambda l: l.account_id == self.account_id)
partial_lines = self.env['account.move.line']
for data_line in data_lines:
if data_line.reconcile_id:
lines = data_line.reconcile_id.line_id
elif data_line.reconcile_partial_id:
lines = data_line.reconcile_partial_id.line_partial_ids
else:
lines = self.env['account.move.line']
partial_lines += data_line
self.move_lines = lines - partial_lines
move_lines = fields.Many2many('account.move.line', string='Entry Lines',
compute='_compute_move_lines')
您可以在odoo插件的 /addons/account/account_invoice.py 文件中看到上述示例。