Fixes a bug where sale orders with a partner_shipping_id not within the same commercial entity as their partner_id could not have collect carrier accounts set after being confirmed. The issue stemmed from the fact that the sale order's recipient_id field was being set to partner_id, while the created delivery order had recipient_id set to its partner_id, which is the partner_shipping_id of the sale order. In other words, the sale order recipient was incorrectly set to the main partner instead of the shipping address. This commit adds a test that was previously failing in this scenario. It also properly sets the recipient_id on the transport selection wizard and on sale orders themselves, fixing the issue.
48 lines
1.7 KiB
Python
48 lines
1.7 KiB
Python
from odoo import models, fields, api, _
|
|
import logging
|
|
|
|
_logger = logging.getLogger(__name__)
|
|
|
|
|
|
class SalesOrder(models.Model):
|
|
_inherit = ["sale.order", "carrier.account.mixin"]
|
|
_name = "sale.order"
|
|
|
|
recipient_id = fields.Many2one(
|
|
comodel_name="res.partner",
|
|
related="partner_shipping_id",
|
|
)
|
|
sender_id = fields.Many2one(
|
|
comodel_name="res.partner",
|
|
related="warehouse_id.partner_id",
|
|
)
|
|
|
|
def _create_delivery_line(self, carrier, price_unit):
|
|
line = super()._create_delivery_line(carrier, price_unit)
|
|
name = line.name
|
|
delivery_billing_mode = self.delivery_billing_mode
|
|
carrier_account = self.carrier_account_id
|
|
if delivery_billing_mode:
|
|
mode_display = delivery_billing_mode.upper()
|
|
name = name + f" [{mode_display}]"
|
|
if delivery_billing_mode in ["collect", "third party"] and carrier_account:
|
|
name = name + f" #{carrier_account.account_number}"
|
|
line.name = name
|
|
return line
|
|
|
|
def _on_carrier_fields_changed(self):
|
|
"""Propagate carrier field changes to pickings."""
|
|
super()._on_carrier_fields_changed()
|
|
for rec in self:
|
|
for picking in rec.picking_ids.filtered(
|
|
lambda pick: pick.state not in ["done", "cancel"]
|
|
):
|
|
picking.write(
|
|
{
|
|
"carrier_id": rec.carrier_id and rec.carrier_id.id,
|
|
"delivery_billing_mode": rec.delivery_billing_mode,
|
|
"carrier_account_id": (
|
|
rec.carrier_account_id and rec.carrier_account_id.id
|
|
),
|
|
}
|
|
)
|