Perform Operations Like Sum/Average On The ListView In Odoo
Tree View, also known as ListView shows multiple records in the form of a list (rows and columns). Each row represents a record of the database table.
Tree View is used to show important data, i.e. only some important columns of the model/table. You can do various operations on Tree view that is sorting, filter, and group by.
Quotes can be thought of as a "presentation layer" of an Opportunity in that a user can create a PDF of the Quote and email it to a Contact straight from Sales.
The total amount of the cost of goods or services billed to a customer, usually covering purchases made or services rendered within a specified period are present at the end of each quotation.
The total is present at the end of the quotation in the form view. This total is of a single quotation.
But what if we want the total of all the quotations so far at the end of the list/tree view. Or if we want the total of all the invoices or if we want the total of any number of records. How to achieve that?
We can do so by using this simple syntax –
<field name=”amount_total”sum=”Total Tax included” widget=”monetary”
In the above code,
amount_total= name of the field whose aggregate is to be calculated
sum = name of the attribute
widget = use for displaying the currency symbol
You can use any field you want to calculate the total of and not only just total, but you can also perform various other attributes on the tree view.
You can calculate the total of a field or average value of a field in all the records etc.
Just specify the attribute you want to use, for example:
- sum for total
- avg for calculating the average
- min for the minimum value
- max for maximum value
Using this in the tree view would give you the total amount of all the records in that tree view.
We can use this attribute anywhere to calculate the aggregate at the end of any tree view of the total. In this example, we have to use the sum attribute on the total shown at the end of all the records/quotation.
You can see the code here:
Just make sure you use the field and
its attribute correctly in the tree view.
Have a query related to above-mentioned tips feel free to ask in Comment Section. We try our best to help as much as we can.
If you are looking for an Odoo Consulting Services Provider for your projects, Contact Kanakinfosystems LLP as we are provided
best Odoo Open ERP Solution to our global clients.
In case if you want our services Contact Us via fill the form or directly Call us @ +91-9818211679 or Email at - firstname.lastname@example.org