Skip to content

Commit 60ede80

Browse files
[ADD] delivery_carrier_shipping_label : extracted from base_delivery_carrier_label (issue 896)
1 parent 2413e68 commit 60ede80

19 files changed

+834
-0
lines changed
+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
===============================
2+
Delivery Carrier Shipping Label
3+
===============================
4+
5+
..
6+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
7+
!! This file is generated by oca-gen-addon-readme !!
8+
!! changes will be overwritten. !!
9+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10+
!! source digest: sha256:4fe4b408850191ac08d98293294acc226617419145b2c065873039d185b43f67
11+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
12+
13+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
14+
:target: https://odoo-community.org/page/development-status
15+
:alt: Beta
16+
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
17+
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
18+
:alt: License: AGPL-3
19+
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fdelivery--carrier-lightgray.png?logo=github
20+
:target: https://github.com/OCA/delivery-carrier/tree/18.0/delivery_carrier_shipping_label
21+
:alt: OCA/delivery-carrier
22+
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23+
:target: https://translation.odoo-community.org/projects/delivery-carrier-18-0/delivery-carrier-18-0-delivery_carrier_shipping_label
24+
:alt: Translate me on Weblate
25+
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/delivery-carrier&target_branch=18.0
27+
:alt: Try me on Runboat
28+
29+
|badge1| |badge2| |badge3| |badge4| |badge5|
30+
31+
This module is kind of a technical module as it adds a new model
32+
inheriting the ir.attachment which purpose is to isolate the shipping
33+
label and eventually add some specific fields for this kind of document.
34+
The final main goal beeing to identifiy these shipping labels from the
35+
other documents attached to a picking in order to send it to the right
36+
printer.
37+
38+
**Table of contents**
39+
40+
.. contents::
41+
:local:
42+
43+
Usage
44+
=====
45+
46+
This module is meant to be used in carrier specific implementation. In
47+
the carrier specific label generation method
48+
(delivery.carrier.mycarrier_send_shipping), include the label
49+
information in the result with a dedicated key labels. These labels will
50+
then be attached to the picking and isolated in the dedicated attachment
51+
table. { "labels": [{ "name": "mylabel", "file": base64_label,
52+
"file_type": "zpl", # optional "package_id": package_id, # optional } ]
53+
}
54+
55+
Bug Tracker
56+
===========
57+
58+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/delivery-carrier/issues>`_.
59+
In case of trouble, please check there if your issue has already been reported.
60+
If you spotted it first, help us to smash it by providing a detailed and welcomed
61+
`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**>`_.
62+
63+
Do not contact contributors directly about support or help with technical issues.
64+
65+
Credits
66+
=======
67+
68+
Authors
69+
-------
70+
71+
* Camptocamp
72+
* Akretion
73+
74+
Contributors
75+
------------
76+
77+
- David BEAL <david.beal@akretion.com>
78+
- Sébastien BEAU <sebastien.beau@akretion.com>
79+
- Yannick Vaucher <yannick.vaucher@camptocamp.com>
80+
- Alexis de Lattre <alexis.delattre@akretion.com>
81+
- Angel Moya <angel.moya@pesol.es>
82+
- Ismael Calvo <ismael.calvo@factorlibre.com>
83+
- Dave Lasley <dave@laslabs.com>
84+
- Timothée Ringeard <timothee.ringeard@camptocamp.com>
85+
- Pimolnat Suntian <pimolnats@ecosoft.co.th>
86+
- Raphaël Reverdy <raphael.reverdy@akretion.com>
87+
88+
Maintainers
89+
-----------
90+
91+
This module is maintained by the OCA.
92+
93+
.. image:: https://odoo-community.org/logo.png
94+
:alt: Odoo Community Association
95+
:target: https://odoo-community.org
96+
97+
OCA, or the Odoo Community Association, is a nonprofit organization whose
98+
mission is to support the collaborative development of Odoo features and
99+
promote its widespread use.
100+
101+
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.
102+
103+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import models
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
2+
{
3+
"name": "Delivery Carrier Shipping Label",
4+
"version": "18.0.1.0.0",
5+
"author": "Camptocamp,Akretion,Odoo Community Association (OCA)",
6+
"category": "Delivery",
7+
"depends": [
8+
"stock_delivery",
9+
],
10+
"website": "https://github.com/OCA/delivery-carrier",
11+
"data": [
12+
"security/ir.model.access.csv",
13+
],
14+
"installable": True,
15+
"license": "AGPL-3",
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from . import delivery_carrier
2+
from . import stock_picking
3+
from . import shipping_label
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copyright 2012 Akretion <http://www.akretion.com>.
2+
# Copyright 2013-2016 Camptocamp SA
3+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
4+
5+
from odoo import models
6+
7+
8+
class DeliveryCarrier(models.Model):
9+
_inherit = "delivery.carrier"
10+
11+
def send_shipping(self, pickings):
12+
"""Handle labels and if we have them. Expected format is {'labels': [{}, ...]}
13+
The dicts are input for stock.picking#attach_label"""
14+
result = super().send_shipping(pickings)
15+
if result:
16+
for result_dict, picking in zip(result, pickings, strict=False):
17+
for label in result_dict.get("labels", []):
18+
picking.attach_shipping_label(label)
19+
return result
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Copyright 2013-2016 Camptocamp SA
2+
# Copyright 2014 Akretion <http://www.akretion.com>
3+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
4+
5+
from odoo import fields, models
6+
7+
8+
class ShippingLabel(models.Model):
9+
"""Child class of ir attachment to identify which are labels"""
10+
11+
_name = "shipping.label"
12+
_inherits = {"ir.attachment": "attachment_id"}
13+
_description = "Shipping Label"
14+
15+
file_type = fields.Char(string="File type", default="pdf")
16+
package_id = fields.Many2one(comodel_name="stock.quant.package", string="Pack")
17+
attachment_id = fields.Many2one(
18+
comodel_name="ir.attachment",
19+
string="Attachement",
20+
required=True,
21+
ondelete="cascade",
22+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Copyright 2012-2015 Akretion <http://www.akretion.com>.
2+
# Copyright 2013-2016 Camptocamp SA
3+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
4+
5+
from odoo import _, models
6+
from odoo.exceptions import UserError
7+
8+
9+
class StockPicking(models.Model):
10+
_inherit = "stock.picking"
11+
12+
def get_shipping_label_values(self, label):
13+
self.ensure_one()
14+
return {
15+
"name": label["name"],
16+
"res_id": self.id,
17+
"res_model": "stock.picking",
18+
"datas": label["file"],
19+
"file_type": label["file_type"],
20+
"package_id": label.get("package_id", False),
21+
}
22+
23+
def attach_shipping_label(self, label):
24+
"""Attach a label returned by send_to_shipper to a picking"""
25+
self.ensure_one()
26+
data = self.get_shipping_label_values(label)
27+
context_attachment = self.env.context.copy()
28+
# remove default_type setted for stock_picking
29+
# as it would try to define default value of attachement
30+
if "default_type" in context_attachment:
31+
del context_attachment["default_type"]
32+
return (
33+
self.env["shipping.label"].with_context(**context_attachment).create(data)
34+
)
35+
36+
def _check_existing_shipping_label(self):
37+
"""Check that labels don't already exist for this picking"""
38+
self.ensure_one()
39+
labels = self.env["shipping.label"].search(
40+
[("res_id", "=", self.id), ("res_model", "=", "stock.picking")]
41+
)
42+
if labels:
43+
raise UserError(
44+
_(
45+
"Some labels already exist for the picking %s.\n"
46+
"Please delete the existing labels in the "
47+
"attachments of this picking and try again"
48+
)
49+
% self.name
50+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[build-system]
2+
requires = ["whool"]
3+
build-backend = "whool.buildapi"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
- David BEAL \<<david.beal@akretion.com>\>
2+
- Sébastien BEAU \<<sebastien.beau@akretion.com>\>
3+
- Yannick Vaucher \<<yannick.vaucher@camptocamp.com>\>
4+
- Alexis de Lattre \<<alexis.delattre@akretion.com>\>
5+
- Angel Moya \<<angel.moya@pesol.es>\>
6+
- Ismael Calvo \<<ismael.calvo@factorlibre.com>\>
7+
- Dave Lasley \<<dave@laslabs.com>\>
8+
- Timothée Ringeard \<<timothee.ringeard@camptocamp.com>\>
9+
- Pimolnat Suntian \<<pimolnats@ecosoft.co.th>\>
10+
- Raphaël Reverdy \<<raphael.reverdy@akretion.com>\>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This module is kind of a technical module as it adds a new model inheriting the ir.attachment
2+
which purpose is to isolate the shipping label and eventually add some specific fields for this kind of document.
3+
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.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
This module is meant to be used in carrier specific implementation.
2+
In the carrier specific label generation method (delivery.carrier.mycarrier_send_shipping), include the label information in the result with
3+
a dedicated key labels. These labels will then be attached to the picking and isolated in the dedicated attachment table.
4+
{
5+
"labels": [{
6+
"name": "mylabel",
7+
"file": base64_label,
8+
"file_type": "zpl", # optional
9+
"package_id": package_id, # optional
10+
}
11+
]
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
2+
access_shipping_label_user,shipping.label user,model_shipping_label,stock.group_stock_user,1,1,1,0
3+
access_shipping_label_manager,shipping.label manager,model_shipping_label,stock.group_stock_manager,1,1,1,1

0 commit comments

Comments
 (0)