[IMP] Allow to define a default printer for the printing wizard

This commit is contained in:
Florent de Labarre
2018-01-23 00:56:50 +01:00
committed by Lois Rilo
parent a2d632337c
commit 2b02938cd8
2 changed files with 6 additions and 1 deletions

View File

@@ -39,6 +39,7 @@ class TestWizardPrintRecordLabel(TransactionCase):
active_model='printing.printer', active_model='printing.printer',
active_id=self.printer.id, active_id=self.printer.id,
active_ids=[self.printer.id], active_ids=[self.printer.id],
printer_zpl2_id=self.printer.id,
) )
wizard = wizard_obj.create({}) wizard = wizard_obj.create({})
self.assertEqual(wizard.printer_id, self.printer) self.assertEqual(wizard.printer_id, self.printer)
@@ -87,6 +88,7 @@ class TestWizardPrintRecordLabel(TransactionCase):
active_model='printing.printer', active_model='printing.printer',
active_id=self.printer.id, active_id=self.printer.id,
active_ids=[self.printer.id], active_ids=[self.printer.id],
printer_zpl2_id=self.printer.id,
) )
wizard = wizard_obj.create({}) wizard = wizard_obj.create({})
self.assertEqual(wizard.label_id, self.label) self.assertEqual(wizard.label_id, self.label)

View File

@@ -23,6 +23,9 @@ class PrintRecordLabel(models.TransientModel):
values = super(PrintRecordLabel, self).default_get(fields_list) values = super(PrintRecordLabel, self).default_get(fields_list)
# Automatically select the printer and label, if only one is available # Automatically select the printer and label, if only one is available
printers = self.env['printing.printer'].search(
[('id', '=', self.env.context.get('printer_zpl2_id'))])
if not printers:
printers = self.env['printing.printer'].search([]) printers = self.env['printing.printer'].search([])
if len(printers) == 1: if len(printers) == 1:
values['printer_id'] = printers.id values['printer_id'] = printers.id