mirror of
https://github.com/OCA/report-print-send.git
synced 2025-02-16 07:11:31 +02:00
[PORT] Finalize move of printer_tray to base_report_to_printer,
fix tests as report param is not a string but recordset
This commit is contained in:
@@ -14,12 +14,12 @@ class IrActionsReport(models.Model):
|
||||
|
||||
property_printing_action_id = fields.Many2one(
|
||||
comodel_name='printing.action',
|
||||
string='Action',
|
||||
string='Default Behaviour',
|
||||
company_dependent=True,
|
||||
)
|
||||
printing_printer_id = fields.Many2one(
|
||||
comodel_name='printing.printer',
|
||||
string='Printer'
|
||||
string='Default Printer'
|
||||
)
|
||||
printer_tray_id = fields.Many2one(
|
||||
comodel_name='printing.tray',
|
||||
|
||||
@@ -63,9 +63,20 @@ class PrintingPrinter(models.Model):
|
||||
|
||||
@api.multi
|
||||
def _prepare_update_from_cups(self, cups_connection, cups_printer):
|
||||
vals = super(PrintingPrinter, self)._prepare_update_from_cups(
|
||||
cups_connection, cups_printer)
|
||||
|
||||
mapping = {
|
||||
3: 'available',
|
||||
4: 'printing',
|
||||
5: 'error'
|
||||
}
|
||||
vals = {
|
||||
'name': cups_printer['printer-info'],
|
||||
'model': cups_printer.get('printer-make-and-model', False),
|
||||
'location': cups_printer.get('printer-location', False),
|
||||
'uri': cups_printer.get('device-uri', False),
|
||||
'status': mapping.get(cups_printer.get(
|
||||
'printer-state'), 'unknown'),
|
||||
'status_message': cups_printer.get('printer-state-message', ''),
|
||||
}
|
||||
printer_uri = cups_printer['printer-uri-supported']
|
||||
printer_system_name = printer_uri[printer_uri.rfind('/') + 1:]
|
||||
ppd_info = cups_connection.getPPD3(printer_system_name)
|
||||
@@ -104,25 +115,6 @@ class PrintingPrinter(models.Model):
|
||||
for tray in self.tray_ids.filtered(
|
||||
lambda record: record.system_name not in cups_trays.keys())
|
||||
])
|
||||
|
||||
return vals
|
||||
|
||||
@api.multi
|
||||
def _prepare_update_from_cups(self, cups_connection, cups_printer):
|
||||
mapping = {
|
||||
3: 'available',
|
||||
4: 'printing',
|
||||
5: 'error'
|
||||
}
|
||||
vals = {
|
||||
'name': cups_printer['printer-info'],
|
||||
'model': cups_printer.get('printer-make-and-model', False),
|
||||
'location': cups_printer.get('printer-location', False),
|
||||
'uri': cups_printer.get('device-uri', False),
|
||||
'status': mapping.get(cups_printer.get(
|
||||
'printer-state'), 'unknown'),
|
||||
'status_message': cups_printer.get('printer-state-message', ''),
|
||||
}
|
||||
return vals
|
||||
|
||||
@api.multi
|
||||
|
||||
@@ -33,6 +33,17 @@ class ResUsers(models.Model):
|
||||
domain="[('printer_id', '=', printing_printer_id)]",
|
||||
)
|
||||
|
||||
@api.model
|
||||
def _register_hook(self):
|
||||
self.SELF_WRITEABLE_FIELDS.extend([
|
||||
'printing_action',
|
||||
'printing_printer_id',
|
||||
])
|
||||
self.SELF_READABLE_FIELDS.extend([
|
||||
'printing_action',
|
||||
'printing_printer_id',
|
||||
])
|
||||
|
||||
@api.onchange('printing_printer_id')
|
||||
def onchange_printing_printer_id(self):
|
||||
""" Reset the tray when the printer is changed """
|
||||
|
||||
@@ -31,19 +31,22 @@ class TestPrintingPrinter(TransactionCase):
|
||||
'location': 'Location',
|
||||
'uri': 'URI',
|
||||
}
|
||||
self.report = self.env['ir.actions.report'].search([], limit=1)
|
||||
|
||||
def new_record(self):
|
||||
return self.Model.create(self.printer_vals)
|
||||
|
||||
def test_printing_options(self):
|
||||
""" It should generate the right options dictionnary """
|
||||
self.assertEqual(self.Model.print_options('report', 'raw'), {
|
||||
# TODO: None here used as report - tests here should be merged
|
||||
# with tests in test_printing_printer_tray from when modules merged
|
||||
self.assertEqual(self.Model.print_options(None, 'raw'), {
|
||||
'raw': 'True',
|
||||
})
|
||||
self.assertEqual(self.Model.print_options('report', 'pdf', 2), {
|
||||
self.assertEqual(self.Model.print_options(None, 'pdf', 2), {
|
||||
'copies': '2',
|
||||
})
|
||||
self.assertEqual(self.Model.print_options('report', 'raw', 2), {
|
||||
self.assertEqual(self.Model.print_options(None, 'raw', 2), {
|
||||
'raw': 'True',
|
||||
'copies': '2',
|
||||
})
|
||||
@@ -55,7 +58,7 @@ class TestPrintingPrinter(TransactionCase):
|
||||
with mock.patch('%s.mkstemp' % model) as mkstemp:
|
||||
mkstemp.return_value = fd, file_name
|
||||
printer = self.new_record()
|
||||
printer.print_document('report_name', b'content to print', 'pdf')
|
||||
printer.print_document(self.report, b'content to print', 'pdf')
|
||||
cups.Connection().printFile.assert_called_once_with(
|
||||
printer.system_name,
|
||||
file_name,
|
||||
@@ -72,14 +75,14 @@ class TestPrintingPrinter(TransactionCase):
|
||||
printer = self.new_record()
|
||||
with self.assertRaises(UserError):
|
||||
printer.print_document(
|
||||
'report_name', b'content to print', 'pdf')
|
||||
self.report, b'content to print', 'pdf')
|
||||
|
||||
@mock.patch('%s.cups' % server_model)
|
||||
def test_print_file(self, cups):
|
||||
""" It should print a file through CUPS """
|
||||
file_name = 'file_name'
|
||||
printer = self.new_record()
|
||||
printer.print_file(file_name, 'pdf')
|
||||
printer.print_file(file_name, report=self.report, format='pdf')
|
||||
cups.Connection().printFile.assert_called_once_with(
|
||||
printer.system_name,
|
||||
file_name,
|
||||
|
||||
@@ -26,6 +26,7 @@ class TestPrintingPrinterWizard(TransactionCase):
|
||||
'printer-make-and-model': 'Make and Model',
|
||||
'printer-location': "location",
|
||||
'device-uri': 'URI',
|
||||
'printer-uri-supported': 'uri'
|
||||
}
|
||||
|
||||
def _record_vals(self, sys_name='sys_name'):
|
||||
@@ -52,6 +53,7 @@ class TestPrintingPrinterWizard(TransactionCase):
|
||||
cups.Connection().getPrinters.return_value = {
|
||||
'sys_name': self.printer_vals,
|
||||
}
|
||||
cups.Connection().getPPD3.return_value = (200, 0, '')
|
||||
self.Model.action_ok()
|
||||
cups.Connection().getPrinters.assert_called_once_with()
|
||||
|
||||
@@ -68,6 +70,7 @@ class TestPrintingPrinterWizard(TransactionCase):
|
||||
cups.Connection().getPrinters.return_value = {
|
||||
'sys_name': self.printer_vals,
|
||||
}
|
||||
cups.Connection().getPPD3.return_value = (200, 0, '')
|
||||
self.Model.action_ok()
|
||||
rec_id = self.env['printing.printer'].search([
|
||||
('system_name', '=', 'sys_name')
|
||||
@@ -89,6 +92,7 @@ class TestPrintingPrinterWizard(TransactionCase):
|
||||
cups.Connection().getPrinters.return_value = {
|
||||
'sys_name': self.printer_vals,
|
||||
}
|
||||
cups.Connection().getPPD3.return_value = (200, 0, '')
|
||||
self.env['printing.printer'].create(
|
||||
self._record_vals()
|
||||
)
|
||||
|
||||
@@ -47,12 +47,14 @@ class TestPrintingReportXmlAction(TransactionCase):
|
||||
self.assertEqual(xml_action.behaviour(), {
|
||||
'action': xml_action.action,
|
||||
'printer': xml_action.printer_id,
|
||||
'tray': False,
|
||||
})
|
||||
|
||||
xml_action = self.new_record({'printer_id': self.new_printer().id})
|
||||
self.assertEqual(xml_action.behaviour(), {
|
||||
'action': xml_action.action,
|
||||
'printer': xml_action.printer_id,
|
||||
'tray': False,
|
||||
})
|
||||
|
||||
self.assertEqual(self.Model.behaviour(), {})
|
||||
|
||||
@@ -1,38 +1,37 @@
|
||||
<?xml version="1.0"?>
|
||||
<odoo>
|
||||
|
||||
<record model="ir.ui.view" id="printing_report_xml_action_view_form">
|
||||
<field name="name">printing.report.xml.action.form</field>
|
||||
<field name="model">printing.report.xml.action</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Report Printing Actions">
|
||||
<group col="2">
|
||||
<field name="user_id"/>
|
||||
<field name="action"/>
|
||||
<field name="printer_id" select="1"/>
|
||||
<field name="printer_tray_id"/>
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
<record model="ir.ui.view" id="printing_report_xml_action_view_form">
|
||||
<field name="name">printing.report.xml.action.form</field>
|
||||
<field name="model">printing.report.xml.action</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Report Printing Actions">
|
||||
<group col="2">
|
||||
<field name="user_id" options="{'no_create': True}"/>
|
||||
<field name="action"/>
|
||||
<field name="printer_id" options="{'no_create': True}"/>
|
||||
<field name="printer_tray_id"/>
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
<record model="ir.ui.view" id="printing_report_xml_action_view_tree">
|
||||
<field name="name">printing.report.xml.action.tree</field>
|
||||
<field name="model">printing.report.xml.action</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="Report Printing Actions" editable="bottom">
|
||||
<field name="user_id" options="{'no_create': True}"/>
|
||||
<field name="action" />
|
||||
<field name="printer_id" options="{'no_create': True}"/>
|
||||
<field name="printer_tray_id"/>
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="printing_report_xml_action_view_tree">
|
||||
<field name="name">printing.report.xml.action.tree</field>
|
||||
<field name="model">printing.report.xml.action</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="Report Printing Actions">
|
||||
<field name="user_id"/>
|
||||
<field name="action"/>
|
||||
<field name="printer_id"/>
|
||||
<field name="printer_tray_id"/>
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- Add a shorcut to "Actions/Report" in the Printing menu -->
|
||||
<menuitem id="printing_report_xml_action_menu"
|
||||
sequence="30"
|
||||
parent="printing_menu"
|
||||
action="base.ir_action_report"/>
|
||||
<!-- Add a shorcut to "Actions/Report" in the Printing menu -->
|
||||
<menuitem id="printing_report_xml_action_menu"
|
||||
sequence="30"
|
||||
parent="printing_menu"
|
||||
action="base.ir_action_report"/>
|
||||
|
||||
</odoo>
|
||||
|
||||
@@ -9,7 +9,8 @@
|
||||
<xpath expr="//group[@name='preferences']/ancestor::page" position="inside">
|
||||
<group string="Printing" name="printing">
|
||||
<field name="printing_action"/>
|
||||
<field name="printing_printer_id"/>
|
||||
<field name="printing_printer_id" options="{'no_create': True}"/>
|
||||
<field name="printer_tray_id" options="{'no_create': True}"/>
|
||||
</group>
|
||||
</xpath>
|
||||
</field>
|
||||
@@ -22,8 +23,9 @@
|
||||
<field name="arch" type="xml">
|
||||
<footer position="before">
|
||||
<group string="Printing" name="printing">
|
||||
<field name="printing_action"/>
|
||||
<field name="printing_printer_id"/>
|
||||
<field name="printing_action" readonly="0"/>
|
||||
<field name="printing_printer_id" readonly="0" options="{'no_create': True}"/>
|
||||
<field name="printer_tray_id" readonly="0" options="{'no_create': True}"/>
|
||||
</group>
|
||||
</footer>
|
||||
</field>
|
||||
|
||||
Reference in New Issue
Block a user