Skip to content

Commit e8f0e7e

Browse files
committed
[ADD] stock_picking_delivery_label_to_printer: New module
TT51077
1 parent 9a9021b commit e8f0e7e

File tree

17 files changed

+723
-0
lines changed

17 files changed

+723
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../stock_picking_delivery_label_to_printer
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import setuptools
2+
3+
setuptools.setup(
4+
setup_requires=['setuptools-odoo'],
5+
odoo_addon=True,
6+
)
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
=====================================
2+
Print shipping labels on CUPS printer
3+
=====================================
4+
5+
..
6+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
7+
!! This file is generated by oca-gen-addon-readme !!
8+
!! changes will be overwritten. !!
9+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10+
!! source digest: sha256:527ee725e2a4ae3cb421e13dca36683b453053ac68a16684717eb7c99f87eab0
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/15.0/stock_picking_delivery_label_to_printer
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-15-0/delivery-carrier-15-0-stock_picking_delivery_label_to_printer
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=15.0
27+
:alt: Try me on Runboat
28+
29+
|badge1| |badge2| |badge3| |badge4| |badge5|
30+
31+
This module allows print the carrier labels into a CUPS printer defined
32+
in an special report.
33+
34+
**Table of contents**
35+
36+
.. contents::
37+
:local:
38+
39+
Configuration
40+
=============
41+
42+
Configure the report preferences:
43+
44+
- Go to...
45+
46+
Configure the picking operation type preferences:
47+
48+
- Go to...
49+
50+
Usage
51+
=====
52+
53+
Once a picking for a type with label autoprint set is validated, those
54+
will be sent to the printer.
55+
56+
Bug Tracker
57+
===========
58+
59+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/delivery-carrier/issues>`_.
60+
In case of trouble, please check there if your issue has already been reported.
61+
If you spotted it first, help us to smash it by providing a detailed and welcomed
62+
`feedback <https://github.com/OCA/delivery-carrier/issues/new?body=module:%20stock_picking_delivery_label_to_printer%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
63+
64+
Do not contact contributors directly about support or help with technical issues.
65+
66+
Credits
67+
=======
68+
69+
Authors
70+
-------
71+
72+
* Tecnativa
73+
74+
Contributors
75+
------------
76+
77+
- `Tecnativa <https://tecnativa.com>`__
78+
79+
- David Vidal
80+
- Sergio Teruel
81+
82+
Maintainers
83+
-----------
84+
85+
This module is maintained by the OCA.
86+
87+
.. image:: https://odoo-community.org/logo.png
88+
:alt: Odoo Community Association
89+
:target: https://odoo-community.org
90+
91+
OCA, or the Odoo Community Association, is a nonprofit organization whose
92+
mission is to support the collaborative development of Odoo features and
93+
promote its widespread use.
94+
95+
This module is part of the `OCA/delivery-carrier <https://github.com/OCA/delivery-carrier/tree/15.0/stock_picking_delivery_label_to_printer>`_ project on GitHub.
96+
97+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import models
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright 2024 Tecnativa - David Vidal
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
{
4+
"name": "Print shipping labels on CUPS printer",
5+
"summary": "Send shipping labels to CUPS printer",
6+
"author": "Tecnativa, Odoo Community Association (OCA)",
7+
"website": "https://github.com/OCA/delivery-carrier",
8+
"license": "AGPL-3",
9+
"category": "Delivery",
10+
"version": "15.0.1.0.0",
11+
"depends": [
12+
"stock_picking_delivery_label_link",
13+
"base_report_to_printer",
14+
"stock_picking_auto_print",
15+
],
16+
"data": [
17+
"views/stock_picking_views.xml",
18+
"views/stock_picking_type_views.xml",
19+
"reports/shipping_label_report.xml",
20+
],
21+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from . import stock_picking_type
2+
from . import ir_actions_report
3+
from . import stock_picking
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Copyright 2024 Tecnativa - David Vidal
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
from odoo import Command, _, models
4+
from odoo.exceptions import UserError
5+
6+
7+
class IrActionsReport(models.Model):
8+
_inherit = "ir.actions.report"
9+
10+
def print_document(self, record_ids, data=None):
11+
if (
12+
self.report_name
13+
!= "stock_picking_delivery_label_to_printer.report_shipping_label"
14+
):
15+
return super().print_document(record_ids, data)
16+
return self.print_shipping_label(record_ids, data)
17+
18+
def print_shipping_label(self, res_ids, data):
19+
behaviour = self.behaviour()
20+
printer = behaviour.pop("printer", None)
21+
can_print_report = behaviour["action"] == "server" and printer
22+
shipping_label_ids = data.get("shipping_label_ids")
23+
if not can_print_report or not shipping_label_ids:
24+
# Maybe we could trigger the download...
25+
raise UserError(_("Labels can only be printed with CUPS"))
26+
print_attachment = self.env["wizard.print.attachment"].create(
27+
{
28+
"printer_id": printer.id,
29+
"attachment_line_ids": [
30+
Command.create({"attachment_id": attachment})
31+
for attachment in shipping_label_ids
32+
],
33+
}
34+
)
35+
print_attachment.print_attachments()
36+
# This might be untrue!
37+
return True
38+
39+
def _render_qweb_pdf(self, res_ids=None, data=None):
40+
if (
41+
self.report_name
42+
!= "stock_picking_delivery_label_to_printer.report_shipping_label"
43+
):
44+
return super()._render_qweb_pdf(res_ids, data)
45+
return self.print_shipping_label(res_ids, data)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Copyright 2024 Tecnativa - David Vidal
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
from odoo import models
4+
5+
from odoo.addons.web.controllers.main import clean_action
6+
7+
8+
class StockPicking(models.Model):
9+
_inherit = "stock.picking"
10+
11+
def _get_autoprint_report_actions(self):
12+
report_actions = super()._get_autoprint_report_actions()
13+
pickings_to_print = self.filtered(
14+
lambda p: p.picking_type_id.auto_print_shipping_labels
15+
and p.shipping_label_ids
16+
)
17+
if pickings_to_print:
18+
action = pickings_to_print.action_print_shipping_labels()
19+
report_actions.append(action)
20+
return report_actions
21+
22+
def action_print_shipping_labels(self):
23+
action = self.env.ref(
24+
"stock_picking_delivery_label_to_printer.shipping_label_report_action"
25+
).report_action(self.ids, config=False)
26+
action["data"] = {"shipping_label_ids": self.shipping_label_ids.ids}
27+
clean_action(action, self.env)
28+
return action
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Copyright 2024 Tecnativa - David Vidal
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
from odoo import fields, models
4+
5+
6+
class StockPickingType(models.Model):
7+
_inherit = "stock.picking.type"
8+
9+
auto_print_shipping_labels = fields.Boolean(
10+
help="If this checkbox is ticked, Odoo will automatically print the delivery"
11+
"shipping labels if they're available",
12+
)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Configure the report preferences:
2+
- Go to...
3+
4+
Configure the picking operation type preferences:
5+
- Go to...
6+

0 commit comments

Comments
 (0)