-
-
Notifications
You must be signed in to change notification settings - Fork 366
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
[IMP] base_delivery_carrier_label: Externalize automatic package creation #643
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6e437f9
[IMP] base_delivery_carrier_label: Externalize automatic package crea…
rousseldenis 06125d2
[IMP] delivery_postlogistics: Add to rebel module
rousseldenis 7aa53a6
[FIX] base_delivery_carrier_label: Fix parameter in tests
rousseldenis 25eae62
[IMP] base_delivery_carrier_label: Separate test models
rousseldenis 4521cb3
[UPD] delivery_roulier: In tests flow, set an automatic package creation
rousseldenis 242cb68
[IMP] base_delivery_carrier_label: Check warnings in tests
rousseldenis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
@@ -1,4 +1,7 @@ | ||
from . import test_get_weight | ||
from . import test_manifest_wizard | ||
from . import test_helper_functions | ||
from . import test_send | ||
from . import ( | ||
test_get_weight, | ||
test_helper_functions, | ||
test_manifest_wizard, | ||
test_packages, | ||
test_send, | ||
) |
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from odoo import fields, models | ||
|
||
|
||
# pylint: disable=consider-merging-classes-inherited | ||
class DeliveryCarrierTest(models.Model): | ||
|
||
_inherit = "delivery.carrier" | ||
|
||
delivery_type = fields.Selection( | ||
selection_add=[("base_delivery_carrier_label", "Base Delivery Carrier Label")], | ||
ondelete={"base_delivery_carrier_label": "cascade"}, | ||
) | ||
|
||
def base_delivery_carrier_label_send_shipping(self, pickings): | ||
res = [] | ||
for picking in pickings: | ||
tracking_number = "123231" | ||
res += [ | ||
{ | ||
"tracking_number": "123231", | ||
"exact_price": 0.0, | ||
"labels": picking._get_base_delivery_carrier_labels( | ||
tracking_base=tracking_number | ||
), | ||
} | ||
] | ||
return 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import base64 | ||
|
||
from odoo import models | ||
|
||
|
||
# pylint: disable=consider-merging-classes-inherited | ||
class StockPicking(models.Model): | ||
|
||
_inherit = "stock.picking" | ||
|
||
def _get_base_delivery_carrier_labels(self, tracking_base): | ||
self.ensure_one() | ||
i = 1 | ||
result = list() | ||
for package in self.move_line_ids.package_level_id.package_id: | ||
number = tracking_base + "-" + str(i) | ||
result.append( | ||
{ | ||
"package_id": package.id, | ||
"tracking_number": number, | ||
"name": number, | ||
"file": base64.b64encode(b"test"), | ||
"file_type": "zpl2", | ||
} | ||
) | ||
i += 1 | ||
return result |
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 |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# Copyright 2020 Hunki Enterprises BV | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
from odoo_test_helper import FakeModelLoader | ||
|
||
from .carrier_label_case import CarrierLabelCase | ||
|
||
|
||
class TestCarrierPackages(CarrierLabelCase): | ||
@classmethod | ||
def setUpClass(cls): | ||
super().setUpClass() | ||
cls.loader = FakeModelLoader(cls.env, cls.__module__) | ||
cls.loader.backup_registry() | ||
from .models.carrier_test import DeliveryCarrierTest | ||
from .models.stock_picking import StockPicking | ||
|
||
cls.loader.update_registry( | ||
( | ||
DeliveryCarrierTest, | ||
StockPicking, | ||
) | ||
) | ||
product = cls.env["product.product"].create( | ||
{ | ||
"name": "Test Delivery Product", | ||
"type": "service", | ||
} | ||
) | ||
cls.carrier = cls.env["delivery.carrier"].create( | ||
{ | ||
"name": "Test Carrier Packages", | ||
"product_id": product.id, | ||
"delivery_type": "base_delivery_carrier_label", | ||
} | ||
) | ||
|
||
@classmethod | ||
def tearDownClass(cls) -> None: | ||
cls.loader.restore_registry() | ||
super().tearDownClass() | ||
|
||
def _get_carrier(self): | ||
return self.carrier | ||
|
||
def test_labels_with_packages(self): | ||
""" | ||
Test an example of label assignation to a picking's package | ||
""" | ||
self.picking.carrier_id.automatic_package_creation_at_delivery = True | ||
self.picking.send_to_shipper() | ||
|
||
self.assertTrue(self.picking.has_packages) | ||
|
||
lines = self.picking.move_line_ids.filtered("package_level_id") | ||
|
||
self.assertEqual("123231-1", lines.package_level_id.package_id.parcel_tracking) | ||
|
||
def test_labels_without_packages(self): | ||
""" | ||
Test an example of label assignation to a picking without package | ||
""" | ||
self.picking.carrier_id.automatic_package_creation_at_delivery = False | ||
self.picking.send_to_shipper() | ||
self.assertFalse(self.picking.has_packages) | ||
self.assertEqual("123231", self.picking.carrier_tracking_ref) |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@florian-dacosta I've updated the test here to get the same behavior as before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A migration script is missing to set the value also on existing carriers,
otherwise it is a breaking change.