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.
39 lines
1.4 KiB
Python
39 lines
1.4 KiB
Python
from odoo import models, fields
|
|
|
|
|
|
class ChooseDeliveryCarrier(models.TransientModel):
|
|
"""Add options to select the carrier account and billing mode."""
|
|
|
|
_inherit = ["choose.delivery.carrier", "carrier.account.mixin"]
|
|
_name = "choose.delivery.carrier"
|
|
|
|
sender_id = fields.Many2one(related="company_id.partner_id")
|
|
recipient_id = fields.Many2one(related="order_id.partner_shipping_id")
|
|
|
|
def button_confirm(self):
|
|
vals = {}
|
|
if self.delivery_billing_mode:
|
|
vals.update(delivery_billing_mode=self.delivery_billing_mode)
|
|
if self.carrier_account_id:
|
|
vals.update(carrier_account_id=self.carrier_account_id.id)
|
|
if self.carrier_id:
|
|
vals.update(carrier_id=self.carrier_id.id)
|
|
|
|
# Ensure we have a valid carrier account
|
|
if (
|
|
self.carrier_id
|
|
and self.delivery_billing_mode
|
|
and not self.carrier_account_id
|
|
):
|
|
# Force recompute of valid carrier accounts
|
|
self._compute_valid_carrier_account_ids()
|
|
default_account = self._get_default_carrier_account()
|
|
if default_account:
|
|
vals.update(carrier_account_id=default_account.id)
|
|
|
|
# Write values to the order before calling super
|
|
if vals:
|
|
self.order_id.with_context(no_carrier_update=True).write(vals)
|
|
|
|
res = super().button_confirm()
|
|
return res
|