Skip to content

Commit

Permalink
Merge PR #914 into 16.0
Browse files Browse the repository at this point in the history
Signed-off-by jbaudoux
  • Loading branch information
OCA-git-bot committed Dec 10, 2024
2 parents 06c4b14 + bdff1b3 commit 05683c9
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions delivery_auto_refresh/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,14 @@ def _compute_available_carrier_ids(self):
# End migration note

# Migration Note 17.0: move this section to module sale_order_carrier_auto_assign
def _set_delivery_carrier(self, set_delivery_line=True):
def _set_delivery_carrier(
self, set_delivery_line=True, preserve_order_carrier=True
):
"""Automatically change delivery carrier.
:param set_delivery_line: It will create or update the delivery line
:param preserve_order_carrier: It will respect the carrier set on the order
"""
for order in self:
delivery_wiz_action = order.action_open_delivery_wizard()
delivery_wiz_context = delivery_wiz_action.get("context", {})
Expand All @@ -38,7 +45,7 @@ def _set_delivery_carrier(self, set_delivery_line=True):
)

# Do not override carrier
if order.carrier_id:
if preserve_order_carrier and order.carrier_id:
delivery_wiz.carrier_id = order.carrier_id

# If the carrier isn't allowed, we won't default to it
Expand All @@ -62,7 +69,10 @@ def _add_delivery_carrier_on_partner_change(self):
if not partner:
return
if self.company_id.sale_auto_assign_carrier_on_create:
self._set_delivery_carrier(set_delivery_line=False)
self._set_delivery_carrier(
set_delivery_line=False,
preserve_order_carrier=False,
)

def _is_auto_set_carrier_on_create(self):
self.ensure_one()
Expand Down

0 comments on commit 05683c9

Please sign in to comment.