콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
3 답글
2075 화면

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!

관련 게시물 답글 화면 활동
2
3월 15
7885
0
6월 25
421
2
12월 24
1541
0
12월 24
1686
2
2월 23
2319