Help

0

Add Filter to Sales Analysis Pivot

Avatar
Bernardo

Hello, its hard to find useful and detailed documentation for Odoo, thats why i have the next question:

How can I add a custom field to the Sales Analysis dropdown filter?

I've created an inhertied report view like:
```<record id="view_order_product_search_inherit" model="ir.ui.view">

<field name="name">sale.report.search.extend</field>
<field name="model">sale.report</field>
<field name="inherit_id" ref="sale.view_order_product_search"/>
<field name="arch" type="xml">
<search>
<field name="is_paid"/>
<filter string="Is Paid" name="is_paid" context="{'group_by':'is_paid'}"/>
</search>
</field>
</record>```


And its corresponding model like:
```

class SaleReportExtended(models.Model):
_inherit = "sale.report"
is_paid = fields.Boolean(string='Is Paid?', readonly=True)

```

and the field now appears on the dropdown, but when i click on it i get:
```

psycopg2.ProgrammingError: column sale_report.is_paid does not exist
LINE 2: ...t"."price_subtotal") AS "price_subtotal",coalesce("sale_repo..

```

AFAIK the column should be added when you install the module, but looks like it isn't the case

Also I'm not sure, how should i link the `is_paid` field from the report model to the `is_paid` field from the Sale.Order


thanks

Avatar
Discard
1 Answer
1

Hi,

For adding a custom field to the Sales Analysis drop down filter, first you have to add the same custom field in the model sale.order and sale.report.
Then modify the existing query to add the new groupby feature in sales analysis.

def _query(self, with_clause='', fields={}, groupby='', from_clause=''):
fields['custom_field'] = ", s. custom_field as custom_field"
groupby += ', s.custom_field '
return super(ClassName, self)._query(with_clause, fields, groupby, from_clause)

Regards

Avatar
Discard