使用函数批量对账 - xiaohao0576/odoo-doc GitHub Wiki

以下代码是Odoo企业版会计模块中的一个函数, 这个函数在 account.move.line下。 使用代码选中多个需要对账的日记账条目,调用这个函数就能实现批量对账。

    def action_reconcile(self):
        """ This function is called by the 'Reconcile' button of account.move.line's
        tree view. It performs reconciliation between the selected lines.
        - If the reconciliation can be done directly we do it silently
        - Else, if a write-off is required we open the wizard to let the client enter required information
        """
        wizard = self.env['account.reconcile.wizard'].with_context(
            active_model='account.move.line',
            active_ids=self.ids,
        ).new({})
        return wizard._action_open_wizard() if wizard.is_write_off_required else wizard.reconcile()

以下代码是一个自定义开发项目中用到的,客户先开销售订单,在销售订单上登记付款,银行对账,最后才是开发票。开的发票可以使用下面的代码去自动寻找对账的项目

record.ensure_one()
if record.line_ids.sale_line_ids:
    source_orders = record.line_ids.sale_line_ids.order_id
else:
    raise UserError("此发票没有关联销售订单!")
if source_orders.x_studio_payments:
    payments_move_ids = source_orders.x_studio_payments.move_id
else:
    raise UserError("销售订单中没有找到付款记录!")
payments_move_line_ids = payments_move_ids.line_ids.filtered_domain(["&", "&", ("account_id", "in", [6,42]), ("parent_state", "=", "posted"), ("amount_residual", "!=", 0)])
invoice_move_line_ids = record.line_ids.filtered_domain(["&", "&", ("account_id", "=", 6), ("parent_state", "=", "posted"), ("amount_residual", "!=", 0)])
move_line_ids = payments_move_line_ids + invoice_move_line_ids

action = env["ir.actions.actions"]._for_xml_id("account.action_account_moves_all")
action.update({
    'view':[(False,'tree')],
    'limit': 500,
    'domain': [("id", "in", move_line_ids.ids)]
})