diff --git a/sf_base/static/src/js/custom_barcode_handlers.js b/sf_base/static/src/js/custom_barcode_handlers.js new file mode 100644 index 00000000..2f988d0b --- /dev/null +++ b/sf_base/static/src/js/custom_barcode_handlers.js @@ -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" + }); + } + } + }); + } +}) diff --git a/sf_base/static/src/js/remove_focus.js b/sf_base/static/src/js/remove_focus.js index 3e4cbb22..9a524360 100644 --- a/sf_base/static/src/js/remove_focus.js +++ b/sf_base/static/src/js/remove_focus.js @@ -5,9 +5,12 @@ import { registry } from '@web/core/registry'; import { formView } from '@web/views/form/form_view'; 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"; -export class RemoveFocusController extends FormController { +export class RemoveFocusFormController extends FormController { 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, - 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, }); \ No newline at end of file diff --git a/sf_manufacturing/__manifest__.py b/sf_manufacturing/__manifest__.py index 35501367..8cf16106 100644 --- a/sf_manufacturing/__manifest__.py +++ b/sf_manufacturing/__manifest__.py @@ -45,6 +45,7 @@ 'sf_manufacturing/static/src/scss/kanban_change.scss', '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/custom_barcode_handlers.js', ] }, diff --git a/sf_manufacturing/static/src/js/workpiece_delivery_wizard_confirm.js b/sf_manufacturing/static/src/js/workpiece_delivery_wizard_confirm.js index 236836ab..d7900984 100644 --- a/sf_manufacturing/static/src/js/workpiece_delivery_wizard_confirm.js +++ b/sf_manufacturing/static/src/js/workpiece_delivery_wizard_confirm.js @@ -10,7 +10,7 @@ odoo.define('sf_manufacturing.action_dispatch_confirm', function (require) { title: "确认", $content: $('
').append("请确认是否仅配送" + params.workorder_count + "个工件?"), 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 }, ], }); diff --git a/sf_manufacturing/views/mrp_workorder_view.xml b/sf_manufacturing/views/mrp_workorder_view.xml index a802266f..aefa2ac5 100644 --- a/sf_manufacturing/views/mrp_workorder_view.xml +++ b/sf_manufacturing/views/mrp_workorder_view.xml @@ -659,9 +659,9 @@ 工件配送 sf.workpiece.delivery - +
-
sf.workpiece.delivery.wizard.form.view sf.workpiece.delivery.wizard -
+ @@ -18,8 +18,8 @@ diff --git a/sf_manufacturing/wizard/workpiece_delivery_wizard.py b/sf_manufacturing/wizard/workpiece_delivery_wizard.py index 5d5dc889..67fb6035 100644 --- a/sf_manufacturing/wizard/workpiece_delivery_wizard.py +++ b/sf_manufacturing/wizard/workpiece_delivery_wizard.py @@ -180,6 +180,13 @@ class WorkpieceDeliveryWizard(models.TransientModel): self.feeder_station_destination_id = self.route_id.end_site_id.id 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') if delivery_type == '上产线': workorder = self.env['mrp.workorder'].search(