mirror of
https://github.com/bringout/oca-ocb-sale.git
synced 2026-04-28 02:52:01 +02:00
19.0 vanilla
This commit is contained in:
parent
79f83631d5
commit
73afc09215
6267 changed files with 1534193 additions and 1130106 deletions
|
|
@ -8,7 +8,7 @@ class SaleOrder(models.Model):
|
|||
_inherit = "sale.order"
|
||||
|
||||
margin = fields.Monetary("Margin", compute='_compute_margin', store=True)
|
||||
margin_percent = fields.Float("Margin (%)", compute='_compute_margin', store=True, group_operator="avg")
|
||||
margin_percent = fields.Float("Margin (%)", compute='_compute_margin', store=True, aggregator="avg")
|
||||
|
||||
@api.depends('order_line.margin', 'amount_untaxed')
|
||||
def _compute_margin(self):
|
||||
|
|
@ -21,11 +21,11 @@ class SaleOrder(models.Model):
|
|||
# with a single read_group query for better performance.
|
||||
# This isn't done in an onchange environment because (part of) the data
|
||||
# may not be stored in database (new records or unsaved modifications).
|
||||
grouped_order_lines_data = self.env['sale.order.line'].read_group(
|
||||
grouped_order_lines_data = self.env['sale.order.line']._read_group(
|
||||
[
|
||||
('order_id', 'in', self.ids),
|
||||
], ['margin', 'order_id'], ['order_id'])
|
||||
mapped_data = {m['order_id'][0]: m['margin'] for m in grouped_order_lines_data}
|
||||
], ['order_id'], ['margin:sum'])
|
||||
mapped_data = {order.id: margin for order, margin in grouped_order_lines_data}
|
||||
for order in self:
|
||||
order.margin = mapped_data.get(order.id, 0.0)
|
||||
order.margin_percent = order.amount_untaxed and order.margin/order.amount_untaxed
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue