From 4a7369b9f0dc1c7d70f2da4b87936fdd0ea53708 Mon Sep 17 00:00:00 2001 From: kamla-dodiya Date: Wed, 17 Sep 2025 12:36:34 +0530 Subject: [PATCH] [IMP] pos_order_attachment: Enhance scan attachment flow.- Added error handling for missing or invalid Scan Server URL.- Supported both file URL and base64 image data from the scan server. --- pos_order_attachment_scan/models/pos_order.py | 17 +++++++++++ .../static/src/js/screens.esm.js | 28 +++++++++---------- 2 files changed, 30 insertions(+), 15 deletions(-) create mode 100644 pos_order_attachment_scan/models/pos_order.py diff --git a/pos_order_attachment_scan/models/pos_order.py b/pos_order_attachment_scan/models/pos_order.py new file mode 100644 index 0000000000..edcdf69c86 --- /dev/null +++ b/pos_order_attachment_scan/models/pos_order.py @@ -0,0 +1,17 @@ + +from odoo import api, models + + +class PosOrder(models.Model): + _name = "pos.order" + + # def pos_attachments(self): + # self.ensure_one() + # return self._get_mail_thread_data_attachments()._attachment_format() + + def attach_document_from_url(self, order_uid, file_url): + pass + + def attach_document(self, order_uid, image_data): + pass + diff --git a/pos_order_attachment_scan/static/src/js/screens.esm.js b/pos_order_attachment_scan/static/src/js/screens.esm.js index 032bc5fec5..c978d4d719 100644 --- a/pos_order_attachment_scan/static/src/js/screens.esm.js +++ b/pos_order_attachment_scan/static/src/js/screens.esm.js @@ -1,15 +1,17 @@ /** @odoo-module **/ -import {AttachmentPopup} from "pos_order_attachment.AttachmentPopup"; import {useService} from "@web/core/utils/hooks"; import {patch} from "@web/core/utils/patch"; -import {_t} from "web.core"; +import {_t} from "@web/core/l10n/translation"; +import {AttachmentPopup} from "@pos_order_attachment/app/utils/attachment_popup/attachment_popup.esm"; +import { usePos } from "@point_of_sale/app/store/pos_hook"; + patch(AttachmentPopup.prototype, { setup() { super.setup(); - this.pos = useService("point_of_sale"); - this.notification = useService("pos.notification"); + this.pos = usePos(); + this.notification = useService("notification"); }, async _onClickScanAttachment() { @@ -27,7 +29,7 @@ patch(AttachmentPopup.prototype, { } try { - const response = await fetch(scanServerURL + "/scan", { + const response = await fetch(scanServerURL + "api/scan", { method: "GET", }); @@ -47,11 +49,9 @@ patch(AttachmentPopup.prototype, { const scanResult = await response.json(); if (scanResult && scanResult.file_url) { - await this.pos.env.services.rpc({ - model: "pos.order", - method: "attach_document_from_url", - args: [[order.uid], scanResult.file_url, "scanned_document"], - }); + await this.orm.call("pos.order", "attach_document_from_url", [ + [order.uid], scanResult.file_url] + ); this.notification.add( _t("Document scanned and attached successfully."), { @@ -60,11 +60,9 @@ patch(AttachmentPopup.prototype, { } ); } else if (scanResult && scanResult.image_data) { - await this.pos.env.services.rpc({ - model: "pos.order", - method: "attach_document", - args: [[order.uid], "scanned_document.png", scanResult.image_data], - }); + await this.orm.call("pos.order", "attach_document", [ + [order.uid], scanResult.image_data] + ); this.notification.add( _t("Document scanned and attached successfully."), {