diff --git a/printer_tray/ir_report.py b/printer_tray/ir_report.py index 6181053..9b36724 100644 --- a/printer_tray/ir_report.py +++ b/printer_tray/ir_report.py @@ -18,46 +18,15 @@ # along with this program. If not, see . # ############################################################################## -from openerp.osv import orm, fields +from openerp import models, fields -class ReportXML(orm.Model): +class IrActionsReportXml(models.Model): _inherit = 'ir.actions.report.xml' - _columns = { - 'printer_tray_id': fields.many2one( - 'printing.tray', 'Paper Source', - domain="[('printer_id', '=', printing_printer_id)]"), - } - - def set_print_options(self, cr, uid, report_id, format, context=None): - """ - Hook to define Tray - """ - printing_act_obj = self.pool.get('printing.report.xml.action') - options = super(ReportXML, self).set_print_options(cr, uid, report_id, format, context=context) - - # Retrieve user default values - user = self.pool.get('res.users').browse(cr, uid, context) - tray = user.printer_tray_id - report = self.browse(cr, uid, report_id, context=context) - - # Retrieve report default values - if report.printer_tray_id: - tray = report.printer_tray_id - - # Retrieve report-user specific values - act_ids = printing_act_obj.search( - cr, uid, - [('report_id', '=', report.id), - ('user_id', '=', uid), - ('action', '!=', 'user_default')], context=context) - if act_ids: - user_action = printing_act_obj.browse(cr, uid, act_ids[0], context=context) - if user_action.tray_id: - tray = user_action.tray_id - - if tray: - options['InputSlot'] = str(tray.system_name) - return options + printer_tray_id = fields.Many2one( + comodel_name='printing.tray', + string='Paper Source', + domain="[('printer_id', '=', printing_printer_id)]", + ) diff --git a/printer_tray/printer.py b/printer_tray/printer.py index 9c18f64..283554f 100644 --- a/printer_tray/printer.py +++ b/printer_tray/printer.py @@ -97,3 +97,34 @@ class Printer(orm.Model): if not printer.tray_ids: self._update_tray_option(db_name, uid, printer, context=context) return res + + def print_options(self, cr, uid, report_id, format, context=None): + """ + Hook to define Tray + """ + printing_act_obj = self.pool.get('printing.report.xml.action') + options = super(ReportXML, self).set_print_options(cr, uid, report_id, format, context=context) + + # Retrieve user default values + user = self.pool.get('res.users').browse(cr, uid, context) + tray = user.printer_tray_id + report = self.browse(cr, uid, report_id, context=context) + + # Retrieve report default values + if report.printer_tray_id: + tray = report.printer_tray_id + + # Retrieve report-user specific values + act_ids = printing_act_obj.search( + cr, uid, + [('report_id', '=', report.id), + ('user_id', '=', uid), + ('action', '!=', 'user_default')], context=context) + if act_ids: + user_action = printing_act_obj.browse(cr, uid, act_ids[0], context=context) + if user_action.tray_id: + tray = user_action.tray_id + + if tray: + options['InputSlot'] = str(tray.system_name) + return options