Skip to content
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

[18][ADD] delivery_carrier_shipping_label : extracted from base_delivery_carrier_label #938

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 111 additions & 0 deletions delivery_carrier_shipping_label/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
===============================
Delivery Carrier Shipping Label
===============================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:4fe4b408850191ac08d98293294acc226617419145b2c065873039d185b43f67
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
: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/18.0/delivery_carrier_shipping_label
: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-18-0/delivery-carrier-18-0-delivery_carrier_shipping_label
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/delivery-carrier&target_branch=18.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module is kind of a technical module as it adds a new model
inheriting the ir.attachment which purpose is to isolate the shipping
label and eventually add some specific fields for this kind of document.
The final main goal beeing to identifiy these shipping labels from the
other documents attached to a picking in order to send it to the right
printer.

**Table of contents**

.. contents::
:local:

Usage
=====

This module is meant to be used in carrier specific implementation. In
the carrier specific label generation method
(delivery.carrier.mycarrier_send_shipping), include the label
information in the result with a dedicated key labels. These labels will
then be attached to the picking and isolated in the dedicated attachment
table. { "labels": [{ "name": "mylabel", "file": base64_label,
"file_type": "zpl", # optional "package_id": package_id, # optional } ]
}

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 to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/delivery-carrier/issues/new?body=module:%20delivery_carrier_shipping_label%0Aversion:%2018.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.

Credits
=======

Authors
-------

* Camptocamp
* Akretion

Contributors
------------

- David BEAL <david.beal@akretion.com>
- Sébastien BEAU <sebastien.beau@akretion.com>
- Yannick Vaucher <yannick.vaucher@camptocamp.com>
- Alexis de Lattre <alexis.delattre@akretion.com>
- Angel Moya <angel.moya@pesol.es>
- Ismael Calvo <ismael.calvo@factorlibre.com>
- Dave Lasley <dave@laslabs.com>
- Timothée Ringeard <timothee.ringeard@camptocamp.com>
- Pimolnat Suntian <pimolnats@ecosoft.co.th>
- Raphaël Reverdy <raphael.reverdy@akretion.com>

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

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.

.. |maintainer-florian-dacosta| image:: https://github.com/florian-dacosta.png?size=40px
:target: https://github.com/florian-dacosta
:alt: florian-dacosta

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-florian-dacosta|

This module is part of the `OCA/delivery-carrier <https://github.com/OCA/delivery-carrier/tree/18.0/delivery_carrier_shipping_label>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions delivery_carrier_shipping_label/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
17 changes: 17 additions & 0 deletions delivery_carrier_shipping_label/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
{
"name": "Delivery Carrier Shipping Label",
"version": "18.0.1.0.0",
"author": "Camptocamp,Akretion,Odoo Community Association (OCA)",
"category": "Delivery",
"maintainers": ["florian-dacosta"],
"depends": [
"stock_delivery",
],
"website": "https://github.com/OCA/delivery-carrier",
"data": [
"security/ir.model.access.csv",
],
"installable": True,
"license": "AGPL-3",
}
3 changes: 3 additions & 0 deletions delivery_carrier_shipping_label/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import delivery_carrier
from . import stock_picking
from . import shipping_label
19 changes: 19 additions & 0 deletions delivery_carrier_shipping_label/models/delivery_carrier.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# 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 send_shipping(self, pickings):
"""Handle labels and if we have them. Expected format is {'labels': [{}, ...]}
The dicts are input for stock.picking#attach_label"""
result = super().send_shipping(pickings)
if result:
for result_dict, picking in zip(result, pickings, strict=False):
for label in result_dict.get("labels", []):
picking.attach_shipping_label(label)

Check warning on line 18 in delivery_carrier_shipping_label/models/delivery_carrier.py

View check run for this annotation

Codecov / codecov/patch

delivery_carrier_shipping_label/models/delivery_carrier.py#L18

Added line #L18 was not covered by tests
return result
22 changes: 22 additions & 0 deletions delivery_carrier_shipping_label/models/shipping_label.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2013-2016 Camptocamp SA
# Copyright 2014 Akretion <http://www.akretion.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models


class ShippingLabel(models.Model):
"""Child class of ir attachment to identify which are labels"""

_name = "shipping.label"
_inherits = {"ir.attachment": "attachment_id"}
_description = "Shipping Label"

file_type = fields.Char(string="File type", default="pdf")
package_id = fields.Many2one(comodel_name="stock.quant.package", string="Pack")
attachment_id = fields.Many2one(
comodel_name="ir.attachment",
string="Attachement",
required=True,
ondelete="cascade",
)
50 changes: 50 additions & 0 deletions delivery_carrier_shipping_label/models/stock_picking.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Copyright 2012-2015 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
from odoo.exceptions import UserError


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

def get_shipping_label_values(self, label):
self.ensure_one()
return {
"name": label["name"],
"res_id": self.id,
"res_model": "stock.picking",
"datas": label["file"],
"file_type": label["file_type"],
"package_id": label.get("package_id", False),
}

def attach_shipping_label(self, label):
"""Attach a label returned by send_to_shipper to a picking"""
self.ensure_one()
data = self.get_shipping_label_values(label)
context_attachment = self.env.context.copy()
# remove default_type setted for stock_picking
# as it would try to define default value of attachement
if "default_type" in context_attachment:
del context_attachment["default_type"]
return (
self.env["shipping.label"].with_context(**context_attachment).create(data)
)

def _check_existing_shipping_label(self):
"""Check that labels don't already exist for this picking"""
self.ensure_one()
labels = self.env["shipping.label"].search(

Check warning on line 39 in delivery_carrier_shipping_label/models/stock_picking.py

View check run for this annotation

Codecov / codecov/patch

delivery_carrier_shipping_label/models/stock_picking.py#L38-L39

Added lines #L38 - L39 were not covered by tests
[("res_id", "=", self.id), ("res_model", "=", "stock.picking")]
)
if labels:
raise UserError(

Check warning on line 43 in delivery_carrier_shipping_label/models/stock_picking.py

View check run for this annotation

Codecov / codecov/patch

delivery_carrier_shipping_label/models/stock_picking.py#L43

Added line #L43 was not covered by tests
_(
"Some labels already exist for the picking %s.\n"
"Please delete the existing labels in the "
"attachments of this picking and try again"
)
% self.name
)
3 changes: 3 additions & 0 deletions delivery_carrier_shipping_label/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
10 changes: 10 additions & 0 deletions delivery_carrier_shipping_label/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
- David BEAL \<<david.beal@akretion.com>\>
- Sébastien BEAU \<<sebastien.beau@akretion.com>\>
- Yannick Vaucher \<<yannick.vaucher@camptocamp.com>\>
- Alexis de Lattre \<<alexis.delattre@akretion.com>\>
- Angel Moya \<<angel.moya@pesol.es>\>
- Ismael Calvo \<<ismael.calvo@factorlibre.com>\>
- Dave Lasley \<<dave@laslabs.com>\>
- Timothée Ringeard \<<timothee.ringeard@camptocamp.com>\>
- Pimolnat Suntian \<<pimolnats@ecosoft.co.th>\>
- Raphaël Reverdy \<<raphael.reverdy@akretion.com>\>
3 changes: 3 additions & 0 deletions delivery_carrier_shipping_label/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This module is kind of a technical module as it adds a new model inheriting the ir.attachment
which purpose is to isolate the shipping label and eventually add some specific fields for this kind of document.
The final main goal beeing to identifiy these shipping labels from the other documents attached to a picking in order to send it to the right printer.
12 changes: 12 additions & 0 deletions delivery_carrier_shipping_label/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
This module is meant to be used in carrier specific implementation.
In the carrier specific label generation method (delivery.carrier.mycarrier_send_shipping), include the label information in the result with
a dedicated key labels. These labels will then be attached to the picking and isolated in the dedicated attachment table.
{
"labels": [{
"name": "mylabel",
"file": base64_label,
"file_type": "zpl", # optional
"package_id": package_id, # optional
}
]
}
3 changes: 3 additions & 0 deletions delivery_carrier_shipping_label/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_shipping_label_user,shipping.label user,model_shipping_label,stock.group_stock_user,1,1,1,0
access_shipping_label_manager,shipping.label manager,model_shipping_label,stock.group_stock_manager,1,1,1,1
Loading
Loading