diff --git a/setup/stock_picking_auto_print/odoo/addons/stock_picking_auto_print b/setup/stock_picking_auto_print/odoo/addons/stock_picking_auto_print new file mode 120000 index 0000000..4b9e771 --- /dev/null +++ b/setup/stock_picking_auto_print/odoo/addons/stock_picking_auto_print @@ -0,0 +1 @@ +../../../../stock_picking_auto_print \ No newline at end of file diff --git a/setup/stock_picking_auto_print/setup.py b/setup/stock_picking_auto_print/setup.py new file mode 100644 index 0000000..28c57bb --- /dev/null +++ b/setup/stock_picking_auto_print/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/stock_picking_auto_print/README.rst b/stock_picking_auto_print/README.rst new file mode 100644 index 0000000..f2f9973 --- /dev/null +++ b/stock_picking_auto_print/README.rst @@ -0,0 +1,79 @@ +======================== +Stock Picking Auto Print +======================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:7edeca4d86af2c7a6795bab19ea2e6749ccc34f49ef0a463a73c266514810ba2 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fstock--logistics--reporting-lightgray.png?logo=github + :target: https://github.com/OCA/stock-logistics-reporting/tree/15.0/stock_picking_auto_print + :alt: OCA/stock-logistics-reporting +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/stock-logistics-reporting-15-0/stock-logistics-reporting-15-0-stock_picking_auto_print + :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/stock-logistics-reporting&target_branch=15.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This is a backport of the Odoo 17 functionality that allows to auto print delivery +slip after validation + +**Table of contents** + +.. contents:: + :local: + +Bug Tracker +=========== + +Bugs are tracked on `GitHub 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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Tecnativa + +Contributors +~~~~~~~~~~~~ + +* `Tecnativa `_: + + * 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/stock-logistics-reporting `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/stock_picking_auto_print/__init__.py b/stock_picking_auto_print/__init__.py new file mode 100644 index 0000000..0650744 --- /dev/null +++ b/stock_picking_auto_print/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/stock_picking_auto_print/__manifest__.py b/stock_picking_auto_print/__manifest__.py new file mode 100644 index 0000000..39e9e74 --- /dev/null +++ b/stock_picking_auto_print/__manifest__.py @@ -0,0 +1,17 @@ +# Copyright 2024 Tecnativa - Sergio Teruel +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Stock Picking Auto Print", + "summary": "Print picking delivery slip automatically after validation", + "version": "15.0.1.0.0", + "author": "Tecnativa, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/stock-logistics-reporting", + "category": "Warehouse Management", + "license": "AGPL-3", + "depends": ["stock", "web_ir_actions_act_multi"], + "data": [ + "views/stock_picking_type_views.xml", + ], + "installable": True, +} diff --git a/stock_picking_auto_print/models/__init__.py b/stock_picking_auto_print/models/__init__.py new file mode 100644 index 0000000..dae0bb2 --- /dev/null +++ b/stock_picking_auto_print/models/__init__.py @@ -0,0 +1,2 @@ +from . import stock_picking +from . import stock_picking_type diff --git a/stock_picking_auto_print/models/stock_picking.py b/stock_picking_auto_print/models/stock_picking.py new file mode 100644 index 0000000..031332d --- /dev/null +++ b/stock_picking_auto_print/models/stock_picking.py @@ -0,0 +1,56 @@ +# Copyright 2024 Tecnativa - Sergio Teruel +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +import logging + +from odoo import api, models + +from odoo.addons.web.controllers.main import clean_action + +_logger = logging.getLogger(__name__) + + +class StockPicking(models.Model): + _inherit = "stock.picking" + + def button_validate(self): + res = super().button_validate() + # Determine if res contains the report reception action to launch after + # pdf downloaded + auto_print_stock_reception_report = False + if ( + isinstance(res, dict) + and res.get("xml_id", False) == "stock.stock_reception_action" + ): + auto_print_stock_reception_report = True + if res is True or auto_print_stock_reception_report: + report_actions = self._get_autoprint_report_actions() + return self._auto_print_on_validate( + report_actions, res if auto_print_stock_reception_report else False + ) + return res + + @api.model + def _auto_print_on_validate(self, reports, other_action=False): + report_action_list = [] + if other_action: + report_action_list = reports + [other_action] + else: + report_action_list = reports + [ + {"type": "ir.actions.act_window_close"}, + {"type": "ir.actions.client", "tag": "reload"}, + ] + return {"type": "ir.actions.act_multi", "actions": report_action_list} + + def _get_autoprint_report_actions(self): + report_actions = [] + pickings_to_print = self.filtered( + lambda p: p.picking_type_id.auto_print_delivery_slip + ) + if pickings_to_print: + action = self.env.ref("stock.action_report_delivery").report_action( + pickings_to_print.ids, config=False + ) + clean_action(action, self.env) + report_actions.append(action) + return report_actions diff --git a/stock_picking_auto_print/models/stock_picking_type.py b/stock_picking_auto_print/models/stock_picking_type.py new file mode 100644 index 0000000..d671d06 --- /dev/null +++ b/stock_picking_auto_print/models/stock_picking_type.py @@ -0,0 +1,13 @@ +# Copyright 2024 Tecnativa - Sergio Teruel +# 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_delivery_slip = fields.Boolean( + help="If this checkbox is ticked, Odoo will automatically print the delivery" + "slip of a picking when it is validated.", + ) diff --git a/stock_picking_auto_print/readme/CONTRIBUTORS.rst b/stock_picking_auto_print/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000..e88095e --- /dev/null +++ b/stock_picking_auto_print/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* `Tecnativa `_: + + * Sergio Teruel diff --git a/stock_picking_auto_print/readme/DESCRIPTION.rst b/stock_picking_auto_print/readme/DESCRIPTION.rst new file mode 100644 index 0000000..8ef58a6 --- /dev/null +++ b/stock_picking_auto_print/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +This is a backport of the Odoo 17 functionality that allows to auto print delivery +slip after validation diff --git a/stock_picking_auto_print/static/description/icon.png b/stock_picking_auto_print/static/description/icon.png new file mode 100644 index 0000000..3a0328b Binary files /dev/null and b/stock_picking_auto_print/static/description/icon.png differ diff --git a/stock_picking_auto_print/static/description/index.html b/stock_picking_auto_print/static/description/index.html new file mode 100644 index 0000000..11dc24d --- /dev/null +++ b/stock_picking_auto_print/static/description/index.html @@ -0,0 +1,424 @@ + + + + + +Stock Picking Auto Print + + + +
+

Stock Picking Auto Print

+ + +

Beta License: AGPL-3 OCA/stock-logistics-reporting Translate me on Weblate Try me on Runboat

+

This is a backport of the Odoo 17 functionality that allows to auto print delivery +slip after validation

+

Table of contents

+ +
+

Bug Tracker

+

Bugs are tracked on GitHub 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.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Tecnativa
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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/stock-logistics-reporting project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/stock_picking_auto_print/tests/__init__.py b/stock_picking_auto_print/tests/__init__.py new file mode 100644 index 0000000..fdc5dab --- /dev/null +++ b/stock_picking_auto_print/tests/__init__.py @@ -0,0 +1 @@ +from . import test_stock_picking_auto_print diff --git a/stock_picking_auto_print/tests/common.py b/stock_picking_auto_print/tests/common.py new file mode 100644 index 0000000..69774fc --- /dev/null +++ b/stock_picking_auto_print/tests/common.py @@ -0,0 +1,69 @@ +# Copyright 2024 Tecnativa - Sergio Teruel +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0) + +from odoo.tests.common import TransactionCase, tagged + + +@tagged("-at_install", "post_install") +class StockPickingAutoPrintCommon(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.ModelDataObj = cls.env["ir.model.data"] + cls.picking_type_in = cls.env["stock.picking.type"].browse( + cls.ModelDataObj._xmlid_to_res_id("stock.picking_type_in") + ) + cls.picking_type_out = cls.env["stock.picking.type"].browse( + cls.ModelDataObj._xmlid_to_res_id("stock.picking_type_out") + ) + cls.customer_location = cls.env["stock.location"].browse( + cls.ModelDataObj._xmlid_to_res_id("stock.stock_location_customers") + ) + cls.supplier_location = cls.env["stock.location"].browse( + cls.ModelDataObj._xmlid_to_res_id("stock.stock_location_suppliers") + ) + cls.stock_location = cls.env["stock.location"].browse( + cls.ModelDataObj._xmlid_to_res_id("stock.stock_location_stock") + ) + + # Active auto print after validate + (cls.picking_type_out + cls.picking_type_in).auto_print_delivery_slip = True + + cls.product1 = cls.env["product.product"].create( + { + "name": "Test por auto print", + "type": "product", + "categ_id": cls.env.ref("product.product_category_all").id, + } + ) + + def _create_picking(self, picking_type, products): + if picking_type == self.picking_type_out: + location = self.stock_location + location_dest = self.customer_location + else: + location = self.supplier_location + location_dest = self.stock_location + + return self.env["stock.picking"].create( + { + "picking_type_id": picking_type.id, + "location_id": location.id, + "location_dest_id": location_dest.id, + "move_lines": [ + ( + 0, + 0, + { + "name": product.name, + "product_id": product.id, + "product_uom": product.uom_id.id, + "location_id": self.stock_location.id, + "location_dest_id": self.supplier_location.id, + "product_uom_qty": 1, + }, + ) + for product in products + ], + } + ) diff --git a/stock_picking_auto_print/tests/test_stock_picking_auto_print.py b/stock_picking_auto_print/tests/test_stock_picking_auto_print.py new file mode 100644 index 0000000..fb60ea1 --- /dev/null +++ b/stock_picking_auto_print/tests/test_stock_picking_auto_print.py @@ -0,0 +1,27 @@ +# Copyright 2024 Tecnativa - Sergio Teruel +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0) + +from .common import StockPickingAutoPrintCommon, tagged + + +@tagged("-at_install", "post_install") +class TestStockPickingAutoPrint(StockPickingAutoPrintCommon): + def test_incoming_picking_reception_report(self): + """Test a complex case. Automatic reception report activates, so the + delivery slip must be downloaded and other action must be opened. + """ + self.env.user.groups_id += self.env.ref("stock.group_reception_report") + self.env.user.groups_id += self.env.ref("stock.group_auto_reception_report") + + picking_out = self._create_picking(self.picking_type_out, self.product1) + picking_out.action_assign() + + picking_in = self._create_picking(self.picking_type_in, self.product1) + picking_in.action_confirm() + picking_in.action_assign() + picking_in.move_lines.quantity_done = 1 + res = picking_in.button_validate() + reports = res["actions"][0] + annother_action = res["actions"][1] + self.assertEqual(annother_action["xml_id"], "stock.stock_reception_action") + self.assertEqual(reports["report_name"], "stock.report_deliveryslip") diff --git a/stock_picking_auto_print/views/stock_picking_type_views.xml b/stock_picking_auto_print/views/stock_picking_type_views.xml new file mode 100644 index 0000000..22677a0 --- /dev/null +++ b/stock_picking_auto_print/views/stock_picking_type_views.xml @@ -0,0 +1,18 @@ + + + + + stock.picking.type + + + + + + + + + + + + +