-
-
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.
- Loading branch information
Showing
13 changed files
with
127 additions
and
159 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,13 +14,13 @@ Default label for carrier labels | |
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html | ||
:alt: License: AGPL-3 | ||
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fdelivery--carrier-lightgray.png?logo=github | ||
:target: https://github.com/OCA/delivery-carrier/tree/12.0/delivery_carrier_label_default | ||
:target: https://github.com/OCA/delivery-carrier/tree/14.0/delivery_carrier_label_default | ||
:alt: OCA/delivery-carrier | ||
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png | ||
:target: https://translation.odoo-community.org/projects/delivery-carrier-12-0/delivery-carrier-12-0-delivery_carrier_label_default | ||
:target: https://translation.odoo-community.org/projects/delivery-carrier-14-0/delivery-carrier-14-0-delivery_carrier_label_default | ||
:alt: Translate me on Weblate | ||
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png | ||
:target: https://runbot.odoo-community.org/runbot/99/12.0 | ||
:target: https://runbot.odoo-community.org/runbot/99/14.0 | ||
:alt: Try me on Runbot | ||
|
||
|badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
@@ -43,7 +43,7 @@ Bug Tracker | |
Bugs are tracked on `GitHub Issues <https://github.com/OCA/delivery-carrier/issues>`_. | ||
In case of trouble, please check there if your issue has already been reported. | ||
If you spotted it first, help us smashing it by providing a detailed and welcomed | ||
`feedback <https://github.com/OCA/delivery-carrier/issues/new?body=module:%20delivery_carrier_label_default%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. | ||
`feedback <https://github.com/OCA/delivery-carrier/issues/new?body=module:%20delivery_carrier_label_default%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. | ||
|
||
Do not contact contributors directly about support or help with technical issues. | ||
|
||
|
@@ -54,6 +54,7 @@ Authors | |
~~~~~~~ | ||
|
||
* Camptocamp | ||
* Sunflower IT | ||
|
||
Contributors | ||
~~~~~~~~~~~~ | ||
|
@@ -62,6 +63,7 @@ Contributors | |
* Sébastien Alix <[email protected]> | ||
* Sergio Teruel <[email protected]> | ||
* Iryna Vyshnevska <[email protected]> | ||
* Kevin Kamau <[email protected]> | ||
|
||
Other credits | ||
~~~~~~~~~~~~~ | ||
|
@@ -84,6 +86,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose | |
mission is to support the collaborative development of Odoo features and | ||
promote its widespread use. | ||
|
||
This module is part of the `OCA/delivery-carrier <https://github.com/OCA/delivery-carrier/tree/12.0/delivery_carrier_label_default>`_ project on GitHub. | ||
This module is part of the `OCA/delivery-carrier <https://github.com/OCA/delivery-carrier/tree/14.0/delivery_carrier_label_default>`_ project on GitHub. | ||
|
||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
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 +1,4 @@ | ||
# Copyright 2021 Sunflower IT | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) | ||
|
||
from . import models |
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 +1,5 @@ | ||
from . import stock_picking | ||
# Copyright 2013-2019 Camptocamp SA | ||
# Copyright 2021 Sunflower IT | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) | ||
|
||
from . import delivery_carrier |
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,38 @@ | ||
# Copyright 2013-2019 Camptocamp SA | ||
# Copyright 2021 Sunflower IT | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) | ||
import base64 | ||
|
||
from odoo import models | ||
|
||
|
||
class DeliveryCarrier(models.Model): | ||
_inherit = "delivery.carrier" | ||
|
||
def send_shipping(self, pickings): | ||
# call parent chain. | ||
result = super().send_shipping(pickings) | ||
# check if parent result has label defined, if not, add default label | ||
# Avoid more than one default attachment to be added. (No dups) | ||
if "labels" not in result[0]: | ||
attachment = self.env["ir.attachment"].search( | ||
[("name", "=ilike", ("%" + pickings[0].name + "%"))] | ||
) | ||
if not attachment: | ||
pdf_report = self.env.ref( | ||
"delivery_carrier_label_default.action_default_label" | ||
)._render_qweb_pdf([pickings[0].id]) | ||
if pdf_report: | ||
result[0]["labels"] = [ | ||
{ | ||
"name": "Shipping Label %s.pdf" % pickings[0].name, | ||
"file": base64.b64encode(pdf_report[0]), | ||
"file_type": "pdf", | ||
} | ||
] | ||
if result is None: | ||
result = self.alternative_send_shipping(pickings) | ||
for result_dict, picking in zip(result, pickings): | ||
for label in result_dict.get("labels", []): | ||
picking.attach_shipping_label(label) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
* Sébastien Alix <[email protected]> | ||
* Sergio Teruel <[email protected]> | ||
* Iryna Vyshnevska <[email protected]> | ||
* Kevin Kamau <[email protected]> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 +1,4 @@ | ||
# Copyright 2021 Sunflower IT | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) | ||
|
||
from . import test_print_label |
This file was deleted.
Oops, something went wrong.
138 changes: 29 additions & 109 deletions
138
delivery_carrier_label_default/tests/test_print_label.py
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,118 +1,38 @@ | ||
# Copyright 2013-2019 Camptocamp SA | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) | ||
import base64 | ||
# Copyright 2021 Sunflower IT (http://sunflowerweb.nl) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
import mock | ||
|
||
from odoo.tests import common | ||
from odoo.tests.common import Form, TransactionCase | ||
|
||
from .common import HTMLRenderMixin | ||
|
||
MOD_PATH = "odoo.addons.base_delivery_carrier_label.models" | ||
LABEL_MODEL = MOD_PATH + ".shipping_label.ShippingLabel" | ||
class TestPrintLabel(TransactionCase): | ||
"""Test print a default label """ | ||
|
||
|
||
def patch_label_file_type(function): | ||
"""Decorator to patch the 'shipping.label.file_type' selection field | ||
to allow the 'html' type when running tests. | ||
""" | ||
|
||
def wrapper(*args, **kwargs): | ||
with mock.patch(LABEL_MODEL + ".file_type") as (file_type): | ||
file_type.return_value = "html" | ||
result = function(*args, **kwargs) | ||
return result | ||
|
||
return wrapper | ||
|
||
|
||
class TestPrintLabel(common.SavepointCase, HTMLRenderMixin): | ||
"""Test label printing. | ||
When running tests Odoo renders PDF reports as HTML, | ||
so we are going to test the shipping labels as HTML document only. | ||
A good side effect: we are able to test the rendered content. | ||
""" | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
super().setUpClass() | ||
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True)) | ||
Product = cls.env["product.product"] | ||
stock_location = cls.env.ref("stock.stock_location_stock") | ||
customer_location = cls.env.ref("stock.stock_location_customers") | ||
Picking = cls.env["stock.picking"] | ||
cls.picking = Picking.create( | ||
{ | ||
"picking_type_id": cls.env.ref("stock.picking_type_out").id, | ||
"location_id": stock_location.id, | ||
"location_dest_id": customer_location.id, | ||
} | ||
def test_print_label(self): | ||
"""Test if the module picks up default labels returned from | ||
delivery.carrier#send""" | ||
carrier = self.env.ref("delivery.normal_delivery_carrier") | ||
picking_form = Form( | ||
self.env["stock.picking"].with_context( | ||
default_picking_type_id=self.env.ref("stock.picking_type_out").id, | ||
) | ||
) | ||
product_a = Product.create({"name": "Product A"}) | ||
product_b = Product.create({"name": "Product B"}) | ||
|
||
cls.env["stock.move"].create( | ||
{ | ||
"name": "a move", | ||
"product_id": product_a.id, | ||
"product_uom_qty": 3.0, | ||
"product_uom": product_a.uom_id.id, | ||
"picking_id": cls.picking.id, | ||
"location_id": stock_location.id, | ||
"location_dest_id": customer_location.id, | ||
} | ||
picking_form.carrier_id = carrier | ||
picking = picking_form.save() | ||
|
||
with mock.patch.object(type(carrier), "fixed_send_shipping") as mocked: | ||
mocked.return_value = [ | ||
{ | ||
"exact_price": carrier.fixed_price, | ||
"tracking_number": False, | ||
} | ||
] | ||
carrier.send_shipping(picking) | ||
attachment = self.env["ir.attachment"].search( | ||
[("name", "=ilike", ("%" + picking.name + "%"))] | ||
) | ||
cls.env["stock.move"].create( | ||
{ | ||
"name": "a second move", | ||
"product_id": product_b.id, | ||
"product_uom_qty": 12.0, | ||
"product_uom": product_b.uom_id.id, | ||
"picking_id": cls.picking.id, | ||
"location_id": stock_location.id, | ||
"location_dest_id": customer_location.id, | ||
} | ||
self.assertEqual( | ||
attachment.mimetype, "application/pdf", "Wrong attachment created" | ||
) | ||
|
||
def check_label_content(self, b64_datas): | ||
html_datas = base64.b64decode(b64_datas) | ||
node = self.to_xml_node(html_datas)[0] | ||
for div_class in ["page", "address", "recipient"]: | ||
tags = self.find_div_class(node, div_class) | ||
self.assertEqual(len(tags), 1) | ||
|
||
@patch_label_file_type | ||
def test_print_default_label(self): | ||
# assign picking to generate 'stock.move.line' | ||
self.picking.action_confirm() | ||
self.picking.action_assign() | ||
self.picking.action_generate_carrier_label() | ||
label = self.env["shipping.label"].search([("res_id", "=", self.picking.id)]) | ||
self.assertEquals(len(label), 1) | ||
self.assertTrue(label.datas) | ||
self.assertEquals(label.name, "Shipping Label.html") | ||
self.assertEquals(label.file_type, "html") | ||
self.check_label_content(label.datas) | ||
|
||
@patch_label_file_type | ||
def test_print_default_label_selected_packs(self): | ||
# create packs | ||
self.picking.action_confirm() | ||
self.picking.action_assign() | ||
self.picking.move_line_ids[0].qty_done = 3 | ||
self.picking.move_line_ids[1].qty_done = 3 | ||
self.picking.put_in_pack() | ||
for ope in self.picking.move_line_ids: | ||
if ope.qty_done == 0: | ||
ope.qty_done = 9 | ||
break | ||
self.picking.put_in_pack() | ||
self.picking.action_generate_carrier_label() | ||
labels = self.env["shipping.label"].search([("res_id", "=", self.picking.id)]) | ||
self.assertEquals(len(labels), 2) | ||
for label in labels: | ||
self.assertTrue(label.datas) | ||
self.assertEquals(label.name, "Shipping Label.html") | ||
self.assertEquals(label.file_type, "html") | ||
self.check_label_content(label.datas) | ||
self.assertTrue(len(attachment) == 1) |
Oops, something went wrong.