Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions pos_order_attachment_scan/models/pos_order.py
Original file line number Diff line number Diff line change
@@ -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

28 changes: 13 additions & 15 deletions pos_order_attachment_scan/static/src/js/screens.esm.js
Original file line number Diff line number Diff line change
@@ -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() {
Expand All @@ -27,7 +29,7 @@ patch(AttachmentPopup.prototype, {
}

try {
const response = await fetch(scanServerURL + "/scan", {
const response = await fetch(scanServerURL + "api/scan", {
method: "GET",
});

Expand All @@ -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."),
{
Expand All @@ -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."),
{
Expand Down
Loading