Skip to content

Commit

Permalink
[ADD] stock_picking_delivery_label_to_printer: New module
Browse files Browse the repository at this point in the history
TT51077
  • Loading branch information
chienandalu committed Oct 18, 2024
1 parent 9a9021b commit 1b54d1d
Show file tree
Hide file tree
Showing 17 changed files with 720 additions and 0 deletions.
6 changes: 6 additions & 0 deletions setup/stock_picking_delivery_label_to_printer/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
97 changes: 97 additions & 0 deletions stock_picking_delivery_label_to_printer/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
=====================================
Print shipping labels on CUPS printer
=====================================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:527ee725e2a4ae3cb421e13dca36683b453053ac68a16684717eb7c99f87eab0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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/15.0/stock_picking_delivery_label_to_printer
: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-15-0/delivery-carrier-15-0-stock_picking_delivery_label_to_printer
: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=15.0
:alt: Try me on Runboat

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

This module allows print the carrier labels into a CUPS printer defined
in an special report.

**Table of contents**

.. contents::
:local:

Configuration
=============

Configure the report preferences:

- Go to...

Configure the picking operation type preferences:

- Go to...

Usage
=====

Once a picking for a type with label autoprint set is validated, those
will be sent to the printer.

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:%20stock_picking_delivery_label_to_printer%0Aversion:%2015.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
-------

* Tecnativa

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

- `Tecnativa <https://tecnativa.com>`__

- David Vidal
- Sergio Teruel

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/15.0/stock_picking_delivery_label_to_printer>`_ 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 stock_picking_delivery_label_to_printer/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
21 changes: 21 additions & 0 deletions stock_picking_delivery_label_to_printer/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2024 Tecnativa - David Vidal
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Print shipping labels on CUPS printer",
"summary": "Send shipping labels to CUPS printer",
"author": "Tecnativa, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/delivery-carrier",
"license": "AGPL-3",
"category": "Delivery",
"version": "15.0.1.0.0",
"depends": [
"stock_picking_delivery_label_link",
"base_report_to_printer",
"stock_picking_auto_print",
],
"data": [
"views/stock_picking_views.xml",
"views/stock_picking_type_views.xml",
"reports/shipping_label_report.xml",
],
}
3 changes: 3 additions & 0 deletions stock_picking_delivery_label_to_printer/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import stock_picking_type
from . import ir_actions_report
from . import stock_picking
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Copyright 2024 Tecnativa - David Vidal
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import Command, _, api, models
from odoo.exceptions import UserError


class IrActionsReport(models.Model):
_inherit = "ir.actions.report"

@api.model
def print_action_for_report_name(self, report_name):
if (
report_name
== "stock_picking_delivery_label_to_printer.report_shipping_label"
):
return {}
return super().print_action_for_report_name(report_name)

def _render_qweb_pdf(self, res_ids=None, data=None):
if (
self.report_name
!= "stock_picking_delivery_label_to_printer.report_shipping_label"
):
return super()._render_qweb_pdf(res_ids, data)
behaviour = self.behaviour()
printer = behaviour.pop("printer", None)
can_print_report = behaviour["action"] == "server" and printer
shipping_label_ids = data.get("shipping_label_ids")
if not can_print_report or not shipping_label_ids:
# Maybe we could trigger the download...
raise UserError(_("Labels can only be printed with CUPS"))
print_attachment = self.env["wizard.print.attachment"].create(
{
"printer_id": printer.id,
"attachment_line_ids": [
Command.create({"attachment_id": attachment})
for attachment in shipping_label_ids
],
}
)
print_attachment.print_attachments()
return (b"", "pdf")
28 changes: 28 additions & 0 deletions stock_picking_delivery_label_to_printer/models/stock_picking.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright 2024 Tecnativa - David Vidal
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import models

from odoo.addons.web.controllers.main import clean_action


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

def _get_autoprint_report_actions(self):
report_actions = super()._get_autoprint_report_actions()
pickings_to_print = self.filtered(
lambda p: p.picking_type_id.auto_print_shipping_labels
and p.shipping_label_ids
)
if pickings_to_print:
action = pickings_to_print.action_print_shipping_labels()
report_actions.append(action)
return report_actions

def action_print_shipping_labels(self):
action = self.env.ref(
"stock_picking_delivery_label_to_printer.shipping_label_report_action"
).report_action(self.ids, config=False)
action["data"] = {"shipping_label_ids": self.shipping_label_ids.ids}
clean_action(action, self.env)
return action
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright 2024 Tecnativa - David Vidal
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import fields, models


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

auto_print_shipping_labels = fields.Boolean(
help="If this checkbox is ticked, Odoo will automatically print the delivery"
"shipping labels if they're available",
)
6 changes: 6 additions & 0 deletions stock_picking_delivery_label_to_printer/readme/CONFIGURE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Configure the report preferences:
- Go to...

Configure the picking operation type preferences:
- Go to...

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- [Tecnativa](https://tecnativa.com)
- David Vidal
- Sergio Teruel
2 changes: 2 additions & 0 deletions stock_picking_delivery_label_to_printer/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This module allows print the carrier labels into a CUPS printer defined in an special
report.
2 changes: 2 additions & 0 deletions stock_picking_delivery_label_to_printer/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Once a picking for a type with label autoprint set is validated, those will be sent
to the printer.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<template id="report_shipping_label" />
<record id="shipping_label_report_action" model="ir.actions.report">
<field name="name">Shipping Label</field>
<field name="model">stock.picking</field>
<field name="report_type">qweb-pdf</field>
<field
name="report_name"
>stock_picking_delivery_label_to_printer.report_shipping_label</field>
<field
name="report_file"
>stock_picking_delivery_label_to_printer.report_shipping_label</field>
<field name="print_report_name">Shipping label</field>
</record>
</odoo>
Loading

0 comments on commit 1b54d1d

Please sign in to comment.