Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
1 Відповісти
6093 Переглядів

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

Аватар
Відмінити

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 ?

Найкраща відповідь

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

Аватар
Відмінити
Related Posts Відповіді Переглядів Дія
2
жовт. 23
6549
2
бер. 21
3459
1
трав. 23
7425
1
лист. 22
2449
1
серп. 21
2045