Created a custom field named x_brand on the Product form (product.template). I would like to include this field in the Sales → Reporting → Group By options
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Contabilidad
- Inventario
- PoS
- Project
- MRP
Se marcó esta pregunta
Hi,
To include your custom x_brand field from product.template in the Sales Reporting "Group By" options, create a custom Odoo module and inherit the sale.report model. Add x_brand as a related field, linking it to the original field on product.template using the correct data model path.
from odoo import models, fields
class SaleReport(models.Model):
_inherit = 'sale.report'
x_brand = fields.Many2one(
'product.template',
string='Brand',
readonly=True,
related='product_id.product_tmpl_id.x_brand'
)
Next, inherit the sale.sale_report_search_view and add a <filter> element to the search view, enabling grouping by x_brand. Install your custom module and clear the Odoo cache to apply the changes. This makes the x_brand field available for grouping in the Sales Reporting view.
<odoo>
<data>
<record id="sale_report_search_view_inherit_x_brand" model="ir.ui.view">
<field name="name">sale.report.search.view.inherit.x_brand</field>
<field name="model">sale.report</field>
<field name="inherit_id" ref="sale.sale_report_search_view"/>
<field name="arch" type="xml">
<xpath expr="//group/filter[last()]" position="after">
<filter string="Brand" name="brand" domain="[]" context="{'group_by': 'x_brand'}"/>
</xpath>
</field>
</record>
</data>
</odoo>
If you want to display the x_brand field directly in the Sales Report pivot view (not just as a grouping option), you'll need to inherit the sale.report.pivot view and add the field to the view's structure. This is less common, but included for completeness.
<odoo>
<data>
<record id="sale_report_pivot_view_inherit_x_brand" model="ir.ui.view">
<field name="name">sale.report.pivot.view.inherit.x_brand</field>
<field name="model">sale.report</field>
<field name="inherit_id" ref="sale.sale_report_pivot"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='product_id']" position="after">
<field name="x_brand"/>
</xpath>
</field>
</record>
</data>
</odoo>
Hope it helps
Check this video:
¿Le interesa esta conversación? ¡Participe en ella!
Cree una cuenta para poder utilizar funciones exclusivas e interactuar con la comunidad.
Inscribirse
RPC_ERROR
Odoo Server Error
Occured on localhost:8069 on model sale.report on 2025-11-11 10:20:41 GMT
Traceback (most recent call last):
File "C:\Project\odoo-18.0\odoo\http.py", line 2123, in _transactioning
return service_model.retrying(func, env=self.env)
File "C:\Project\odoo-18.0\odoo\service\model.py", line 156, in retrying
result = func()
File "C:\Project\odoo-18.0\odoo\http.py", line 2090, in _serve_ir_http
response = self.dispatcher.dispatch(rule.endpoint, args)
File "C:\Project\odoo-18.0\odoo\http.py", line 2338, in dispatch
result = self.request.registry['ir.http']._dispatch(endpoint)
File "C:\Project\odoo-18.0\odoo\addons\base\models\ir_http.py", line 333, in _dispatch
result = endpoint(**request.params)
File "C:\Project\odoo-18.0\odoo\http.py", line 754, in route_wrapper
result = endpoint(self, *args, **params_ok)
File "c:\project\odoo-18.0\addons\web\controllers\dataset.py", line 36, in call_kw
return call_kw(request.env[model], method, args, kwargs)
File "C:\Project\odoo-18.0\odoo\api.py", line 535, in call_kw
result = getattr(recs, name)(*args, **kwargs)
File "c:\project\odoo-18.0\addons\web\models\models.py", line 246, in web_read_group
groups = self._web_read_group(domain, fields, groupby, limit, offset, orderby, lazy)
File "c:\project\odoo-18.0\addons\web\models\models.py", line 272, in _web_read_group
groups = self.read_group(domain, fields, groupby, offset=offset, limit=limit,
File "C:\Project\odoo-18.0\odoo\models.py", line 2887, in read_group
rows = self._read_group(domain, annotated_groupby.values(), annotated_aggregates.values(), offset=offset, limit=limit, order=orderby)
File "C:\Project\odoo-18.0\odoo\models.py", line 2021, in _read_group
row_values = self.env.execute_query(query.select(*[groupby_terms[spec] for spec in groupby], *select_terms))
File "C:\Project\odoo-18.0\odoo\api.py", line 993, in execute_query
self.cr.execute(query)
File "C:\Project\odoo-18.0\odoo\sql_db.py", line 357, in execute
res = self._obj.execute(query, params)
psycopg2.errors.UndefinedColumn: column sale_report.x_studio_brand_1 does not exist
LINE 1: SELECT "sale_report"."x_studio_brand_1", COUNT(*), COUNT(DIS...
^
The above server error caused the following client error:
RPC_ERROR: Odoo Server Error
RPC_ERROR
at makeErrorFromResponse (http://localhost:8069/web/assets/afab0df/web.assets_web.min.js:3148:163)
at XMLHttpRequest.<anonymous> (http://localhost:8069/web/assets/afab0df/web.assets_web.min.js:3153:13)