Skip to content

Commit 669db01

Browse files
committed
[IMP] supplier_portal: added supplier portal
-Introduced a new route allowing suppliers to upload invoices in PDF and XML format. -Added a webpage with a company selection dropdown, displaying companies linked to the user. -Successfully uploaded documents will generate a new draft vendor bill in the backend.
1 parent 4c650f3 commit 669db01

File tree

6 files changed

+118
-0
lines changed

6 files changed

+118
-0
lines changed

supplier_portal/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import controllers

supplier_portal/__manifest__.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "Supplier Portal",
3+
"version": "1.0",
4+
"author": "Harsh Siddhapara siha",
5+
"depends": ["account", "website"],
6+
"data": [
7+
"views/supplier_portal_template.xml",
8+
"views/supplier_portal_website_menu.xml",
9+
],
10+
"installable": True,
11+
"license": "LGPL-3",
12+
}
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import supplier_portal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import base64
2+
from odoo import http
3+
from odoo.http import request
4+
from odoo.exceptions import ValidationError
5+
6+
7+
class SupplierPortal(http.Controller):
8+
@http.route("/supplier/upload", type="http", auth="user", website=True)
9+
def supplier_portal_upload_document(self):
10+
return request.render("supplier_portal.supplier_portal_upload_template")
11+
12+
@http.route("/supplier/portal/submit", type="http", auth="user", website=True)
13+
def supplier_portal_submit_document(self, **kwargs):
14+
"""Handles supplier document upload by creating a vendor bill (`account.move`) and attaching uploaded PDF and XML files."""
15+
16+
bills = (
17+
request.env["account.move"]
18+
.sudo().create(
19+
{
20+
"partner_id": request.env.user.partner_id.id,
21+
"move_type": "in_invoice",
22+
"company_id": int(kwargs.get("company")),
23+
}
24+
)
25+
)
26+
attachments = []
27+
uploaded_files = request.httprequest.files.getlist("upload_file")
28+
for file in uploaded_files:
29+
file_name = file.filename
30+
file_extension = file_name.split(".")[-1].lower()
31+
if file_extension not in ["pdf", "xml"]:
32+
raise ValidationError("Invalid file type. Please upload only PDF or XML files.")
33+
mimetype = "application/pdf" if file_extension == "pdf" else "application/xml"
34+
attachment = request.env["ir.attachment"].sudo().create(
35+
{
36+
"res_id": bills.id,
37+
"res_model": "account.move",
38+
"name": file.filename or "Uploaded PDF",
39+
"datas": base64.b64encode(file.read()),
40+
"mimetype": mimetype,
41+
"type": "binary",
42+
}
43+
)
44+
attachments.append(attachment)
45+
46+
return request.render("supplier_portal.after_submit_message_template",
47+
{"success_message": f"{len(attachments)} files uploaded successfully."})
48+
49+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<odoo>
3+
<template id="supplier_portal_upload_template">
4+
<t t-call="website.layout">
5+
<div class="container mt-5">
6+
<h2 class="text-center text-primary mb-4">Upload Supplier Documents</h2>
7+
<form action="/supplier/portal/submit" method="post" enctype="multipart/form-data" class="shadow p-4 bg-white rounded">
8+
<input type="hidden" name="csrf_token" t-att-value="request.csrf_token()"/>
9+
<!-- Company Selection -->
10+
<div class="mb-3">
11+
<label class="form-label fw-bold">Select Company</label>
12+
<select id="company" name="company" class="form-select" required="true">
13+
<t t-foreach="request.env.user.company_ids" t-as="company">
14+
<option t-att-value="company.id">
15+
<t t-esc="company.name"/>
16+
</option>
17+
</t>
18+
</select>
19+
</div>
20+
<!-- Upload file with .pdf or .xml extension -->
21+
<div class="mb-3">
22+
<label class="form-label fw-bold">Upload PDF File</label>
23+
<input type="file" name="upload_file" class="form-control" multiple="multiple" accept=".pdf,.xml"/>
24+
</div>
25+
<div class="text-center">
26+
<button type="submit" class="btn btn-primary px-4">Submit</button>
27+
</div>
28+
</form>
29+
</div>
30+
</t>
31+
</template>
32+
<template id="after_submit_message_template">
33+
<t t-call="website.layout">
34+
<div class="container mt-5">
35+
<t t-if="success_message">
36+
<div class="alert alert-success text-center" role="alert">
37+
<t t-esc="success_message" />
38+
</div>
39+
</t>
40+
</div>
41+
</t>
42+
</template>
43+
</odoo>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<odoo>
3+
4+
<record id="menu_supplier_portal" model="website.menu">
5+
<field name="name">Upload Document</field>
6+
<field name="url">/supplier/upload/</field>
7+
<field name="parent_id" ref="website.main_menu"/>
8+
<field name="sequence">10</field>
9+
<field name="group_ids" eval="[(6, 0, [ref('base.group_portal')])]"/>
10+
</record>
11+
12+
</odoo>

0 commit comments

Comments
 (0)