odoo owl 如何重写父类方法
当你不想修改源码,又想在控件中新增自己参数的时候,你就可以这么干
1 /** @odoo-module */ 2 import { Order, Orderline } from "@point_of_sale/app/store/models"; 3 import { patch } from "@web/core/utils/patch"; 4 5 patch(Orderline.prototype, { 6 getDisplayData() { 7 /**Add the product id to update the image**/ 8 return { 9 ...super.getDisplayData(), 10 product_id: this.get_product().id, 11 12 }; 13 }, 14 15 export_as_JSON() { 16 return { 17 ...super.export_as_JSON(), 18 epc_barcode: this.epc_barcode, 19 20 }; 21 } 22 }); 23 24 // export class Orderline extends Order { 25 // setup(_defaultObj, options) { 26 // super.setup(...arguments); 27 // } 28 // } 29 30 patch(Order.prototype, { 31 set_orderline_options(orderline, options) { 32 if (options.epc_barcode !== undefined) { 33 orderline.epc_barcode = options.epc_barcode 34 } 35 super.set_orderline_options(...arguments) 36 37 } 38 39 });
或者这样操作
1 /** @odoo-module */ 2 3 import { Orderline } from "@point_of_sale/app/generic_components/orderline/orderline"; 4 import { patch } from "@web/core/utils/patch"; 5 import { useService } from "@web/core/utils/hooks"; 6 7 8 const itemRemoveOrder = { 9 setup() { 10 super.setup(); 11 this.numberBuffer = useService("number_buffer"); 12 }, 13 clear_button_fun() { 14 this.numberBuffer.sendKey("Backspace"); 15 this.numberBuffer.sendKey("Backspace"); 16 } 17 }; 18 19 patch(Orderline.prototype, itemRemoveOrder);