Pular para o conteúdo
Menu
Esta pergunta foi sinalizada
1 Responder
6077 Visualizações

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
Cancelar

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 ?

Melhor resposta

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
Cancelar
Publicações relacionadas Respostas Visualizações Atividade
2
out. 23
6531
2
mar. 21
3449
1
mai. 23
7418
1
nov. 22
2444
1
ago. 21
2043