'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'account.bank.statement',context=c),
}
+ def _check_company_id(self, cr, uid, ids, context=None):
+ for statement in self.browse(cr, uid, ids, context=context):
+ if statement.company_id.id != statement.period_id.company_id.id:
+ return False
+ return True
+
+ _constraints = [
+ (_check_company_id, 'The journal and period chosen have to belong to the same company.', ['journal_id','period_id']),
+ ]
+
def onchange_date(self, cr, uid, ids, date, company_id, context=None):
"""
Find the correct period to use for the given date and company_id, return it and set it in the context
_name = "account.common.report"
_description = "Account Common Report"
+ def onchange_chart_id(self, cr, uid, ids, chart_account_id=False, context=None):
+ if chart_account_id:
+ company_id = self.pool.get('account.account').browse(cr, uid, chart_account_id, context=context).company_id.id
+ return {'value': {'company_id': company_id}}
+
_columns = {
'chart_account_id': fields.many2one('account.account', 'Chart of Account', help='Select Charts of Accounts', required=True, domain = [('parent_id','=',False)]),
+ 'company_id': fields.related('chart_account_id', 'company_id', type='many2one', relation='res.company', string='Company', readonly=True),
'fiscalyear_id': fields.many2one('account.fiscalyear', 'Fiscal Year', help='Keep empty for all open fiscal year'),
'filter': fields.selection([('filter_no', 'No Filters'), ('filter_date', 'Date'), ('filter_period', 'Periods')], "Filter by", required=True),
'period_from': fields.many2one('account.period', 'Start Period'),
}
+ def _check_company_id(self, cr, uid, ids, context=None):
+ for wiz in self.browse(cr, uid, ids, context=context):
+ company_id = wiz.company_id.id
+ if company_id != wiz.fiscalyear_id.company_id.id:
+ return False
+ if wiz.period_from and company_id != wiz.period_from.company_id.id:
+ return False
+ if wiz.period_to and company_id != wiz.period_to.company_id.id:
+ return False
+ return True
+
+ _constraints = [
+ (_check_company_id, 'The fiscalyear, periods or chart of account chosen have to belong to the same company.', ['chart_account_id','fiscalyear_id','period_from','period_to']),
+ ]
+
+
def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
res = super(account_common_report, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=False)
if context.get('active_model', False) == 'account.account' and view_id:
<form string="Report Options">
<label nolabel="1" string=""/>
<newline/>
- <field name="chart_account_id" widget='selection'/>
- <field name="fiscalyear_id"/>
+ <field name="chart_account_id" widget='selection' on_change="onchange_chart_id(chart_account_id, context)"/>
+ <field name="company_id" invisible="1"/>
+ <field name="fiscalyear_id" domain="[('company_id','=',company_id)]"/>
<field name="target_move"/>
<notebook tabpos="up" colspan="4">
<page string="Filters" name="filters">
<field name="date_from" attrs="{'readonly':[('filter', '!=', 'filter_date')], 'required':[('filter', '=', 'filter_date')]}" colspan="4"/>
<field name="date_to" attrs="{'readonly':[('filter', '!=', 'filter_date')], 'required':[('filter', '=', 'filter_date')]}" colspan="4"/>
<separator string="Periods" colspan="4"/>
- <field name="period_from" domain="[('fiscalyear_id', '=', fiscalyear_id)]" attrs="{'readonly':[('filter','!=','filter_period')], 'required':[('filter', '=', 'filter_period')]}" colspan="4"/>
+ <field name="period_from" domain="[('fiscalyear_id', '=', fiscalyear_id)]" attrs="{'readonly':[('filter','!=','filter_period')], 'required':[('filter', '=', 'filter_period')]}" colspan="4"/>
<field name="period_to" domain="[('fiscalyear_id', '=', fiscalyear_id)]" attrs="{'readonly':[('filter','!=','filter_period')], 'required':[('filter', '=', 'filter_period')]}" colspan="4"/>
</page>
<page string="Journals" name="journal_ids">