Skip to Content
Menu
This question has been flagged
2 Replies
1954 Views

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.
Avatar
Discard
Best Answer

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');

},

})



Avatar
Discard

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

Author Best Answer

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)

Avatar
Discard

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

Are you a dude ?

Author

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

Author

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),
};

Related Posts Replies Views Activity
4
Feb 25
600
1
Aug 24
1159
3
Oct 23
13917
2
Feb 23
1761
1
Dec 22
1371