Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
1 Rispondi
2635 Visualizzazioni

Hello, in v14 I am trying to show a string "aggregate" in the group by on the front end. In the backend I defined.

category_name = fields.Char(group_operator='array_agg')

@api.model
def read_group(self, domain, fields, groupby, offset=0, limit=None, orderby=False, lazy=True):
"""
Override read_group to display the first category of each group
"""
res = super().read_group(domain, fields, groupby, offset=offset, limit=limit, orderby=orderby, lazy=lazy)
report_lines = self.env['my_module.my_model']
for line in res:
if '__domain' in line:
report_lines = self.search(line['__domain'])
if 'category_name' in fields:
line['category_name'] = report_lines[0].category_name
return res

If I go to addons/web/static/src/js/views/basic/basic_model.js

and edit the following line

const AGGREGATABLE_TYPES = ['float', 'integer', 'monetary'];

Into the following

const AGGREGATABLE_TYPES = ['float', 'integer', 'monetary', 'char'];

My view displays the aggregate type.

How can I add this functionality into my module? I have added an xml template inheritance to load my js file but that is as far as I've gotten. I cannot access the content of the original basic_model.js to do anything.

Another less elegant solution would be to override the _readGroup function and redeclare another list inside it with the types I want to use, then use that one instead. I am thinking that since we are dealing with a const, it might be necesary to work around it.

JavaScript is not my strong point and I have spent hours on this, please help me





Avatar
Abbandona
Risposta migliore

to override the const, try this :
remove the old one

registry.category("fields").remove("aggregatable_types");

and then add the new one

const AGGREGATABLE_TYPES = ['float', 'integer', 'monetary', 'char'];

registry.category("fields").add("aggregatable_types", AGGREGATABLE_TYPES);
Avatar
Abbandona
Post correlati Risposte Visualizzazioni Attività
0
mag 23
3026
1
gen 23
7834
2
giu 22
11424
3
mar 22
9499
1
dic 20
7380