diff --git a/supplier_portal/__init__.py b/supplier_portal/__init__.py new file mode 100644 index 00000000000..e046e49fbe2 --- /dev/null +++ b/supplier_portal/__init__.py @@ -0,0 +1 @@ +from . import controllers diff --git a/supplier_portal/__manifest__.py b/supplier_portal/__manifest__.py new file mode 100644 index 00000000000..b84116449c6 --- /dev/null +++ b/supplier_portal/__manifest__.py @@ -0,0 +1,12 @@ +{ + "name": "Supplier Portal", + "version": "1.0", + "author": "Harsh Siddhapara siha", + "depends": ["account", "website"], + "data": [ + "views/supplier_portal_template.xml", + "views/supplier_portal_website_menu.xml", + ], + "installable": True, + "license": "LGPL-3", +} diff --git a/supplier_portal/controllers/__init__.py b/supplier_portal/controllers/__init__.py new file mode 100644 index 00000000000..6e87eba014f --- /dev/null +++ b/supplier_portal/controllers/__init__.py @@ -0,0 +1 @@ +from . import supplier_portal diff --git a/supplier_portal/controllers/supplier_portal.py b/supplier_portal/controllers/supplier_portal.py new file mode 100644 index 00000000000..0490cb9b1b2 --- /dev/null +++ b/supplier_portal/controllers/supplier_portal.py @@ -0,0 +1,47 @@ +import base64 +from odoo import http +from odoo.http import request +from odoo.exceptions import ValidationError + + +class SupplierPortal(http.Controller): + @http.route("/supplier/upload", type="http", auth="user", website=True) + def supplier_portal_upload_document(self): + return request.render("supplier_portal.supplier_portal_upload_template") + + @http.route("/supplier/portal/submit", type="http", auth="user", website=True) + def supplier_portal_submit_document(self, **kwargs): + """Handles supplier document upload by creating a vendor bill (`account.move`) and attaching uploaded PDF and XML files.""" + + bills = ( + request.env["account.move"] + .sudo().create( + { + "partner_id": request.env.user.partner_id.id, + "move_type": "in_invoice", + "company_id": int(kwargs.get("company")), + } + ) + ) + attachments = [] + uploaded_files = request.httprequest.files.getlist("upload_file") + for file in uploaded_files: + file_name = file.filename + file_extension = file_name.split(".")[-1].lower() + if file_extension not in ["pdf", "xml"]: + raise ValidationError("Invalid file type. Please upload only PDF or XML files.") + mimetype = "application/pdf" if file_extension == "pdf" else "application/xml" + attachment = request.env["ir.attachment"].sudo().create( + { + "res_id": bills.id, + "res_model": "account.move", + "name": file.filename or "Uploaded PDF", + "datas": base64.b64encode(file.read()), + "mimetype": mimetype, + "type": "binary", + } + ) + attachments.append(attachment) + + return request.render("supplier_portal.after_submit_message_template", + {"success_message": f"{len(attachments)} files uploaded successfully."}) diff --git a/supplier_portal/views/supplier_portal_template.xml b/supplier_portal/views/supplier_portal_template.xml new file mode 100644 index 00000000000..6b48d89c282 --- /dev/null +++ b/supplier_portal/views/supplier_portal_template.xml @@ -0,0 +1,43 @@ + + + + + + Upload Supplier Documents + + + + + Select Company + + + + + + + + + + + Upload + + + + Submit + + + + + + + + + + + + + + + + + diff --git a/supplier_portal/views/supplier_portal_website_menu.xml b/supplier_portal/views/supplier_portal_website_menu.xml new file mode 100644 index 00000000000..faf6205815d --- /dev/null +++ b/supplier_portal/views/supplier_portal_website_menu.xml @@ -0,0 +1,12 @@ + + + + + Upload Document + /supplier/upload/ + + 10 + + + +