Merge branch '7.0-base_report_to_printer_company-lga' of https://github.com/acsone/report-print-send into 7.0

This commit is contained in:
Yannick Vaucher
2015-11-24 13:37:54 +01:00
4 changed files with 51 additions and 6 deletions

View File

@@ -24,7 +24,7 @@
############################################################################## ##############################################################################
{ {
'name': "Report to printer", 'name': "Report to printer",
'version': '0.1.1', 'version': '0.2',
'category': 'Generic Modules/Base', 'category': 'Generic Modules/Base',
'description': """ 'description': """
Report to printer Report to printer
@@ -46,6 +46,8 @@ Settings can be configured:
* per user * per user
* per report * per report
* per user and report * per user and report
* per company and report
* per user/company and report
After installing enable the "Printing / Print Operator" option under access After installing enable the "Printing / Print Operator" option under access

View File

@@ -85,9 +85,31 @@ class report_xml(orm.Model):
'printing_action_ids': fields.one2many( 'printing_action_ids': fields.one2many(
'printing.report.xml.action', 'report_id', 'Actions', 'printing.report.xml.action', 'report_id', 'Actions',
help='This field allows configuring action and printer on a per ' 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): def behaviour(self, cr, uid, ids, context=None):
result = {} result = {}
printer_obj = self.pool['printing.printer'] printer_obj = self.pool['printing.printer']
@@ -100,6 +122,8 @@ class report_xml(orm.Model):
default_printer = printer_obj.browse(cr, uid, default_printer, default_printer = printer_obj.browse(cr, uid, default_printer,
context=context) context=context)
company_id = self._get_company_id(cr, uid, context)
# Retrieve user default values # Retrieve user default values
user = self.pool['res.users'].browse(cr, uid, uid, context=context) user = self.pool['res.users'].browse(cr, uid, uid, context=context)
if user.printing_action: if user.printing_action:
@@ -118,12 +142,28 @@ class report_xml(orm.Model):
if report.printing_printer_id: if report.printing_printer_id:
printer = 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 # Retrieve report-user specific values
act_ids = printing_act_obj.search( act_ids = printing_act_obj.search(
cr, uid, cr, uid,
[('report_id', '=', report.id), [('report_id', '=', report.id),
('user_id', '=', uid), ('user_id', '=', uid),
('action', '!=', 'user_default')], context=context) ('action', '!=', 'user_default'),
'|', ('company_id', '=', company_id),
('company_id', '=', False)], context=context)
if act_ids: if act_ids:
user_action = printing_act_obj.behaviour(cr, uid, act_ids[0], user_action = printing_act_obj.behaviour(cr, uid, act_ids[0],
context) context)

View File

@@ -107,7 +107,8 @@
<field name="arch" type="xml"> <field name="arch" type="xml">
<form string="Report Printing Actions"> <form string="Report Printing Actions">
<group col="2"> <group col="2">
<field name="user_id"/> <field name="company_id" groups="base.group_multi_company" attrs="{'required':[('user_id', '=', False)]}"/>
<field name="user_id" attrs="{'required':[('company_id', '=', False)]}"/>
<field name="action"/> <field name="action"/>
<field name="printer_id" select="1"/> <field name="printer_id" select="1"/>
</group> </group>
@@ -119,6 +120,7 @@
<field name="model">printing.report.xml.action</field> <field name="model">printing.report.xml.action</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<tree string="Report Printing Actions"> <tree string="Report Printing Actions">
<field name="company_id" groups="base.group_multi_company"/>
<field name="user_id"/> <field name="user_id"/>
<field name="action" /> <field name="action" />
<field name="printer_id" /> <field name="printer_id" />

View File

@@ -34,7 +34,8 @@ class report_xml_action(orm.Model):
_columns = { _columns = {
'report_id': fields.many2one('ir.actions.report.xml', 'Report', 'report_id': fields.many2one('ir.actions.report.xml', 'Report',
required=True, ondelete='cascade'), required=True, ondelete='cascade'),
'user_id': fields.many2one('res.users', 'User', required=True, 'user_id': fields.many2one('res.users', 'User', ondelete='cascade'),
'company_id': fields.many2one('res.company', 'Company',
ondelete='cascade'), ondelete='cascade'),
'action': fields.selection(_available_action_types, 'Action', 'action': fields.selection(_available_action_types, 'Action',
required=True), required=True),