平板扫码绑定托盘基本完成,但还存在小问题
This commit is contained in:
@@ -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`
|
||||
// <button
|
||||
// t-on-click="onBarcodeBtnClick"
|
||||
// type="button"
|
||||
// class="btn ms-3 o_barcode"
|
||||
// tabindex="-1"
|
||||
// draggable="false"
|
||||
// aria-label="Scan barcode"
|
||||
// title="Scan barcode"
|
||||
// data-tooltip="Scan barcode"
|
||||
// />
|
||||
// `;
|
||||
// // 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`
|
||||
<div class="o_field_widget o_input o_barcode_field">
|
||||
<!-- <input class="o_input" type="text" t-att-value="value"/>-->
|
||||
<div class="o_input_container">
|
||||
<t t-raw="widget"/>
|
||||
</div>
|
||||
<button
|
||||
t-on-click="onBarcodeBtnClick"
|
||||
type="button"
|
||||
class="btn ms-3 o_barcode"
|
||||
class="sf_button o_barcode btn ms-3 o_barcode"
|
||||
tabindex="-1"
|
||||
draggable="false"
|
||||
aria-label="Scan barcode"
|
||||
title="Scan barcode"
|
||||
data-tooltip="Scan barcode"
|
||||
data-tooltip="Scan barcode"
|
||||
/>
|
||||
</div>
|
||||
`;
|
||||
// CodeField.template = 'sf_machine_connect.CodeField';
|
||||
CodeField.props = standardFieldProps;
|
||||
|
||||
// Add the field to the correct category
|
||||
registry.category("fields").add("code", CodeField);
|
||||
registry.category("fields").add("code", CodeField);
|
||||
|
||||
// style="position: relative; left: 200px;"
|
||||
Reference in New Issue
Block a user