تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
2 الردود
3349 أدوات العرض

Dear all,

I want to override a method in a parent class in JavaScript:

/** @odoo-module */

import { Product } from '@sale_product_configurator/js/product/product';

Product.include({
/**
* @override
*/
setQuantity() {
console.log('zzzzz');
},
});

TypeError: Product.include is not a function

Help me please. Than you very much.
الصورة الرمزية
إهمال
أفضل إجابة

Odoo 17 has new syntax, use this

/** @odoo-module */


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

import { Product } from '@sale_product_configurator/js/product/product';


patch(Product.prototype, {

/**

* @override

*/

setQuantity() {

console.log('zzzzz');

},

})



الصورة الرمزية
إهمال

This new syntax confuses me. I am trying to do something similar. My code is:

odoo.define('pkcg_appointments_customizations.CustomCalendarCommonRenderer', ['web.CalendarCommonRenderer'], function (require) {
'use strict';

const CalendarCommonRenderer = require('web.CalendarCommonRenderer');

CalendarCommonRenderer.include({
onEventRender: function (event) {
this._super.apply(this, arguments);

console.log('TESTING TESTING TESTING');
}
});
});

I am trying to override the onEventRender method to include some additional logic. Would I use the same structure as you suggest above somehow?

Last time i check, Calendar JS has been converted into Owl entirely in odoo 17, so yes you should use the same structure i suggest

الكاتب أفضل إجابة

It is done.

Thank you very much, Duong Nguyen.

Can you help me how to add a new method in an existing JS class in odoo17? (not create a new JS class)

الصورة الرمزية
إهمال

just write your method, like the code i give.
P/S can you mark my answer as best one please

Are you a dude ?

الكاتب

Thank Duong Nguyen. I am newbie, I can not vote. I am very sorry.

Ok if you need help you ask me via my facebook https://www.facebook.com/duong.messi.3/ or you can post on this forum, i need to gain more vote to get more xp

الكاتب

Hi Duong Nguyen,
I have a JS class with setup method as below:
export class ProductConfiguratorDialog extends Component {
setup() {
useSubEnv({
mainProductTmplId: this.props.productTemplateId,
currencyId: this.props.currencyId,
setQuantity: this._setQuantity.bind(this),
});
}
Now I want to inherit and add more items for useSubEnv:
useSubEnv({
setFromDate: this._setFromDate.bind(this),
setToDate: this._setToDate.bind(this),
});
How can I do?

I haven't tested it, but try to import it then write like this
ProductConfiguratorDialog.props = {
...ProductConfiguratorDialog.props,
setFromDate: this._setFromDate.bind(this),
setToDate: this._setToDate.bind(this),
};

المنشورات ذات الصلة الردود أدوات العرض النشاط
4
فبراير 25
2642
1
أغسطس 24
2218
3
أكتوبر 23
14885
2
فبراير 23
2497
1
ديسمبر 22
1371