通过库存上的服务器操作将销售订单合并到一张发票。挑选

问题描述 投票:0回答:1

我如何调整以下代码,以便 dat odoo 将同一客户的销售订单合并到一张发票中,就像您从 sales.orders 中的树视图中执行的那样。

for record in records:
    if record.picking_type_code == 'outgoing':
        sale_order = record.sale_id
        if sale_order:
            sale_order.action_invoice_create()
            invoices = sale_order.invoice_ids
            if invoices:
                last_invoice = invoices.sorted(key=lambda i: i.id, reverse=True)[0]
                
                last_invoice.action_invoice_open()
                error_message='FACTUUR OKE: ('+ str(last_invoice.number) +')'
                record.write({'x_error': error_message})
                
            else:
                record.write({'x_error': 'No invoices found for the sale order'})
        else:
            record.write({'x_error': 'No sale order associated with the record'})

上面的代码是模型 stock.picking 上的服务器操作。它工作正常,但为每个交货/销售订单制作单独的发票。如果可能的话,我还想调用一个 id 为 1183 的自定义服务器操作来在last_invoice上运行

odoo odoo-10 server-action
1个回答
0
投票

您必须先收集所有订单,然后对它们拨打

action_invoice_create
。 Odoo 会在此过程中对它们进行分组。它与使用列表功能非常相似。

例如:

orders = self.env["sale.order"]
for picking in records:
    if picking.picking_type_code == "outgoing":
        orders |= picking.sale_id
orders.action_invoice_create()

for order in orders:
    # do you error stuff here
© www.soinside.com 2019 - 2024. All rights reserved.