diff --git a/account_supplier_portal/__init__.py b/account_supplier_portal/__init__.py new file mode 100644 index 00000000000..e046e49fbe2 --- /dev/null +++ b/account_supplier_portal/__init__.py @@ -0,0 +1 @@ +from . import controllers diff --git a/account_supplier_portal/__manifest__.py b/account_supplier_portal/__manifest__.py new file mode 100644 index 00000000000..537613f4d27 --- /dev/null +++ b/account_supplier_portal/__manifest__.py @@ -0,0 +1,14 @@ +{ + "name": "Supplier Portal", + "application": False, + "installable": True, + "author": "sngoh", + "depends": ["base", "website", "account"], + "auto_install": True, + "license": "LGPL-3", + "data": [ + "data/supplier_portal_data.xml", + "views/portal_templates.xml", + "views/account_supplier_portal_view.xml", + ], +} diff --git a/account_supplier_portal/controllers/__init__.py b/account_supplier_portal/controllers/__init__.py new file mode 100644 index 00000000000..12a7e529b67 --- /dev/null +++ b/account_supplier_portal/controllers/__init__.py @@ -0,0 +1 @@ +from . import main diff --git a/account_supplier_portal/controllers/main.py b/account_supplier_portal/controllers/main.py new file mode 100644 index 00000000000..1ee6ec04739 --- /dev/null +++ b/account_supplier_portal/controllers/main.py @@ -0,0 +1,75 @@ +import base64 + +from odoo import http +from odoo.http import request + + +class SupplierPortalController(http.Controller): + @http.route( + "/my/supplier/upload_bill", + type="http", + auth="public", + methods=["get"], + website=True, + ) + def supplierPortal(self): + user = request.env.user + + return request.render( + "account_supplier_portal.account_supplier_portal_view", + { + "allowed_companies": user.partner_id.parent_id, + }, + ) + + @http.route( + "/my/supplier/upload_bill", + type="http", + auth="public", + methods=["post"], + website=True, + ) + def submitBill(self, **kwargs): + + partner_id = int(kwargs.get("partner_id")) + pdf_file = kwargs.get("pdf_file") + xml_file = kwargs.get("xml_file") + + bill_vals = { + "move_type": "in_invoice", # Inbound Vendor Bill + "state": "draft", + "partner_id": partner_id, + } + new_bill = request.env["account.move"].sudo().create(bill_vals) + + attachments_to_create = [] + + if pdf_file: + attachments_to_create.append( + { + "name": pdf_file.filename, + "datas": base64.b64encode(pdf_file.read()), + "res_model": "account.move", + "res_id": new_bill.id, + } + ) + + if xml_file: + attachments_to_create.append( + { + "name": xml_file.filename, + "datas": base64.b64encode(xml_file.read()), + "res_model": "account.move", + "res_id": new_bill.id, + } + ) + + if attachments_to_create: + request.env["ir.attachment"].sudo().create(attachments_to_create) + + new_bill.sudo().message_post( + body="Vendor Bill submitted via Supplier Portal.", + attachment_ids=[att.id for att in new_bill.attachment_ids], + ) + + return request.redirect("/supplier-portal-bill-added") diff --git a/account_supplier_portal/data/supplier_portal_data.xml b/account_supplier_portal/data/supplier_portal_data.xml new file mode 100644 index 00000000000..cde0769ba56 --- /dev/null +++ b/account_supplier_portal/data/supplier_portal_data.xml @@ -0,0 +1,45 @@ + + + + + Bill Added + qweb + /supplier-portal-bill-added + + True + account_supplier_portal.bill_added_page + + + +
+
+
+
+
+
+
+ +
+ +

Bill Successfully Uploaded

+

+ Your vendor bill has been received. +

+ + +
+
+
+
+
+
+
+
+
+
+ +
diff --git a/account_supplier_portal/views/account_supplier_portal_view.xml b/account_supplier_portal/views/account_supplier_portal_view.xml new file mode 100644 index 00000000000..5a0033f875c --- /dev/null +++ b/account_supplier_portal/views/account_supplier_portal_view.xml @@ -0,0 +1,52 @@ + + + + + + diff --git a/account_supplier_portal/views/portal_templates.xml b/account_supplier_portal/views/portal_templates.xml new file mode 100644 index 00000000000..6ecc21a1442 --- /dev/null +++ b/account_supplier_portal/views/portal_templates.xml @@ -0,0 +1,15 @@ + + + + + + \ No newline at end of file