From ec87b147de6f2f9e1490952f2adb0852b9414e3f Mon Sep 17 00:00:00 2001 From: GarethGloSystems Date: Wed, 24 Apr 2024 11:03:43 +0100 Subject: [PATCH] [FEAT][FIX] Sale Stock Force PDF Download module --- sale_stock_force_pdf_download/README.rst | 6 +++++ sale_stock_force_pdf_download/__init__.py | 1 + sale_stock_force_pdf_download/__manifest__.py | 9 +++++++ .../controllers/__init__.py | 1 + .../controllers/portal.py | 24 +++++++++++++++++++ .../models/__init__.py | 1 + .../models/stock_picking.py | 9 +++++++ .../odoo/addons/sale_stock_force_pdf_download | 1 + setup/sale_stock_force_pdf_download/setup.py | 6 +++++ 9 files changed, 58 insertions(+) create mode 100644 sale_stock_force_pdf_download/README.rst create mode 100644 sale_stock_force_pdf_download/__init__.py create mode 100644 sale_stock_force_pdf_download/__manifest__.py create mode 100644 sale_stock_force_pdf_download/controllers/__init__.py create mode 100644 sale_stock_force_pdf_download/controllers/portal.py create mode 100644 sale_stock_force_pdf_download/models/__init__.py create mode 100644 sale_stock_force_pdf_download/models/stock_picking.py create mode 120000 setup/sale_stock_force_pdf_download/odoo/addons/sale_stock_force_pdf_download create mode 100644 setup/sale_stock_force_pdf_download/setup.py diff --git a/sale_stock_force_pdf_download/README.rst b/sale_stock_force_pdf_download/README.rst new file mode 100644 index 0000000..b1c5310 --- /dev/null +++ b/sale_stock_force_pdf_download/README.rst @@ -0,0 +1,6 @@ +Sale Stock Force PDF Download +============================= + +Force PDF download instead of PDF preview when viewing stock picking records via the sales order portal + +This fixes a bug related to certain PDF extensions that run in Chrome whereby the request to "Print" via the portal causes the PDF preview to request the same file repeatedly in a loop, which eventually consumes all available workers. diff --git a/sale_stock_force_pdf_download/__init__.py b/sale_stock_force_pdf_download/__init__.py new file mode 100644 index 0000000..72d3ea6 --- /dev/null +++ b/sale_stock_force_pdf_download/__init__.py @@ -0,0 +1 @@ +from . import controllers, models diff --git a/sale_stock_force_pdf_download/__manifest__.py b/sale_stock_force_pdf_download/__manifest__.py new file mode 100644 index 0000000..91747d9 --- /dev/null +++ b/sale_stock_force_pdf_download/__manifest__.py @@ -0,0 +1,9 @@ +{ + "name": "Sale Stock Force PDF Download", + "version": "15.0.1.0.0", + "category": "Hidden", + "author": "Glo Networks", + "website": "https://github.com/GlodoUK/sale", + "depends": ["sale_stock"], + "license": "LGPL-3", +} diff --git a/sale_stock_force_pdf_download/controllers/__init__.py b/sale_stock_force_pdf_download/controllers/__init__.py new file mode 100644 index 0000000..8c3feb6 --- /dev/null +++ b/sale_stock_force_pdf_download/controllers/__init__.py @@ -0,0 +1 @@ +from . import portal diff --git a/sale_stock_force_pdf_download/controllers/portal.py b/sale_stock_force_pdf_download/controllers/portal.py new file mode 100644 index 0000000..f5ee1e5 --- /dev/null +++ b/sale_stock_force_pdf_download/controllers/portal.py @@ -0,0 +1,24 @@ +from odoo import exceptions +from odoo.http import request, route + +from odoo.addons.sale_stock.controllers.portal import SaleStockPortal + + +class DriftworksSaleStockPortal(SaleStockPortal): + # Hard Override https://github.com/odoo/odoo/blob/16.0/addons/sale_stock/controllers/portal.py#L24 + @route() + def portal_my_picking_report(self, picking_id, access_token=None, **kw): + try: + picking_sudo = self._stock_picking_check_access( + picking_id, + access_token=access_token, + ) + except exceptions.AccessError: + return request.redirect("/my") + + return self._show_report( + model=picking_sudo, + report_type="pdf", + report_ref="stock.action_report_delivery", + download=True, + ) diff --git a/sale_stock_force_pdf_download/models/__init__.py b/sale_stock_force_pdf_download/models/__init__.py new file mode 100644 index 0000000..ae4c272 --- /dev/null +++ b/sale_stock_force_pdf_download/models/__init__.py @@ -0,0 +1 @@ +from . import stock_picking diff --git a/sale_stock_force_pdf_download/models/stock_picking.py b/sale_stock_force_pdf_download/models/stock_picking.py new file mode 100644 index 0000000..93b8205 --- /dev/null +++ b/sale_stock_force_pdf_download/models/stock_picking.py @@ -0,0 +1,9 @@ +from odoo import models + + +class StockPicking(models.Model): + _inherit = "stock.picking" + + def _get_report_base_filename(self): + self.ensure_one() + return "%s" % self.name diff --git a/setup/sale_stock_force_pdf_download/odoo/addons/sale_stock_force_pdf_download b/setup/sale_stock_force_pdf_download/odoo/addons/sale_stock_force_pdf_download new file mode 120000 index 0000000..310601b --- /dev/null +++ b/setup/sale_stock_force_pdf_download/odoo/addons/sale_stock_force_pdf_download @@ -0,0 +1 @@ +../../../../sale_stock_force_pdf_download \ No newline at end of file diff --git a/setup/sale_stock_force_pdf_download/setup.py b/setup/sale_stock_force_pdf_download/setup.py new file mode 100644 index 0000000..28c57bb --- /dev/null +++ b/setup/sale_stock_force_pdf_download/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)