From 1d45dac7ef1a607deae62980d1f9bb29f4418748 Mon Sep 17 00:00:00 2001 From: David Date: Wed, 20 Sep 2023 11:19:15 +0200 Subject: [PATCH] [FIX] base_report_to_printer: update printers wizard - Add access rules to the wizard - Set a fallback name for the printers and respect the user custom ones TT45159 --- base_report_to_printer/__manifest__.py | 1 + base_report_to_printer/models/printing_printer.py | 2 +- base_report_to_printer/models/printing_server.py | 5 +++++ base_report_to_printer/security/ir.model.access.csv | 2 ++ base_report_to_printer/tests/test_printing_printer_tray.py | 7 ++++--- 5 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 base_report_to_printer/security/ir.model.access.csv diff --git a/base_report_to_printer/__manifest__.py b/base_report_to_printer/__manifest__.py index 9f25fd4980e..47c2c42cef7 100644 --- a/base_report_to_printer/__manifest__.py +++ b/base_report_to_printer/__manifest__.py @@ -18,6 +18,7 @@ "data": [ "data/printing_data.xml", "security/security.xml", + "security/ir.model.access.csv", "views/printing_printer.xml", "views/printing_server.xml", "views/printing_job.xml", diff --git a/base_report_to_printer/models/printing_printer.py b/base_report_to_printer/models/printing_printer.py index d954acf0ea2..f6af23031df 100644 --- a/base_report_to_printer/models/printing_printer.py +++ b/base_report_to_printer/models/printing_printer.py @@ -70,7 +70,7 @@ class PrintingPrinter(models.Model): def _prepare_update_from_cups(self, cups_connection, cups_printer): mapping = {3: "available", 4: "printing", 5: "error"} cups_vals = { - "name": cups_printer["printer-info"], + "name": self.name or cups_printer["printer-info"], "model": cups_printer.get("printer-make-and-model", False), "location": cups_printer.get("printer-location", False), "uri": cups_printer.get("device-uri", False), diff --git a/base_report_to_printer/models/printing_server.py b/base_report_to_printer/models/printing_server.py index 06de8faf474..69c9eb3ed3f 100644 --- a/base_report_to_printer/models/printing_server.py +++ b/base_report_to_printer/models/printing_server.py @@ -121,6 +121,11 @@ def update_printers(self, domain=None, raise_on_error=False): printer_values["server_id"] = server.id updated_printers.append(name) + # We want to keep any existing customized name over existing printer + # We want also to rely in the system name as a fallback to avoid + # empty names. + if not printer_values.get("name") and not printer.name: + printer_values["name"] = name if not printer: printer_values["system_name"] = name printer.create(printer_values) diff --git a/base_report_to_printer/security/ir.model.access.csv b/base_report_to_printer/security/ir.model.access.csv new file mode 100644 index 00000000000..b97fc91290e --- /dev/null +++ b/base_report_to_printer/security/ir.model.access.csv @@ -0,0 +1,2 @@ +id,name,model_id/id,group_id/id,perm_read,perm_write,perm_create,perm_unlink +access_printing_printer_update_wizard,printers update,model_printing_printer_update_wizard,base.group_system,1,1,1,1 diff --git a/base_report_to_printer/tests/test_printing_printer_tray.py b/base_report_to_printer/tests/test_printing_printer_tray.py index 22bbcc4bfb8..64402064fe7 100644 --- a/base_report_to_printer/tests/test_printing_printer_tray.py +++ b/base_report_to_printer/tests/test_printing_printer_tray.py @@ -40,7 +40,7 @@ def setUp(self): self.server = self.env["printing.server"].create({}) self.printer = self.env["printing.printer"].create( { - "name": "Printer", + "name": "", "server_id": self.server.id, "system_name": "Sys Name", "default": True, @@ -105,10 +105,11 @@ def test_update_printers(self, cups): Check that the update_printers method calls _prepare_update_from_cups """ self.mock_cups_ppd(cups, file_name=False) - - self.assertEqual(self.printer.name, "Printer") self.ServerModel.update_printers() self.assertEqual(self.printer.name, "info") + self.printer.name = "My custom name" + self.ServerModel.update_printers() + self.assertEqual(self.printer.name, "My custom name") @mock.patch("%s.cups" % server_model) def test_prepare_update_from_cups_no_ppd(self, cups):