链接Odoo中自动生成记录的id

Linking The id of the Automaticlly Genereated Records in Odoo

我创建了自定义模块,当用户点击按钮时自动创建日记项目。在这个自定义模块中,我有一个名为 x_move_id

的 many2one 字段
  x_move_id = fields.Many2one('account.move', string="Journal", readonly=True)

应该自动显示创建的日记帐项目的引用,类似于 account.invoice 模块,当用户验证帐单时,日记帐项目被创建并显示其 ID。

代码:

class BillOfEntry(models.Model):
  _name = 'entry.bill'
  _description = 'Bill of Entry'

name = fields.Char()
state = fields.Selection([
    ('draft', 'Draft'),
    ('sent', 'Validate'),
    ('done', 'Paid'),
    ('cancel', 'Cancelled'),
], string='BOE Status', readonly=True, copy=False, store=True, default='draft')
date = fields.Date(string="Date")
custom_agent = fields.Many2one('res.partner', string="Custom Agent")
reference = fields.Char(string="Reference")
total_customs = fields.Float(string='Total Customs', store=True, readonly=True, track_visibility='always', digits=(14, 3))
total_tax = fields.Float(string='Total Tax', store=True, readonly=True, track_visibility='always', digits=(14, 3))
inelig_tax = fields.Float(string="Ineligible Tax", store=True, readonly=True, track_visibility='always', digits=(14, 3))
total_amount = fields.Float(string='Total Amount', store=True, readonly=True, track_visibility='always', digits=(14, 3))
entry_line = fields.One2many('entry.bill.line', 'entry_ref', string="Bill of Entry Line")
input_vat = fields.Many2one('account.account', string="Input VAT")
output_vat = fields.Many2one('account.account', string="Output VAT")
customs_account = fields.Many2one('account.account', string="Customs Account")
x_move_id = fields.Many2one('account.move', string="Journal", readonly=True)

def entry_move_line(self):
    data_line = []
    line = {}
    for record in self:
        for move in record.entry_line:
            tax = move.tax_id.id
            data = (0,0, {
            'account_id': record.input_vat.id,
            'partner_id': record.custom_agent.id,
            'name': move.product_ids.name,
            'debit': 0,
            'credit': 0,
            'x_vat_code': move.vat_code_id.id,
            'tax_ids': [(6, 0, [tax])],
            })
            data_line.append(data)
            line = {
                'name': record.name,
                'date': record.date,
                'ref': record.reference,
                'line_ids': data_line,
                'journal_id': 3,
                'state': 'posted'
            }
        record.move_id.create(line)
        record.update({
            'state': 'sent'
        })




class BillOfEntry(models.Model):
_name = 'entry.bill.line'
_description = 'Bill of Entry Line'

assessable_amount = fields.Float('Assessable Amount', digits=(14, 3))
customs_amount = fields.Float('Customs + Additional Cost', digits=(14, 3))
tax_amount = fields.Float('Tax Amount', digits=(14, 3))
taxable_amount = fields.Float('Taxable Amount', digits=(14, 3))
elig_perc = fields.Float(string="ITC Eligibility %", help="Input Tax Credit Eligibility", digits=(14, 3))
vat_code_id = fields.Many2one('vat.configuration', string="VAT Code")
tax_id = fields.Many2many('account.tax', string='Taxes', domain=['|', ('active', '=', False), ('active', '=', True)])
product_ids = fields.Many2one('product.product', string="product")
inelegible = fields.Float(string="Ineleigible", digits=(14, 3))
entry_ref = fields.Many2one('entry.bill', string='Bill of Entry')

所以我的问题是如何在自定义模块中获取创建的日记项目的 (id)?

你可以这样写:

def entry_move_line(self):
    data_line = []
    line = {}
    for record in self:
        for move in record.entry_line:
            tax = move.tax_id.id
            data = (0,0, {
            'account_id': record.input_vat.id,
            'partner_id': record.custom_agent.id,
            'name': move.product_ids.name,
            'debit': 0,
            'credit': 0,
            'x_vat_code': move.vat_code_id.id,
            'tax_ids': [(6, 0, [tax])],
            })
            data_line.append(data)
            line = {
                'name': record.name,
                'date': record.date,
                'ref': record.reference,
                'line_ids': data_line,
                'journal_id': 3,
                'state': 'posted'
            }
        account_move = self.env['account.move'].create(line)
        record.write({'x_move_id':account_move.id})
        record.update({
            'state': 'sent'
        })