diff --git a/addons/account/account.py b/addons/account/account.py index 8681ec3506c..237969d18f5 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -629,8 +629,8 @@ class account_journal(osv.osv): 'currency': fields.many2one('res.currency', 'Currency', help='The currency used to enter statement'), 'entry_posted': fields.boolean('Skip \'Draft\' State for Created Entries', help='Check this box if you don\'t want new account moves to pass through the \'draft\' state and instead goes directly to the \'posted state\' without any manual validation.'), 'company_id': fields.many2one('res.company', 'Company', required=True, select=1, help="Company related to this journal"), -# 'invoice_sequence_id': fields.many2one('ir.sequence', 'Invoice Sequence', \ -# help="The sequence used for invoice numbers in this journal."), + 'invoice_sequence_id': fields.many2one('ir.sequence', 'Invoice Sequence', \ + help="The sequence used for invoice numbers in this journal."), 'allow_date':fields.boolean('Check Date not in the Period', help= 'If set to True then do not accept the entry if the entry date is not into the period dates'), } @@ -695,13 +695,13 @@ class account_journal(osv.osv): 'sequence_id':seq_id }) -# if journal.type in journal_type and not journal.invoice_sequence_id: -# res_ids = date_pool.search(cr, uid, [('model','=','ir.sequence'), ('name','=',journal_seq.get(journal.type, 'sale'))]) -# inv_seq_id = date_pool.browse(cr, uid, res_ids[0]).res_id -# inv_seq_id -# res.update({ -# 'invoice_sequence_id':inv_seq_id -# }) + if journal.type in journal_type and not journal.invoice_sequence_id: + res_ids = date_pool.search(cr, uid, [('model','=','ir.sequence'), ('name','=',journal_seq.get(journal.type, 'sale'))]) + inv_seq_id = date_pool.browse(cr, uid, res_ids[0]).res_id + inv_seq_id + res.update({ + 'invoice_sequence_id':inv_seq_id + }) result = self.write(cr, uid, [journal.id], res) diff --git a/addons/account/account_bank_statement.py b/addons/account/account_bank_statement.py index e5581f3f05d..52e1b20a744 100644 --- a/addons/account/account_bank_statement.py +++ b/addons/account/account_bank_statement.py @@ -49,9 +49,16 @@ class account_bank_statement(osv.osv): } def _default_journal_id(self, cr, uid, context={}): - if context.get('journal_id', False): - return context['journal_id'] - return False + journal_pool = self.pool.get('account.journal') + journal_type = context.get('journal_type', False) + journal_id = False + + if journal_type: + ids = journal_pool.search(cr, uid, [('type', '=', journal_type)]) + if ids: + journal_id = ids[0] + + return journal_id def _default_balance_start(self, cr, uid, context={}): cr.execute('select id from account_bank_statement where journal_id=%s order by date desc limit 1', (1,)) @@ -128,7 +135,7 @@ class account_bank_statement(osv.osv): 'date': fields.date('Date', required=True, states={'confirm': [('readonly', True)]}), 'journal_id': fields.many2one('account.journal', 'Journal', required=True, - states={'confirm': [('readonly', True)]}, domain=[('type', '=', 'cash')]), + states={'confirm': [('readonly', True)]}, domain=[('type', '=', 'bank')]), 'period_id': fields.many2one('account.period', 'Period', required=True, states={'confirm':[('readonly', True)]}), 'balance_start': fields.float('Starting Balance', digits_compute=dp.get_precision('Account'), diff --git a/addons/account/account_cash_statement.py b/addons/account/account_cash_statement.py index af92d59b89b..f618bcfeefd 100644 --- a/addons/account/account_cash_statement.py +++ b/addons/account/account_cash_statement.py @@ -118,18 +118,18 @@ class account_cash_statement(osv.osv): res2[statement.id]=encoding_total return res2 - def _default_journal_id(self, cr, uid, context={}): +# def _default_journal_id(self, cr, uid, context={}): - """ To get default journal for the object" - @param name: Names of fields. - @return: journal - """ - company_id = self.pool.get('res.users').browse(cr, uid, uid).company_id.id - journal = self.pool.get('account.journal').search(cr, uid, [('type', '=', 'cash'), ('company_id', '=', company_id)]) - if journal: - return journal[0] - else: - return False +# """ To get default journal for the object" +# @param name: Names of fields. +# @return: journal +# """ +# company_id = self.pool.get('res.users').browse(cr, uid, uid).company_id.id +# journal = self.pool.get('account.journal').search(cr, uid, [('type', '=', 'cash'), ('company_id', '=', company_id)]) +# if journal: +# return journal[0] +# else: +# return False def _end_balance(self, cursor, user, ids, name, attr, context=None): res_currency_obj = self.pool.get('res.currency') @@ -174,7 +174,7 @@ class account_cash_statement(osv.osv): return company_id - def _get_cash_box_lines(self, cr, uid, ids, context={}): + def _get_cash_open_box_lines(self, cr, uid, ids, context={}): res = [] curr = [1, 2, 5, 10, 20, 50, 100, 500] for rs in curr: @@ -182,12 +182,23 @@ class account_cash_statement(osv.osv): 'pieces':rs, 'number':0 } - res.append((0,0,dct)) + res.append(dct) return res - + + def _get_cash_close_box_lines(self, cr, uid, ids, context={}): + res = [] + curr = [1, 2, 5, 10, 20, 50, 100, 500] + for rs in curr: + dct = { + 'pieces':rs, + 'number':0 + } + res.append((0, 0, dct)) + return res + _columns = { 'company_id':fields.many2one('res.company', 'Company', required=False), - 'journal_id': fields.many2one('account.journal', 'Journal', required=True), + 'journal_id': fields.many2one('account.journal', 'Journal', required=True, domain=[('type', '=', 'cash')]), 'balance_end_real': fields.float('Closing Balance', digits_compute=dp.get_precision('Account'), states={'confirm':[('readonly', True)]}, help="closing balance entered by the cashbox verifier"), 'state': fields.selection( [('draft', 'Draft'), @@ -206,11 +217,10 @@ class account_cash_statement(osv.osv): 'state': lambda *a: 'draft', 'name': lambda *a: '/', 'date': lambda *a:time.strftime("%Y-%m-%d %H:%M:%S"), - 'journal_id': _default_journal_id, 'user_id': lambda self, cr, uid, context=None: uid, 'company_id': _get_company, - 'starting_details_ids':_get_cash_box_lines, - 'ending_details_ids':_get_cash_box_lines + 'starting_details_ids':_get_cash_open_box_lines, + 'ending_details_ids':_get_cash_open_box_lines } def create(self, cr, uid, vals, context=None): @@ -224,7 +234,19 @@ class account_cash_statement(osv.osv): open_jrnl = self.search(cr, uid, sql) if open_jrnl: raise osv.except_osv('Error', _('You can not have two open register for the same journal')) + + if self.pool.get('account.journal').browse(cr, uid, vals['journal_id']).type == 'cash': + lines = end_lines = self._get_cash_close_box_lines(cr, uid, [], context) + vals.update({ + 'ending_details_ids':lines + }) + else: + vals.update({ + 'ending_details_ids':False, + 'starting_details_ids':False + }) res_id = super(account_cash_statement, self).create(cr, uid, vals, context=context) + self.write(cr, uid, [res_id], {}) return res_id def write(self, cr, uid, ids, vals, context=None): diff --git a/addons/account/account_view.xml b/addons/account/account_view.xml index 99c29ef18b9..d1cb2558f38 100644 --- a/addons/account/account_view.xml +++ b/addons/account/account_view.xml @@ -388,14 +388,15 @@ + + + + + - - - - @@ -530,9 +531,13 @@ - + + +