From c2a22b5ac74a9f387e5e7b9b058dafa83eccab7d Mon Sep 17 00:00:00 2001 From: mgw <1392924357@qq.com> Date: Wed, 12 Apr 2023 17:43:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B9=B3=E6=9D=BF=E6=89=AB=E7=A0=81=E7=BB=91?= =?UTF-8?q?=E5=AE=9A=E6=89=98=E7=9B=98=E5=9F=BA=E6=9C=AC=E5=AE=8C=E6=88=90?= =?UTF-8?q?=EF=BC=8C=E4=BD=86=E8=BF=98=E5=AD=98=E5=9C=A8=E5=B0=8F=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_machine_connect/static/src/js/test.js | 212 +++++++++++++++++++++-- 1 file changed, 193 insertions(+), 19 deletions(-) diff --git a/sf_machine_connect/static/src/js/test.js b/sf_machine_connect/static/src/js/test.js index 1f1c1d58..9744a786 100644 --- a/sf_machine_connect/static/src/js/test.js +++ b/sf_machine_connect/static/src/js/test.js @@ -1,3 +1,85 @@ +// /** @odoo-module **/ +// +// import { browser } from "@web/core/browser/browser"; +// import { Dialog } from "@web/core/dialog/dialog"; +// import { _lt } from "@web/core/l10n/translation"; +// import { useChildRef, useOwnedDialogs, useService } from "@web/core/utils/hooks"; +// import { sprintf } from "@web/core/utils/strings"; +// import { isMobileOS } from "@web/core/browser/feature_detection"; +// import * as BarcodeScanner from "@web/webclient/barcode/barcode_scanner"; +// +// const {xml, Component} = owl; +// import { standardFieldProps } from "@web/views/fields/standard_field_props"; +// // Import the registry +// import {registry} from "@web/core/registry"; +// +// +// export class CodeField extends Component { +// setup() { +// super.setup(); +// } +// async onBarcodeBtnClick() { +// const barcode = await BarcodeScanner.scanBarcode(); +// if (barcode) { +// await this.onBarcodeScanned(barcode); +// if ("vibrate" in browser.navigator) { +// browser.navigator.vibrate(100); +// } +// } else { +// this.notification.add(this.env._t("Please, scan again !"), { +// type: "warning", +// }); +// } +// } +// async search(barcode) { +// const results = await this.orm.call("sf.tray", "name_search", [code], { +// name: barcode, +// args: this.getDomain(), +// operator: "ilike", +// limit: 2, // If one result we set directly and if more than one we use normal flow so no need to search more +// context: this.context, +// }); +// return results.map((result) => { +// const [id, displayName] = result; +// return { +// id, +// name: displayName, +// }; +// }); +// } +// async onBarcodeScanned(barcode) { +// const results = await this.search(barcode); +// const records = results.filter((r) => !!r.id); +// if (records.length === 1) { +// this.update([{ id: records[0].id, name: records[0].name }]); +// } else { +// const searchInput = this.autocompleteContainerRef.el.querySelector("input"); +// searchInput.value = barcode; +// searchInput.dispatchEvent(new Event("input")); +// if (this.env.isSmall) { +// searchInput.click(); +// } +// } +// } +// } +// +// CodeField.template = xml` +// +// `; +// // CodeField.template = 'sf_machine_connect.CodeField'; +// CodeField.props = standardFieldProps; +// +// // Add the field to the correct category +// registry.category("fields").add("code", CodeField); /** @odoo-module **/ import { browser } from "@web/core/browser/browser"; @@ -17,41 +99,125 @@ import {registry} from "@web/core/registry"; export class CodeField extends Component { setup() { super.setup(); + this.orm = this.env.services.orm; + this.record = this.props.record; } - async onBarcodeBtnClick() { + // get domain() { + // return this.props.record.getFieldDomain(this.props.name); + + async onBarcodeBtnClick() { + // console.log(BarcodeScanner) const barcode = await BarcodeScanner.scanBarcode(); + // console.log(typeof barcode) + // alert(barcode) + if (barcode) { - await this.onBarcodeScanned(barcode); + // console.log("存在") + // alert('存在') + await this.onBarcodeScanned(barcode); if ("vibrate" in browser.navigator) { browser.navigator.vibrate(100); } } else { + // console.log("不存在") + // alert('不存在') this.notification.add(this.env._t("Please, scan again !"), { type: "warning", }); } } async search(barcode) { - const results = await this.orm.call("sf.tray", "name_search", [code], { - name: barcode, - args: this.getDomain(), - operator: "ilike", - limit: 2, // If one result we set directly and if more than one we use normal flow so no need to search more - context: this.context, - }); + alert('我是search') + const domain = [["code", "=", barcode]]; + // const domain = []; + console.log(domain) + alert('走到这里了') + const fields = ["id", "code", "name", "state"]; + console.log(fields) + alert('走到这里了1') + const results = await this.orm.call("sf.tray", "search_read", [domain, fields]); + const values = await this.orm.call("sf.tray", "search_read", [domain]); + console.log(results) + alert('走到这里了2') return results.map((result) => { - const [id, displayName] = result; - return { - id, - name: displayName, - }; - }); + return { + id: result.id, + code: result.code, + name: result.name, + state: result.state, + values: values, + }; + }); } async onBarcodeScanned(barcode) { + // alert('我是ONbarcodeScanned') const results = await this.search(barcode); + console.log(results) const records = results.filter((r) => !!r.id); + console.log(records) if (records.length === 1) { - this.update([{ id: records[0].id, name: records[0].name }]); + if (records[0].state === '空闲') { + // const currentModel = this.env.models['mrp.workorder']; + console.log('currentModel',this) + console.log('this.record.data',this.record.data) + // const recordID = this.controllerParams.recordID; + // console.log('当前页面记录 ID:', recordID); + // console.log('this.record',this.record.id) + // console.log('this.record',this.controllerParams.recordID) + // const workorder = await this.orm.call('mrp.workorder', 'read', [this.record.data.id, ['id']]); + console.log('this.record.data.id', this.record.data.id) + const workorder = await this.orm.call('mrp.workorder', 'read', [this.record.data.id]); + console.log('workorder', workorder[0]) + const updatedRecord = await this.orm.call("sf.tray", "write", [ + [records[0].id], + { + // state: "占用", + workorder_id: workorder[0].id, + production_id: workorder[0].product_id[0], + // workorder_id: workorder.id, + }]); + console.log(workorder[0].routing_type); + console.log(workorder[0].production_id); + // const productionIDS = await this.orm.call('mrp.production', 'search', [[['id', '=', workorder[0].production_id[0]]]]); + const productionIDS = await this.orm.call('mrp.workorder', 'search', [[["production_id", "=", workorder[0].production_id[0]]]]); + console.log('prooooooo', productionIDS); + console.log('values', records[0].values[0]); + productionIDS.forEach(async (data) => { + // 处理每一个数据 + console.log(data); + const updatetrayRecord = await this.orm.call("mrp.workorder", "write", [ + [data], + { + tray_id: records[0].values[0].id, + // tray_id: false, + }]); + console.log(updatetrayRecord) + }); + // this.trigger_up('reload') + // this.props.update(records[0].code, records[0].values); + this.props.update(records[0].code, records[0].tray_id); + // this.trigger_up('button_clicked', { + // attrs: { + // name: 'save', + // }, + // }); + // this.do_action({ + // 'type': 'ir.actions.act_window', + // 'res_model': 'mrp.workorder', + // 'view_mode': 'form', + // 'view_type': 'form', + // 'res_id': workorder[0].id, + // 'target': 'current', + // }) + } else { + if (records[0].state === '占用') { + console.log('此托盘已占用,请检查') + alert('此托盘已占用,请检查') + } else { + console.log('此托盘已损坏,请登记') + } + } + } else { const searchInput = this.autocompleteContainerRef.el.querySelector("input"); searchInput.value = barcode; @@ -64,19 +230,27 @@ export class CodeField extends Component { } CodeField.template = xml` +
`; // CodeField.template = 'sf_machine_connect.CodeField'; CodeField.props = standardFieldProps; // Add the field to the correct category -registry.category("fields").add("code", CodeField); \ No newline at end of file +registry.category("fields").add("code", CodeField); + +// style="position: relative; left: 200px;" \ No newline at end of file