From f362fbd91593fd9bf703f643d1959bfb992c58f5 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 9 Mar 2026 21:25:05 +0000 Subject: [PATCH] fix: ADP portal - sidebar amount, claim details, signature report --- fusion_claims/controllers/portal.py | 106 ++++++++++++++++++++++------ 1 file changed, 86 insertions(+), 20 deletions(-) diff --git a/fusion_claims/controllers/portal.py b/fusion_claims/controllers/portal.py index df79030..4ee44cf 100644 --- a/fusion_claims/controllers/portal.py +++ b/fusion_claims/controllers/portal.py @@ -3,52 +3,118 @@ # License OPL-1 (Odoo Proprietary License v1.0) # 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 class FusionCustomerPortal(CustomerPortal): - def _determine_is_down_payment(self, order_sudo, amount_selection, payment_amount): - """Override to use client portion for ADP down-payment comparison.""" - if ( + def _is_adp_order(self, order_sudo): + return ( hasattr(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': return True elif amount_selection == 'full_amount': return False - else: - return ( - order_sudo.prepayment_percent < 1.0 if payment_amount is None - else payment_amount < payable - ) + return ( + order_sudo.prepayment_percent < 1.0 if payment_amount is None + else payment_amount < payable + ) 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): - """Override to cap payment amount at client portion for ADP orders.""" values = super()._get_payment_values( order_sudo, is_down_payment=is_down_payment, payment_amount=payment_amount, **kwargs, ) - - if not ( - hasattr(order_sudo, '_is_adp_sale') - and order_sudo._is_adp_sale() - and order_sudo.x_fc_client_type == 'REG' - ): + if not self._is_adp_reg(order_sudo): 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: return values current_amount = values.get('amount', 0) if current_amount > client_portion: values['amount'] = order_sudo.currency_id.round(client_portion) - 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), + }