-
-
Notifications
You must be signed in to change notification settings - Fork 365
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] delivery_carrier_shipping_label : extracted from base_delivery_…
…carrier_label (issue 896)
- Loading branch information
1 parent
2413e68
commit a6c77e3
Showing
19 changed files
with
845 additions
and
0 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 |
---|---|---|
@@ -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 <[email protected]> | ||
- Sébastien BEAU <[email protected]> | ||
- Yannick Vaucher <[email protected]> | ||
- Alexis de Lattre <[email protected]> | ||
- Angel Moya <[email protected]> | ||
- Ismael Calvo <[email protected]> | ||
- Dave Lasley <[email protected]> | ||
- Timothée Ringeard <[email protected]> | ||
- Pimolnat Suntian <[email protected]> | ||
- Raphaël Reverdy <[email protected]> | ||
|
||
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. |
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 @@ | ||
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
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", | ||
} |
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,3 @@ | ||
from . import delivery_carrier | ||
from . import stock_picking | ||
from . import shipping_label |
19 changes: 19 additions & 0 deletions
19
delivery_carrier_shipping_label/models/delivery_carrier.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 |
---|---|---|
@@ -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) | ||
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 |
---|---|---|
@@ -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", | ||
) |
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,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( | ||
[("res_id", "=", self.id), ("res_model", "=", "stock.picking")] | ||
) | ||
if labels: | ||
raise UserError( | ||
_( | ||
"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 | ||
) |
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,3 @@ | ||
[build-system] | ||
requires = ["whool"] | ||
build-backend = "whool.buildapi" |
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,10 @@ | ||
- David BEAL \<<[email protected]>\> | ||
- Sébastien BEAU \<<[email protected]>\> | ||
- Yannick Vaucher \<<[email protected]>\> | ||
- Alexis de Lattre \<<[email protected]>\> | ||
- Angel Moya \<<[email protected]>\> | ||
- Ismael Calvo \<<[email protected]>\> | ||
- Dave Lasley \<<[email protected]>\> | ||
- Timothée Ringeard \<<[email protected]>\> | ||
- Pimolnat Suntian \<<[email protected]>\> | ||
- Raphaël Reverdy \<<[email protected]>\> |
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,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. |
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,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 | ||
} | ||
] | ||
} |
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,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 |
Oops, something went wrong.