Reformatted after template update

This commit is contained in:
Enric Tobella
2022-09-01 11:04:43 +02:00
parent 479efcaa46
commit 0203e5b621
25 changed files with 136 additions and 126 deletions

View File

@@ -15,7 +15,7 @@ default_language_version:
node: "14.13.0" node: "14.13.0"
repos: repos:
- repo: https://github.com/psf/black - repo: https://github.com/psf/black
rev: 19.10b0 rev: 22.3.0
hooks: hooks:
- id: black - id: black
- repo: https://github.com/prettier/pre-commit - repo: https://github.com/prettier/pre-commit

View File

@@ -35,12 +35,12 @@ class IrActionsReport(models.Model):
@api.onchange("printing_printer_id") @api.onchange("printing_printer_id")
def onchange_printing_printer_id(self): def onchange_printing_printer_id(self):
""" Reset the tray when the printer is changed """ """Reset the tray when the printer is changed"""
self.printer_tray_id = False self.printer_tray_id = False
@api.model @api.model
def print_action_for_report_name(self, report_name): def print_action_for_report_name(self, report_name):
""" Returns if the action is a direct print or pdf """Returns if the action is a direct print or pdf
Called from js Called from js
""" """
@@ -99,7 +99,7 @@ class IrActionsReport(models.Model):
return result return result
def print_document(self, record_ids, data=None): def print_document(self, record_ids, data=None):
""" Print a document, do not return the document file """ """Print a document, do not return the document file"""
document, doc_format = self.with_context( document, doc_format = self.with_context(
must_skip_send_to_printer=True must_skip_send_to_printer=True
).render_qweb_pdf(record_ids, data=data) ).render_qweb_pdf(record_ids, data=data)
@@ -143,7 +143,7 @@ class IrActionsReport(models.Model):
return res return res
def render_qweb_pdf(self, res_ids=None, data=None): def render_qweb_pdf(self, res_ids=None, data=None):
""" Generate a PDF and returns it. """Generate a PDF and returns it.
If the action configured on the report is server, it prints the If the action configured on the report is server, it prints the
generated document as well. generated document as well.

View File

@@ -132,7 +132,7 @@ class PrintingPrinter(models.Model):
return vals return vals
def print_document(self, report, content, **print_opts): def print_document(self, report, content, **print_opts):
""" Print a file """Print a file
Format could be pdf, qweb-pdf, raw, ... Format could be pdf, qweb-pdf, raw, ...
""" """
self.ensure_one() self.ensure_one()
@@ -173,7 +173,7 @@ class PrintingPrinter(models.Model):
return options return options
def print_file(self, file_name, report=None, **print_opts): def print_file(self, file_name, report=None, **print_opts):
""" Print a file """ """Print a file"""
self.ensure_one() self.ensure_one()
title = print_opts.pop("title", file_name) title = print_opts.pop("title", file_name)
connection = self.server_id._open_connection(raise_on_error=True) connection = self.server_id._open_connection(raise_on_error=True)

View File

@@ -35,7 +35,7 @@ class PrintingReportXmlAction(models.Model):
@api.onchange("printer_id") @api.onchange("printer_id")
def onchange_printer_id(self): def onchange_printer_id(self):
""" Reset the tray when the printer is changed """ """Reset the tray when the printer is changed"""
self.printer_tray_id = False self.printer_tray_id = False
def behaviour(self): def behaviour(self):

View File

@@ -38,5 +38,5 @@ class ResUsers(models.Model):
@api.onchange("printing_printer_id") @api.onchange("printing_printer_id")
def onchange_printing_printer_id(self): def onchange_printing_printer_id(self):
""" Reset the tray when the printer is changed """ """Reset the tray when the printer is changed"""
self.printer_tray_id = False self.printer_tray_id = False

View File

@@ -52,14 +52,14 @@ class TestIrActionsReportXml(TransactionCase):
return self.env["printing.tray"].create(values) return self.env["printing.tray"].create(values)
def test_print_action_for_report_name_gets_report(self): def test_print_action_for_report_name_gets_report(self):
""" It should get report by name """ """It should get report by name"""
with mock.patch.object(self.Model, "_get_report_from_name") as mk: with mock.patch.object(self.Model, "_get_report_from_name") as mk:
expect = "test" expect = "test"
self.Model.print_action_for_report_name(expect) self.Model.print_action_for_report_name(expect)
mk.assert_called_once_with(expect) mk.assert_called_once_with(expect)
def test_print_action_for_report_name_returns_if_no_report(self): def test_print_action_for_report_name_returns_if_no_report(self):
""" It should return empty dict when no matching report """ """It should return empty dict when no matching report"""
with mock.patch.object(self.Model, "_get_report_from_name") as mk: with mock.patch.object(self.Model, "_get_report_from_name") as mk:
expect = "test" expect = "test"
mk.return_value = False mk.return_value = False
@@ -67,7 +67,7 @@ class TestIrActionsReportXml(TransactionCase):
self.assertDictEqual({}, res) self.assertDictEqual({}, res)
def test_print_action_for_report_name_returns_if_report(self): def test_print_action_for_report_name_returns_if_report(self):
""" It should return correct serializable result for behaviour """ """It should return correct serializable result for behaviour"""
with mock.patch.object(self.Model, "_get_report_from_name") as mk: with mock.patch.object(self.Model, "_get_report_from_name") as mk:
res = self.Model.print_action_for_report_name("test") res = self.Model.print_action_for_report_name("test")
behaviour = mk().behaviour() behaviour = mk().behaviour()
@@ -78,7 +78,7 @@ class TestIrActionsReportXml(TransactionCase):
self.assertDictEqual(expect, res, "Expect {}, Got {}".format(expect, res)) self.assertDictEqual(expect, res, "Expect {}, Got {}".format(expect, res))
def test_behaviour_default_values(self): def test_behaviour_default_values(self):
""" It should return the default action and printer """ """It should return the default action and printer"""
report = self.Model.search([], limit=1) report = self.Model.search([], limit=1)
self.env.user.printing_action = False self.env.user.printing_action = False
self.env.user.printing_printer_id = False self.env.user.printing_printer_id = False
@@ -94,7 +94,7 @@ class TestIrActionsReportXml(TransactionCase):
) )
def test_behaviour_user_values(self): def test_behaviour_user_values(self):
""" It should return the action and printer from user """ """It should return the action and printer from user"""
report = self.Model.search([], limit=1) report = self.Model.search([], limit=1)
self.env.user.printing_action = "client" self.env.user.printing_action = "client"
self.env.user.printing_printer_id = self.new_printer() self.env.user.printing_printer_id = self.new_printer()
@@ -108,7 +108,7 @@ class TestIrActionsReportXml(TransactionCase):
) )
def test_behaviour_report_values(self): def test_behaviour_report_values(self):
""" It should return the action and printer from report """ """It should return the action and printer from report"""
report = self.Model.search([], limit=1) report = self.Model.search([], limit=1)
self.env.user.printing_action = "client" self.env.user.printing_action = "client"
report.property_printing_action_id = self.new_action() report.property_printing_action_id = self.new_action()
@@ -123,7 +123,7 @@ class TestIrActionsReportXml(TransactionCase):
) )
def test_behaviour_user_action(self): def test_behaviour_user_action(self):
""" It should return the action and printer from user action""" """It should return the action and printer from user action"""
report = self.Model.search([], limit=1) report = self.Model.search([], limit=1)
self.env.user.printing_action = "client" self.env.user.printing_action = "client"
report.property_printing_action_id.action_type = "user_default" report.property_printing_action_id.action_type = "user_default"
@@ -133,8 +133,7 @@ class TestIrActionsReportXml(TransactionCase):
) )
def test_behaviour_printing_action_on_wrong_user(self): def test_behaviour_printing_action_on_wrong_user(self):
""" It should return the action and printer ignoring printing action """It should return the action and printer ignoring printing action"""
"""
report = self.Model.search([], limit=1) report = self.Model.search([], limit=1)
self.env.user.printing_action = "client" self.env.user.printing_action = "client"
printing_action = self.new_printing_action() printing_action = self.new_printing_action()
@@ -147,8 +146,7 @@ class TestIrActionsReportXml(TransactionCase):
) )
def test_behaviour_printing_action_on_wrong_report(self): def test_behaviour_printing_action_on_wrong_report(self):
""" It should return the action and printer ignoring printing action """It should return the action and printer ignoring printing action"""
"""
report = self.Model.search([], limit=1) report = self.Model.search([], limit=1)
self.env.user.printing_action = "client" self.env.user.printing_action = "client"
printing_action = self.new_printing_action() printing_action = self.new_printing_action()
@@ -162,7 +160,7 @@ class TestIrActionsReportXml(TransactionCase):
) )
def test_behaviour_printing_action_with_no_printer(self): def test_behaviour_printing_action_with_no_printer(self):
""" It should return the action from printing action and printer from """It should return the action from printing action and printer from
other other
""" """
report = self.Model.search([], limit=1) report = self.Model.search([], limit=1)
@@ -180,7 +178,7 @@ class TestIrActionsReportXml(TransactionCase):
) )
def test_behaviour_printing_action_with_printer(self): def test_behaviour_printing_action_with_printer(self):
""" It should return the action and printer from printing action """ """It should return the action and printer from printing action"""
report = self.Model.search([], limit=1) report = self.Model.search([], limit=1)
self.env.user.printing_action = "client" self.env.user.printing_action = "client"
printing_action = self.new_printing_action() printing_action = self.new_printing_action()
@@ -196,7 +194,7 @@ class TestIrActionsReportXml(TransactionCase):
) )
def test_behaviour_printing_action_user_defaults(self): def test_behaviour_printing_action_user_defaults(self):
""" It should return the action and printer from user with printing """It should return the action and printer from user with printing
action action
""" """
report = self.Model.search([], limit=1) report = self.Model.search([], limit=1)

View File

@@ -44,7 +44,7 @@ class TestPrintingJob(TransactionCase):
@mock.patch("%s.cups" % model) @mock.patch("%s.cups" % model)
def test_cancel_job_error(self, cups): def test_cancel_job_error(self, cups):
""" It should catch any exception from CUPS and update status """ """It should catch any exception from CUPS and update status"""
cups.Connection.side_effect = Exception cups.Connection.side_effect = Exception
printer = self.new_printer() printer = self.new_printer()
job = self.new_job(printer, {"job_id_cups": 2}) job = self.new_job(printer, {"job_id_cups": 2})
@@ -54,7 +54,7 @@ class TestPrintingJob(TransactionCase):
@mock.patch("%s.cups" % model) @mock.patch("%s.cups" % model)
def test_cancel_job(self, cups): def test_cancel_job(self, cups):
""" It should catch any exception from CUPS and update status """ """It should catch any exception from CUPS and update status"""
printer = self.new_printer() printer = self.new_printer()
job = self.new_job(printer) job = self.new_job(printer)
job.cancel() job.cancel()

View File

@@ -65,7 +65,7 @@ class TestPrintingPrinter(TransactionCase):
self.assertEqual(self.Model._set_option_format(None, "pdf"), {}) self.assertEqual(self.Model._set_option_format(None, "pdf"), {})
def test_print_options(self): def test_print_options(self):
""" It should generate the right options dictionnary """ """It should generate the right options dictionnary"""
# TODO: None here used as report - tests here should be merged # TODO: None here used as report - tests here should be merged
# with tests in test_printing_printer_tray from when modules merged # with tests in test_printing_printer_tray from when modules merged
report = self.env["ir.actions.report"].search([], limit=1) report = self.env["ir.actions.report"].search([], limit=1)
@@ -82,7 +82,7 @@ class TestPrintingPrinter(TransactionCase):
@mock.patch("%s.cups" % server_model) @mock.patch("%s.cups" % server_model)
def test_print_report(self, cups): def test_print_report(self, cups):
""" It should print a report through CUPS """ """It should print a report through CUPS"""
fd, file_name = tempfile.mkstemp() fd, file_name = tempfile.mkstemp()
with mock.patch("%s.mkstemp" % model) as mkstemp: with mock.patch("%s.mkstemp" % model) as mkstemp:
mkstemp.return_value = fd, file_name mkstemp.return_value = fd, file_name
@@ -94,7 +94,7 @@ class TestPrintingPrinter(TransactionCase):
@mock.patch("%s.cups" % server_model) @mock.patch("%s.cups" % server_model)
def test_print_report_error(self, cups): def test_print_report_error(self, cups):
""" It should print a report through CUPS """ """It should print a report through CUPS"""
cups.Connection.side_effect = Exception cups.Connection.side_effect = Exception
fd, file_name = tempfile.mkstemp() fd, file_name = tempfile.mkstemp()
with mock.patch("%s.mkstemp" % model) as mkstemp: with mock.patch("%s.mkstemp" % model) as mkstemp:
@@ -107,7 +107,7 @@ class TestPrintingPrinter(TransactionCase):
@mock.patch("%s.cups" % server_model) @mock.patch("%s.cups" % server_model)
def test_print_file(self, cups): def test_print_file(self, cups):
""" It should print a file through CUPS """ """It should print a file through CUPS"""
file_name = "file_name" file_name = "file_name"
printer = self.new_record() printer = self.new_record()
printer.print_file(file_name, "pdf") printer.print_file(file_name, "pdf")
@@ -117,7 +117,7 @@ class TestPrintingPrinter(TransactionCase):
@mock.patch("%s.cups" % server_model) @mock.patch("%s.cups" % server_model)
def test_print_file_error(self, cups): def test_print_file_error(self, cups):
""" It should print a file through CUPS """ """It should print a file through CUPS"""
cups.Connection.side_effect = Exception cups.Connection.side_effect = Exception
file_name = "file_name" file_name = "file_name"
printer = self.new_record() printer = self.new_record()
@@ -125,7 +125,7 @@ class TestPrintingPrinter(TransactionCase):
printer.print_file(file_name) printer.print_file(file_name)
def test_set_default(self): def test_set_default(self):
""" It should set a single record as default """ """It should set a single record as default"""
printer = self.new_record() printer = self.new_record()
self.assertTrue(printer.default) self.assertTrue(printer.default)
other_printer = self.new_record() other_printer = self.new_record()
@@ -137,7 +137,7 @@ class TestPrintingPrinter(TransactionCase):
self.assertEqual(other_printer, self.Model.get_default()) self.assertEqual(other_printer, self.Model.get_default())
def test_unset_default(self): def test_unset_default(self):
""" It should unset the default state of the printer """ """It should unset the default state of the printer"""
printer = self.new_record() printer = self.new_record()
self.assertTrue(printer.default) self.assertTrue(printer.default)
printer.unset_default() printer.unset_default()
@@ -145,7 +145,7 @@ class TestPrintingPrinter(TransactionCase):
@mock.patch("%s.cups" % server_model) @mock.patch("%s.cups" % server_model)
def test_cancel_all_jobs(self, cups): def test_cancel_all_jobs(self, cups):
""" It should cancel all jobs """ """It should cancel all jobs"""
printer = self.new_record() printer = self.new_record()
printer.action_cancel_all_jobs() printer.action_cancel_all_jobs()
cups.Connection().cancelAllJobs.assert_called_once_with( cups.Connection().cancelAllJobs.assert_called_once_with(
@@ -154,7 +154,7 @@ class TestPrintingPrinter(TransactionCase):
@mock.patch("%s.cups" % server_model) @mock.patch("%s.cups" % server_model)
def test_cancel_and_purge_all_jobs(self, cups): def test_cancel_and_purge_all_jobs(self, cups):
""" It should cancel all jobs """ """It should cancel all jobs"""
printer = self.new_record() printer = self.new_record()
printer.cancel_all_jobs(purge_jobs=True) printer.cancel_all_jobs(purge_jobs=True)
cups.Connection().cancelAllJobs.assert_called_once_with( cups.Connection().cancelAllJobs.assert_called_once_with(
@@ -163,14 +163,14 @@ class TestPrintingPrinter(TransactionCase):
@mock.patch("%s.cups" % server_model) @mock.patch("%s.cups" % server_model)
def test_enable_printer(self, cups): def test_enable_printer(self, cups):
""" It should enable the printer """ """It should enable the printer"""
printer = self.new_record() printer = self.new_record()
printer.enable() printer.enable()
cups.Connection().enablePrinter.assert_called_once_with(printer.system_name) cups.Connection().enablePrinter.assert_called_once_with(printer.system_name)
@mock.patch("%s.cups" % server_model) @mock.patch("%s.cups" % server_model)
def test_disable_printer(self, cups): def test_disable_printer(self, cups):
""" It should disable the printer """ """It should disable the printer"""
printer = self.new_record() printer = self.new_record()
printer.disable() printer.disable()
cups.Connection().disablePrinter.assert_called_once_with(printer.system_name) cups.Connection().disablePrinter.assert_called_once_with(printer.system_name)

View File

@@ -38,7 +38,7 @@ class TestPrintingPrinterWizard(TransactionCase):
@mock.patch("%s.cups" % model) @mock.patch("%s.cups" % model)
def test_action_ok_inits_connection(self, cups): def test_action_ok_inits_connection(self, cups):
""" It should initialize CUPS connection """ """It should initialize CUPS connection"""
self.Model.action_ok() self.Model.action_ok()
cups.Connection.assert_called_once_with( cups.Connection.assert_called_once_with(
host=self.server.address, port=self.server.port host=self.server.address, port=self.server.port
@@ -46,7 +46,7 @@ class TestPrintingPrinterWizard(TransactionCase):
@mock.patch("%s.cups" % model) @mock.patch("%s.cups" % model)
def test_action_ok_gets_printers(self, cups): def test_action_ok_gets_printers(self, cups):
""" It should get printers from CUPS """ """It should get printers from CUPS"""
cups.Connection().getPrinters.return_value = {"sys_name": self.printer_vals} cups.Connection().getPrinters.return_value = {"sys_name": self.printer_vals}
cups.Connection().getPPD3.return_value = (200, 0, "") cups.Connection().getPPD3.return_value = (200, 0, "")
self.Model.action_ok() self.Model.action_ok()
@@ -54,14 +54,14 @@ class TestPrintingPrinterWizard(TransactionCase):
@mock.patch("%s.cups" % model) @mock.patch("%s.cups" % model)
def test_action_ok_raises_warning_on_error(self, cups): def test_action_ok_raises_warning_on_error(self, cups):
""" It should raise Warning on any error """ """It should raise Warning on any error"""
cups.Connection.side_effect = StopTest cups.Connection.side_effect = StopTest
with self.assertRaises(UserError): with self.assertRaises(UserError):
self.Model.action_ok() self.Model.action_ok()
@mock.patch("%s.cups" % model) @mock.patch("%s.cups" % model)
def test_action_ok_creates_new_printer(self, cups): def test_action_ok_creates_new_printer(self, cups):
""" It should create new printer w/ proper vals """ """It should create new printer w/ proper vals"""
cups.Connection().getPrinters.return_value = {"sys_name": self.printer_vals} cups.Connection().getPrinters.return_value = {"sys_name": self.printer_vals}
cups.Connection().getPPD3.return_value = (200, 0, "") cups.Connection().getPPD3.return_value = (200, 0, "")
self.Model.action_ok() self.Model.action_ok()
@@ -77,7 +77,7 @@ class TestPrintingPrinterWizard(TransactionCase):
@mock.patch("%s.cups" % model) @mock.patch("%s.cups" % model)
def test_action_ok_skips_existing_printer(self, cups): def test_action_ok_skips_existing_printer(self, cups):
""" It should not recreate existing printers """ """It should not recreate existing printers"""
cups.Connection().getPrinters.return_value = {"sys_name": self.printer_vals} cups.Connection().getPrinters.return_value = {"sys_name": self.printer_vals}
cups.Connection().getPPD3.return_value = (200, 0, "") cups.Connection().getPPD3.return_value = (200, 0, "")
self.env["printing.printer"].create(self._record_vals()) self.env["printing.printer"].create(self._record_vals())

View File

@@ -41,7 +41,7 @@ class TestPrintingReportXmlAction(TransactionCase):
) )
def test_behaviour(self): def test_behaviour(self):
""" It should return some action's data, unless called on empty """It should return some action's data, unless called on empty
recordset recordset
""" """
xml_action = self.new_record() xml_action = self.new_record()

View File

@@ -44,7 +44,7 @@ class TestPrintingServer(TransactionCase):
@mock.patch("%s.cups" % model) @mock.patch("%s.cups" % model)
def test_update_printers_error(self, cups): def test_update_printers_error(self, cups):
""" It should catch any exception from CUPS and update status """ """It should catch any exception from CUPS and update status"""
cups.Connection.side_effect = Exception cups.Connection.side_effect = Exception
rec_id = self.new_printer() rec_id = self.new_printer()
self.Model.update_printers() self.Model.update_printers()
@@ -52,7 +52,7 @@ class TestPrintingServer(TransactionCase):
@mock.patch("%s.cups" % model) @mock.patch("%s.cups" % model)
def test_update_printers_inits_cups(self, cups): def test_update_printers_inits_cups(self, cups):
""" It should init CUPS connection """ """It should init CUPS connection"""
self.new_printer() self.new_printer()
self.Model.update_printers() self.Model.update_printers()
cups.Connection.assert_called_once_with( cups.Connection.assert_called_once_with(
@@ -61,21 +61,21 @@ class TestPrintingServer(TransactionCase):
@mock.patch("%s.cups" % model) @mock.patch("%s.cups" % model)
def test_update_printers_gets_all_printers(self, cups): def test_update_printers_gets_all_printers(self, cups):
""" It should get all printers from CUPS server """ """It should get all printers from CUPS server"""
self.new_printer() self.new_printer()
self.Model.update_printers() self.Model.update_printers()
cups.Connection().getPrinters.assert_called_once_with() cups.Connection().getPrinters.assert_called_once_with()
@mock.patch("%s.cups" % model) @mock.patch("%s.cups" % model)
def test_update_printers_search(self, cups): def test_update_printers_search(self, cups):
""" It should search all when no domain """ """It should search all when no domain"""
with mock.patch.object(self.Model, "search") as search: with mock.patch.object(self.Model, "search") as search:
self.Model.update_printers() self.Model.update_printers()
search.assert_called_once_with([]) search.assert_called_once_with([])
@mock.patch("%s.cups" % model) @mock.patch("%s.cups" % model)
def test_update_printers_search_domain(self, cups): def test_update_printers_search_domain(self, cups):
""" It should use specific domain for search """ """It should use specific domain for search"""
with mock.patch.object(self.Model, "search") as search: with mock.patch.object(self.Model, "search") as search:
expect = [("id", ">", 0)] expect = [("id", ">", 0)]
self.Model.update_printers(expect) self.Model.update_printers(expect)
@@ -83,7 +83,7 @@ class TestPrintingServer(TransactionCase):
@mock.patch("%s.cups" % model) @mock.patch("%s.cups" % model)
def test_update_printers_update_unavailable(self, cups): def test_update_printers_update_unavailable(self, cups):
""" It should update status when printer is unavailable """ """It should update status when printer is unavailable"""
rec_id = self.new_printer() rec_id = self.new_printer()
cups.Connection().getPrinters().get.return_value = False cups.Connection().getPrinters().get.return_value = False
self.Model.action_update_printers() self.Model.action_update_printers()
@@ -91,19 +91,20 @@ class TestPrintingServer(TransactionCase):
@mock.patch("%s.cups" % model) @mock.patch("%s.cups" % model)
def test_update_archived_printers(self, cups): def test_update_archived_printers(self, cups):
""" It should update status even if printer is archived """ """It should update status even if printer is archived"""
rec_id = self.new_printer() rec_id = self.new_printer()
rec_id.toggle_active() rec_id.toggle_active()
self.server.refresh() self.server.refresh()
cups.Connection().getPrinters().get.return_value = False cups.Connection().getPrinters().get.return_value = False
self.Model.action_update_printers() self.Model.action_update_printers()
self.assertEqual( self.assertEqual(
"unavailable", rec_id.status, "unavailable",
rec_id.status,
) )
@mock.patch("%s.cups" % model) @mock.patch("%s.cups" % model)
def test_update_jobs_cron(self, cups): def test_update_jobs_cron(self, cups):
""" It should get all jobs from CUPS server """ """It should get all jobs from CUPS server"""
self.new_printer() self.new_printer()
self.Model.action_update_jobs() self.Model.action_update_jobs()
cups.Connection().getPrinters.assert_called_once_with() cups.Connection().getPrinters.assert_called_once_with()
@@ -125,7 +126,7 @@ class TestPrintingServer(TransactionCase):
@mock.patch("%s.cups" % model) @mock.patch("%s.cups" % model)
def test_update_jobs_button(self, cups): def test_update_jobs_button(self, cups):
""" It should get all jobs from CUPS server """ """It should get all jobs from CUPS server"""
self.new_printer() self.new_printer()
self.server.action_update_jobs() self.server.action_update_jobs()
cups.Connection().getPrinters.assert_called_once_with() cups.Connection().getPrinters.assert_called_once_with()
@@ -147,7 +148,7 @@ class TestPrintingServer(TransactionCase):
@mock.patch("%s.cups" % model) @mock.patch("%s.cups" % model)
def test_update_jobs_error(self, cups): def test_update_jobs_error(self, cups):
""" It should catch any exception from CUPS and update status """ """It should catch any exception from CUPS and update status"""
cups.Connection.side_effect = Exception cups.Connection.side_effect = Exception
self.new_printer() self.new_printer()
self.server.update_jobs() self.server.update_jobs()

View File

@@ -34,7 +34,7 @@ class TestPrintingTray(TransactionCase):
return self.env["printing.tray"].create(self.tray_vals) return self.env["printing.tray"].create(self.tray_vals)
def test_report_behaviour(self): def test_report_behaviour(self):
""" It should add the selected tray in the report data """ """It should add the selected tray in the report data"""
ir_report = self.env["ir.actions.report"].search([], limit=1) ir_report = self.env["ir.actions.report"].search([], limit=1)
report = self.env["printing.report.xml.action"].create( 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"}

View File

@@ -66,24 +66,23 @@ class TestReport(common.HttpCase):
) )
def test_can_print_report_context_skip(self): def test_can_print_report_context_skip(self):
""" It should return False based on context """ """It should return False based on context"""
rec_id = self.new_record().with_context(must_skip_send_to_printer=True) rec_id = self.new_record().with_context(must_skip_send_to_printer=True)
res = rec_id._can_print_report({"action": "server"}, True, True) res = rec_id._can_print_report({"action": "server"}, True, True)
self.assertFalse(res) self.assertFalse(res)
def test_can_print_report_true(self): def test_can_print_report_true(self):
""" It should return True when server print allowed """ """It should return True when server print allowed"""
res = self.new_record()._can_print_report({"action": "server"}, True, True) res = self.new_record()._can_print_report({"action": "server"}, True, True)
self.assertTrue(res) self.assertTrue(res)
def test_can_print_report_false(self): def test_can_print_report_false(self):
""" It should return False when server print not allowed """ """It should return False when server print not allowed"""
res = self.new_record()._can_print_report({"action": "server"}, True, False) res = self.new_record()._can_print_report({"action": "server"}, True, False)
self.assertFalse(res) self.assertFalse(res)
def test_render_qweb_pdf_not_printable(self): def test_render_qweb_pdf_not_printable(self):
""" It should print the report, only if it is printable """It should print the report, only if it is printable"""
"""
with mock.patch( with mock.patch(
"odoo.addons.base_report_to_printer.models." "odoo.addons.base_report_to_printer.models."
"printing_printer.PrintingPrinter." "printing_printer.PrintingPrinter."
@@ -93,8 +92,7 @@ class TestReport(common.HttpCase):
print_document.assert_not_called() print_document.assert_not_called()
def test_render_qweb_pdf_printable(self): def test_render_qweb_pdf_printable(self):
""" It should print the report, only if it is printable """It should print the report, only if it is printable"""
"""
with mock.patch( with mock.patch(
"odoo.addons.base_report_to_printer.models." "odoo.addons.base_report_to_printer.models."
"printing_printer.PrintingPrinter." "printing_printer.PrintingPrinter."
@@ -112,7 +110,7 @@ class TestReport(common.HttpCase):
) )
def test_print_document_not_printable(self): def test_print_document_not_printable(self):
""" It should print the report, regardless of the defined behaviour """ """It should print the report, regardless of the defined behaviour"""
self.report.printing_printer_id = self.new_printer() self.report.printing_printer_id = self.new_printer()
with mock.patch( with mock.patch(
"odoo.addons.base_report_to_printer.models." "odoo.addons.base_report_to_printer.models."
@@ -123,7 +121,7 @@ class TestReport(common.HttpCase):
print_document.assert_called_once() print_document.assert_called_once()
def test_print_document_printable(self): def test_print_document_printable(self):
""" It should print the report, regardless of the defined behaviour """ """It should print the report, regardless of the defined behaviour"""
self.report.property_printing_action_id.action_type = "server" self.report.property_printing_action_id.action_type = "server"
self.report.printing_printer_id = self.new_printer() self.report.printing_printer_id = self.new_printer()
with mock.patch( with mock.patch(
@@ -135,6 +133,6 @@ class TestReport(common.HttpCase):
print_document.assert_called_once() print_document.assert_called_once()
def test_print_document_no_printer(self): def test_print_document_no_printer(self):
""" It should raise an error """ """It should raise an error"""
with self.assertRaises(exceptions.UserError): with self.assertRaises(exceptions.UserError):
self.report.print_document(self.partners.ids) self.report.print_document(self.partners.ids)

View File

@@ -15,13 +15,13 @@ class TestResUsers(common.TransactionCase):
return self.env["res.users"].create(self.user_vals) return self.env["res.users"].create(self.user_vals)
def test_available_action_types_excludes_user_default(self): def test_available_action_types_excludes_user_default(self):
""" It should not contain `user_default` in avail actions """ """It should not contain `user_default` in avail actions"""
self.user_vals["printing_action"] = "user_default" self.user_vals["printing_action"] = "user_default"
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
self.new_record() self.new_record()
def test_available_action_types_includes_something_else(self): def test_available_action_types_includes_something_else(self):
""" It should still contain other valid keys """ """It should still contain other valid keys"""
self.user_vals["printing_action"] = "server" self.user_vals["printing_action"] = "server"
self.assertTrue(self.new_record()) self.assertTrue(self.new_record())

View File

@@ -66,7 +66,9 @@ class PrintingLabelZpl2(models.Model):
default=True, default=True,
) )
action_window_id = fields.Many2one( action_window_id = fields.Many2one(
comodel_name="ir.actions.act_window", string="Action", readonly=True, comodel_name="ir.actions.act_window",
string="Action",
readonly=True,
) )
test_print_mode = fields.Boolean(string="Mode Print") test_print_mode = fields.Boolean(string="Mode Print")
test_labelary_mode = fields.Boolean(string="Mode Labelary") test_labelary_mode = fields.Boolean(string="Mode Labelary")

View File

@@ -34,11 +34,11 @@ class TestWizardPrintRecordLabel(TransactionCase):
) )
def test_create_action(self): def test_create_action(self):
""" Check the creation of action """ """Check the creation of action"""
self.label.create_action() self.label.create_action()
self.assertTrue(self.label.action_window_id) self.assertTrue(self.label.action_window_id)
def test_unlink_action(self): def test_unlink_action(self):
""" Check the unlink of action """ """Check the unlink of action"""
self.label.unlink_action() self.label.unlink_action()
self.assertFalse(self.label.action_window_id) self.assertFalse(self.label.action_window_id)

View File

@@ -58,20 +58,20 @@ class TestPrintingLabelZpl2(TransactionCase):
return self.ComponentModel.create(values) return self.ComponentModel.create(values)
def test_print_on_bad_model(self): def test_print_on_bad_model(self):
""" Check that printing on the bad model raises an exception """ """Check that printing on the bad model raises an exception"""
label = self.new_label() label = self.new_label()
with self.assertRaises(exceptions.UserError): with self.assertRaises(exceptions.UserError):
label.print_label(self.printer, label) label.print_label(self.printer, label)
@mock.patch("%s.cups" % model) @mock.patch("%s.cups" % model)
def test_print_empty_label(self, cups): def test_print_empty_label(self, cups):
""" Check that printing an empty label works """ """Check that printing an empty label works"""
label = self.new_label() label = self.new_label()
label.print_label(self.printer, self.printer) label.print_label(self.printer, self.printer)
cups.Connection().printFile.assert_called_once() cups.Connection().printFile.assert_called_once()
def test_empty_label_contents(self): def test_empty_label_contents(self):
""" Check contents of an empty label """ """Check contents of an empty label"""
label = self.new_label() label = self.new_label()
contents = label._generate_zpl2_data(self.printer).decode("utf-8") contents = label._generate_zpl2_data(self.printer).decode("utf-8")
self.assertEqual( self.assertEqual(
@@ -91,7 +91,7 @@ class TestPrintingLabelZpl2(TransactionCase):
) )
def test_sublabel_label_contents(self): def test_sublabel_label_contents(self):
""" Check contents of a sublabel label component """ """Check contents of a sublabel label component"""
sublabel = self.new_label({"name": "Sublabel"}) sublabel = self.new_label({"name": "Sublabel"})
data = "Some text" data = "Some text"
self.new_component({"label_id": sublabel.id, "data": '"' + data + '"'}) self.new_component({"label_id": sublabel.id, "data": '"' + data + '"'})
@@ -134,7 +134,7 @@ class TestPrintingLabelZpl2(TransactionCase):
) )
def test_repeatable_component_label_fixed_contents(self): def test_repeatable_component_label_fixed_contents(self):
""" Check contents of a repeatable label component """Check contents of a repeatable label component
Check that a fixed value is repeated each time Check that a fixed value is repeated each time
""" """
@@ -193,7 +193,7 @@ class TestPrintingLabelZpl2(TransactionCase):
) )
def test_repeatable_component_label_iterable_contents(self): def test_repeatable_component_label_iterable_contents(self):
""" Check contents of a repeatable label component """Check contents of a repeatable label component
Check that an iterable contents (list, tuple, etc.) is browsed Check that an iterable contents (list, tuple, etc.) is browsed
If the repeat_count is higher than the value length, all values are If the repeat_count is higher than the value length, all values are
@@ -247,7 +247,7 @@ class TestPrintingLabelZpl2(TransactionCase):
) )
def test_repeatable_component_label_iterable_offset(self): def test_repeatable_component_label_iterable_offset(self):
""" Check contents of a repeatable label component with an offset """Check contents of a repeatable label component with an offset
Check that an iterable contents (list, tuple, etc.) is browsed Check that an iterable contents (list, tuple, etc.) is browsed
If the repeat_count is higher than the value length, all values are If the repeat_count is higher than the value length, all values are
@@ -309,7 +309,7 @@ class TestPrintingLabelZpl2(TransactionCase):
) )
def test_repeatable_sublabel_contents(self): def test_repeatable_sublabel_contents(self):
""" Check contents of a repeatable sublabel label component """ """Check contents of a repeatable sublabel label component"""
sublabel = self.new_label( sublabel = self.new_label(
{ {
"name": "Sublabel", "name": "Sublabel",
@@ -407,7 +407,7 @@ class TestPrintingLabelZpl2(TransactionCase):
) )
def test_text_label_contents(self): def test_text_label_contents(self):
""" Check contents of a text label """ """Check contents of a text label"""
label = self.new_label() label = self.new_label()
data = "Some text" data = "Some text"
self.new_component({"label_id": label.id, "data": '"%s"' % data}) self.new_component({"label_id": label.id, "data": '"%s"' % data})
@@ -437,7 +437,7 @@ class TestPrintingLabelZpl2(TransactionCase):
) )
def test_reversed_text_label_contents(self): def test_reversed_text_label_contents(self):
""" Check contents of a text label """ """Check contents of a text label"""
label = self.new_label() label = self.new_label()
data = "Some text" data = "Some text"
self.new_component( self.new_component(
@@ -471,7 +471,7 @@ class TestPrintingLabelZpl2(TransactionCase):
) )
def test_block_text_label_contents(self): def test_block_text_label_contents(self):
""" Check contents of a text label """ """Check contents of a text label"""
label = self.new_label() label = self.new_label()
data = "Some text" data = "Some text"
self.new_component( self.new_component(
@@ -505,7 +505,7 @@ class TestPrintingLabelZpl2(TransactionCase):
) )
def test_rectangle_label_contents(self): def test_rectangle_label_contents(self):
""" Check contents of a rectangle label """ """Check contents of a rectangle label"""
label = self.new_label() label = self.new_label()
self.new_component({"label_id": label.id, "component_type": "rectangle"}) self.new_component({"label_id": label.id, "component_type": "rectangle"})
contents = label._generate_zpl2_data(self.printer).decode("utf-8") contents = label._generate_zpl2_data(self.printer).decode("utf-8")
@@ -532,7 +532,7 @@ class TestPrintingLabelZpl2(TransactionCase):
) )
def test_diagonal_line_label_contents(self): def test_diagonal_line_label_contents(self):
""" Check contents of a diagonal line label """ """Check contents of a diagonal line label"""
label = self.new_label() label = self.new_label()
self.new_component({"label_id": label.id, "component_type": "diagonal"}) self.new_component({"label_id": label.id, "component_type": "diagonal"})
contents = label._generate_zpl2_data(self.printer).decode("utf-8") contents = label._generate_zpl2_data(self.printer).decode("utf-8")
@@ -559,7 +559,7 @@ class TestPrintingLabelZpl2(TransactionCase):
) )
def test_circle_label_contents(self): def test_circle_label_contents(self):
""" Check contents of a circle label """ """Check contents of a circle label"""
label = self.new_label() label = self.new_label()
self.new_component({"label_id": label.id, "component_type": "circle"}) self.new_component({"label_id": label.id, "component_type": "circle"})
contents = label._generate_zpl2_data(self.printer).decode("utf-8") contents = label._generate_zpl2_data(self.printer).decode("utf-8")
@@ -586,7 +586,7 @@ class TestPrintingLabelZpl2(TransactionCase):
) )
def test_code11_barcode_label_contents(self): def test_code11_barcode_label_contents(self):
""" Check contents of a code 11 barcode label """ """Check contents of a code 11 barcode label"""
label = self.new_label() label = self.new_label()
data = "Some text" data = "Some text"
self.new_component( self.new_component(
@@ -624,7 +624,7 @@ class TestPrintingLabelZpl2(TransactionCase):
) )
def test_2of5_barcode_label_contents(self): def test_2of5_barcode_label_contents(self):
""" Check contents of a interleaved 2 of 5 barcode label """ """Check contents of a interleaved 2 of 5 barcode label"""
label = self.new_label() label = self.new_label()
data = "Some text" data = "Some text"
self.new_component( self.new_component(
@@ -662,7 +662,7 @@ class TestPrintingLabelZpl2(TransactionCase):
) )
def test_code39_barcode_label_contents(self): def test_code39_barcode_label_contents(self):
""" Check contents of a code 39 barcode label """ """Check contents of a code 39 barcode label"""
label = self.new_label() label = self.new_label()
data = "Some text" data = "Some text"
self.new_component( self.new_component(
@@ -700,7 +700,7 @@ class TestPrintingLabelZpl2(TransactionCase):
) )
def test_code49_barcode_label_contents(self): def test_code49_barcode_label_contents(self):
""" Check contents of a code 49 barcode label """ """Check contents of a code 49 barcode label"""
label = self.new_label() label = self.new_label()
data = "Some text" data = "Some text"
self.new_component( self.new_component(
@@ -738,7 +738,7 @@ class TestPrintingLabelZpl2(TransactionCase):
) )
def test_code49_barcode_label_contents_line(self): def test_code49_barcode_label_contents_line(self):
""" Check contents of a code 49 barcode label """ """Check contents of a code 49 barcode label"""
label = self.new_label() label = self.new_label()
data = "Some text" data = "Some text"
self.new_component( self.new_component(
@@ -777,7 +777,7 @@ class TestPrintingLabelZpl2(TransactionCase):
) )
def test_code49_barcode_label_contents_with_above(self): def test_code49_barcode_label_contents_with_above(self):
""" Check contents of a code 49 barconde label """Check contents of a code 49 barconde label
with interpretation line above with interpretation line above
""" """
label = self.new_label() label = self.new_label()
@@ -819,7 +819,7 @@ class TestPrintingLabelZpl2(TransactionCase):
) )
def test_pdf417_barcode_label_contents(self): def test_pdf417_barcode_label_contents(self):
""" Check contents of a pdf417 barcode label """ """Check contents of a pdf417 barcode label"""
label = self.new_label() label = self.new_label()
data = "Some text" data = "Some text"
self.new_component( self.new_component(
@@ -853,7 +853,7 @@ class TestPrintingLabelZpl2(TransactionCase):
) )
def test_ean8_barcode_label_contents(self): def test_ean8_barcode_label_contents(self):
""" Check contents of a ean-8 barcode label """ """Check contents of a ean-8 barcode label"""
label = self.new_label() label = self.new_label()
data = "Some text" data = "Some text"
self.new_component( self.new_component(
@@ -887,7 +887,7 @@ class TestPrintingLabelZpl2(TransactionCase):
) )
def test_upce_barcode_label_contents(self): def test_upce_barcode_label_contents(self):
""" Check contents of a upc-e barcode label """ """Check contents of a upc-e barcode label"""
label = self.new_label() label = self.new_label()
data = "Some text" data = "Some text"
self.new_component( self.new_component(
@@ -921,7 +921,7 @@ class TestPrintingLabelZpl2(TransactionCase):
) )
def test_code128_barcode_label_contents(self): def test_code128_barcode_label_contents(self):
""" Check contents of a code 128 barcode label """ """Check contents of a code 128 barcode label"""
label = self.new_label() label = self.new_label()
data = "Some text" data = "Some text"
self.new_component( self.new_component(
@@ -959,7 +959,7 @@ class TestPrintingLabelZpl2(TransactionCase):
) )
def test_ean13_barcode_label_contents(self): def test_ean13_barcode_label_contents(self):
""" Check contents of a ean-13 barcode label """ """Check contents of a ean-13 barcode label"""
label = self.new_label() label = self.new_label()
data = "Some text" data = "Some text"
self.new_component( self.new_component(
@@ -993,7 +993,7 @@ class TestPrintingLabelZpl2(TransactionCase):
) )
def test_qrcode_barcode_label_contents(self): def test_qrcode_barcode_label_contents(self):
""" Check contents of a qr code barcode label """ """Check contents of a qr code barcode label"""
label = self.new_label() label = self.new_label()
data = "Some text" data = "Some text"
self.new_component( self.new_component(
@@ -1031,7 +1031,7 @@ class TestPrintingLabelZpl2(TransactionCase):
) )
def test_graphic_label_contents_blank(self): def test_graphic_label_contents_blank(self):
""" Check contents of a image label """ """Check contents of a image label"""
label = self.new_label() label = self.new_label()
data = "R0lGODlhAQABAIAAAP7//wAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" data = "R0lGODlhAQABAIAAAP7//wAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw=="
self.new_component( self.new_component(
@@ -1054,7 +1054,7 @@ class TestPrintingLabelZpl2(TransactionCase):
) )
def test_graphic_label_contents_blank_rotated(self): def test_graphic_label_contents_blank_rotated(self):
""" Check contents of image rotated label """ """Check contents of image rotated label"""
label = self.new_label() label = self.new_label()
data = "R0lGODlhAQABAIAAAP7//wAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" data = "R0lGODlhAQABAIAAAP7//wAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw=="
self.new_component( self.new_component(
@@ -1082,7 +1082,7 @@ class TestPrintingLabelZpl2(TransactionCase):
) )
def test_graphic_label_contents_blank_inverted(self): def test_graphic_label_contents_blank_inverted(self):
""" Check contents of a image inverted label """ """Check contents of a image inverted label"""
label = self.new_label() label = self.new_label()
data = "R0lGODlhAQABAIAAAP7//wAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" data = "R0lGODlhAQABAIAAAP7//wAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw=="
self.new_component( self.new_component(
@@ -1106,7 +1106,7 @@ class TestPrintingLabelZpl2(TransactionCase):
) )
def test_graphic_label_contents_blank_bottom(self): def test_graphic_label_contents_blank_bottom(self):
""" Check contents of a image bottom label """ """Check contents of a image bottom label"""
label = self.new_label() label = self.new_label()
data = "R0lGODlhAQABAIAAAP7//wAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" data = "R0lGODlhAQABAIAAAP7//wAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw=="
self.new_component( self.new_component(
@@ -1130,7 +1130,7 @@ class TestPrintingLabelZpl2(TransactionCase):
) )
def test_zpl2_raw_contents_blank(self): def test_zpl2_raw_contents_blank(self):
""" Check contents of a image label """ """Check contents of a image label"""
label = self.new_label() label = self.new_label()
data = "^FO50,50^GB100,100,100^FS" data = "^FO50,50^GB100,100,100^FS"
self.new_component( self.new_component(
@@ -1153,7 +1153,7 @@ class TestPrintingLabelZpl2(TransactionCase):
) )
def test_zpl2_component_not_show(self): def test_zpl2_component_not_show(self):
""" Check to don't show no things """ """Check to don't show no things"""
label = self.new_label() label = self.new_label()
data = "component_not_show" data = "component_not_show"
self.new_component( self.new_component(
@@ -1169,7 +1169,7 @@ class TestPrintingLabelZpl2(TransactionCase):
) )
def test_zpl2_component_quick_move(self): def test_zpl2_component_quick_move(self):
""" Check component quick move """ """Check component quick move"""
label = self.new_label() label = self.new_label()
component = self.new_component( component = self.new_component(
{ {

View File

@@ -35,7 +35,7 @@ class TestWizardPrintRecordLabel(TransactionCase):
) )
def test_get_record(self): def test_get_record(self):
""" Check if return a record """ """Check if return a record"""
self.label.record_id = 10 self.label.record_id = 10
res = self.label._get_record() res = self.label._get_record()
@@ -47,7 +47,7 @@ class TestWizardPrintRecordLabel(TransactionCase):
@mock.patch("%s.cups" % model) @mock.patch("%s.cups" % model)
def test_print_label_test(self, cups): def test_print_label_test(self, cups):
""" Check if print test """ """Check if print test"""
self.label.test_print_mode = True self.label.test_print_mode = True
self.label.printer_id = self.printer self.label.printer_id = self.printer
self.label.record_id = 10 self.label.record_id = 10
@@ -55,12 +55,12 @@ class TestWizardPrintRecordLabel(TransactionCase):
cups.Connection().printFile.assert_called_once() cups.Connection().printFile.assert_called_once()
def test_emulation_without_params(self): def test_emulation_without_params(self):
""" Check if not execute next if not in this mode """ """Check if not execute next if not in this mode"""
self.label.test_labelary_mode = False self.label.test_labelary_mode = False
self.assertIs(self.label.labelary_image, False) self.assertIs(self.label.labelary_image, False)
def test_emulation_with_bad_header(self): def test_emulation_with_bad_header(self):
""" Check if bad header """ """Check if bad header"""
self.label.test_labelary_mode = True self.label.test_labelary_mode = True
self.label.labelary_width = 80 self.label.labelary_width = 80
self.label.labelary_dpmm = "8dpmm" self.label.labelary_dpmm = "8dpmm"
@@ -71,7 +71,7 @@ class TestWizardPrintRecordLabel(TransactionCase):
self.assertFalse(self.label.labelary_image) self.assertFalse(self.label.labelary_image)
def test_emulation_with_bad_data_compute(self): def test_emulation_with_bad_data_compute(self):
""" Check if bad data compute """ """Check if bad data compute"""
self.label.test_labelary_mode = True self.label.test_labelary_mode = True
self.label.labelary_width = 80 self.label.labelary_width = 80
self.label.labelary_height = 30 self.label.labelary_height = 30
@@ -83,7 +83,7 @@ class TestWizardPrintRecordLabel(TransactionCase):
self.assertIs(self.label.labelary_image, False) self.assertIs(self.label.labelary_image, False)
def test_emulation_with_good_data(self): def test_emulation_with_good_data(self):
""" Check if ok """ """Check if ok"""
self.label.test_labelary_mode = True self.label.test_labelary_mode = True
self.label.labelary_width = 80 self.label.labelary_width = 80
self.label.labelary_height = 30 self.label.labelary_height = 30

View File

@@ -32,12 +32,12 @@ class TestWizardImportZpl2(TransactionCase):
) )
def test_open_wizard(self): def test_open_wizard(self):
""" open wizard from label""" """open wizard from label"""
res = self.label.import_zpl2() res = self.label.import_zpl2()
self.assertEqual(res.get("context").get("default_label_id"), self.label.id) self.assertEqual(res.get("context").get("default_label_id"), self.label.id)
def test_wizard_import_zpl2(self): def test_wizard_import_zpl2(self):
""" Import ZPL2 from wizard """ """Import ZPL2 from wizard"""
zpl_data = ( zpl_data = (
"^XA\n" "^XA\n"
"^CI28\n" "^CI28\n"
@@ -76,7 +76,7 @@ class TestWizardImportZpl2(TransactionCase):
self.assertEqual(18, len(self.label.component_ids)) self.assertEqual(18, len(self.label.component_ids))
def test_wizard_import_zpl2_add(self): def test_wizard_import_zpl2_add(self):
""" Import ZPL2 from wizard ADD""" """Import ZPL2 from wizard ADD"""
self.env["printing.label.zpl2.component"].create( self.env["printing.label.zpl2.component"].create(
{ {
"name": "ZPL II Label", "name": "ZPL II Label",

View File

@@ -37,7 +37,7 @@ class TestWizardPrintRecordLabel(TransactionCase):
@mock.patch("%s.cups" % model) @mock.patch("%s.cups" % model)
def test_print_record_label(self, cups): def test_print_record_label(self, cups):
""" Check that printing a label using the generic wizard works """ """Check that printing a label using the generic wizard works"""
wizard_obj = self.Model.with_context( wizard_obj = self.Model.with_context(
active_model="printing.printer", active_model="printing.printer",
active_id=self.printer.id, active_id=self.printer.id,
@@ -51,7 +51,7 @@ class TestWizardPrintRecordLabel(TransactionCase):
cups.Connection().printFile.assert_called_once() cups.Connection().printFile.assert_called_once()
def test_wizard_multiple_printers_and_labels(self): def test_wizard_multiple_printers_and_labels(self):
""" Check that printer_id and label_id are not automatically filled """Check that printer_id and label_id are not automatically filled
when there are multiple possible values when there are multiple possible values
""" """
self.env["printing.printer"].create( self.env["printing.printer"].create(
@@ -85,7 +85,7 @@ class TestWizardPrintRecordLabel(TransactionCase):
self.assertEqual(values.get("label_id", False), False) self.assertEqual(values.get("label_id", False), False)
def test_wizard_multiple_labels_but_on_different_models(self): def test_wizard_multiple_labels_but_on_different_models(self):
""" Check that label_id is automatically filled when there are multiple """Check that label_id is automatically filled when there are multiple
labels, but only one on the right model labels, but only one on the right model
""" """
self.env["printing.label.zpl2"].create( self.env["printing.label.zpl2"].create(

View File

@@ -51,7 +51,7 @@ class PrintRecordLabel(models.TransientModel):
return values return values
def print_label(self): def print_label(self):
""" Prints a label per selected record """ """Prints a label per selected record"""
record_model = self.env.context["active_model"] record_model = self.env.context["active_model"]
for record_id in self.env.context["active_ids"]: for record_id in self.env.context["active_ids"]:
record = self.env[record_model].browse(record_id) record = self.env[record_model].browse(record_id)

View File

@@ -13,4 +13,6 @@ class PrintingAction(models.Model):
res.append(("remote_default", "Use remote's default")) res.append(("remote_default", "Use remote's default"))
return res return res
action_type = fields.Selection(selection=_available_action_types,) action_type = fields.Selection(
selection=_available_action_types,
)

View File

@@ -7,7 +7,8 @@ class ResRemote(models.Model):
_inherit = "res.remote" _inherit = "res.remote"
remote_printer_ids = fields.One2many( remote_printer_ids = fields.One2many(
"res.remote.printer", inverse_name="remote_id", "res.remote.printer",
inverse_name="remote_id",
) )
def get_printer_behaviour(self): def get_printer_behaviour(self):

View File

@@ -8,10 +8,19 @@ class ResRemotePrinter(models.Model):
_name = "res.remote.printer" _name = "res.remote.printer"
_description = "Remote Printer" _description = "Remote Printer"
remote_id = fields.Many2one("res.remote", ondelete="cascade", readonly=True,) remote_id = fields.Many2one(
printer_id = fields.Many2one("printing.printer", ondelete="cascade",) "res.remote",
ondelete="cascade",
readonly=True,
)
printer_id = fields.Many2one(
"printing.printer",
ondelete="cascade",
)
printer_tray_id = fields.Many2one( printer_tray_id = fields.Many2one(
"printing.tray", ondelete="cascade", domain="[('printer_id', '=', printer_id)]", "printing.tray",
ondelete="cascade",
domain="[('printer_id', '=', printer_id)]",
) )
is_default = fields.Boolean(default=False) is_default = fields.Boolean(default=False)
printer_usage = fields.Selection([("standard", "Standard")], default="standard") printer_usage = fields.Selection([("standard", "Standard")], default="standard")
@@ -26,7 +35,7 @@ class ResRemotePrinter(models.Model):
@api.onchange("printer_id") @api.onchange("printer_id")
def _onchange_printing_printer_id(self): def _onchange_printing_printer_id(self):
""" Reset the tray when the printer is changed """ """Reset the tray when the printer is changed"""
self.printer_tray_id = False self.printer_tray_id = False
@api.constrains("remote_id", "printer_usage", "is_default") @api.constrains("remote_id", "printer_usage", "is_default")

View File

@@ -68,8 +68,7 @@ class StockPikcing(TransactionCase):
self.uom_unit = self.env.ref("uom.product_uom_unit") self.uom_unit = self.env.ref("uom.product_uom_unit")
def test_stock_picking_auto_print(self): def test_stock_picking_auto_print(self):
""" Auto print when DO is ready or done """Auto print when DO is ready or done"""
"""
self.env["stock.quant"]._update_available_quantity( self.env["stock.quant"]._update_available_quantity(
self.product_A, self.stock_location, 2 self.product_A, self.stock_location, 2
) )