扫码触发按键功能
This commit is contained in:
60
sf_base/static/src/js/custom_barcode_handlers.js
Normal file
60
sf_base/static/src/js/custom_barcode_handlers.js
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
/** @odoo-module **/
|
||||||
|
|
||||||
|
import { registry } from "@web/core/registry";
|
||||||
|
import { barcodeGenericHandlers } from '@barcodes/barcode_handlers';
|
||||||
|
import { patch } from "@web/core/utils/patch";
|
||||||
|
|
||||||
|
// 定义新的 clickOnButton 函数
|
||||||
|
function customClickOnButton(selector) {
|
||||||
|
console.log("This is the custom clickOnButton function!");
|
||||||
|
|
||||||
|
const buttons = document.body.querySelectorAll(selector);
|
||||||
|
|
||||||
|
let length = buttons.length;
|
||||||
|
if (length > 0) {
|
||||||
|
buttons[length - 1].click();
|
||||||
|
} else {
|
||||||
|
console.warn(`Button with selector ${selector} not found`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
patch(barcodeGenericHandlers, "start", {
|
||||||
|
start(env, { ui, barcode, notification }) {
|
||||||
|
// 使用新定义的 clickOnButton 函数
|
||||||
|
const COMMANDS = {
|
||||||
|
"O-CMD.EDIT": () => customClickOnButton(".o_form_button_edit"),
|
||||||
|
"O-CMD.DISCARD": () => customClickOnButton(".o_form_button_cancel"),
|
||||||
|
"O-CMD.SAVE": () => customClickOnButton(".o_form_button_save"),
|
||||||
|
"O-CMD.PREV": () => customClickOnButton(".o_pager_previous"),
|
||||||
|
"O-CMD.NEXT": () => customClickOnButton(".o_pager_next"),
|
||||||
|
"O-CMD.PAGER-FIRST": () => updatePager("first"),
|
||||||
|
"O-CMD.PAGER-LAST": () => updatePager("last"),
|
||||||
|
"O-CMD.CONFIRM": () => customClickOnButton(".jikimo_button_confirm"),
|
||||||
|
|
||||||
|
barcode.bus.addEventListener("barcode_scanned", (ev) => {
|
||||||
|
const barcode = ev.detail.barcode;
|
||||||
|
if (barcode.startsWith("O-BTN.")) {
|
||||||
|
let targets = [];
|
||||||
|
try {
|
||||||
|
targets = getVisibleElements(ui.activeElement, `[barcode_trigger=${barcode.slice(6)}]`);
|
||||||
|
} catch (_e) {
|
||||||
|
console.warn(`Barcode '${barcode}' is not valid`);
|
||||||
|
}
|
||||||
|
for (let elem of targets) {
|
||||||
|
elem.click();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (barcode.startsWith("O-CMD.")) {
|
||||||
|
const fn = COMMANDS[barcode];
|
||||||
|
if (fn) {
|
||||||
|
fn();
|
||||||
|
} else {
|
||||||
|
notification.add(env._t("Barcode: ") + `'${barcode}'`, {
|
||||||
|
title: env._t("Unknown barcode command"),
|
||||||
|
type: "danger"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})
|
||||||
@@ -5,9 +5,12 @@ import { registry } from '@web/core/registry';
|
|||||||
import { formView } from '@web/views/form/form_view';
|
import { formView } from '@web/views/form/form_view';
|
||||||
import { FormController } from '@web/views/form/form_controller';
|
import { FormController } from '@web/views/form/form_controller';
|
||||||
|
|
||||||
|
import { listView } from '@web/views/list/list_view';
|
||||||
|
import { ListController } from '@web/views/list/list_controller'
|
||||||
|
|
||||||
import { onRendered, onMounted } from "@odoo/owl";
|
import { onRendered, onMounted } from "@odoo/owl";
|
||||||
|
|
||||||
export class RemoveFocusController extends FormController {
|
export class RemoveFocusFormController extends FormController {
|
||||||
setup() {
|
setup() {
|
||||||
super.setup();
|
super.setup();
|
||||||
|
|
||||||
@@ -17,7 +20,23 @@ export class RemoveFocusController extends FormController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
registry.category('views').add('remove_focus_view', {
|
registry.category('views').add('remove_focus_form_view', {
|
||||||
...formView,
|
...formView,
|
||||||
Controller: RemoveFocusController,
|
Controller: RemoveFocusFormController,
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
export class RemoveFocusListController extends ListController {
|
||||||
|
setup() {
|
||||||
|
super.setup();
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
this.__owl__.bdom.el.querySelectorAll(':focus').forEach(element => element.blur());
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
registry.category('views').add('remove_focus_list_view', {
|
||||||
|
...listView,
|
||||||
|
Controller: RemoveFocusListController,
|
||||||
});
|
});
|
||||||
@@ -45,6 +45,7 @@
|
|||||||
'sf_manufacturing/static/src/scss/kanban_change.scss',
|
'sf_manufacturing/static/src/scss/kanban_change.scss',
|
||||||
'sf_manufacturing/static/src/xml/button_show_on_tree.xml',
|
'sf_manufacturing/static/src/xml/button_show_on_tree.xml',
|
||||||
'sf_manufacturing/static/src/js/workpiece_delivery_wizard_confirm.js',
|
'sf_manufacturing/static/src/js/workpiece_delivery_wizard_confirm.js',
|
||||||
|
'sf_manufacturing/static/src/js/custom_barcode_handlers.js',
|
||||||
]
|
]
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ odoo.define('sf_manufacturing.action_dispatch_confirm', function (require) {
|
|||||||
title: "确认",
|
title: "确认",
|
||||||
$content: $('<div>').append("请确认是否仅配送" + params.workorder_count + "个工件?"),
|
$content: $('<div>').append("请确认是否仅配送" + params.workorder_count + "个工件?"),
|
||||||
buttons: [
|
buttons: [
|
||||||
{ text: "确认", classes: 'btn-primary', close: true, click: () => dispatchConfirmed(parent, params) },
|
{ text: "确认", classes: 'btn-primary jikimo_button_confirm', close: true, click: () => dispatchConfirmed(parent, params) },
|
||||||
{ text: "取消", close: true },
|
{ text: "取消", close: true },
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -659,9 +659,9 @@
|
|||||||
<field name="name">工件配送</field>
|
<field name="name">工件配送</field>
|
||||||
<field name="model">sf.workpiece.delivery</field>
|
<field name="model">sf.workpiece.delivery</field>
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<tree string="工件配送" class="center" create="0" delete="0">
|
<tree string="工件配送" class="center" create="0" delete="0" js_class="remove_focus_list_view">
|
||||||
<header>
|
<header>
|
||||||
<button name="button_delivery" type="object" string="工件配送" class="btn-primary" attrs="{'force_show':1}"/>
|
<button name="button_delivery" type="object" string="工件配送" class="btn-primary jikimo_button_confirm" attrs="{'force_show':1}"/>
|
||||||
</header>
|
</header>
|
||||||
<field name="status" widget="badge"
|
<field name="status" widget="badge"
|
||||||
decoration-success="status == '已配送'"
|
decoration-success="status == '已配送'"
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
<field name="name">sf.workpiece.delivery.wizard.form.view</field>
|
<field name="name">sf.workpiece.delivery.wizard.form.view</field>
|
||||||
<field name="model">sf.workpiece.delivery.wizard</field>
|
<field name="model">sf.workpiece.delivery.wizard</field>
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<form js_class="remove_focus_view">
|
<form js_class="remove_focus_form_view">
|
||||||
<sheet>
|
<sheet>
|
||||||
<field name="delivery_ids" invisible="True"/>
|
<field name="delivery_ids" invisible="True"/>
|
||||||
<field name="workorder_ids" invisible="True"/>
|
<field name="workorder_ids" invisible="True"/>
|
||||||
@@ -18,8 +18,8 @@
|
|||||||
<field name="workcenter_id" options="{'no_create': True}"/>
|
<field name="workcenter_id" options="{'no_create': True}"/>
|
||||||
</group>
|
</group>
|
||||||
<footer>
|
<footer>
|
||||||
<button string="确认配送" name="dispatch_confirm" type="object" class="oe_highlight o_wizard_confirm_button" attrs="{'invisible': [('confirm_button', '!=', '确认配送')]}"/>
|
<button string="确认配送" name="dispatch_confirm" type="object" class="oe_highlight o_wizard_confirm_button jikimo_button_confirm" attrs="{'invisible': [('confirm_button', '!=', '确认配送')]}"/>
|
||||||
<button string="确认解除" name="dispatch_confirm" type="object" class="oe_highlight o_wizard_confirm_button" attrs="{'invisible': [('confirm_button', '!=', '确认解除')]}"/>
|
<button string="确认解除" name="dispatch_confirm" type="object" class="oe_highlight o_wizard_confirm_button jikimo_button_confirm" attrs="{'invisible': [('confirm_button', '!=', '确认解除')]}"/>
|
||||||
<button string="取消" class="btn btn-secondary" special="cancel"/>
|
<button string="取消" class="btn btn-secondary" special="cancel"/>
|
||||||
</footer>
|
</footer>
|
||||||
</sheet>
|
</sheet>
|
||||||
|
|||||||
@@ -180,6 +180,13 @@ class WorkpieceDeliveryWizard(models.TransientModel):
|
|||||||
self.feeder_station_destination_id = self.route_id.end_site_id.id
|
self.feeder_station_destination_id = self.route_id.end_site_id.id
|
||||||
|
|
||||||
def on_barcode_scanned(self, barcode):
|
def on_barcode_scanned(self, barcode):
|
||||||
|
# 判断barcode是否是数字
|
||||||
|
if not barcode.isdigit():
|
||||||
|
# 判断是否是AGV接驳站名称
|
||||||
|
agv_site = self.env['sf.agv.site'].search([('name', '=', barcode)])
|
||||||
|
if agv_site:
|
||||||
|
self.feeder_station_start_id = agv_site.id
|
||||||
|
return
|
||||||
delivery_type = self.env.context.get('default_delivery_type')
|
delivery_type = self.env.context.get('default_delivery_type')
|
||||||
if delivery_type == '上产线':
|
if delivery_type == '上产线':
|
||||||
workorder = self.env['mrp.workorder'].search(
|
workorder = self.env['mrp.workorder'].search(
|
||||||
|
|||||||
Reference in New Issue
Block a user