Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
2644 Widoki

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





Awatar
Odrzuć
Najlepsza odpowiedź

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);
Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
0
maj 23
3050
1
sty 23
7843
2
cze 22
11433
3
mar 22
9504
1
gru 20
7390