Skip to content

Commit

Permalink
[ADD] delivery_roulier_picking_batch
Browse files Browse the repository at this point in the history
  • Loading branch information
paradoxxxzero committed Nov 28, 2024
1 parent 85abe2c commit 28dddcb
Show file tree
Hide file tree
Showing 16 changed files with 1,384 additions and 0 deletions.
98 changes: 98 additions & 0 deletions delivery_roulier_picking_batch/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
==============================
Delivery Roulier Picking Batch
==============================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:3874042f9be1a0b3f52c99bbcaf8cde90bc384969de0112059d1fffd216be41c
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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/14.0/delivery_roulier_picking_batch
: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-14-0/delivery-carrier-14-0-delivery_roulier_picking_batch
: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=14.0
:alt: Try me on Runboat

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

This module allows to generate a unique delivery label/tracking for a
whole batch of pickings.

The batch pickings operations will be grouped in a single delivery
package if they are not already in a delivery package. In case of a
batch with multiple packages, a label per package will be created.

This module is only compatible with ``delivery_roulier`` carriers.

**Table of contents**

.. contents::
:local:

Usage
=====

Create a picking batch from
``Inventory > Operations > Batch Transfers``, add some pickings to it
and then enter a valid roulier compatible carrier in the batch
``Additional Info`` notebook page.

Then validate the batch and a delivery label will be generated for each
package in the batch. If there's some operations that are not in a
package, a new package will be created for them.

A tracking number will be generated for each package and the tracking
will be available by clicking the ``Tracking`` smart button.

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_roulier_picking_batch%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.

Credits
=======

Authors
-------

* Akretion

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

- Florian Mounier florian.mounier@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.

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.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions delivery_roulier_picking_batch/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
22 changes: 22 additions & 0 deletions delivery_roulier_picking_batch/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2024 Akretion (http://www.akretion.com).
# @author Florian Mounier <florian.mounier@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
"name": "Delivery Roulier Picking Batch",
"version": "14.0.1.0.0",
"author": "Akretion, Odoo Community Association (OCA)",
"summary": "Use roulier in batch picking",
"category": "Warehouse",
"depends": [
"delivery_roulier",
"stock_picking_batch",
],
"website": "https://github.com/OCA/delivery-carrier",
"data": [
"views/stock_picking_batch_views.xml",
],
"demo": [],
"installable": True,
"license": "AGPL-3",
}
3 changes: 3 additions & 0 deletions delivery_roulier_picking_batch/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import stock_picking
from . import stock_quant_package
from . import stock_picking_batch
123 changes: 123 additions & 0 deletions delivery_roulier_picking_batch/models/stock_picking.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
# Copyright 2024 Akretion (http://www.akretion.com).
# @author Florian Mounier <florian.mounier@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from functools import reduce

from odoo import _, models
from odoo.exceptions import UserError


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

def _is_batch_roulier(self):
# Check if the picking is part of a batch with a roulier carrier
self.ensure_one()
return (
self.batch_id
and self.batch_id.carrier_id
and self.batch_id.carrier_id._is_roulier()
)

def send_to_shipper(self):
self.ensure_one()
if self._is_batch_roulier():
# We are in a batch with a roulier carrier
# We need to send unsent packages
packages = self.package_ids - self.batch_id.sent_package_ids
if not packages:
# Nothing to send
return

# First sanity checks
# Check that all package pickings have the same sender/receiver:
for package in packages:
package_pickings = (
self.env["stock.move.line"]
.search(
[
"|",
("result_package_id", "=", package.id),
("package_id", "=", package.id),
]
)
.mapped("picking_id")
)

# Set carrier on pickings
package_pickings.write({"carrier_id": self.carrier_id.id})

# Check sender/receiver uniformity
for kind in ("sender", "receiver"):
addresses = reduce(
lambda x, y: x | y,
(
getattr(package_picking, f"_get_{kind}")()
or self.env["res.partner"]
for package_picking in package_pickings
),
)
if not addresses:
raise UserError(

Check warning on line 61 in delivery_roulier_picking_batch/models/stock_picking.py

View check run for this annotation

Codecov / codecov/patch

delivery_roulier_picking_batch/models/stock_picking.py#L61

Added line #L61 was not covered by tests
_(
"Can't determine %(kind)s address for pickings: %(pickings)s"
)
% {
"kind": kind,
"pickings": ", ".join(package_pickings.mapped("name")),
}
)
if len(addresses) > 1:
raise UserError(
_(
"Multiple %(kind)s addresses found for pickings: %(pickings)s"
)
% {
"kind": kind,
"pickings": ", ".join(package_pickings.mapped("name")),
}
)

# Send packages
res = self.batch_id.carrier_id.send_shipping(self)[0]
# Mark packages as sent (for use in _roulier_generate_labels)
self.batch_id.sent_package_ids |= packages
# Update tracking number
if res["tracking_number"]:
self.batch_id.carrier_tracking_ref = ";".join(
[
tracking
for tracking in (
self.batch_id.carrier_tracking_ref,
res["tracking_number"],
)
if tracking
]
)
return

return super().send_to_shipper()

def _roulier_generate_labels(self):
if self._is_batch_roulier():
label_info = []
for picking in self:
# Generate labels only for unsent packages
packages = picking.package_ids - picking.batch_id.sent_package_ids
label_info.append(packages._generate_labels(picking))
return label_info

return super()._roulier_generate_labels()

Check warning on line 110 in delivery_roulier_picking_batch/models/stock_picking.py

View check run for this annotation

Codecov / codecov/patch

delivery_roulier_picking_batch/models/stock_picking.py#L110

Added line #L110 was not covered by tests

def get_shipping_label_values(self, label):
self.ensure_one()
if self._is_batch_roulier():
# Attach the label to the batch instead of the picking
return {
"name": label["name"],
"res_id": self.batch_id.id,
"res_model": "stock.picking.batch",
"datas": label["file"],
"file_type": label["file_type"],
}
return super().get_shipping_label_values(label)

Check warning on line 123 in delivery_roulier_picking_batch/models/stock_picking.py

View check run for this annotation

Codecov / codecov/patch

delivery_roulier_picking_batch/models/stock_picking.py#L123

Added line #L123 was not covered by tests
Loading

0 comments on commit 28dddcb

Please sign in to comment.