From 4d7ad7ede9ce988531616f12ffd278bfa64f6747 Mon Sep 17 00:00:00 2001 From: Dmitrijs Ledkovs Date: Fri, 18 Nov 2011 17:00:31 +0000 Subject: [PATCH] [FIX] allow manual statement entry --- account_banking/account_banking.py | 32 ++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/account_banking/account_banking.py b/account_banking/account_banking.py index d0aecd54d..e7ab4a719 100644 --- a/account_banking/account_banking.py +++ b/account_banking/account_banking.py @@ -243,6 +243,7 @@ class account_bank_statement(osv.osv): Extensions from account_bank_statement: 1. Removed period_id (transformed to optional boolean) - as it is no longer needed. + NB! because of #1. changes required to account_voucher! 2. Extended 'button_confirm' trigger to cope with the period per statement_line situation. 3. Added optional relation with imported statements file @@ -453,8 +454,39 @@ class account_bank_statement(osv.osv): return move_id + def button_confirm_bank(self, cr, uid, ids, context=None): + if context is None: context = {} + obj_seq = self.pool.get('ir.sequence') + if not isinstance(ids, list): ids = [ids] + noname_ids = self.search(cr, uid, [('id','in',ids),('name','=','/')]) + for st in self.browse(cr, uid, noname_ids, context=context): + if st.journal_id.sequence_id: + year = self.pool.get('account.period').browse(cr, uid, self._get_period(cr, uid, st.date)).fiscalyear_id.id + c = {'fiscalyear_id': year} + st_number = obj_seq.get_id(cr, uid, st.journal_id.sequence_id.id, context=c) + self.write(cr, uid, ids, {'name': st_number}) + + return super(account_bank_statement, self).button_confirm_bank(cr, uid, ids, context) + account_bank_statement() +class account_voucher(osv.osv): + _inherit = 'account.voucher' + + def _get_period(self, cr, uid, context=None): + if context is None: context = {} + if not context.get('period_id') and context.get('move_line_ids'): + res = self.pool.get('account.move.line').browse(cr, uid , context.get('move_line_ids'))[0].period_id.id + context['period_id'] = res + return super(account_voucher, self)._get_period(cr, uid, context) + + def create(self, cr, uid, values, context=None): + if values.get('period_id') == False and context.get('move_line_ids'): + values['period_id'] = self._get_period(cr, uid, context) + return super(account_voucher, self).create(cr, uid, values, context) + +account_voucher() + class account_bank_statement_line(osv.osv): ''' Extension on basic class: