fix: ADP portal - sidebar amount, claim details, signature report

This commit is contained in:
2026-03-09 21:25:05 +00:00
parent 35399170b3
commit f362fbd915

View File

@@ -3,24 +3,40 @@
# License OPL-1 (Odoo Proprietary License v1.0) # License OPL-1 (Odoo Proprietary License v1.0)
# Part of the Fusion Claim Assistant product family. # Part of the Fusion Claim Assistant product family.
import binascii
from odoo import fields, _
from odoo.exceptions import AccessError, MissingError
from odoo.http import request
from odoo.addons.sale.controllers.portal import CustomerPortal from odoo.addons.sale.controllers.portal import CustomerPortal
class FusionCustomerPortal(CustomerPortal): class FusionCustomerPortal(CustomerPortal):
def _determine_is_down_payment(self, order_sudo, amount_selection, payment_amount): def _is_adp_order(self, order_sudo):
"""Override to use client portion for ADP down-payment comparison.""" return (
if (
hasattr(order_sudo, '_is_adp_sale') hasattr(order_sudo, '_is_adp_sale')
and order_sudo._is_adp_sale() and order_sudo._is_adp_sale()
and order_sudo.x_fc_client_type == 'REG' )
):
payable = order_sudo.x_fc_client_portion_total or 0 def _is_adp_reg(self, order_sudo):
return self._is_adp_order(order_sudo) and order_sudo.x_fc_client_type == 'REG'
def _get_adp_payable(self, order_sudo):
if self._is_adp_reg(order_sudo):
return order_sudo.x_fc_client_portion_total or 0
return order_sudo.amount_total
# ------------------------------------------------------------------
# Payment amount overrides
# ------------------------------------------------------------------
def _determine_is_down_payment(self, order_sudo, amount_selection, payment_amount):
if self._is_adp_reg(order_sudo):
payable = self._get_adp_payable(order_sudo)
if amount_selection == 'down_payment': if amount_selection == 'down_payment':
return True return True
elif amount_selection == 'full_amount': elif amount_selection == 'full_amount':
return False return False
else:
return ( return (
order_sudo.prepayment_percent < 1.0 if payment_amount is None order_sudo.prepayment_percent < 1.0 if payment_amount is None
else payment_amount < payable else payment_amount < payable
@@ -28,27 +44,77 @@ class FusionCustomerPortal(CustomerPortal):
return super()._determine_is_down_payment(order_sudo, amount_selection, payment_amount) return super()._determine_is_down_payment(order_sudo, amount_selection, payment_amount)
def _get_payment_values(self, order_sudo, is_down_payment=False, payment_amount=None, **kwargs): def _get_payment_values(self, order_sudo, is_down_payment=False, payment_amount=None, **kwargs):
"""Override to cap payment amount at client portion for ADP orders."""
values = super()._get_payment_values( values = super()._get_payment_values(
order_sudo, order_sudo,
is_down_payment=is_down_payment, is_down_payment=is_down_payment,
payment_amount=payment_amount, payment_amount=payment_amount,
**kwargs, **kwargs,
) )
if not self._is_adp_reg(order_sudo):
if not (
hasattr(order_sudo, '_is_adp_sale')
and order_sudo._is_adp_sale()
and order_sudo.x_fc_client_type == 'REG'
):
return values return values
client_portion = order_sudo.x_fc_client_portion_total or 0 client_portion = self._get_adp_payable(order_sudo)
if client_portion <= 0: if client_portion <= 0:
return values return values
current_amount = values.get('amount', 0) current_amount = values.get('amount', 0)
if current_amount > client_portion: if current_amount > client_portion:
values['amount'] = order_sudo.currency_id.round(client_portion) values['amount'] = order_sudo.currency_id.round(client_portion)
return values return values
# ------------------------------------------------------------------
# Signature: attach ADP report instead of default Odoo quotation
# ------------------------------------------------------------------
def portal_quote_accept(self, order_id, access_token=None, name=None, signature=None):
access_token = access_token or request.httprequest.args.get('access_token')
try:
order_sudo = self._document_check_access('sale.order', order_id, access_token=access_token)
except (AccessError, MissingError):
return {'error': _('Invalid order.')}
if not order_sudo._has_to_be_signed():
return {'error': _('The order is not in a state requiring customer signature.')}
if not signature:
return {'error': _('Signature is missing.')}
try:
order_sudo.write({
'signed_by': name,
'signed_on': fields.Datetime.now(),
'signature': signature,
})
request.env.cr.flush()
except (TypeError, binascii.Error):
return {'error': _('Invalid signature data.')}
if not order_sudo._has_to_be_paid():
order_sudo._validate_order()
if self._is_adp_order(order_sudo):
report_ref = 'fusion_claims.action_report_saleorder_portrait'
else:
report_ref = 'sale.action_report_saleorder'
pdf = request.env['ir.actions.report'].sudo()._render_qweb_pdf(
report_ref, [order_sudo.id]
)[0]
order_sudo.message_post(
attachments=[('%s.pdf' % order_sudo.name, pdf)],
author_id=(
order_sudo.partner_id.id
if request.env.user._is_public()
else request.env.user.partner_id.id
),
body=_('Order signed by %s', name),
message_type='comment',
subtype_xmlid='mail.mt_comment',
)
query_string = '&message=sign_ok'
if order_sudo._has_to_be_paid():
query_string += '&allow_payment=yes'
return {
'force_refresh': True,
'redirect_url': order_sudo.get_portal_url(query_string=query_string),
}