[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
This commit is contained in:
David
2023-09-20 11:19:15 +02:00
committed by trisdoan
parent 43eab67b60
commit 92723f3b7c
5 changed files with 13 additions and 4 deletions

View File

@@ -18,6 +18,7 @@
"data": [ "data": [
"data/printing_data.xml", "data/printing_data.xml",
"security/security.xml", "security/security.xml",
"security/ir.model.access.csv",
"views/printing_printer.xml", "views/printing_printer.xml",
"views/printing_server.xml", "views/printing_server.xml",
"views/printing_job.xml", "views/printing_job.xml",

View File

@@ -71,7 +71,7 @@ class PrintingPrinter(models.Model):
def _prepare_update_from_cups(self, cups_connection, cups_printer): def _prepare_update_from_cups(self, cups_connection, cups_printer):
mapping = {3: "available", 4: "printing", 5: "error"} mapping = {3: "available", 4: "printing", 5: "error"}
cups_vals = { cups_vals = {
"name": cups_printer["printer-info"], "name": self.name or cups_printer["printer-info"],
"model": cups_printer.get("printer-make-and-model", False), "model": cups_printer.get("printer-make-and-model", False),
"location": cups_printer.get("printer-location", False), "location": cups_printer.get("printer-location", False),
"uri": cups_printer.get("device-uri", False), "uri": cups_printer.get("device-uri", False),

View File

@@ -121,6 +121,11 @@ class PrintingServer(models.Model):
printer_values["server_id"] = server.id printer_values["server_id"] = server.id
updated_printers.append(name) 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: if not printer:
printer_values["system_name"] = name printer_values["system_name"] = name
printer.create(printer_values) printer.create(printer_values)

View File

@@ -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
1 id name model_id/id group_id/id perm_read perm_write perm_create perm_unlink
2 access_printing_printer_update_wizard printers update model_printing_printer_update_wizard base.group_system 1 1 1 1

View File

@@ -40,7 +40,7 @@ class TestPrintingPrinter(TransactionCase):
self.server = self.env["printing.server"].create({}) self.server = self.env["printing.server"].create({})
self.printer = self.env["printing.printer"].create( self.printer = self.env["printing.printer"].create(
{ {
"name": "Printer", "name": "",
"server_id": self.server.id, "server_id": self.server.id,
"system_name": "Sys Name", "system_name": "Sys Name",
"default": True, "default": True,
@@ -105,10 +105,11 @@ class TestPrintingPrinter(TransactionCase):
Check that the update_printers method calls _prepare_update_from_cups Check that the update_printers method calls _prepare_update_from_cups
""" """
self.mock_cups_ppd(cups, file_name=False) self.mock_cups_ppd(cups, file_name=False)
self.assertEqual(self.printer.name, "Printer")
self.ServerModel.update_printers() self.ServerModel.update_printers()
self.assertEqual(self.printer.name, "info") 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) @mock.patch("%s.cups" % server_model)
def test_prepare_update_from_cups_no_ppd(self, cups): def test_prepare_update_from_cups_no_ppd(self, cups):