Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
6537 Lượt xem

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

Ảnh đại diện
Huỷ bỏ

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 ?

Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 10 23
7182
2
thg 3 21
3886
1
thg 5 23
7769
1
thg 11 22
2822
1
thg 8 21
2314