Skip to content

Commit

Permalink
[14.0] [MIG] delivery_carrier_label_default: Migrate to 14.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sonhd committed Jan 12, 2022
1 parent a09e1eb commit 95305b1
Show file tree
Hide file tree
Showing 11 changed files with 145 additions and 86 deletions.
27 changes: 14 additions & 13 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 @@ -58,18 +58,19 @@ Authors
Contributors
~~~~~~~~~~~~

* Yannick Vaucher <[email protected]>
* Sébastien Alix <[email protected]>
* Sergio Teruel <[email protected]>
* Iryna Vyshnevska <[email protected]>
* `Camptocamp <https://camptocamp.com>`_:
* Yannick Vaucher <[email protected]>
* Sébastien Alix <[email protected]>
* Iryna Vyshnevska <[email protected]>
* `Tecnativa <https://tecnativa.com/>`_:
* Sergio Teruel <[email protected]>
* `Trobz <https://trobz.com>`_:
* Son Ho <[email protected]>

Other credits
~~~~~~~~~~~~~

Images
------

* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.
The migration of this module from 12.0 to 14.0 was financially supported by Camptocamp

Maintainers
~~~~~~~~~~~
Expand All @@ -84,6 +85,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.
2 changes: 1 addition & 1 deletion delivery_carrier_label_default/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"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",
Expand Down
1 change: 1 addition & 0 deletions delivery_carrier_label_default/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import stock_picking
from . import delivery_carrier
24 changes: 24 additions & 0 deletions delivery_carrier_label_default/models/delivery_carrier.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2012 Akretion <http://www.akretion.com>.
# Copyright 2013-2016 Camptocamp SA
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import models


class DeliveryCarrier(models.Model):
_inherit = "delivery.carrier"

def alternative_send_shipping(self, pickings):
default_label = pickings.generate_default_label()
labels = []
for package in pickings._get_packages_from_picking():
pack_label = default_label.copy()
pack_label["tracking_number"] = package.id
labels.append(pack_label)
return [
{
"exact_price": pickings.carrier_price,
"tracking_number": pickings.package_ids,
"labels": labels,
}
]
24 changes: 21 additions & 3 deletions delivery_carrier_label_default/models/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,38 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
import base64

from odoo import api, models
from odoo import models


class StockPicking(models.Model):
_inherit = "stock.picking"

@api.multi
def generate_default_label(self):
"""Generate a label from a qweb report."""
self.ensure_one()
report = self.env.ref("delivery_carrier_label_default.default_label")
file_, file_type = report.render(res_ids=self.ids)
file_, file_type = report._render(res_ids=self.ids)
return {
"name": "%s.%s" % (report.name, file_type),
"file": base64.b64encode(file_),
"file_type": file_type,
}

def _get_packages_from_picking(self):
""" Get all the packages from the picking """
self.ensure_one()
operation_obj = self.env["stock.move.line"]
packages = self.env["stock.quant.package"].browse()
operations = operation_obj.search(
[
"|",
("package_id", "!=", False),
("result_package_id", "!=", False),
("picking_id", "=", self.id),
]
)
for operation in operations:
# Take the destination package. If empty, the package is
# moved so take the source one.
packages |= operation.result_package_id or operation.package_id
return packages
12 changes: 8 additions & 4 deletions delivery_carrier_label_default/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
* Yannick Vaucher <[email protected]>
* Sébastien Alix <[email protected]>
* Sergio Teruel <[email protected]>
* Iryna Vyshnevska <[email protected]>
* `Camptocamp <https://camptocamp.com>`_:
* Yannick Vaucher <[email protected]>
* Sébastien Alix <[email protected]>
* Iryna Vyshnevska <[email protected]>
* `Tecnativa <https://tecnativa.com/>`_:
* Sergio Teruel <[email protected]>
* `Trobz <https://trobz.com>`_:
* Son Ho <[email protected]>
5 changes: 1 addition & 4 deletions delivery_carrier_label_default/readme/CREDITS.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
Images
------

* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.
The migration of this module from 12.0 to 14.0 was financially supported by Camptocamp
48 changes: 31 additions & 17 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 All @@ -377,11 +377,8 @@ <h1 class="title">Default label for carrier labels</h1>
<li><a class="reference internal" href="#credits" id="id3">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="id4">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="id5">Contributors</a></li>
<li><a class="reference internal" href="#other-credits" id="id6">Other credits</a><ul>
<li><a class="reference internal" href="#images" id="id7">Images</a></li>
</ul>
</li>
<li><a class="reference internal" href="#maintainers" id="id8">Maintainers</a></li>
<li><a class="reference internal" href="#other-credits" id="id6">Other credits</a></li>
<li><a class="reference internal" href="#maintainers" id="id7">Maintainers</a></li>
</ul>
</li>
</ul>
Expand All @@ -397,7 +394,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 @@ -411,29 +408,46 @@ <h2><a class="toc-backref" href="#id4">Authors</a></h2>
<div class="section" id="contributors">
<h2><a class="toc-backref" href="#id5">Contributors</a></h2>
<ul class="simple">
<li><dl class="first docutils">
<dt><a class="reference external" href="https://camptocamp.com">Camptocamp</a>:</dt>
<dd><ul class="first last">
<li>Yannick Vaucher &lt;<a class="reference external" href="mailto:yannick.vaucher&#64;camptocamp.com">yannick.vaucher&#64;camptocamp.com</a>&gt;</li>
<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>Iryna Vyshnevska &lt;<a class="reference external" href="mailto:i.vyshnevska&#64;camptocamp.com">i.vyshnevska&#64;camptocamp.com</a>&gt;</li>
</ul>
</dd>
</dl>
</li>
<li><dl class="first docutils">
<dt><a class="reference external" href="https://tecnativa.com/">Tecnativa</a>:</dt>
<dd><ul class="first last">
<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>
</ul>
</dd>
</dl>
</li>
<li><dl class="first docutils">
<dt><a class="reference external" href="https://trobz.com">Trobz</a>:</dt>
<dd><ul class="first last">
<li>Son Ho &lt;<a class="reference external" href="mailto:sonhd&#64;trobz.com">sonhd&#64;trobz.com</a>&gt;</li>
</ul>
</dd>
</dl>
</li>
</ul>
</div>
<div class="section" id="other-credits">
<h2><a class="toc-backref" href="#id6">Other credits</a></h2>
<div class="section" id="images">
<h3><a class="toc-backref" href="#id7">Images</a></h3>
<ul class="simple">
<li>Odoo Community Association: <a class="reference external" href="https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg">Icon</a>.</li>
</ul>
</div>
<p>The migration of this module from 12.0 to 14.0 was financially supported by Camptocamp</p>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#id8">Maintainers</a></h2>
<h2><a class="toc-backref" href="#id7">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<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
23 changes: 11 additions & 12 deletions delivery_carrier_label_default/tests/test_print_label.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# Copyright 2013-2019 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
import base64

import mock
from unittest import mock

from odoo.tests import common

Expand Down Expand Up @@ -87,12 +86,12 @@ 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()
self.picking.send_to_shipper()
label = self.env["shipping.label"].search([("res_id", "=", self.picking.id)])
self.assertEquals(len(label), 1)
self.assertEqual(len(label), 1)
self.assertTrue(label.datas)
self.assertEquals(label.name, "Shipping Label.html")
self.assertEquals(label.file_type, "html")
self.assertEqual(label.name, "Shipping Label.html")
self.assertEqual(label.file_type, "html")
self.check_label_content(label.datas)

@patch_label_file_type
Expand All @@ -102,17 +101,17 @@ def test_print_default_label_selected_packs(self):
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()
self.picking.action_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()
self.picking.action_put_in_pack()
self.picking.send_to_shipper()
labels = self.env["shipping.label"].search([("res_id", "=", self.picking.id)])
self.assertEquals(len(labels), 2)
self.assertEqual(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.assertEqual(label.name, "Shipping Label.html")
self.assertEqual(label.file_type, "html")
self.check_label_content(label.datas)
20 changes: 10 additions & 10 deletions delivery_carrier_label_default/views/report_default_label.xml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<odoo>
<template id="report_default_label">
<t t-foreach="docs" t-as="o">
<t t-call="web.basic_layout">
<div class="page">
<div class="address">
<div class="recipient">
<address
<template id="report_default_label">
<t t-foreach="docs" t-as="o">
<t t-call="web.basic_layout">
<div class="page">
<div class="address">
<div class="recipient">
<address
t-field="o.partner_id"
t-field-options='{"widget": "contact", "fields": ["address", "name"], "no_marker": true}'
/>
</div>
</div>
</div>
</div>
</t>
</t>
</t>
</template>
</template>
</odoo>
45 changes: 23 additions & 22 deletions delivery_carrier_label_default/views/reports.xml
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record model="report.paperformat" id="paperformat_a7_label">
<field name="name">Label A7 format</field>
<field name="format">A7</field>
<field name="orientation">Landscape</field>
<field name="margin_top">20</field>
<field name="margin_bottom">20</field>
<field name="margin_left">7</field>
</record>

<record model="report.paperformat" id="paperformat_a7_label">
<field name="name">Label A7 format</field>
<field name="format">A7</field>
<field name="orientation">Landscape</field>
<field name="margin_top">20</field>
<field name="margin_bottom">20</field>
<field name="margin_left">7</field>
</record>

<report
id="default_label"
model="stock.picking"
string="Shipping Label"
name="delivery_carrier_label_default.report_default_label"
file="delivery_carrier_label_default.report_default_label"
report_type="qweb-pdf"
attachment_use="True"
multi="False"
paperformat="paperformat_a7_label"
/>
/>

<record id="default_label" model="ir.actions.report">
<field name="name">Shipping Label</field>
<field name="model">stock.picking</field>
<field name="report_type">qweb-pdf</field>
<field
name="report_name"
>delivery_carrier_label_default.report_default_label</field>
<field
name="report_file"
>delivery_carrier_label_default.report_default_label</field>
<field
name="paperformat_id"
ref="delivery_carrier_label_default.paperformat_a7_label"
/>
</record>
</odoo>

0 comments on commit 95305b1

Please sign in to comment.