Skip to Content
Menu
This question has been flagged
1 Reply
6035 Views

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

Hi, 

I am facing the same problem, followed your solution but I keep getting 

in _query
return super(SaleReportBranch, self)._query(with_clause, fields, groupby, from_clause)
TypeError: SaleReport._query() takes 1 positional argument but 5 were given

Any suggestions ?

Best Answer

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
Related Posts Replies Views Activity
2
Oct 23
6492
2
Mar 21
3411
1
May 23
7394
1
Nov 22
2389
1
Aug 21
1971