Skip to content

Commit

Permalink
[MIG] migration to v14.0
Browse files Browse the repository at this point in the history
  • Loading branch information
KKamaa committed Feb 26, 2022
1 parent b93deda commit d68f715
Show file tree
Hide file tree
Showing 13 changed files with 127 additions and 159 deletions.
12 changes: 7 additions & 5 deletions delivery_carrier_label_default/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand All @@ -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.

Expand All @@ -54,6 +54,7 @@ Authors
~~~~~~~

* Camptocamp
* Sunflower IT

Contributors
~~~~~~~~~~~~
Expand All @@ -62,6 +63,7 @@ Contributors
* Sébastien Alix <[email protected]>
* Sergio Teruel <[email protected]>
* Iryna Vyshnevska <[email protected]>
* Kevin Kamau <[email protected]>

Other credits
~~~~~~~~~~~~~
Expand All @@ -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.
3 changes: 3 additions & 0 deletions delivery_carrier_label_default/__init__.py
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
6 changes: 4 additions & 2 deletions delivery_carrier_label_default/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
# Copyright 2013-2019 Camptocamp SA
# Copyright 2021 Sunflower IT
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
{
"name": "Default label for carrier labels",
"summary": "This module defines a basic label to print "
"when no specific carrier is selected.",
"version": "12.0.1.0.0",
"version": "14.0.1.0.0",
"development_status": "Production/Stable",
"category": "Delivery",
"website": "https://github.com/OCA/delivery-carrier",
"author": "Camptocamp, Odoo Community Association (OCA)",
"author": "Camptocamp, Sunflower IT, Odoo Community Association (OCA)",
"license": "AGPL-3",
"installable": True,
"depends": [
"stock",
"base_delivery_carrier_label",
],
"data": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 12.0\n"
"Project-Id-Version: Odoo Server 14.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: <>\n"
"Language-Team: \n"
Expand All @@ -14,7 +14,7 @@ msgstr ""
"Plural-Forms: \n"

#. module: delivery_carrier_label_default
#: model:ir.actions.report,name:delivery_carrier_label_default.default_label
#: model:ir.actions.report,name:delivery_carrier_label_default.action_default_label
msgid "Shipping Label"
msgstr ""

Expand Down
6 changes: 5 additions & 1 deletion delivery_carrier_label_default/models/__init__.py
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
38 changes: 38 additions & 0 deletions delivery_carrier_label_default/models/delivery_carrier.py
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
1 change: 1 addition & 0 deletions delivery_carrier_label_default/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
10 changes: 6 additions & 4 deletions delivery_carrier_label_default/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.15.1: http://docutils.sourceforge.net/" />
<meta name="generator" content="Docutils: http://docutils.sourceforge.net/" />
<title>Default label for carrier labels</title>
<style type="text/css">

Expand Down Expand Up @@ -367,7 +367,7 @@ <h1 class="title">Default label for carrier labels</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Production/Stable" src="https://img.shields.io/badge/maturity-Production%2FStable-green.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/delivery-carrier/tree/12.0/delivery_carrier_label_default"><img alt="OCA/delivery-carrier" src="https://img.shields.io/badge/github-OCA%2Fdelivery--carrier-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/delivery-carrier-12-0/delivery-carrier-12-0-delivery_carrier_label_default"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/99/12.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Production/Stable" src="https://img.shields.io/badge/maturity-Production%2FStable-green.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/delivery-carrier/tree/14.0/delivery_carrier_label_default"><img alt="OCA/delivery-carrier" src="https://img.shields.io/badge/github-OCA%2Fdelivery--carrier-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/delivery-carrier-14-0/delivery-carrier-14-0-delivery_carrier_label_default"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/99/14.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p>This module defines a basic label to print when no specific carrier is selected.</p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
Expand Down Expand Up @@ -397,7 +397,7 @@ <h1><a class="toc-backref" href="#id2">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/delivery-carrier/issues">GitHub Issues</a>.
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
<a class="reference external" href="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</a>.</p>
<a class="reference external" href="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**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
Expand All @@ -406,6 +406,7 @@ <h1><a class="toc-backref" href="#id3">Credits</a></h1>
<h2><a class="toc-backref" href="#id4">Authors</a></h2>
<ul class="simple">
<li>Camptocamp</li>
<li>Sunflower IT</li>
</ul>
</div>
<div class="section" id="contributors">
Expand All @@ -415,6 +416,7 @@ <h2><a class="toc-backref" href="#id5">Contributors</a></h2>
<li>Sébastien Alix &lt;<a class="reference external" href="mailto:sebastien.alix&#64;camptocamp.com">sebastien.alix&#64;camptocamp.com</a>&gt;</li>
<li>Sergio Teruel &lt;<a class="reference external" href="mailto:sergio.teruel&#64;tecnativa.com">sergio.teruel&#64;tecnativa.com</a>&gt;</li>
<li>Iryna Vyshnevska &lt;<a class="reference external" href="mailto:i.vyshnevska&#64;mobilunity.com">i.vyshnevska&#64;mobilunity.com</a>&gt;</li>
<li>Kevin Kamau &lt;<a class="reference external" href="mailto:kevin&#64;sunflowerweb.nl">kevin&#64;sunflowerweb.nl</a>&gt;</li>
</ul>
</div>
<div class="section" id="other-credits">
Expand All @@ -433,7 +435,7 @@ <h2><a class="toc-backref" href="#id8">Maintainers</a></h2>
<p>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.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/delivery-carrier/tree/12.0/delivery_carrier_label_default">OCA/delivery-carrier</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/delivery-carrier/tree/14.0/delivery_carrier_label_default">OCA/delivery-carrier</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
Expand Down
3 changes: 3 additions & 0 deletions delivery_carrier_label_default/tests/__init__.py
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
16 changes: 0 additions & 16 deletions delivery_carrier_label_default/tests/common.py

This file was deleted.

138 changes: 29 additions & 109 deletions delivery_carrier_label_default/tests/test_print_label.py
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)
Loading

0 comments on commit d68f715

Please sign in to comment.