Add better carrier linking for purchasing

delivery_carrier_partner_account and purchase_delivery_carrier
This commit is contained in:
Marc Durepos 2025-01-17 13:25:40 -05:00
parent bcd92d5039
commit f4c6d0c21e
2 changed files with 10 additions and 9 deletions

View file

@ -160,7 +160,7 @@ class CarrierAccountMixin(models.AbstractModel):
):
if rec.carrier_account_id:
raise UserError(
_("No carrier account should be set for no charge delivery.")
"No carrier account should be set for no charge delivery."
)
continue
# We allow empty carrier account for third party since we can't always
@ -170,8 +170,15 @@ class CarrierAccountMixin(models.AbstractModel):
and not rec.carrier_account_id
):
continue
if rec.carrier_account_id not in rec.valid_carrier_account_ids:
raise UserError(_("Invalid carrier account selected."))
if (
rec.carrier_account_id
and rec.carrier_account_id not in rec.valid_carrier_account_ids
):
raise UserError(
f"Invalid carrier account selected. Account: {rec.carrier_account_id} for carrier {rec.carrier_id} from sender {rec.sender_id} to recipient {rec.recipient_id} in mode {rec.delivery_billing_mode}."
f"\nSender accounts: {rec.sender_id.carrier_account_ids}"
f"\nRecipient accounts: {rec.recipient_id.carrier_account_ids}"
)
def _inverse_carrier_account_id(self):
pass

View file

@ -39,12 +39,6 @@ class DeliveryCarrierAccount(models.Model):
for record in self:
record.display_name = record.account_number
@api.constrains("partner_id", "delivery_carrier_id")
def _constrain_partner_carrier_same_company(self):
for rec in self:
if rec.partner_id.company_id != rec.delivery_carrier_id.company_id:
raise UserError(_("Partner and Carrier must be in the same company."))
def write(self, vals):
res = super().write(vals)
for partner in self.partner_id.filtered(