-
-
Notifications
You must be signed in to change notification settings - Fork 364
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by sebalix
- Loading branch information
Showing
7 changed files
with
50 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,10 +2,13 @@ | |
# Copyright 2017 Luis M. Ontalba <[email protected]> | ||
# Copyright 2021 Gianmarco Conte <[email protected]> | ||
# 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" | ||
|
@@ -77,33 +80,34 @@ def send_shipping(self, pickings): | |
"""We have to override this method for redirecting the result to the | ||
proper "child" carrier. | ||
""" | ||
if self.destination_type == "one": | ||
# falsy type is considered as one destination | ||
if not self.destination_type or self.destination_type == "one": | ||
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: | ||
carrier = self.with_context(show_children_carriers=True) | ||
res = [] | ||
for p in pickings: | ||
picking_res = False | ||
for subcarrier in carrier.child_ids: | ||
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: | ||
picking_res = super( | ||
DeliveryCarrier, | ||
subcarrier, | ||
).send_shipping(pickings) | ||
break | ||
except Exception: | ||
pass | ||
if not picking_res: | ||
raise ValidationError(_("There is no matching delivery rule.")) | ||
res += picking_res | ||
return res | ||
try: | ||
picking_res = super().send_shipping(picking) | ||
except Exception as err: | ||
_logger.warning("%s: %s", "_send_shipping_next", str(err)) | ||
return picking_res |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters