[ADD] sale_exception_portal: show exceptions on portal

H4721
This commit is contained in:
Cedric Collins
2020-12-30 17:02:15 -06:00
parent 9959acd46f
commit 8363dc3657
6 changed files with 149 additions and 0 deletions

View File

@@ -0,0 +1 @@
from . import models

View File

@@ -0,0 +1,22 @@
{
'name': 'Sale Exception Portal',
'summary': 'Display sale exceptions on customer portal',
'version': '13.0.1.0.0',
'author': "Hibou Corp.",
'category': 'Sale',
'license': 'AGPL-3',
'website': "https://hibou.io",
'description': """
Display sale exceptions on customer portal and prevent further action
""",
'depends': [
'sale_exception',
],
'demo': [],
'data': [
'views/sale_portal_templates.xml',
'views/sale_views.xml',
],
'auto_install': False,
'installable': True,
}

View File

@@ -0,0 +1 @@
from . import sale

View File

@@ -0,0 +1,35 @@
import time
from odoo import fields, models
class ExceptionRule(models.Model):
_inherit = 'exception.rule'
website_description = fields.Text('Description for Website')
class SaleOrder(models.Model):
_inherit = 'sale.order'
def _check_sale_order_exceptions(self):
so_exceptions = self.env['exception.rule'].search([('active', '=', True),
('model', '=', 'sale.order'),
('exception_type', '=', 'by_py_code')])
reasons = []
for ex in so_exceptions:
# Globals won't expose modules used in exception rules python code.
# They will have to be manually passed through params. ex [time]
# Locals() can be used instead of defined params, but can also cause buggy behavior on return
params = {'sale': self, 'exception': ex, 'time': time}
try:
exec(ex.code, globals(), params)
if 'failed' in params:
desc = ex.website_description or ex.description
message = {'title': ex.name, 'description': desc}
reasons.append(message)
except:
pass
return reasons

View File

@@ -0,0 +1,75 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<template id="sale_order_portal_template_inherit" inherit_id="sale.sale_order_portal_template">
<!-- LEFT COLUMN ACTIONS -->
<xpath expr="//li[1]" position="replace">
<t t-set="sale_order_exceptions" t-value="sale_order._check_sale_order_exceptions()"/>
<li class="list-group-item flex-grow-1">
<a t-if="sale_order.has_to_be_signed(True) and not sale_order_exceptions"
role="button" class="btn btn-primary btn-block mb8"
data-toggle="modal"
data-target="#modalaccept"
href="#">
<i class="fa fa-check"/>
<t t-if="sale_order.has_to_be_paid(True)"> Sign &amp; Pay</t>
<t t-else=""> Accept &amp; Sign</t>
</a>
<a t-elif="sale_order.has_to_be_paid(True) and not sale_order_exceptions"
role="button"
id="o_sale_portal_paynow"
data-toggle="modal"
data-target="#modalaccept"
href="#"
t-att-class="'btn-block mb8 %s' % ('btn btn-light' if sale_order.transaction_ids else 'btn btn-primary')">
<i class="fa fa-check"/>
<t t-if="not sale_order.signature">Accept &amp; Pay</t>
<t t-else="">Pay Now</t>
</a>
<t t-if="sale_order_exceptions">
<t t-foreach="sale_order_exceptions" t-as="exception">
<a href="#discussion" role="button" class="btn btn-danger btn-block mb8"
style="max-width: 180px;">
<i class="fa fa-warning"/>
<span t-esc="exception['description']"/>
</a>
</t>
</t>
</li>
</xpath>
<!-- BOTTOM ACTIONS -->
<xpath expr="//div[@t-if='sale_order.has_to_be_signed(True) or sale_order.has_to_be_paid(True)']" position="replace">
<div t-if="sale_order.has_to_be_signed(True) or sale_order.has_to_be_paid(True)"
class="row justify-content-center text-center d-print-none pt-1 pb-4">
<t t-set="sale_order_exceptions" t-value="sale_order._check_sale_order_exceptions()"/>
<t t-if="sale_order.has_to_be_signed(True)">
<div t-if="not sale_order_exceptions" class="col-sm-auto mt8">
<a role="button" class="btn btn-primary" data-toggle="modal"
data-target="#modalaccept" href="#">
<i class="fa fa-check"/>
<t t-if="sale_order.has_to_be_paid(True)"> Sign &amp; Pay</t>
<t t-else=""> Accept &amp; Sign</t>
</a>
</div>
<div class="col-sm-auto mt8">
<a role="button" class="btn btn-secondary" href="#discussion">
<i class="fa fa-comment"/> Feedback</a>
</div>
<div class="col-sm-auto mt8">
<a role="button" class="btn btn-danger" data-toggle="modal"
data-target="#modaldecline" href="#"> <i class="fa fa-times"/> Reject</a>
</div>
</t>
<div t-elif="sale_order.has_to_be_paid(True) and not sale_order_exceptions" class="col-sm-auto mt8">
<a role="button" data-toggle="modal" data-target="#modalaccept" href="#"
t-att-class="'%s' % ('btn btn-light' if sale_order.transaction_ids else 'btn btn-primary')">
<i class="fa fa-check"/> <t t-if="not sale_order.signature">Accept &amp; Pay</t>
<t t-else="">Pay Now</t>
</a>
</div>
</div>
</xpath>
</template>
</odoo>

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record id="exception_rule_form_inherit" model="ir.ui.view">
<field name="name">exception.rule.form.inherit</field>
<field name="model">exception.rule</field>
<field name="inherit_id" ref="base_exception.view_exception_rule_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='description']" position="after">
<field name="website_description"/>
</xpath>
</field>
</record>
</odoo>