diff --git a/base_report_to_printer/__openerp__.py b/base_report_to_printer/__openerp__.py index 3ba8cac..3ce8f64 100644 --- a/base_report_to_printer/__openerp__.py +++ b/base_report_to_printer/__openerp__.py @@ -24,7 +24,7 @@ ############################################################################## { 'name': "Report to printer", - 'version': '0.1.1', + 'version': '0.2', 'category': 'Generic Modules/Base', 'description': """ Report to printer @@ -46,6 +46,8 @@ Settings can be configured: * per user * per report * per user and report +* per company and report +* per user/company and report After installing enable the "Printing / Print Operator" option under access diff --git a/base_report_to_printer/ir_report.py b/base_report_to_printer/ir_report.py index fb3e36d..cbd24fd 100644 --- a/base_report_to_printer/ir_report.py +++ b/base_report_to_printer/ir_report.py @@ -85,9 +85,31 @@ class report_xml(orm.Model): 'printing_action_ids': fields.one2many( 'printing.report.xml.action', 'report_id', 'Actions', help='This field allows configuring action and printer on a per ' - 'user basis'), + 'user / company basis'), } + def _get_company_id(self, cr, uid, context=None): + """ + As it may happend that OpenERP force the uid to 1 to bypass rule (in + function field), we may sometimes use the company of user + id 1 instead of the good one. Because we found the real uid and + company_id in the context in that case, I return this one. It also + allow other module to give the proper company_id in the context. + + If force_company is in context, use it in prioriy. + + If company_id not in context, take the one from uid. + """ + if context is None: + context = {} + res = context.get('force_company') or context.get('company_id') + if not res: + user_obj = self.pool['res.users'] + res = user_obj.read(cr, uid, uid, + ['company_id'], + context=context)['company_id'][0] + return res + def behaviour(self, cr, uid, ids, context=None): result = {} printer_obj = self.pool['printing.printer'] @@ -100,6 +122,8 @@ class report_xml(orm.Model): default_printer = printer_obj.browse(cr, uid, default_printer, context=context) + company_id = self._get_company_id(cr, uid, context) + # Retrieve user default values user = self.pool['res.users'].browse(cr, uid, uid, context=context) if user.printing_action: @@ -118,12 +142,28 @@ class report_xml(orm.Model): if report.printing_printer_id: printer = report.printing_printer_id + # Retrieve report-company specific values + act_ids = printing_act_obj.search( + cr, uid, + [('report_id', '=', report.id), + ('user_id', '=', False), + ('company_id', '=', company_id), + ('action', '!=', 'user_default')], context=context) + if act_ids: + company_action = printing_act_obj.behaviour( + cr, uid, act_ids[0], context) + action = company_action['action'] + if company_action['printer']: + printer = company_action['printer'] + # 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) + ('action', '!=', 'user_default'), + '|', ('company_id', '=', company_id), + ('company_id', '=', False)], context=context) if act_ids: user_action = printing_act_obj.behaviour(cr, uid, act_ids[0], context) diff --git a/base_report_to_printer/printing_view.xml b/base_report_to_printer/printing_view.xml index d9c7986..fccf466 100644 --- a/base_report_to_printer/printing_view.xml +++ b/base_report_to_printer/printing_view.xml @@ -107,7 +107,8 @@
- + + @@ -119,6 +120,7 @@ printing.report.xml.action + diff --git a/base_report_to_printer/report_xml_action.py b/base_report_to_printer/report_xml_action.py index 4734c78..f3951ad 100644 --- a/base_report_to_printer/report_xml_action.py +++ b/base_report_to_printer/report_xml_action.py @@ -34,8 +34,9 @@ class report_xml_action(orm.Model): _columns = { 'report_id': fields.many2one('ir.actions.report.xml', 'Report', required=True, ondelete='cascade'), - 'user_id': fields.many2one('res.users', 'User', required=True, - ondelete='cascade'), + 'user_id': fields.many2one('res.users', 'User', ondelete='cascade'), + 'company_id': fields.many2one('res.company', 'Company', + ondelete='cascade'), 'action': fields.selection(_available_action_types, 'Action', required=True), 'printer_id': fields.many2one('printing.printer', 'Printer'),