From 68d415fa1786ac14f5fc8617a25bd7ed4467e19a Mon Sep 17 00:00:00 2001 From: Marc Durepos Date: Wed, 26 Feb 2025 10:52:00 -0500 Subject: [PATCH] attempt fix to delivery carrier account - selecting collect account raising error --- .../__manifest__.py | 2 +- .../models/carrier_account_mixin.py | 34 +++++-------------- 2 files changed, 10 insertions(+), 26 deletions(-) diff --git a/delivery_carrier_partner_account/__manifest__.py b/delivery_carrier_partner_account/__manifest__.py index 8aae19a..ac5261a 100644 --- a/delivery_carrier_partner_account/__manifest__.py +++ b/delivery_carrier_partner_account/__manifest__.py @@ -19,7 +19,7 @@ # { "name": "Carrier Accounts by Partner", - "version": "18.0.0.1.1", + "version": "18.0.0.1.2", "summary": "Add one or many carrier accounts per partner", "category": "Delivery", "author": "Bemade Inc.", diff --git a/delivery_carrier_partner_account/models/carrier_account_mixin.py b/delivery_carrier_partner_account/models/carrier_account_mixin.py index 62b809b..86dffd9 100644 --- a/delivery_carrier_partner_account/models/carrier_account_mixin.py +++ b/delivery_carrier_partner_account/models/carrier_account_mixin.py @@ -322,37 +322,21 @@ class CarrierAccountMixin(models.AbstractModel): @api.constrains("delivery_billing_mode", "carrier_id", "carrier_account_id") def _check_carrier_account(self): for rec in self: - if rec.carrier_account_id and rec.delivery_billing_mode: - if ( - rec.delivery_billing_mode == "collect" - and rec.carrier_account_id - not in ( - rec.recipient_id | rec.recipient_id.commercial_partner_id - ).carrier_account_ids - ): + if ( + rec.carrier_account_id + and rec.delivery_billing_mode + and rec.carrier_account_id not in rec.valid_carrier_account_ids + ): + + if rec.delivery_billing_mode == "collect": raise UserError( "Carrier account is not associated with the recipient, but billing mode is collect." ) - elif ( - rec.delivery_billing_mode in ["prepaid", "ppc", "no charge"] - and rec.carrier_account_id - not in ( - rec.sender_id | rec.sender_id.commercial_partner_id - ).carrier_account_ids - ): + elif rec.delivery_billing_mode in ["prepaid", "ppc", "no charge"]: raise UserError( "Carrier account is not associated with the sender, but billing mode is prepaid, ppc or no charge." ) - elif ( - rec.delivery_billing_mode == "third party" - and rec.carrier_account_id - in ( - rec.sender_id - | rec.sender_id.commercial_partner_id - | rec.recipient_id - | rec.recipient_id.commercial_partner_id - ).carrier_account_ids - ): + elif rec.delivery_billing_mode == "third party": raise UserError( "Third party carrier account cannot belong to sender or recipient." )