diff --git a/base_report_to_printer/__manifest__.py b/base_report_to_printer/__manifest__.py
index 21051614345..d39689ee01e 100644
--- a/base_report_to_printer/__manifest__.py
+++ b/base_report_to_printer/__manifest__.py
@@ -7,7 +7,7 @@
{
"name": "Report to printer",
- "version": "17.0.1.0.1",
+ "version": "17.0.1.0.2",
"category": "Generic Modules/Base",
"author": "Agile Business Group & Domsense, Pegueroles SCP, NaN,"
" LasLabs, Camptocamp, Odoo Community Association (OCA),"
diff --git a/base_report_to_printer/i18n/sv.po b/base_report_to_printer/i18n/sv.po
index 6c84e319630..3f0f41905d2 100644
--- a/base_report_to_printer/i18n/sv.po
+++ b/base_report_to_printer/i18n/sv.po
@@ -921,7 +921,7 @@ msgstr "Guide"
#: code:addons/base_report_to_printer/wizards/print_attachment_report.py:0
#, python-format
msgid "{name} ({copies} copies)"
-msgstr "{namn} ({kopior} kopior)"
+msgstr "{name} ({copies} kopior)"
#~ msgid "Job"
#~ msgstr "Jobb"
diff --git a/base_report_to_printer/models/ir_actions_report.py b/base_report_to_printer/models/ir_actions_report.py
index bff68974bc3..de756ec08aa 100644
--- a/base_report_to_printer/models/ir_actions_report.py
+++ b/base_report_to_printer/models/ir_actions_report.py
@@ -22,11 +22,16 @@ class IrActionsReport(models.Model):
printing_printer_id = fields.Many2one(
comodel_name="printing.printer", string="Default Printer"
)
- printer_tray_id = fields.Many2one(
- comodel_name="printing.tray",
+ printer_input_tray_id = fields.Many2one(
+ comodel_name="printing.tray.input",
string="Paper Source",
domain="[('printer_id', '=', printing_printer_id)]",
)
+ printer_output_tray_id = fields.Many2one(
+ comodel_name="printing.tray.output",
+ string="Output Bin",
+ domain="[('printer_id', '=', printing_printer_id)]",
+ )
printing_action_ids = fields.One2many(
comodel_name="printing.report.xml.action",
inverse_name="report_id",
@@ -37,7 +42,8 @@ class IrActionsReport(models.Model):
@api.onchange("printing_printer_id")
def onchange_printing_printer_id(self):
"""Reset the tray when the printer is changed"""
- self.printer_tray_id = False
+ self.printer_input_tray_id = False
+ self.printer_output_tray_id = False
@api.model
def print_action_for_report_name(self, report_name):
@@ -61,8 +67,11 @@ def _get_user_default_print_behaviour(self):
return dict(
action=user.printing_action or "client",
printer=user.printing_printer_id or printer_obj.get_default(),
- tray=str(user.printer_tray_id.system_name)
- if user.printer_tray_id
+ input_tray=str(user.printer_input_tray_id.system_name)
+ if user.printer_input_tray_id
+ else False,
+ output_tray=str(user.printer_output_tray_id.system_name)
+ if user.printer_output_tray_id
else False,
)
@@ -73,8 +82,10 @@ def _get_report_default_print_behaviour(self):
result["action"] = report_action.action_type
if self.printing_printer_id:
result["printer"] = self.printing_printer_id
- if self.printer_tray_id:
- result["tray"] = self.printer_tray_id.system_name
+ if self.printer_input_tray_id:
+ result["input_tray"] = self.printer_input_tray_id.system_name
+ if self.printer_output_tray_id:
+ result["output_tray"] = self.printer_output_tray_id.system_name
return result
def behaviour(self):
diff --git a/base_report_to_printer/models/printing_printer.py b/base_report_to_printer/models/printing_printer.py
index 8d2811ef29f..eb15c35b8ff 100644
--- a/base_report_to_printer/models/printing_printer.py
+++ b/base_report_to_printer/models/printing_printer.py
@@ -64,8 +64,15 @@ class PrintingPrinter(models.Model):
model = fields.Char(readonly=True)
location = fields.Char(readonly=True)
uri = fields.Char(string="URI", readonly=True)
- tray_ids = fields.One2many(
- comodel_name="printing.tray", inverse_name="printer_id", string="Paper Sources"
+ input_tray_ids = fields.One2many(
+ comodel_name="printing.tray.input",
+ inverse_name="printer_id",
+ string="Paper Sources",
+ )
+ output_tray_ids = fields.One2many(
+ comodel_name="printing.tray.output",
+ inverse_name="printer_id",
+ string="Output trays",
)
def _prepare_update_from_cups(self, cups_connection, cups_printer):
@@ -94,7 +101,8 @@ def _prepare_update_from_cups(self, cups_connection, cups_printer):
return vals
ppd = cups.PPD(ppd_path)
- option = ppd.findOption("InputSlot")
+ input_options = ppd.findOption("InputSlot")
+ output_options = ppd.findOption("OutputBin")
try:
os.unlink(ppd_path)
except OSError as err:
@@ -102,34 +110,35 @@ def _prepare_update_from_cups(self, cups_connection, cups_printer):
# The file has already been deleted, we can continue the update
if err.errno != errno.ENOENT:
raise
- if not option:
- return vals
-
- tray_commands = []
- cups_trays = {
- tray_option["choice"]: tray_option["text"] for tray_option in option.choices
- }
-
- # Add new trays
- tray_commands.extend(
- [
- (0, 0, {"name": text, "system_name": choice})
- for choice, text in cups_trays.items()
- if choice not in self.tray_ids.mapped("system_name")
+ if input_options:
+ vals["input_tray_ids"] = [
+ (0, 0, {"name": opt["text"], "system_name": opt["choice"]})
+ for opt in input_options.choices
+ if opt["choice"] not in self.input_tray_ids.mapped("system_name")
]
- )
-
- # Remove deleted trays
- tray_commands.extend(
- [
- (2, tray.id)
- for tray in self.tray_ids.filtered(
- lambda record: record.system_name not in cups_trays.keys()
- )
+ trays = [opt["choice"] for opt in input_options.choices]
+ vals["input_tray_ids"].extend(
+ [
+ (2, tray.id)
+ for tray in self.input_tray_ids
+ if tray.system_name not in trays
+ ]
+ )
+
+ if output_options:
+ vals["output_tray_ids"] = [
+ (0, 0, {"name": opt["text"], "system_name": opt["choice"]})
+ for opt in output_options.choices
+ if opt["choice"] not in self.output_tray_ids.mapped("system_name")
]
- )
- if tray_commands:
- vals["tray_ids"] = tray_commands
+ trays = [opt["choice"] for opt in output_options.choices]
+ vals["output_tray_ids"].extend(
+ [
+ (2, tray.id)
+ for tray in self.output_tray_ids
+ if tray.system_name not in trays
+ ]
+ )
return vals
def print_document(self, report, content, **print_opts):
@@ -154,11 +163,14 @@ def _set_option_doc_format(report, value):
# Backwards compatibility of builtin used as kwarg
_set_option_format = _set_option_doc_format
- def _set_option_tray(self, report, value):
+ def _set_option_input_tray(self, report, value):
"""Note we use self here as some older PPD use tray
rather than InputSlot so we may need to query printer in override"""
return {"InputSlot": str(value)} if value else {}
+ def _set_option_output_tray(self, report, value):
+ return {"OutputBin": str(value)} if value else {}
+
@staticmethod
def _set_option_noop(report, value):
return {}
diff --git a/base_report_to_printer/models/printing_report_xml_action.py b/base_report_to_printer/models/printing_report_xml_action.py
index cac2a0b39b7..610a334b352 100644
--- a/base_report_to_printer/models/printing_report_xml_action.py
+++ b/base_report_to_printer/models/printing_report_xml_action.py
@@ -27,16 +27,22 @@ class PrintingReportXmlAction(models.Model):
)
printer_id = fields.Many2one(comodel_name="printing.printer", string="Printer")
- printer_tray_id = fields.Many2one(
- comodel_name="printing.tray",
+ printer_input_tray_id = fields.Many2one(
+ comodel_name="printing.tray.input",
string="Paper Source",
domain="[('printer_id', '=', printer_id)]",
)
+ printer_output_tray_id = fields.Many2one(
+ comodel_name="printing.tray.output",
+ string="Output Bin",
+ domain="[('printer_id', '=', printer_id)]",
+ )
@api.onchange("printer_id")
def onchange_printer_id(self):
"""Reset the tray when the printer is changed"""
- self.printer_tray_id = False
+ self.printer_input_tray_id = False
+ self.printer_output_tray_id = False
def behaviour(self):
if not self:
@@ -44,5 +50,6 @@ def behaviour(self):
return {
"action": self.action,
"printer": self.printer_id,
- "tray": self.printer_tray_id.system_name,
+ "input_tray": self.printer_input_tray_id.system_name,
+ "output_tray": self.printer_output_tray_id.system_name,
}
diff --git a/base_report_to_printer/models/printing_tray.py b/base_report_to_printer/models/printing_tray.py
index f3d9b5c7f6d..af9d70ecba4 100644
--- a/base_report_to_printer/models/printing_tray.py
+++ b/base_report_to_printer/models/printing_tray.py
@@ -4,7 +4,7 @@
from odoo import fields, models
-class PrinterTray(models.Model):
+class PrinterTray(models.AbstractModel):
_name = "printing.tray"
_description = "Printer Tray"
@@ -19,3 +19,15 @@ class PrinterTray(models.Model):
readonly=True,
ondelete="cascade",
)
+
+
+class PrinterInputTray(models.Model):
+ _name = "printing.tray.input"
+ _description = "Printer Tray Input"
+ _inherit = "printing.tray"
+
+
+class PrinterOutputTray(models.Model):
+ _name = "printing.tray.output"
+ _description = "Printer Tray Output"
+ _inherit = "printing.tray"
diff --git a/base_report_to_printer/models/res_users.py b/base_report_to_printer/models/res_users.py
index cb088ed0d1f..f17d529ddb8 100644
--- a/base_report_to_printer/models/res_users.py
+++ b/base_report_to_printer/models/res_users.py
@@ -35,13 +35,19 @@ def SELF_WRITEABLE_FIELDS(self):
"printing_printer_id",
]
- printer_tray_id = fields.Many2one(
- comodel_name="printing.tray",
+ printer_input_tray_id = fields.Many2one(
+ comodel_name="printing.tray.input",
string="Default Printer Paper Source",
domain="[('printer_id', '=', printing_printer_id)]",
)
+ printer_output_tray_id = fields.Many2one(
+ comodel_name="printing.tray.output",
+ string="Default Printer Output Bin",
+ domain="[('printer_id', '=', printing_printer_id)]",
+ )
@api.onchange("printing_printer_id")
def onchange_printing_printer_id(self):
"""Reset the tray when the printer is changed"""
- self.printer_tray_id = False
+ self.printer_input_tray_id = False
+ self.printer_output_tray_id = False
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..4586caa9629
--- /dev/null
+++ b/base_report_to_printer/security/ir.model.access.csv
@@ -0,0 +1,4 @@
+id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
+access_update_cups,update printer from cups manager,base_report_to_printer.model_printing_printer_update_wizard,base_report_to_printer.printing_group_manager,1,1,1,1
+access_print_attachment,print attachment cups manager,base_report_to_printer.model_wizard_print_attachment,base_report_to_printer.printing_group_manager,1,1,1,1
+access_print_attachment_line,print attachment line cups manager,base_report_to_printer.model_wizard_print_attachment_line,base_report_to_printer.printing_group_manager,1,1,1,1
diff --git a/base_report_to_printer/security/security.xml b/base_report_to_printer/security/security.xml
index 8f68e127495..2942f07fbf6 100644
--- a/base_report_to_printer/security/security.xml
+++ b/base_report_to_printer/security/security.xml
@@ -104,8 +104,8 @@
- Printing Tray User
-
+ Printing Input Tray User
+
@@ -113,8 +113,26 @@
- Printing Tray User
-
+ Printing Input Tray Manager
+
+
+
+
+
+
+
+
+ Printing Output Tray User
+
+
+
+
+
+
+
+
+ Printing Output Tray Manager
+
diff --git a/base_report_to_printer/tests/test_ir_actions_report.py b/base_report_to_printer/tests/test_ir_actions_report.py
index 0ba5a873abc..b628dbfe7ae 100644
--- a/base_report_to_printer/tests/test_ir_actions_report.py
+++ b/base_report_to_printer/tests/test_ir_actions_report.py
@@ -47,11 +47,11 @@ def new_printer(self):
}
)
- def new_tray(self, vals=None, defaults=None):
+ def new_tray(self, tray_type="input", vals=None, defaults=None):
values = dict(defaults)
if vals is not None:
values.update(vals)
- return self.env["printing.tray"].create(values)
+ return self.env["printing.tray." + tray_type].create(values)
def test_print_action_for_report_name_gets_report(self):
"""It should get report by name"""
@@ -91,7 +91,8 @@ def test_behaviour_default_values(self):
{
"action": "client",
"printer": self.env["printing.printer"],
- "tray": False,
+ "input_tray": False,
+ "output_tray": False,
},
)
@@ -105,7 +106,8 @@ def test_behaviour_user_values(self):
{
"action": "client",
"printer": self.env.user.printing_printer_id,
- "tray": False,
+ "input_tray": False,
+ "output_tray": False,
},
)
@@ -120,7 +122,8 @@ def test_behaviour_report_values(self):
{
"action": report.property_printing_action_id.action_type,
"printer": report.printing_printer_id,
- "tray": False,
+ "input_tray": False,
+ "output_tray": False,
},
)
@@ -131,7 +134,12 @@ def test_behaviour_user_action(self):
report.property_printing_action_id.action_type = "user_default"
self.assertEqual(
report.behaviour(),
- {"action": "client", "printer": report.printing_printer_id, "tray": False},
+ {
+ "action": "client",
+ "printer": report.printing_printer_id,
+ "input_tray": False,
+ "output_tray": False,
+ },
)
def test_behaviour_printing_action_on_wrong_user(self):
@@ -144,7 +152,12 @@ def test_behaviour_printing_action_on_wrong_user(self):
)
self.assertEqual(
report.behaviour(),
- {"action": "client", "printer": report.printing_printer_id, "tray": False},
+ {
+ "action": "client",
+ "printer": report.printing_printer_id,
+ "input_tray": False,
+ "output_tray": False,
+ },
)
def test_behaviour_printing_action_on_wrong_report(self):
@@ -158,7 +171,12 @@ def test_behaviour_printing_action_on_wrong_report(self):
)
self.assertEqual(
report.behaviour(),
- {"action": "client", "printer": report.printing_printer_id, "tray": False},
+ {
+ "action": "client",
+ "printer": report.printing_printer_id,
+ "input_tray": False,
+ "output_tray": False,
+ },
)
def test_behaviour_printing_action_with_no_printer(self):
@@ -175,7 +193,8 @@ def test_behaviour_printing_action_with_no_printer(self):
{
"action": printing_action.action,
"printer": report.printing_printer_id,
- "tray": False,
+ "input_tray": False,
+ "output_tray": False,
},
)
@@ -191,7 +210,8 @@ def test_behaviour_printing_action_with_printer(self):
{
"action": printing_action.action,
"printer": printing_action.printer_id,
- "tray": False,
+ "input_tray": False,
+ "output_tray": False,
},
)
@@ -206,7 +226,12 @@ def test_behaviour_printing_action_user_defaults(self):
printing_action.action = "user_default"
self.assertEqual(
report.behaviour(),
- {"action": "client", "printer": report.printing_printer_id, "tray": False},
+ {
+ "action": "client",
+ "printer": report.printing_printer_id,
+ "input_tray": False,
+ "output_tray": False,
+ },
)
def test_print_tray_behaviour(self):
@@ -218,57 +243,98 @@ def test_print_tray_behaviour(self):
{"user_id": self.env.user.id, "report_id": report.id, "action": "server"}
)
printer = self.new_printer()
- tray_vals = {"name": "Tray", "system_name": "Tray", "printer_id": printer.id}
- user_tray = self.new_tray({"system_name": "User tray"}, tray_vals)
- report_tray = self.new_tray({"system_name": "Report tray"}, tray_vals)
- action_tray = self.new_tray({"system_name": "Action tray"}, tray_vals)
+ tray_vals = {
+ "name": "Tray",
+ "system_name": "Tray",
+ "printer_id": printer.id,
+ }
+ user_tray_in = self.new_tray("input", {"system_name": "User tray"}, tray_vals)
+ report_tray_in = self.new_tray(
+ "input", {"system_name": "Report tray"}, tray_vals
+ )
+ action_tray_in = self.new_tray(
+ "input", {"system_name": "Action tray"}, tray_vals
+ )
+ user_tray_out = self.new_tray("output", {"system_name": "User tray"}, tray_vals)
+ report_tray_out = self.new_tray(
+ "output", {"system_name": "Report tray"}, tray_vals
+ )
+ action_tray_out = self.new_tray(
+ "output", {"system_name": "Action tray"}, tray_vals
+ )
# No report passed
- self.env.user.printer_tray_id = False
+ self._set_trays(report, action, "input")
+ self._set_trays(report, action, "output")
options = printer.print_options()
self.assertFalse("InputSlot" in options)
+ self.assertFalse("OutputBin" in options)
# No tray defined
- self.env.user.printer_tray_id = False
- report.printer_tray_id = False
- action.printer_tray_id = False
+ self._set_trays(report, action, "input")
+ self._set_trays(report, action, "output")
options = report.behaviour()
- self.assertTrue("tray" in options)
+ self.assertTrue("input_tray" in options)
+ self.assertTrue("output_tray" in options)
# Only user tray is defined
- self.env.user.printer_tray_id = user_tray
- report.printer_tray_id = False
- action.printer_tray_id = False
- self.assertEqual("User tray", report.behaviour()["tray"])
+ self._set_trays(report, action, "input", user_tray_in)
+ self._set_trays(report, action, "output", user_tray_out)
+ self.assertEqual("User tray", report.behaviour()["input_tray"])
+ self.assertEqual("User tray", report.behaviour()["output_tray"])
# Only report tray is defined
- self.env.user.printer_tray_id = False
- report.printer_tray_id = report_tray
- action.printer_tray_id = False
- self.assertEqual("Report tray", report.behaviour()["tray"])
+ self._set_trays(report, action, "input", report_tray=report_tray_in)
+ self._set_trays(report, action, "output", report_tray=report_tray_out)
+ self.assertEqual("Report tray", report.behaviour()["input_tray"])
+ self.assertEqual("Report tray", report.behaviour()["output_tray"])
# Only action tray is defined
- self.env.user.printer_tray_id = False
- report.printer_tray_id = False
- action.printer_tray_id = action_tray
- self.assertEqual("Action tray", report.behaviour()["tray"])
+ self._set_trays(report, action, "input", action_tray=action_tray_in)
+ self._set_trays(report, action, "output", action_tray=action_tray_out)
+ self.assertEqual("Action tray", report.behaviour()["input_tray"])
+ self.assertEqual("Action tray", report.behaviour()["output_tray"])
# User and report tray defined
- self.env.user.printer_tray_id = user_tray
- report.printer_tray_id = report_tray
- action.printer_tray_id = False
- self.assertEqual("Report tray", report.behaviour()["tray"])
+ self._set_trays(report, action, "input", user_tray_in, report_tray_in)
+ self._set_trays(report, action, "output", user_tray_out, report_tray_out)
+ self.assertEqual("Report tray", report.behaviour()["input_tray"])
+ self.assertEqual("Report tray", report.behaviour()["output_tray"])
# All trays are defined
- self.env.user.printer_tray_id = user_tray
- report.printer_tray_id = report_tray
- action.printer_tray_id = action_tray
- self.assertEqual("Action tray", report.behaviour()["tray"])
+ self._set_trays(
+ report, action, "input", user_tray_in, report_tray_in, action_tray_in
+ )
+ self._set_trays(
+ report, action, "output", user_tray_out, report_tray_out, action_tray_out
+ )
+ self.assertEqual("Action tray", report.behaviour()["input_tray"])
+ self.assertEqual("Action tray", report.behaviour()["output_tray"])
+
+ def _set_trays(
+ self,
+ report,
+ action,
+ tray_type="input",
+ user_tray=False,
+ report_tray=False,
+ action_tray=False,
+ ):
+ attr = "printer_" + tray_type + "_tray_id"
+ setattr(self.env.user, attr, user_tray)
+ setattr(report, attr, report_tray)
+ setattr(action, attr, action_tray)
def test_onchange_printer_tray_id_empty(self):
- action = self.env["ir.actions.report"].new({"printer_tray_id": False})
+ action = self.env["ir.actions.report"].new(
+ {
+ "printer_input_tray_id": False,
+ "printer_output_tray_id": False,
+ }
+ )
action.onchange_printing_printer_id()
- self.assertFalse(action.printer_tray_id)
+ self.assertFalse(action.printer_input_tray_id)
+ self.assertFalse(action.printer_output_tray_id)
def test_onchange_printer_tray_id_not_empty(self):
server = self.env["printing.server"].create({})
@@ -285,11 +351,29 @@ def test_onchange_printer_tray_id_not_empty(self):
"uri": "URI",
}
)
- tray = self.env["printing.tray"].create(
- {"name": "Tray", "system_name": "TrayName", "printer_id": printer.id}
+ input_tray = self.env["printing.tray.input"].create(
+ {
+ "name": "Tray",
+ "system_name": "TrayName",
+ "printer_id": printer.id,
+ }
+ )
+ output_tray = self.env["printing.tray.output"].create(
+ {
+ "name": "Tray",
+ "system_name": "TrayName",
+ "printer_id": printer.id,
+ }
)
- action = self.env["ir.actions.report"].new({"printer_tray_id": tray.id})
- self.assertEqual(action.printer_tray_id, tray)
+ action = self.env["ir.actions.report"].new(
+ {
+ "printer_input_tray_id": input_tray.id,
+ "printer_output_tray_id": output_tray.id,
+ }
+ )
+ self.assertEqual(action.printer_input_tray_id, input_tray)
+ self.assertEqual(action.printer_output_tray_id, output_tray)
action.onchange_printing_printer_id()
- self.assertFalse(action.printer_tray_id)
+ self.assertFalse(action.printer_input_tray_id)
+ self.assertFalse(action.printer_output_tray_id)
diff --git a/base_report_to_printer/tests/test_printing_printer.py b/base_report_to_printer/tests/test_printing_printer.py
index 8ea7d83c3a1..c057e786e50 100644
--- a/base_report_to_printer/tests/test_printing_printer.py
+++ b/base_report_to_printer/tests/test_printing_printer.py
@@ -38,9 +38,10 @@ def test_option_tray(self):
It should put the value in InputSlot
"""
self.assertEqual(
- self.Model._set_option_tray(None, "Test Tray"), {"InputSlot": "Test Tray"}
+ self.Model._set_option_input_tray(None, "Test Tray"),
+ {"InputSlot": "Test Tray"},
)
- self.assertEqual(self.Model._set_option_tray(None, False), {})
+ self.assertEqual(self.Model._set_option_input_tray(None, False), {})
def test_option_noops(self):
"""
@@ -77,7 +78,9 @@ def test_print_options(self):
self.Model.print_options(report, doc_format="raw", copies=2),
{"raw": "True", "copies": "2"},
)
- self.assertTrue("InputSlot" in self.Model.print_options(report, tray="Test"))
+ self.assertTrue(
+ "InputSlot" in self.Model.print_options(report, input_tray="Test")
+ )
@mock.patch("%s.cups" % server_model)
def test_print_report(self, cups):
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 158864330b8..956c249c303 100644
--- a/base_report_to_printer/tests/test_printing_printer_tray.py
+++ b/base_report_to_printer/tests/test_printing_printer_tray.py
@@ -30,6 +30,20 @@
ppd_input_slot_footer = """
*CloseUI: *InputSlot
"""
+ppd_output_slot_header = """
+*OpenUI *OutputBin/Output Tray: PickOne
+*OrderDependency: 40 AnySetup *OutputBin
+*DefaultOutputBin: Default
+*OutputBin Default/Default: "
+ << /OutputType (Default) >> setpagedevice"
+"""
+ppd_output_slot_body = """
+*OutputBin {name}/{text}: "
+ << /OutputType (Bin{nb}) >> setpagedevice"
+"""
+ppd_output_slot_footer = """
+*CloseUI: *OutputBin
+"""
class TestPrintingPrinter(TransactionCase):
@@ -57,28 +71,38 @@ def setUp(self):
"printer_id": self.printer.id,
}
- def new_tray(self, vals=None):
+ def new_tray(self, tray_type="input", vals=None):
values = self.tray_vals
if vals is not None:
values.update(vals)
- return self.env["printing.tray"].create(values)
+ return self.env["printing.tray." + tray_type].create(values)
- def build_ppd(self, input_slots=None):
+ def build_ppd(self, trays=None):
"""
Builds a fake PPD file declaring defined input slots
"""
ppd_contents = ppd_header
ppd_contents += ppd_input_slot_header
- if input_slots is not None:
- for input_slot in input_slots:
+ if trays is not None:
+ for slot in trays:
ppd_contents += ppd_input_slot_body.format(
- name=input_slot["name"], text=input_slot["text"]
+ name=slot["name"],
+ text=slot["text"],
)
ppd_contents += ppd_input_slot_footer
+ ppd_contents += ppd_output_slot_header
+ if trays is not None:
+ for slot in trays:
+ ppd_contents += ppd_output_slot_body.format(
+ name=slot["name"],
+ text=slot["text"],
+ nb=slot["text"][-1],
+ )
+ ppd_contents += ppd_output_slot_footer
return ppd_contents
- def mock_cups_ppd(self, cups, file_name=None, input_slots=None):
+ def mock_cups_ppd(self, cups, file_name=None, trays=None):
"""
Create a fake PPD file (if needed), then mock the getPPD3 method
return value to give that file
@@ -87,7 +111,7 @@ def mock_cups_ppd(self, cups, file_name=None, input_slots=None):
fd, file_name = tempfile.mkstemp()
if file_name:
- ppd_contents = self.build_ppd(input_slots=input_slots)
+ ppd_contents = self.build_ppd(trays=trays)
with open(file_name, "w") as fp:
fp.write(ppd_contents)
@@ -96,7 +120,7 @@ def mock_cups_ppd(self, cups, file_name=None, input_slots=None):
self.printer.system_name: {
"printer-info": "info",
"printer-uri-supported": "uri",
- }
+ },
}
@mock.patch("%s.cups" % server_model)
@@ -121,7 +145,8 @@ def test_prepare_update_from_cups_no_ppd(self, cups):
cups_printer = connection.getPrinters()[self.printer.system_name]
vals = self.printer._prepare_update_from_cups(connection, cups_printer)
- self.assertFalse("tray_ids" in vals)
+ self.assertFalse("input_tray_ids" in vals)
+ self.assertFalse("output_tray_ids" in vals)
@mock.patch("%s.cups" % server_model)
def test_prepare_update_from_cups_empty_ppd(self, cups):
@@ -139,7 +164,8 @@ def test_prepare_update_from_cups_empty_ppd(self, cups):
cups_printer = connection.getPrinters()[self.printer.system_name]
vals = self.printer._prepare_update_from_cups(connection, cups_printer)
- self.assertFalse("tray_ids" in vals)
+ self.assertFalse("input_tray_ids" in vals)
+ self.assertFalse("output_tray_ids" in vals)
@mock.patch("%s.cups" % server_model)
@mock.patch("os.unlink")
@@ -176,8 +202,30 @@ def test_prepare_update_from_cups_unlink_error_enoent(self, os_unlink, cups):
vals = self.printer._prepare_update_from_cups(connection, cups_printer)
self.assertEqual(
- vals["tray_ids"],
- [(0, 0, {"name": "Auto (Default)", "system_name": "Auto"})],
+ vals["input_tray_ids"],
+ [
+ (
+ 0,
+ 0,
+ {
+ "name": "Auto (Default)",
+ "system_name": "Auto",
+ },
+ )
+ ],
+ )
+ self.assertEqual(
+ vals["output_tray_ids"],
+ [
+ (
+ 0,
+ 0,
+ {
+ "name": "Default",
+ "system_name": "Default",
+ },
+ )
+ ],
)
@mock.patch("%s.cups" % server_model)
@@ -192,8 +240,30 @@ def test_prepare_update_from_cups(self, cups):
vals = self.printer._prepare_update_from_cups(connection, cups_printer)
self.assertEqual(
- vals["tray_ids"],
- [(0, 0, {"name": "Auto (Default)", "system_name": "Auto"})],
+ vals["input_tray_ids"],
+ [
+ (
+ 0,
+ 0,
+ {
+ "name": "Auto (Default)",
+ "system_name": "Auto",
+ },
+ )
+ ],
+ )
+ self.assertEqual(
+ vals["output_tray_ids"],
+ [
+ (
+ 0,
+ 0,
+ {
+ "name": "Default",
+ "system_name": "Default",
+ },
+ )
+ ],
)
@mock.patch("%s.cups" % server_model)
@@ -201,17 +271,57 @@ def test_prepare_update_from_cups_with_multiple_trays(self, cups):
"""
Check the return value when adding multiple trays at once
"""
- self.mock_cups_ppd(cups, input_slots=[{"name": "Tray1", "text": "Tray 1"}])
+ self.mock_cups_ppd(
+ cups,
+ trays=[
+ {"name": "Tray1", "text": "Tray 1"},
+ ],
+ )
connection = cups.Connection()
cups_printer = connection.getPrinters()[self.printer.system_name]
vals = self.printer._prepare_update_from_cups(connection, cups_printer)
self.assertItemsEqual(
- vals["tray_ids"],
+ vals["input_tray_ids"],
+ [
+ (
+ 0,
+ 0,
+ {
+ "name": "Auto (Default)",
+ "system_name": "Auto",
+ },
+ ),
+ (
+ 0,
+ 0,
+ {
+ "name": "Tray 1",
+ "system_name": "Tray1",
+ },
+ ),
+ ],
+ )
+ self.assertItemsEqual(
+ vals["output_tray_ids"],
[
- (0, 0, {"name": "Auto (Default)", "system_name": "Auto"}),
- (0, 0, {"name": "Tray 1", "system_name": "Tray1"}),
+ (
+ 0,
+ 0,
+ {
+ "name": "Default",
+ "system_name": "Default",
+ },
+ ),
+ (
+ 0,
+ 0,
+ {
+ "name": "Tray 1",
+ "system_name": "Tray1",
+ },
+ ),
],
)
@@ -221,18 +331,46 @@ def test_prepare_update_from_cups_already_known_trays(self, cups):
Check that calling the method twice doesn't create the trays multiple
times
"""
- self.mock_cups_ppd(cups, input_slots=[{"name": "Tray1", "text": "Tray 1"}])
+ self.mock_cups_ppd(
+ cups,
+ trays=[
+ {"name": "Tray1", "text": "Tray 1"},
+ ],
+ )
connection = cups.Connection()
cups_printer = connection.getPrinters()[self.printer.system_name]
# Create a tray which is in the PPD file
- self.new_tray({"system_name": "Tray1"})
+ self.new_tray("input", {"system_name": "Tray1"})
+ self.new_tray("output", {"system_name": "Tray1"})
vals = self.printer._prepare_update_from_cups(connection, cups_printer)
self.assertEqual(
- vals["tray_ids"],
- [(0, 0, {"name": "Auto (Default)", "system_name": "Auto"})],
+ vals["input_tray_ids"],
+ [
+ (
+ 0,
+ 0,
+ {
+ "name": "Auto (Default)",
+ "system_name": "Auto",
+ },
+ )
+ ],
+ )
+ self.assertEqual(
+ vals["output_tray_ids"],
+ [
+ (
+ 0,
+ 0,
+ {
+ "name": "Default",
+ "system_name": "Default",
+ },
+ )
+ ],
)
@mock.patch("%s.cups" % server_model)
@@ -246,10 +384,35 @@ def test_prepare_update_from_cups_unknown_trays(self, cups):
cups_printer = connection.getPrinters()[self.printer.system_name]
# Create a tray which is absent from the PPD file
- tray = self.new_tray()
+ input_tray = self.new_tray()
+ output_tray = self.new_tray("output")
vals = self.printer._prepare_update_from_cups(connection, cups_printer)
self.assertEqual(
- vals["tray_ids"],
- [(0, 0, {"name": "Auto (Default)", "system_name": "Auto"}), (2, tray.id)],
+ vals["input_tray_ids"],
+ [
+ (
+ 0,
+ 0,
+ {
+ "name": "Auto (Default)",
+ "system_name": "Auto",
+ },
+ ),
+ (2, input_tray.id),
+ ],
+ )
+ self.assertEqual(
+ vals["output_tray_ids"],
+ [
+ (
+ 0,
+ 0,
+ {
+ "name": "Default",
+ "system_name": "Default",
+ },
+ ),
+ (2, output_tray.id),
+ ],
)
diff --git a/base_report_to_printer/tests/test_printing_report_xml_action.py b/base_report_to_printer/tests/test_printing_report_xml_action.py
index 56436421991..4b24074b504 100644
--- a/base_report_to_printer/tests/test_printing_report_xml_action.py
+++ b/base_report_to_printer/tests/test_printing_report_xml_action.py
@@ -50,7 +50,8 @@ def test_behaviour(self):
{
"action": xml_action.action,
"printer": xml_action.printer_id,
- "tray": False,
+ "input_tray": False,
+ "output_tray": False,
},
)
@@ -60,16 +61,23 @@ def test_behaviour(self):
{
"action": xml_action.action,
"printer": xml_action.printer_id,
- "tray": False,
+ "input_tray": False,
+ "output_tray": False,
},
)
self.assertEqual(self.Model.behaviour(), {})
def test_onchange_printer_tray_id_empty(self):
- action = self.env["printing.report.xml.action"].new({"printer_tray_id": False})
+ action = self.env["printing.report.xml.action"].new(
+ {
+ "printer_input_tray_id": False,
+ "printer_output_tray_id": False,
+ }
+ )
action.onchange_printer_id()
- self.assertFalse(action.printer_tray_id)
+ self.assertFalse(action.printer_input_tray_id)
+ self.assertFalse(action.printer_output_tray_id)
def test_onchange_printer_tray_id_not_empty(self):
server = self.env["printing.server"].create({})
@@ -86,13 +94,29 @@ def test_onchange_printer_tray_id_not_empty(self):
"uri": "URI",
}
)
- tray = self.env["printing.tray"].create(
- {"name": "Tray", "system_name": "TrayName", "printer_id": printer.id}
+ input_tray = self.env["printing.tray.input"].create(
+ {
+ "name": "Tray",
+ "system_name": "TrayName",
+ "printer_id": printer.id,
+ }
+ )
+ output_tray = self.env["printing.tray.output"].create(
+ {
+ "name": "Tray",
+ "system_name": "TrayName",
+ "printer_id": printer.id,
+ }
)
action = self.env["printing.report.xml.action"].new(
- {"printer_tray_id": tray.id}
+ {
+ "printer_input_tray_id": input_tray.id,
+ "printer_output_tray_id": output_tray.id,
+ }
)
- self.assertEqual(action.printer_tray_id, tray)
+ self.assertEqual(action.printer_input_tray_id, input_tray)
+ self.assertEqual(action.printer_output_tray_id, output_tray)
action.onchange_printer_id()
- self.assertFalse(action.printer_tray_id)
+ self.assertFalse(action.printer_input_tray_id)
+ self.assertFalse(action.printer_output_tray_id)
diff --git a/base_report_to_printer/tests/test_printing_tray.py b/base_report_to_printer/tests/test_printing_tray.py
index ce5f001e697..e36f9180e18 100644
--- a/base_report_to_printer/tests/test_printing_tray.py
+++ b/base_report_to_printer/tests/test_printing_tray.py
@@ -9,7 +9,6 @@
class TestPrintingTray(TransactionCase):
def setUp(self):
super().setUp()
- self.Model = self.env["printing.tray"]
self.server = self.env["printing.server"].create({})
self.printer = self.env["printing.printer"].create(
{
@@ -30,20 +29,32 @@ def setUp(self):
"printer_id": self.printer.id,
}
- def new_tray(self):
- return self.env["printing.tray"].create(self.tray_vals)
+ def new_tray(self, tray_type="input"):
+ return self.env["printing.tray." + tray_type].create(self.tray_vals)
def test_report_behaviour(self):
"""It should add the selected tray in the report data"""
ir_report = self.env["ir.actions.report"].search([], limit=1)
report = self.env["printing.report.xml.action"].create(
- {"user_id": self.env.user.id, "report_id": ir_report.id, "action": "server"}
+ {
+ "user_id": self.env.user.id,
+ "report_id": ir_report.id,
+ "action": "server",
+ }
)
- report.printer_tray_id = False
+ report.printer_input_tray_id = False
+ report.printer_output_tray_id = False
behaviour = report.behaviour()
- self.assertEqual(behaviour["tray"], False)
+ self.assertEqual(behaviour["input_tray"], False)
+ self.assertEqual(behaviour["output_tray"], False)
# Check that we have te right value
- report.printer_tray_id = self.new_tray()
+ report.printer_input_tray_id = self.new_tray()
+ report.printer_output_tray_id = self.new_tray("output")
behaviour = report.behaviour()
- self.assertEqual(behaviour["tray"], report.printer_tray_id.system_name)
+ self.assertEqual(
+ behaviour["input_tray"], report.printer_input_tray_id.system_name
+ )
+ self.assertEqual(
+ behaviour["output_tray"], report.printer_output_tray_id.system_name
+ )
diff --git a/base_report_to_printer/tests/test_report.py b/base_report_to_printer/tests/test_report.py
index e93d0a0adff..10c99e64f20 100644
--- a/base_report_to_printer/tests/test_report.py
+++ b/base_report_to_printer/tests/test_report.py
@@ -161,7 +161,8 @@ def test_render_qweb_text_printable(self):
document[0],
action="server",
doc_format="qweb-text",
- tray=False,
+ input_tray=False,
+ output_tray=False,
)
def test_print_document_not_printable(self):
diff --git a/base_report_to_printer/tests/test_res_users.py b/base_report_to_printer/tests/test_res_users.py
index 020c6323a90..b1a1b82b684 100644
--- a/base_report_to_printer/tests/test_res_users.py
+++ b/base_report_to_printer/tests/test_res_users.py
@@ -24,9 +24,15 @@ def test_available_action_types_includes_something_else(self):
self.assertTrue(self.new_record())
def test_onchange_printer_tray_id_empty(self):
- user = self.env["res.users"].new({"printer_tray_id": False})
+ user = self.env["res.users"].new(
+ {
+ "printer_input_tray_id": False,
+ "printer_output_tray_id": False,
+ }
+ )
user.onchange_printing_printer_id()
- self.assertFalse(user.printer_tray_id)
+ self.assertFalse(user.printer_input_tray_id)
+ self.assertFalse(user.printer_output_tray_id)
def test_onchange_printer_tray_id_not_empty(self):
server = self.env["printing.server"].create({})
@@ -43,11 +49,29 @@ def test_onchange_printer_tray_id_not_empty(self):
"uri": "URI",
}
)
- tray = self.env["printing.tray"].create(
- {"name": "Tray", "system_name": "TrayName", "printer_id": printer.id}
+ input_tray = self.env["printing.tray.input"].create(
+ {
+ "name": "Tray",
+ "system_name": "TrayName",
+ "printer_id": printer.id,
+ }
+ )
+ output_tray = self.env["printing.tray.output"].create(
+ {
+ "name": "Tray",
+ "system_name": "TrayName",
+ "printer_id": printer.id,
+ }
)
- user = self.env["res.users"].new({"printer_tray_id": tray.id})
- self.assertEqual(user.printer_tray_id, tray)
+ user = self.env["res.users"].new(
+ {
+ "printer_input_tray_id": input_tray.id,
+ "printer_output_tray_id": output_tray.id,
+ }
+ )
+ self.assertEqual(user.printer_input_tray_id, input_tray)
+ self.assertEqual(user.printer_output_tray_id, output_tray)
user.onchange_printing_printer_id()
- self.assertFalse(user.printer_tray_id)
+ self.assertFalse(user.printer_input_tray_id)
+ self.assertFalse(user.printer_output_tray_id)
diff --git a/base_report_to_printer/views/ir_actions_report.xml b/base_report_to_printer/views/ir_actions_report.xml
index b250fdf00dd..a41376b1c46 100644
--- a/base_report_to_printer/views/ir_actions_report.xml
+++ b/base_report_to_printer/views/ir_actions_report.xml
@@ -10,7 +10,14 @@
-
+
+
diff --git a/base_report_to_printer/views/printing_printer.xml b/base_report_to_printer/views/printing_printer.xml
index 4424c84b13d..a409d89c223 100644
--- a/base_report_to_printer/views/printing_printer.xml
+++ b/base_report_to_printer/views/printing_printer.xml
@@ -80,7 +80,15 @@
-
+
+
+
+
@@ -25,7 +29,11 @@
-
+
+
+
+
+