Skip to content

Commit a44181e

Browse files
committed
[ADD] Supplier Portal: Generate Draft Bill via Form Submission
In this commit: - Created controllers to handle portal navigation - Designed a supplier portal form for invoice submission with file upload - Implemented draft vendor invoice generation upon form submission - Ensured submitted files appear as attachments in the invoice
1 parent 4c650f3 commit a44181e

File tree

7 files changed

+132
-0
lines changed

7 files changed

+132
-0
lines changed

Diff for: supplier_portal/__init__.py

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

Diff for: supplier_portal/__manifest__.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
'name': 'Supplier Portal',
3+
'installable': True,
4+
'license': 'LGPL-3',
5+
'depends': ['account', 'website'],
6+
'data': [
7+
'views/supplier_portal_template.xml',
8+
'views/supplier_portal_thank_you_template.xml',
9+
'views/website_menu.xml',
10+
],
11+
}

Diff for: supplier_portal/controllers/__init__.py

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

Diff for: supplier_portal/controllers/main.py

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import base64
2+
from odoo import http, exceptions
3+
from odoo.http import request
4+
5+
class SupplierPortal(http.Controller):
6+
@http.route('/supplier_portal', auth='user', type='http', website=True)
7+
def show_supplier_portal(self, *args, **kwargs):
8+
return request.render('supplier_portal.supplier_portal_template', {})
9+
10+
@http.route('/supplier_portal_thank_you', auth='user', type='http', website=True)
11+
def show_supplier_portal_thank_you(self):
12+
return request.render('supplier_portal.supplier_portal_thank_you_template')
13+
14+
@http.route('/submit_supplier_portal_form', auth='user', type='http', website=True)
15+
def submit_supplier_portal_form(self, *args, **kwargs):
16+
partner_id = request.env.user.partner_id.id
17+
18+
try:
19+
# Creating invoice
20+
in_invoice = request.env['account.move'].sudo().create({
21+
'move_type': 'in_invoice',
22+
'partner_id': partner_id,
23+
'company_id': int(kwargs.get('company_id')),
24+
})
25+
26+
# Creating attachments
27+
request.env['ir.attachment'].sudo().create({
28+
'datas': base64.b64encode(kwargs.get('pdf_file').read()),
29+
'type': 'binary',
30+
'name': 'invoice.pdf',
31+
'mimetype': 'application/pdf',
32+
'res_model': 'account.move',
33+
'res_id': in_invoice.id,
34+
})
35+
request.env['ir.attachment'].sudo().create({
36+
'datas': base64.b64encode(kwargs.get('xml_file').read()),
37+
'type': 'binary',
38+
'name': "invoice.xml",
39+
'mimetype': 'text/xml',
40+
'res_model': 'account.move',
41+
'res_id': in_invoice.id,
42+
})
43+
44+
return request.redirect("/supplier_portal_thank_you")
45+
46+
except Exception as e:
47+
raise exceptions.UserError(
48+
f"An unexpected error occurred while processing the invoice: {str(e)}"
49+
)

Diff for: supplier_portal/views/supplier_portal_template.xml

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?xml version="1.0"?>
2+
<odoo>
3+
4+
<template id="supplier_portal_template">
5+
<t t-call="website.layout">
6+
<div class="container-fluid">
7+
<div class="d-flex justify-content-center m-auto p-5 px-0 px-sm-5">
8+
<div class="p-3 shadow bg-body-tertiary rounded">
9+
<form action="/submit_supplier_portal_form" method="post" enctype="multipart/form-data">
10+
<h4 class="mb-3 text-center">Bill Details</h4>
11+
<input type="hidden" name="csrf_token" t-att-value="request.csrf_token()" />
12+
<div class="mb-4">
13+
<label for="orgnisation" class="form-label">Select Organisation</label>
14+
<select name="company_id" class="form-select" id="orgnisation" required="required">
15+
<t t-foreach="request.env.user.company_ids" t-as="company">
16+
<option t-att-value="company.id" t-out="company.name" />
17+
</t>
18+
</select>
19+
</div>
20+
<div class="mb-4">
21+
<label for="pdfFile" class="form-label">Select PDF file</label>
22+
<input name="pdf_file" type="file" class="form-control" id="pdfFile" accept="application/pdf" aria-describedby="inputGroupFileAddon04" aria-label="Upload" required="required" />
23+
</div>
24+
<div class="mb-4">
25+
<label for="xmlFile" class="form-label">Select XML file</label>
26+
<input name="xml_file" type="file" class="form-control" id="xmlFile" accept=".xml, text/xml" aria-describedby="inputGroupFileAddon04" aria-label="Upload" required="required" />
27+
</div>
28+
<div>
29+
<button type="submit" class="btn btn-outline-success">Submit</button>
30+
</div>
31+
</form>
32+
</div>
33+
</div>
34+
</div>
35+
</t>
36+
</template>
37+
38+
</odoo>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0"?>
2+
<odoo>
3+
4+
<template id="supplier_portal_thank_you_template">
5+
6+
<t t-call="website.layout">
7+
<div class="container-fluid">
8+
<div class="d-flex justify-content-center m-auto p-5 px-0 px-sm-5">
9+
<div class="d-inline-block mx-auto p-4">
10+
<i class="fa fa-paper-plane fa-2x mb-3 rounded-circle text-bg-success" role="presentation"></i>
11+
<h1 class="fw-bolder">Thank You!</h1>
12+
<p class="lead mb-0">Your invoice has been sent.</p>
13+
<p class="lead">We will get back to you shortly.</p>
14+
<a href="/">Go to Homepage</a>
15+
</div>
16+
</div>
17+
</div>
18+
</t>
19+
20+
</template>
21+
22+
</odoo>

Diff for: supplier_portal/views/website_menu.xml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0"?>
2+
<odoo>
3+
4+
<record id="website_supplier_portal_menu" model="website.menu">
5+
<field name="name">Supplier Portal</field>
6+
<field name="url">/supplier_portal</field>
7+
<field name="parent_id" ref="website.main_menu" />
8+
</record>
9+
10+
</odoo>

0 commit comments

Comments
 (0)