Skip to content

[ADD] Supplier Portal: Generate Draft Bill via Form Submission #694

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: 18.0
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions supplier_portal/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import controllers
11 changes: 11 additions & 0 deletions supplier_portal/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
'name': 'Supplier Portal',
'installable': True,
'license': 'LGPL-3',
'depends': ['account', 'website'],
'data': [
'views/supplier_portal_template.xml',
'views/supplier_portal_thank_you_template.xml',
'views/website_menu.xml',
],
}
1 change: 1 addition & 0 deletions supplier_portal/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import main
48 changes: 48 additions & 0 deletions supplier_portal/controllers/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import base64
from odoo import http
from odoo.http import request
from odoo.exceptions import UserError


class SupplierPortal(http.Controller):
@http.route('/supplier_portal', auth='user', type='http', website=True)
def show_supplier_portal(self, *args, **kwargs):
return request.render('supplier_portal.supplier_portal_template', {})

@http.route('/supplier_portal_thank_you', auth='user', type='http', website=True)
def show_supplier_portal_thank_you(self):
return request.render('supplier_portal.supplier_portal_thank_you_template')

@http.route('/submit_supplier_portal_form', auth='user', type='http', website=True)
def submit_supplier_portal_form(self, *args, **kwargs):
partner_id = request.env.user.partner_id.id

# Creating invoice
in_invoice = request.env['account.move'].sudo().create({
'move_type': 'in_invoice',
'partner_id': partner_id,
'company_id': int(kwargs.get('company_id')),
})

if not in_invoice:
raise UserError("Something went wrong!!!")

# Creating attachments
request.env['ir.attachment'].sudo().create({
'datas': base64.b64encode(kwargs.get('pdf_file').read()),
'type': 'binary',
'name': 'invoice.pdf',
'mimetype': 'application/pdf',
'res_model': 'account.move',
'res_id': in_invoice.id,
})
request.env['ir.attachment'].sudo().create({
'datas': base64.b64encode(kwargs.get('xml_file').read()),
'type': 'binary',
'name': "invoice.xml",
'mimetype': 'text/xml',
'res_model': 'account.move',
'res_id': in_invoice.id,
})

return request.redirect("/supplier_portal_thank_you")
38 changes: 38 additions & 0 deletions supplier_portal/views/supplier_portal_template.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0"?>
<odoo>

<template id="supplier_portal_template">
<t t-call="website.layout">
<div class="container-fluid">
<div class="d-flex justify-content-center m-auto p-5 px-0 px-sm-5">
<div class="p-3 shadow bg-body-tertiary rounded">
<form action="/submit_supplier_portal_form" method="post" enctype="multipart/form-data">
<h4 class="mb-3 text-center">Bill Details</h4>
<input type="hidden" name="csrf_token" t-att-value="request.csrf_token()" />
<div class="mb-4">
<label for="orgnisation" class="form-label">Select Organisation</label>
<select name="company_id" class="form-select" id="orgnisation" required="required">
<t t-foreach="request.env.user.company_ids" t-as="company">
<option t-att-value="company.id" t-out="company.name" />
</t>
</select>
</div>
<div class="mb-4">
<label for="pdfFile" class="form-label">Select PDF file</label>
<input name="pdf_file" type="file" class="form-control" id="pdfFile" accept="application/pdf" aria-describedby="inputGroupFileAddon04" aria-label="Upload" required="required" />
</div>
<div class="mb-4">
<label for="xmlFile" class="form-label">Select XML file</label>
<input name="xml_file" type="file" class="form-control" id="xmlFile" accept=".xml, text/xml" aria-describedby="inputGroupFileAddon04" aria-label="Upload" required="required" />
</div>
<div>
<button type="submit" class="btn btn-outline-success">Submit</button>
</div>
</form>
</div>
</div>
</div>
</t>
</template>

</odoo>
22 changes: 22 additions & 0 deletions supplier_portal/views/supplier_portal_thank_you_template.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0"?>
<odoo>

<template id="supplier_portal_thank_you_template">

<t t-call="website.layout">
<div class="container-fluid">
<div class="d-flex justify-content-center m-auto p-5 px-0 px-sm-5">
<div class="d-inline-block mx-auto p-4">
<i class="fa fa-paper-plane fa-2x mb-3 rounded-circle text-bg-success" role="presentation"></i>
<h1 class="fw-bolder">Thank You!</h1>
<p class="lead mb-0">Your invoice has been sent.</p>
<p class="lead">We will get back to you shortly.</p>
<a href="/">Go to Homepage</a>
</div>
</div>
</div>
</t>

</template>

</odoo>
10 changes: 10 additions & 0 deletions supplier_portal/views/website_menu.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0"?>
<odoo>

<record id="website_supplier_portal_menu" model="website.menu">
<field name="name">Supplier Portal</field>
<field name="url">/supplier_portal</field>
<field name="parent_id" ref="website.main_menu" />
</record>

</odoo>