计算每销售订单从另一个级别的奥多v8

2024-04-20 03:26:34 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要计算每个销售订单在draft状态下的所有amount_total。在

我可以通过以下操作阅读此域中的所有销售:

sale_order = fields.Many2one('sale.order', domain=[('state', '=', 'draft')], string="Sales Planned")
amount_total = fields.Float("Total Planned Sales", related="sale_order.amount_total")

但是通过这种方式,我一次只能搜索一个销售订单,然后amount_total只显示我销售的销售订单的总数。在

那么,如何读取draft状态下的所有销售订单,并在此基础上计算所有amount_total?在

有一个_amount_all函数,但我想它需要以某种方式重写。在

编辑

我的班级现在是这样的:

^{pr2}$

Tags: 订单fieldsstringdomain状态方式ordersale
1条回答
网友
1楼 · 发布于 2024-04-20 03:26:34

你没有提到创建这些字段的模型,所以我在这里猜测一下。在

你为什么不把amount_total变成computed field?在

amount_total = fields.Float("Total Planned Sales", compute="_compute_amount_total")

@api.multi
@api.depends('fields_depended_on')
def _compute_amount_total(self):
    draft_orders = self.env['sale.order'].search([('state', '=', 'draft')])
    amount_total = sum(draft_orders.mapped('amount_total'))
    for record in self:
        record.amount_total = amount_total

相关问题 更多 >