How to change sum headers in group_by of a tree view into min?

Viewed 851

I need to remove the sum header of some columns that it automatically calculated for me.

I created a new tree view without inheriting any view, and have the fields like so:

. . .
<field name="model">my.purchase.order.line.inherit</field>
. . .
  . . .
  <field name="product_uom_qty"/>
  <field name="price_unit"/>
  . . .
  <field name="price_subtotal" widget="monetary"/>
  . . .
. . .

Column Sum

The main model is from purchase.order.line.

Now with the answer from CZoellner, my model is now something like this.

class purchase_order_line_inherit(models.Model):
    _name = "my.purchase.order.line.inherit"
    _inherit = "purchase.order.line"

    product_uom_qty = fields.Float(group_operator="min")

I think the system just calculated them for me but the point is that I want to change it from sum to min.

I have seen this but my fields (as shown earlier) do not have the sum attribute. I also have tried something like this but the sum headers are still there.

How can I achieve such task?

1 Answers

You can define that on field definition. In your case it would be:

my_field = fields.Float(compute="_compute_my_field", group_operator="min")

The possible operators can be found in the documentation.

group_operator (str) – aggregate function used by read_group() when grouping on this field.

Supported aggregate functions are:

array_agg : values, including nulls, concatenated into an array

count : number of rows

count_distinct : number of distinct rows

bool_and : true if all values are true, otherwise false

bool_or : true if at least one value is true, otherwise false

max : maximum value of all values

min : minimum value of all values

avg : the average (arithmetic mean) of all values

sum : sum of all values

Related