Skip to content

Commit 4ac1950

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 4ac1950

File tree

6 files changed

+141
-0
lines changed

6 files changed

+141
-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": ["base", "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,63 @@
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()
19+
.create(
20+
{
21+
"partner_id": request.env.user.partner_id.id,
22+
"move_type": "in_invoice",
23+
"company_id": int(kwargs.get("company")),
24+
}
25+
)
26+
)
27+
# Handle PDF Upload
28+
pdf_file = kwargs.get("pdf_file")
29+
if pdf_file:
30+
request.env["ir.attachment"].sudo().create(
31+
{
32+
"res_id": bills.id,
33+
"res_model": "account.move",
34+
"name": pdf_file.filename or "Uploaded PDF",
35+
"datas": base64.b64encode(pdf_file.read()),
36+
"mimetype": "application/pdf",
37+
"type": "binary",
38+
}
39+
)
40+
# Handle XML Upload
41+
xml_file = kwargs.get("xml_file")
42+
if xml_file:
43+
request.env["ir.attachment"].sudo().create(
44+
{
45+
"res_id": bills.id,
46+
"res_model": "account.move",
47+
"name": xml_file.filename or "Uploaded XML",
48+
"datas": base64.b64encode(xml_file.read()),
49+
"mimetype": "application/xml",
50+
"type": "binary",
51+
}
52+
)
53+
# Redirect based on whether files were uploaded
54+
if pdf_file and xml_file:
55+
return request.render(
56+
"supplier_portal.after_submit_message_template",
57+
{"success_message": "Documents uploaded successfully."},
58+
)
59+
else:
60+
return request.render(
61+
"supplier_portal.after_submit_message_template",
62+
{"error_message": "Please upload both pdf and xml files."},
63+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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+
<!-- PDF Upload Field -->
21+
<div class="mb-3">
22+
<label class="form-label fw-bold">Upload PDF File</label>
23+
<input type="file" name="pdf_file" class="form-control" accept=".pdf"/>
24+
</div>
25+
<!-- XML Upload Field -->
26+
<div class="mb-3">
27+
<label class="form-label fw-bold">Upload XML File</label>
28+
<input type="file" name="xml_file" class="form-control" accept=".xml"/>
29+
</div>
30+
<div class="text-center">
31+
<button type="submit" class="btn btn-primary px-4">Submit</button>
32+
</div>
33+
</form>
34+
</div>
35+
</t>
36+
</template>
37+
<template id="after_submit_message_template">
38+
<t t-call="website.layout">
39+
<div class="container mt-5">
40+
<t t-if="success_message">
41+
<div class="alert alert-success text-center" role="alert">
42+
<t t-esc="success_message" />
43+
</div>
44+
</t>
45+
<t t-if="error_message">
46+
<div class="alert alert-danger text-center" role="alert">
47+
<t t-esc="error_message" />
48+
</div>
49+
</t>
50+
</div>
51+
</t>
52+
</template>
53+
</odoo>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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+
</record>
10+
11+
</odoo>

0 commit comments

Comments
 (0)