Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
3 Ответы
1993 Представления

I am trying to add more date ranges to the spreadsheet/dashboard filters. This worked in 16, but it does not work in 17.


import { patch } from "@web/core/utils/patch";
import { _t } from "@web/core/l10n/translation";

patch(require('@spreadsheet/helpers/constants'), {
    RELATIVE_DATE_RANGE_TYPES: [
        { type: "year_to_date", description: _t("Year to Date") },
        { type: "last_week", description: _t("Last 7 Days") },
        { type: "last_month", description: _t("Last 30 Days") },
        { type: "last_three_months", description: _t("Last 90 Days") },
        { type: "last_six_months", description: _t("Last 180 Days") },
        { type: "last_year", description: _t("Last 365 Days") },
        { type: "last_three_years", description: _t("Last 3 Years") },
        { type: "o_last_business_day", description: _t("Last Business Day") },
        { type: "o_last_week", description: _t("Last Week") },
        { type: "o_last_month", description: _t("Last Month") },
    ]
});

And I insert in the __manifest__.py after the original:

'assets': {
    'spreadsheet.o_spreadsheet': [
        ('after', 'spreadsheet/static/src/helpers/constants.js', 'spreadsheet_dates/static/src/helpers_constants.js'),
        ('after', 'spreadsheet/static/src/global_filters/helpers.js', 'spreadsheet_dates/static/src/global_filters_helpers.js'),
    ],
}

I see the patch code in the final javascript looking at the browsers code, but it does not seem to apply. (I also patched getRelativeDateDomain to support the new filters, but that does not seem to apply either. I am testing that with just a conole.log)


What am I doing wrong, any help is appreciated.

Thanks,

-Matt

Аватар
Отменить
Автор Лучший ответ

I found the issue. I need to prepend the patch files. I believe (and someone can correct me if I wrong for the next person), that odoo.define dependencies parameter will cause the module to queue until after the dependent modules are loaded. So in my case, a module that depends on '@spreadsheet/helpers/constants' was defined before the module '@spreadsheet/helpers/constants' was defined, and then loaded before my patch is loaded.

odoo.define('@spreadsheet/global_filters/components/filter_value/filter_value', ['@spreadsheet/helpers/constants' ], function() {})
odoo.define('@spreadsheet/helpers/constants', function() { RELATIVE_DATE_RANGE_TYPES  = ...)
// @spreadsheet/global_filters/components/filter_value/filter_value is now loaded with the original RELATIVE_DATE_RANGE_TYPES 
odoo.define('@spreadsheet_dates/constants', ['@spreadsheet/helpers/constants' ], function() { RELATIVE_DATE_RANGE_TYPES  = ...)
// Now my patch applies

With my module prepended:

odoo.define('@spreadsheet_dates/constants', ['@spreadsheet/helpers/constants' ], function() { RELATIVE_DATE_RANGE_TYPES  = ...)
odoo.define('@spreadsheet/global_filters/components/filter_value/filter_value', ['@spreadsheet/helpers/constants' ], function() {})
odoo.define('@spreadsheet/helpers/constants', function() { RELATIVE_DATE_RANGE_TYPES  = ...)
// Now my patch applies
// @spreadsheet/global_filters/components/filter_value/filter_value is now loaded with the patched RELATIVE_DATE_RANGE_TYPES 

 

Аватар
Отменить
Лучший ответ

It helped me also, Thank you.

Аватар
Отменить
Лучший ответ

Is it possible to give more details on your solution? I am trying to do the exact same thing as you and cannot get it to work. Are you still using patch in your final solution with your added files loaded after the source files in the manifest?

Аватар
Отменить
Автор

The files are prepended in the __manifest__.py file:
```
'assets': {
'spreadsheet.o_spreadsheet': [
('prepend', 'spreadsheet_dates/static/src/helpers_constants.js'),
('prepend', 'spreadsheet_dates/static/src/global_filters_helpers.js'),
],
}
```

Then in helpers_contants.js:
```
import { patch } from "@web/core/utils/patch";
import { _t } from "@web/core/l10n/translation";

patch(require('@spreadsheet/helpers/constants'), {
RELATIVE_DATE_RANGE_TYPES: [
{ type: "year_to_date", description: _t("Year to Date") },
{ type: "last_week", description: _t("Last 7 Days") },
{ type: "last_month", description: _t("Last 30 Days") },
{ type: "last_three_months", description: _t("Last 90 Days") },
{ type: "last_six_months", description: _t("Last 180 Days") },
{ type: "last_year", description: _t("Last 365 Days") },
{ type: "last_three_years", description: _t("Last 3 Years") },
{ type: "o_last_business_day", description: _t("Last Business Day") },
{ type: "o_last_week", description: _t("Last Week") },
{ type: "o_last_month", description: _t("Last Month") },
]
});
```

And global_filters_helpers.js
```
import { patch } from "@web/core/utils/patch";
import { serializeDate, serializeDateTime } from "@web/core/l10n/dates";
import { Domain } from "@web/core/domain";

var helpers = require('@spreadsheet/global_filters/helpers');
var _super = helpers.getRelativeDateDomain;
patch(helpers, {
getRelativeDateDomain(now, offset, rangeType, fieldName, fieldType) {
var s = _super(...arguments)
// Do stuff if _super returns none
}
});
```

I got it to work, thank you so much!

Related Posts Ответы Просмотры Активность
2
мар. 15
7815
0
июн. 25
369
2
дек. 24
1479
0
дек. 24
1625
2
февр. 23
2269