首页 > 其他分享 >odoo 继承(owl继承、web继承、view继承)

odoo 继承(owl继承、web继承、view继承)

时间:2024-03-29 09:33:05浏览次数:17  
标签:owl product web 继承 barcode pos import config view

owl继承

  1 /** @odoo-module */
  2 
  3 import { AbstractAwaitablePopup } from "@point_of_sale/app/popup/abstract_awaitable_popup";
  4 import { _t } from "@web/core/l10n/translation";
  5 import { onMounted, useRef, useState, onWillDestroy } from "@odoo/owl";
  6 import { Orderline } from "@point_of_sale/app/generic_components/orderline/orderline";
  7 import { OrderWidget } from "@point_of_sale/app/generic_components/order_widget/order_widget";
  8 import { omit } from "@web/core/utils/objects";
  9 import { useService } from "@web/core/utils/hooks";
 10 import { usePos } from "@point_of_sale/app/store/pos_hook";
 11 import { makeEnv } from "@web/env";
 12 
 13 
 14 // IMPROVEMENT: This code is very similar to TextInputPopup.
 15 //      Combining them would reduce the code.
 16 export class FRIDPopup extends AbstractAwaitablePopup {
 17     static template = "esale_frid.FRIDPopup";
 18     static components = {
 19         Orderline,
 20         OrderWidget,
 21     };
 22 
 23     static defaultProps = {
 24         confirmText: _t("OK"),
 25         cancelText: _t("Cancel"),
 26         clearText: _t("Clear All"),
 27         title: "RFID Reading",
 28     };
 29 
 30     static props = {
 31         data: Object,
 32         formatCurrency: Function,
 33     };
 34 
 35     get totalQty() {
 36         let sum = 0.0
 37         this.props.data.forEach(function(item) {
 38             sum += parseInt(item.qty);
 39         });
 40         return sum.toFixed(2);
 41     }
 42 
 43     /**
 44      * @param {Object} props
 45      * @param {string} props.startingValue
 46      */
 47     setup() {  // 钩子,第一次安装
 48         super.setup();
 49         this.orm = useService("orm"); // 获取orm全局状态
 50         this.pos = usePos(); // 获取pos全局状态
 51         const env = makeEnv(); // 语言、登录信息之类
 52         
 53         console.log('这里是pos的配置信息:',this.pos.config)
 54 
 55 
 56         onWillDestroy(this.onWillDestroy) // 销毁钩子
 57         onMounted(this.onMounted); // 挂载钩子
 58     }
 59 
 60     
 61     async addProductData (epc_barcode) {  // 普通方法
 62         if (this.epcList.has(epc_barcode)) {
 63             return
 64         }
 65         this.epcList.add(epc_barcode)
 66         let barcode = this.decodeEPC(epc_barcode)
 67         barcode = barcode.barcode
 68         console.log("barcode:", barcode)
 69         try {
 70             const limit = 30;
 71             const ProductIds = await this.orm.call(
 72                 "product.product",
 73                 "search",
 74                 [
 75                     [
 76                         ["barcode", "=", barcode],
 77                     ],
 78                 ],
 79                 {
 80                     offset: 0,
 81                     limit: limit,
 82                 }
 83             );
 84             console.log("ProductIds:",ProductIds)
 85             if (ProductIds.length > 0){
 86                 const product = await this.pos.db.get_product_by_id(ProductIds[0])
 87                 console.log("product:",product)
 88                 if (product) {
 89                     let pdata = {
 90                         'attributes':[],
 91                         'discount': '0',
 92                         'pack_lot_lines': false,
 93                         'price': product.lst_price.toFixed(2),
 94                         'price_without_discount': product.lst_price.toFixed(2),
 95                         'productName': product.display_name, //product.description_sale,
 96                         'product_id': ProductIds[0], //product.product_tmpl_id,
 97                         'qty': "1.00",
 98                         'unit': product.uom_id[1],
 99                         'unitPrice':product.lst_price.toFixed(2),
100                         'noDel': true,
101                         'epc_barcode': epc_barcode,
102                         "product": product,
103                     }
104                     console.log("pdata:",pdata)
105                     this.props.data.push(pdata)
106    
107                 }
108             }
109 
110         } catch (error) {
111             if (error instanceof ConnectionLostError || error instanceof ConnectionAbortedError) {
112                 return this.popup.add(OfflineErrorPopup, {
113                     title: _t("Network Error"),
114                     body: _t(
115                         "Product is not loaded. Tried loading the product from the server but there is a network error."
116                     ),
117                 });
118             } else {
119                 throw error;
120             }
121         }
122        
123     };
124 
125     onMounted() {  
126         // this.inputRef.el.focus()
127         this.epcList = new Set();
128         this.heartbeatTimer = null;
129         this.connectWebSocket(this.pos.config.rfid_url, this.pos.config.rfid_client_id,this.pos.config.rfid_room,this.pos.config.rfid_account,this.pos.config.rfid_devicename);
130         console.log('onMounted')
131     }
132 
133     onWillDestroy(){
134         clearInterval(this.heartbeatTimer);
135         this.stopRead()
136         this.socket.close();
137         console.log('onWillDestroy')
138     }
139    
140     getPayload() {
141         this.props.formatCurrency(this.props.data)
142         return "";
143     }
144 
145 }

 

web继承

 1 <?xml version="1.0" encoding="UTF-8" ?>
 2 <!-- point_of_sale_template 是固定语法 -->
 3 <template id="ClearItemIcon" inherit="point_of_sale_template" xml:space="preserve">  
 4     <t t-inherit="point_of_sale.Orderline" t-inherit-mode="extension">
 5         <xpath expr="//div[hasclass('product-price')]" position="inside">
 6             <t t-if="!line.noDel">
 7                 <i style="margin-left:6px;cursor:pointer;color:red;" id="clear_icon" class="fa fa-trash" t-on-click="clear_button_fun"/>
 8             </t>
 9 
10         </xpath>
11     </t>
12 </template>

 

view继承

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <odoo>
 3     <data>
 4 
 5         <record id="rfid_pos_config_view_form_inherit" model="ir.ui.view">
 6             <field name="name">rfid.pos.config</field>
 7             <field name="model">pos.config</field>
 8             <field name="inherit_id" ref="point_of_sale.pos_config_view_form"/>
 9             <field eval="9" name="priority"/>
10             <field name="arch" type="xml">
11                 <xpath expr="//div[@groups='base.group_system']" position="before">
12                     <group>
13                         <group>
14                             <field name="yourself_field" />
15                             
16                         </group>
17                         <group>
18                             
19                         </group>
20                     </group>
21                     
22                 </xpath>
23             </field>
24         </record>
25     </data>
26 </odoo>

注意,这三个资源在__manifest__.py中,view是配置到data中,owl和web是在assets中,如:

 1 # -*- coding: utf-8 -*-
 2 {
 3     'depends': ['base', 'point_of_sale'],
 4     'assets': {
 5         'point_of_sale._assets_pos': [
 6             'esale_frid/static/src/**/*',
 7         ],
 8     },
 9     'data': [
10         'views/pos_config_rfid.xml',
11     ],
12 
13 }

 

标签:owl,product,web,继承,barcode,pos,import,config,view
From: https://www.cnblogs.com/watermeloncode/p/18103063

相关文章

  • odoo owl 如何重写父类方法
    当你不想修改源码,又想在控件中新增自己参数的时候,你就可以这么干1/**@odoo-module*/2import{Order,Orderline}from"@point_of_sale/app/store/models";3import{patch}from"@web/core/utils/patch";45patch(Orderline.prototype,{6getDisplay......
  • FLASK学习记录-宏、模板继承
    宏{%macroname%}{%endmacro%}app.pyfromflaskimportFlask,render_templateapp=Flask(__name__)@app.route('/')defindex1():returnrender_template("macro1.html")@app.route("/")defindex2():returnrend......
  • 论文:Improving Entity Disambiguation by Reasoning over a Knowledge Base翻译笔记(通
    文章目录论文题目:通过在知识库中进行推理来改进实体消歧摘要1介绍2相关工作2.1带有知识库上下文的勃起功能障碍(ED)问题2.2基于知识图谱嵌入的ED2.3全局ED(实体解析)2.4多模块的实体识别3拟议的方法3.1任务表述3.2概述3.3提及表示3.4初始实体得分ψ~a~3.4.1实体......
  • vue extends继承后修改template的解决方案
    vueextends继承后怎么注入虚拟DOM节点1.需求使用extends继承一个组件并在上面做功能的修改和扩展,同时需要小小修改一部分的template。2.extend原理使用extends时,你实际上是创建了一个新组件,它包含了父组件的所有选项和数据,但是你可以覆盖或添加新的选项。3.问题修改通过ext......
  • svg中viewbox图解分析
     svg中有一个viewbox属性,中文翻译为视区,就是在svg上截取一小块,放大到整个svg显示。这个属性初学的话有点难以理解,这边做一个简单的示例,一看就明白了。1)先来一个svg,宽高各位300,设置一下边框:<svgwidth="300"height="300"style="border:1pxsolidsteelblue"></svg>......
  • 2-16. 实现 ListView 添加删除同步信息功能
    本节目标实现添加和删除按钮的功能代码实现项目相关代码代码仓库:https://gitee.com/nbda1121440/DreamOfTheKingdom.git标签:20240328_0913......
  • 4.列表控件的总结(ListView)
    ListView常用的属性android:divider分割线的颜色数据适配器三个BaseAdapterimplementsListAdapter,SpinnerAdapterpublicclassSimpleAdapterextendsBaseAdapterpublicclassArrayAdapter<T>extendsBaseAdapterSimpleAdapter主要是显示图片加文字的东西例如:......
  • WPF解决当ScrollViewer中嵌套ItemsControl时,不能使用鼠标来滚动翻页
    1.在DataGrid中添加PreviewMouseWheel事件,并将事件的Handled属性设置为false,以便将滚动事件传递给ScrollViewer。示例代码如下:<DataGridPreviewMouseWheel="DataGrid_PreviewMouseWheel"><!--DataGrid的其他设置--></DataGrid>privatevoidDataGrid_PreviewMouseWh......
  • Java ----- 静态、继承、引用类型使用
    面向对象最重要的两个概念:类和对象;类名的首字母大写,满足“驼峰写法”;一个Java代码文件中,可以定义多个类,但是只有一个类是public修饰的,而且public修饰的类名必须成为代码的文件名称;、类中的成分研究:类中有且仅有五大成分(五大金刚)1.成员变量(Field:描述类和对象的属性信......
  • LabVIEW智能降噪系统
    LabVIEW智能降噪系统随着噪声污染问题的日益严重,寻找有效的降噪技术变得尤为关键。介绍了一种基于LabVIEW平台开发的智能降噪系统,该系统能够实时采集环境噪声,并通过先进的信号处理技术实现主动降噪,从而有效改善生活和工作环境的噪声状况。项目背景在于,噪声污染已经成为影响人......