add multi company record rule on mis report instance
parent
6fa2a75c01
commit
5ef8dcb68c
|
@ -36,6 +36,7 @@
|
|||
'wizard/mis_builder_dashboard.xml',
|
||||
'views/mis_builder.xml',
|
||||
'security/ir.model.access.csv',
|
||||
'security/mis_builder_security.xml',
|
||||
],
|
||||
'test': [
|
||||
],
|
||||
|
|
|
@ -87,6 +87,11 @@ def _get_bal_vars_in_report(report):
|
|||
return res
|
||||
|
||||
|
||||
def _is_valid_python_var(name):
|
||||
return re.match("[_A-Za-z][_a-zA-Z0-9]*$", name) \
|
||||
and not name.startswith('bal_')
|
||||
|
||||
|
||||
class mis_report_kpi(orm.Model):
|
||||
|
||||
""" A KPI is an element of a MIS report.
|
||||
|
@ -144,10 +149,8 @@ class mis_report_kpi(orm.Model):
|
|||
_order = 'sequence'
|
||||
|
||||
def _check_name(self, cr, uid, ids, context=None):
|
||||
# TODO: kpi name cannot start with bal
|
||||
# TODO: factor out the name check function (DRY)
|
||||
for record_name in self.read(cr, uid, ids, ['name']):
|
||||
if not re.match("[_A-Za-z][_a-zA-Z0-9]*$", record_name['name']):
|
||||
if not _is_valid_python_var(record_name['name']):
|
||||
return False
|
||||
return True
|
||||
|
||||
|
@ -156,10 +159,8 @@ class mis_report_kpi(orm.Model):
|
|||
]
|
||||
|
||||
def onchange_name(self, cr, uid, ids, name, context=None):
|
||||
# TODO: factor out the name check function (DRY)
|
||||
# check it is a valid python identifier
|
||||
res = {}
|
||||
if name and not re.match("[_A-Za-z][_a-zA-Z0-9]*$", name):
|
||||
if name and not _is_valid_python_var(name):
|
||||
res['warning'] = {
|
||||
'title': 'Invalid name',
|
||||
'message': 'The name must be a valid python identifier'}
|
||||
|
@ -167,7 +168,7 @@ class mis_report_kpi(orm.Model):
|
|||
|
||||
def onchange_description(self, cr, uid, ids, description, name,
|
||||
context=None):
|
||||
# construct name from description
|
||||
""" construct name from description """
|
||||
res = {}
|
||||
if description and not name:
|
||||
res = {'value': {'name': _python_var(description)}}
|
||||
|
@ -291,10 +292,8 @@ class mis_report_query(orm.Model):
|
|||
_order = 'name'
|
||||
|
||||
def _check_name(self, cr, uid, ids, context=None):
|
||||
# TODO: factor out the name check function (DRY)
|
||||
# TODO: query name must start with bal
|
||||
for record_name in self.read(cr, uid, ids, ['name']):
|
||||
if not re.match("[_A-Za-z][_a-zA-Z0-9]*$", record_name['name']):
|
||||
if not _is_valid_python_var(record_name['name']):
|
||||
return False
|
||||
return True
|
||||
|
||||
|
@ -470,7 +469,9 @@ class mis_report_instance_period(orm.Model):
|
|||
'period_id',
|
||||
'compare_period_id',
|
||||
string='Compare with'),
|
||||
'company_id': fields.many2one('res.company', 'Company', required=True),
|
||||
'company_id': fields.related('report_instance_id', 'company_id',
|
||||
type="many2one", relation="res.company",
|
||||
string="Company", readonly=True),
|
||||
'normalize_factor': fields.integer(
|
||||
string='Factor',
|
||||
help='Factor to use to normalize the period (used in comparison'),
|
||||
|
@ -481,11 +482,6 @@ class mis_report_instance_period(orm.Model):
|
|||
'duration': 1,
|
||||
'sequence': 100,
|
||||
'normalize_factor': 1,
|
||||
'company_id': lambda s, cr, uid, c:
|
||||
s.pool.get('res.company')._company_default_get(
|
||||
cr, uid,
|
||||
'mis.report.instance.period',
|
||||
context=c)
|
||||
}
|
||||
|
||||
_order = 'sequence'
|
||||
|
@ -663,10 +659,16 @@ class mis_report_instance(orm.Model):
|
|||
'target_move': fields.selection([('posted', 'All Posted Entries'),
|
||||
('all', 'All Entries'),
|
||||
], 'Target Moves', required=True),
|
||||
'company_id': fields.many2one('res.company', 'Company', required=True),
|
||||
}
|
||||
|
||||
_defaults = {
|
||||
'target_move': 'posted',
|
||||
'company_id': lambda s, cr, uid, c:
|
||||
s.pool.get('res.company')._company_default_get(
|
||||
cr, uid,
|
||||
'mis.report.instance',
|
||||
context=c)
|
||||
}
|
||||
|
||||
def create(self, cr, uid, vals, context=None):
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data noupdate="0">
|
||||
|
||||
<record id="mis_builder_multi_company_rule" model="ir.rule">
|
||||
<field name="name">Mis Builder multi company</field>
|
||||
<field name="model_id" ref="model_mis_report_instance"/>
|
||||
<field name="global" eval="True"/>
|
||||
<field name="domain_force">['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])]</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
|
@ -128,6 +128,7 @@
|
|||
<group col="2">
|
||||
<field name="description"/>
|
||||
<field name="report_id"/>
|
||||
<field name="company_id" groups="base.group_multi_company"/>
|
||||
<field name="target_move"/>
|
||||
<field name="date"/>
|
||||
<field name="period_ids">
|
||||
|
|
Loading…
Reference in New Issue