Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[15.0][FIX] delivery_multi_destination: Several fixes + revert #653

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 36 additions & 32 deletions delivery_multi_destination/models/delivery_carrier.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@
# Copyright 2017 Tecnativa - Luis M. Ontalba
# Copyright 2021 Gianmarco Conte <gconte@dinamicheaziendali.it>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
import logging

from odoo import _, api, fields, models
from odoo.exceptions import ValidationError

_logger = logging.getLogger(__name__)


class DeliveryCarrier(models.Model):
_inherit = "delivery.carrier"
Expand Down Expand Up @@ -87,34 +84,41 @@ def send_shipping(self, pickings):
"""We have to override this method for redirecting the result to the
proper "child" carrier.
"""
# falsy type is considered as one destination
if not self.destination_type or self.destination_type == "one":
if self.destination_type == "one" or not self:
return super().send_shipping(pickings)
carrier = self.with_context(show_children_carriers=True)
res = []
for p in pickings:
picking_res = False
for subcarrier in carrier.child_ids:
picking_res = subcarrier._send_shipping_next(p, picking_res)
if not picking_res:
raise ValidationError(_("There is no matching delivery rule."))
res += picking_res
return res

def _send_shipping_next(self, picking, picking_res):
if self.delivery_type == "fixed":
if self._match_address(picking.partner_id):
picking_res = [
{
"exact_price": self.fixed_price,
"tracking_number": False,
}
]
# TODO: verify if not match address, previous picking_res (passed
# in method's argument) can be used.
else:
try:
picking_res = super().send_shipping(picking)
except Exception as err:
_logger.warning("%s: %s", "_send_shipping_next", str(err))
return picking_res
carrier = self.with_context(show_children_carriers=True)
res = []
for p in pickings:
picking_res = False
for subcarrier in carrier.child_ids.filtered(
lambda x: not x.company_id or x.company_id == p.company_id
):
if subcarrier.delivery_type == "fixed":
if subcarrier._match_address(p.partner_id):
picking_res = [
{
"exact_price": subcarrier.fixed_price,
"tracking_number": False,
}
]
break
else:
try:
# on base_on_rule_send_shipping, the method
# _get_price_available is called using p.carrier_id,
# ignoring the self arg, so we need to temporarily replace
# it with the subcarrier
p.carrier_id = subcarrier.id
picking_res = super(
DeliveryCarrier, subcarrier
).send_shipping(p)
break
except Exception: # pylint: disable=except-pass
pass
finally:
p.carrier_id = carrier
if not picking_res:
raise ValidationError(_("There is no matching delivery rule."))
res += picking_res
return res