Skip to content

Commit 1c2e92d

Browse files
committed
[ADD] delivery_roulier_picking_batch
1 parent 85abe2c commit 1c2e92d

16 files changed

+1384
-0
lines changed
+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
==============================
2+
Delivery Roulier Picking Batch
3+
==============================
4+
5+
..
6+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
7+
!! This file is generated by oca-gen-addon-readme !!
8+
!! changes will be overwritten. !!
9+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10+
!! source digest: sha256:3874042f9be1a0b3f52c99bbcaf8cde90bc384969de0112059d1fffd216be41c
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/14.0/delivery_roulier_picking_batch
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-14-0/delivery-carrier-14-0-delivery_roulier_picking_batch
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=14.0
27+
:alt: Try me on Runboat
28+
29+
|badge1| |badge2| |badge3| |badge4| |badge5|
30+
31+
This module allows to generate a unique delivery label/tracking for a
32+
whole batch of pickings.
33+
34+
The batch pickings operations will be grouped in a single delivery
35+
package if they are not already in a delivery package. In case of a
36+
batch with multiple packages, a label per package will be created.
37+
38+
This module is only compatible with ``delivery_roulier`` carriers.
39+
40+
**Table of contents**
41+
42+
.. contents::
43+
:local:
44+
45+
Usage
46+
=====
47+
48+
Create a picking batch from
49+
``Inventory > Operations > Batch Transfers``, add some pickings to it
50+
and then enter a valid roulier compatible carrier in the batch
51+
``Additional Info`` notebook page.
52+
53+
Then validate the batch and a delivery label will be generated for each
54+
package in the batch. If there's some operations that are not in a
55+
package, a new package will be created for them.
56+
57+
A tracking number will be generated for each package and the tracking
58+
will be available by clicking the ``Tracking`` smart button.
59+
60+
Bug Tracker
61+
===========
62+
63+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/delivery-carrier/issues>`_.
64+
In case of trouble, please check there if your issue has already been reported.
65+
If you spotted it first, help us to smash it by providing a detailed and welcomed
66+
`feedback <https://github.com/OCA/delivery-carrier/issues/new?body=module:%20delivery_roulier_picking_batch%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
67+
68+
Do not contact contributors directly about support or help with technical issues.
69+
70+
Credits
71+
=======
72+
73+
Authors
74+
-------
75+
76+
* Akretion
77+
78+
Contributors
79+
------------
80+
81+
- Florian Mounier florian.mounier@akretion.com
82+
83+
Maintainers
84+
-----------
85+
86+
This module is maintained by the OCA.
87+
88+
.. image:: https://odoo-community.org/logo.png
89+
:alt: Odoo Community Association
90+
:target: https://odoo-community.org
91+
92+
OCA, or the Odoo Community Association, is a nonprofit organization whose
93+
mission is to support the collaborative development of Odoo features and
94+
promote its widespread use.
95+
96+
This module is part of the `OCA/delivery-carrier <https://github.com/OCA/delivery-carrier/tree/14.0/delivery_roulier_picking_batch>`_ project on GitHub.
97+
98+
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,22 @@
1+
# Copyright 2024 Akretion (http://www.akretion.com).
2+
# @author Florian Mounier <florian.mounier@akretion.com>
3+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
4+
5+
{
6+
"name": "Delivery Roulier Picking Batch",
7+
"version": "14.0.1.0.0",
8+
"author": "Akretion, Odoo Community Association (OCA)",
9+
"summary": "Use roulier in batch picking",
10+
"category": "Warehouse",
11+
"depends": [
12+
"delivery_roulier",
13+
"stock_picking_batch",
14+
],
15+
"website": "https://github.com/OCA/delivery-carrier",
16+
"data": [
17+
"views/stock_picking_batch_views.xml",
18+
],
19+
"demo": [],
20+
"installable": True,
21+
"license": "AGPL-3",
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from . import stock_picking
2+
from . import stock_quant_package
3+
from . import stock_picking_batch
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
# Copyright 2024 Akretion (http://www.akretion.com).
2+
# @author Florian Mounier <florian.mounier@akretion.com>
3+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
4+
from functools import reduce
5+
6+
from odoo import _, models
7+
from odoo.exceptions import UserError
8+
9+
10+
class StockPicking(models.Model):
11+
_inherit = "stock.picking"
12+
13+
def _is_batch_roulier(self):
14+
# Check if the picking is part of a batch with a roulier carrier
15+
self.ensure_one()
16+
return (
17+
self.batch_id
18+
and self.batch_id.carrier_id
19+
and self.batch_id.carrier_id._is_roulier()
20+
)
21+
22+
def send_to_shipper(self):
23+
self.ensure_one()
24+
if self._is_batch_roulier():
25+
# We are in a batch with a roulier carrier
26+
# We need to send unsent packages
27+
packages = self.package_ids - self.batch_id.sent_package_ids
28+
if not packages:
29+
# Nothing to send
30+
return
31+
32+
# First sanity checks
33+
# Check that all package pickings have the same sender/receiver:
34+
for package in packages:
35+
package_pickings = (
36+
self.env["stock.move.line"]
37+
.search(
38+
[
39+
"|",
40+
("result_package_id", "=", package.id),
41+
("package_id", "=", package.id),
42+
]
43+
)
44+
.mapped("picking_id")
45+
)
46+
47+
# Set carrier on pickings
48+
package_pickings.write({"carrier_id": self.carrier_id.id})
49+
50+
# Check sender/receiver uniformity
51+
for kind in ("sender", "receiver"):
52+
addresses = reduce(
53+
lambda x, y: x | y,
54+
(
55+
getattr(package_picking, f"_get_{kind}")()
56+
or self.env["res.partner"]
57+
for package_picking in package_pickings
58+
),
59+
)
60+
if not addresses:
61+
raise UserError(
62+
_(
63+
"Can't determine %(kind)s address for pickings: %(pickings)s"
64+
)
65+
% {
66+
"kind": kind,
67+
"pickings": ", ".join(package_pickings.mapped("name")),
68+
}
69+
)
70+
if len(addresses) > 1:
71+
raise UserError(
72+
_(
73+
"Multiple %(kind)s addresses found for pickings: %(pickings)s"
74+
)
75+
% {
76+
"kind": kind,
77+
"pickings": ", ".join(package_pickings.mapped("name")),
78+
}
79+
)
80+
81+
# Send packages
82+
res = self.batch_id.carrier_id.send_shipping(self)[0]
83+
# Mark packages as sent (for use in _roulier_generate_labels)
84+
self.batch_id.sent_package_ids |= packages
85+
# Update tracking number
86+
if res["tracking_number"]:
87+
self.batch_id.carrier_tracking_ref = ";".join(
88+
[
89+
tracking
90+
for tracking in (
91+
self.batch_id.carrier_tracking_ref,
92+
res["tracking_number"],
93+
)
94+
if tracking
95+
]
96+
)
97+
return
98+
99+
return super().send_to_shipper()
100+
101+
def _roulier_generate_labels(self):
102+
if self._is_batch_roulier():
103+
label_info = []
104+
for picking in self:
105+
# Generate labels only for unsent packages
106+
packages = picking.package_ids - picking.batch_id.sent_package_ids
107+
label_info.append(packages._generate_labels(picking))
108+
return label_info
109+
110+
return super()._roulier_generate_labels()
111+
112+
def get_shipping_label_values(self, label):
113+
self.ensure_one()
114+
if self._is_batch_roulier():
115+
# Attach the label to the batch instead of the picking
116+
return {
117+
"name": label["name"],
118+
"res_id": self.batch_id.id,
119+
"res_model": "stock.picking.batch",
120+
"datas": label["file"],
121+
"file_type": label["file_type"],
122+
}
123+
return super().get_shipping_label_values(label)

0 commit comments

Comments
 (0)