Add better carrier linking for purchasing
delivery_carrier_partner_account and purchase_delivery_carrier
This commit is contained in:
parent
f0d05b4003
commit
12274002fd
5 changed files with 47 additions and 9 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -1,2 +1,3 @@
|
|||
from . import res_partner
|
||||
from . import purchase_order
|
||||
from . import delivery_carrier_account
|
||||
|
|
|
|||
11
purchase_delivery_carrier/models/delivery_carrier_account.py
Normal file
11
purchase_delivery_carrier/models/delivery_carrier_account.py
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
from odoo import fields, models, api
|
||||
|
||||
|
||||
class DeliveryCarrierAccount(models.Model):
|
||||
_inherit = "delivery.carrier.account"
|
||||
|
||||
supplier_ids = fields.One2many(
|
||||
comodel_name="res.partner",
|
||||
inverse_name="purchase_delivery_carrier_account_id",
|
||||
string="Suppliers",
|
||||
)
|
||||
|
|
@ -13,3 +13,28 @@ class ResPartner(models.Model):
|
|||
comodel_name="delivery.carrier.account",
|
||||
string="Default Carrier Account (Inbound)",
|
||||
)
|
||||
|
||||
@api.model_create_multi
|
||||
def create(self, vals_list):
|
||||
res = super().create(vals_list)
|
||||
for partner in res:
|
||||
if (
|
||||
partner.purchase_delivery_carrier_account_id
|
||||
and not partner.purchase_delivery_carrier_id
|
||||
):
|
||||
partner.purchase_delivery_carrier_id = (
|
||||
partner.purchase_delivery_carrier_account_id.delivery_carrier_id
|
||||
)
|
||||
return res
|
||||
|
||||
def write(self, vals):
|
||||
res = super().write(vals)
|
||||
for partner in self:
|
||||
if (
|
||||
partner.purchase_delivery_carrier_account_id
|
||||
and not partner.purchase_delivery_carrier_id
|
||||
):
|
||||
partner.purchase_delivery_carrier_id = (
|
||||
partner.purchase_delivery_carrier_account_id.delivery_carrier_id
|
||||
)
|
||||
return res
|
||||
|
|
|
|||
Loading…
Reference in a new issue