diff --git a/addons/account/account.py b/addons/account/account.py index 432a90a653e..278e752cfe4 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -2524,7 +2524,10 @@ class account_account_template(osv.osv): #deactivate the parent_store functionnality on account_account for rapidity purpose ctx = context.copy() ctx.update({'defer_parent_store_computation': True}) - children_acc_template = self.search(cr, uid, ['|', ('chart_template_id','=', chart_template_id),'&',('parent_id','child_of', [template.account_root_id.id]),('chart_template_id','=', False), ('nocreate','!=',True)], order='id') + children_acc_criteria = [('chart_template_id','=', chart_template_id)] + if template.account_root_id.id: + children_acc_criteria = ['|'] + children_acc_criteria + ['&',('parent_id','child_of', [template.account_root_id.id]),('chart_template_id','=', False)] + children_acc_template = self.search(cr, uid, [('nocreate','!=',True)] + children_acc_criteria, order='id') for account_template in self.browse(cr, uid, children_acc_template, context=context): # skip the root of COA if it's not the main one if (template.account_root_id.id == account_template.id) and template.parent_id: @@ -2982,7 +2985,7 @@ class wizard_multi_charts_accounts(osv.osv_memory): tax_templ_obj = self.pool.get('account.tax.template') if 'bank_accounts_id' in fields: - res.update({'bank_accounts_id': [{'acc_name': _('Cash'), 'account_type': 'cash'}]}) + res.update({'bank_accounts_id': [{'acc_name': _('Cash'), 'account_type': 'cash'},{'acc_name': _('Bank'), 'account_type': 'bank'}]}) if 'company_id' in fields: res.update({'company_id': self.pool.get('res.users').browse(cr, uid, [uid], context=context)[0].company_id.id}) if 'seq_journal' in fields: diff --git a/addons/account/account_bank_statement.py b/addons/account/account_bank_statement.py index bd31b01a41d..9cfda051ec1 100644 --- a/addons/account/account_bank_statement.py +++ b/addons/account/account_bank_statement.py @@ -52,8 +52,9 @@ class account_bank_statement(osv.osv): journal_pool = self.pool.get('account.journal') journal_type = context.get('journal_type', False) journal_id = False + company_id = self.pool.get('res.company')._company_default_get(cr, uid, 'account.bank.statement',context=context) if journal_type: - ids = journal_pool.search(cr, uid, [('type', '=', journal_type)]) + ids = journal_pool.search(cr, uid, [('type', '=', journal_type),('company_id','=',company_id)]) if ids: journal_id = ids[0] return journal_id @@ -169,30 +170,31 @@ class account_bank_statement(osv.osv): 'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'account.bank.statement',context=c), } - def onchange_date(self, cr, user, ids, date, context=None): + 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): """ - Returns a dict that contains new values and context - @param cr: A database cursor - @param user: ID of the user currently logged in - @param date: latest value from user input for field date - @param args: other arguments - @param context: context arguments, like lang, time zone - @return: Returns a dict which contains new values, and context + Find the correct period to use for the given date and company_id, return it and set it in the context """ res = {} period_pool = self.pool.get('account.period') if context is None: context = {} - - pids = period_pool.search(cr, user, [('date_start','<=',date), ('date_stop','>=',date)]) + ctx = context.copy() + ctx.update({'company_id': company_id}) + pids = period_pool.find(cr, uid, dt=date, context=ctx) if pids: - res.update({ - 'period_id':pids[0] - }) - context.update({ - 'period_id':pids[0] - }) + res.update({'period_id': pids[0]}) + context.update({'period_id': pids[0]}) return { 'value':res, @@ -385,8 +387,10 @@ class account_bank_statement(osv.osv): ORDER BY date DESC,id DESC LIMIT 1', (journal_id, 'draft')) res = cr.fetchone() balance_start = res and res[0] or 0.0 - account_id = self.pool.get('account.journal').read(cr, uid, journal_id, ['default_debit_account_id'], context=context)['default_debit_account_id'] - return {'value': {'balance_start': balance_start, 'account_id': account_id}} + journal_data = self.pool.get('account.journal').read(cr, uid, journal_id, ['default_debit_account_id', 'company_id'], context=context) + account_id = journal_data['default_debit_account_id'] + company_id = journal_data['company_id'] + return {'value': {'balance_start': balance_start, 'account_id': account_id, 'company_id': company_id}} def unlink(self, cr, uid, ids, context=None): stat = self.read(cr, uid, ids, ['state'], context=context) diff --git a/addons/account/account_view.xml b/addons/account/account_view.xml index 3d34396248b..3a28ea9a244 100644 --- a/addons/account/account_view.xml +++ b/addons/account/account_view.xml @@ -594,7 +594,7 @@