diff --git a/addons/account/account.py b/addons/account/account.py index 9aadf24b7dd..1817d50901e 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -248,59 +248,59 @@ class account_account(osv.osv): def __compute(self, cr, uid, ids, field_names, arg=None, context=None, query='', query_params=()): - """ compute the balance, debit and/or credit for the provided - account ids - Arguments: - `ids`: account ids - `field_names`: the fields to compute (a list of any of - 'balance', 'debit' and 'credit') - `arg`: unused fields.function stuff - `query`: additional query filter (as a string) - `query_params`: parameters for the provided query string - (__compute will handle their escaping) as a - tuple - """ - mapping = { - 'balance': "COALESCE(SUM(l.debit),0) " \ - "- COALESCE(SUM(l.credit), 0) as balance", - 'debit': "COALESCE(SUM(l.debit), 0) as debit", - 'credit': "COALESCE(SUM(l.credit), 0) as credit" - } - #get all the necessary accounts - children_and_consolidated = self._get_children_and_consol(cr, uid, ids, context=context) - #compute for each account the balance/debit/credit from the move lines - accounts = {} - if children_and_consolidated: - aml_query = self.pool.get('account.move.line')._query_get(cr, uid, context=context) + """ compute the balance, debit and/or credit for the provided + account ids + Arguments: + `ids`: account ids + `field_names`: the fields to compute (a list of any of + 'balance', 'debit' and 'credit') + `arg`: unused fields.function stuff + `query`: additional query filter (as a string) + `query_params`: parameters for the provided query string + (__compute will handle their escaping) as a + tuple + """ + mapping = { + 'balance': "COALESCE(SUM(l.debit),0) " \ + "- COALESCE(SUM(l.credit), 0) as balance", + 'debit': "COALESCE(SUM(l.debit), 0) as debit", + 'credit': "COALESCE(SUM(l.credit), 0) as credit" + } + #get all the necessary accounts + children_and_consolidated = self._get_children_and_consol(cr, uid, ids, context=context) + #compute for each account the balance/debit/credit from the move lines + accounts = {} + if children_and_consolidated: + aml_query = self.pool.get('account.move.line')._query_get(cr, uid, context=context) - wheres = [""] - if query.strip(): - wheres.append(query.strip()) - if aml_query.strip(): - wheres.append(aml_query.strip()) - filters = " AND ".join(wheres) - self.logger.notifyChannel('addons.'+self._name, netsvc.LOG_DEBUG, - 'Filters: %s'%filters) - # IN might not work ideally in case there are too many - # children_and_consolidated, in that case join on a - # values() e.g.: - # SELECT l.account_id as id FROM account_move_line l - # INNER JOIN (VALUES (id1), (id2), (id3), ...) AS tmp (id) - # ON l.account_id = tmp.id - # or make _get_children_and_consol return a query and join on that - request = ("SELECT l.account_id as id, " +\ - ' , '.join(map(mapping.__getitem__, field_names)) + - " FROM account_move_line l" \ - " WHERE l.account_id IN %s " \ - + filters + - " GROUP BY l.account_id") - params = (tuple(children_and_consolidated),) + query_params - cr.execute(request, params) - self.logger.notifyChannel('addons.'+self._name, netsvc.LOG_DEBUG, - 'Status: %s'%cr.statusmessage) + wheres = [""] + if query.strip(): + wheres.append(query.strip()) + if aml_query.strip(): + wheres.append(aml_query.strip()) + filters = " AND ".join(wheres) + self.logger.notifyChannel('addons.'+self._name, netsvc.LOG_DEBUG, + 'Filters: %s'%filters) + # IN might not work ideally in case there are too many + # children_and_consolidated, in that case join on a + # values() e.g.: + # SELECT l.account_id as id FROM account_move_line l + # INNER JOIN (VALUES (id1), (id2), (id3), ...) AS tmp (id) + # ON l.account_id = tmp.id + # or make _get_children_and_consol return a query and join on that + request = ("SELECT l.account_id as id, " +\ + ' , '.join(map(mapping.__getitem__, field_names)) + + " FROM account_move_line l" \ + " WHERE l.account_id IN %s " \ + + filters + + " GROUP BY l.account_id") + params = (tuple(children_and_consolidated),) + query_params + cr.execute(request, params) + self.logger.notifyChannel('addons.'+self._name, netsvc.LOG_DEBUG, + 'Status: %s'%cr.statusmessage) - for res in cr.dictfetchall(): - accounts[res['id']] = res + for res in cr.dictfetchall(): + accounts[res['id']] = res # consolidate accounts with direct children children_and_consolidated.reverse() @@ -656,9 +656,18 @@ class account_journal(osv.osv): @param context: context arguments, like lang, time zone @return: return a result """ + + journal_type = ('sale', 'sale_refund', 'purchase', 'purchase_refund') + journal_seq = { + 'sale':'seq_out_invoice', + 'purchase':'seq_in_invoice', + 'purchase_refund':'seq_out_refund', + 'sale_refund':'seq_in_refund' + } seq_pool = self.pool.get('ir.sequence') seq_typ_pool = self.pool.get('ir.sequence.type') + date_pool = self.pool.get('ir.model.data') result = True @@ -685,10 +694,13 @@ class account_journal(osv.osv): res.update({ 'sequence_id':seq_id }) - - if not journal.invoice_sequence_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':seq_id + 'invoice_sequence_id':inv_seq_id }) result = self.write(cr, uid, [journal.id], res) @@ -1066,24 +1078,13 @@ class account_move(osv.osv): 'partner_id': fields.related('line_id', 'partner_id', type="many2one", relation="res.partner", string="Partner"), 'amount': fields.function(_amount_compute, method=True, string='Amount', digits_compute=dp.get_precision('Account'), type='float', fnct_search=_search_amount), 'date': fields.date('Date', required=True, states={'posted':[('readonly',True)]}), - 'type': fields.selection([ - ('pay_voucher','Cash Payment'), - ('bank_pay_voucher','Bank Payment'), - ('rec_voucher','Cash Receipt'), - ('bank_rec_voucher','Bank Receipt'), - ('cont_voucher','Contra'), - ('journal_sale_vou','Journal Sale'), - ('journal_pur_voucher','Journal Purchase'), - ('journal_voucher','Journal Voucher'), - ],'Entry Type', select=True , size=128, readonly=True, states={'draft':[('readonly',False)]}), - 'narration':fields.text('Narration', readonly=True, select=True, states={'draft':[('readonly',False)]}), + 'narration':fields.text('Narration', select=True), 'company_id': fields.related('journal_id','company_id',type='many2one',relation='res.company',string='Company',store=True), } _defaults = { 'name': lambda *a: '/', 'state': lambda *a: 'draft', 'period_id': _get_period, - 'type' : lambda *a : 'journal_voucher', 'date': lambda *a:time.strftime('%Y-%m-%d'), 'company_id': lambda self,cr,uid,c: self.pool.get('res.users').browse(cr, uid, uid, c).company_id.id, } @@ -1162,8 +1163,20 @@ class account_move(osv.osv): # TODO: Check if period is closed ! # def create(self, cr, uid, vals, context={}): - if 'line_id' in vals: - if 'journal_id' in vals: + if 'line_id' in vals and context.get('copy'): + for l in vals['line_id']: + if not l[0]: + l[2].update({ + 'reconcile_id':False, + 'reconcil_partial_id':False, + 'analytic_lines':False, + 'invoice':False, + 'ref':False, + 'balance':False, + 'account_tax_id':False, + }) + + if 'journal_id' in vals and vals.get('journal_id', False): for l in vals['line_id']: if not l[0]: l[2]['journal_id'] = vals['journal_id'] @@ -1189,11 +1202,14 @@ class account_move(osv.osv): result = super(account_move, self).create(cr, uid, vals, context) return result - def copy(self, cr, uid, id, default=None, context=None): - if default is None: - default = {} - default = default.copy() - default.update({'state':'draft', 'name':'/',}) + def copy(self, cr, uid, id, default={}, context={}): + default.update({ + 'state':'draft', + 'name':'/', + }) + context.update({ + 'copy':True + }) return super(account_move, self).copy(cr, uid, id, default, context) def unlink(self, cr, uid, ids, context={}, check=True): @@ -2527,9 +2543,9 @@ class wizard_multi_charts_accounts(osv.osv_memory): 'account_paid_id': acc_template_ref[value['account_paid_id']], }) - # Creating Journals + # Creating Journals Sales and Purchase vals_journal={} - data_id = data_pool.search(cr, uid, [('model','=','account.journal.view'), ('name','=','account_journal_view')]) + data_id = data_pool.search(cr, uid, [('model','=','account.journal.view'), ('name','=','account_sp_journal_view')]) data = data_pool.browse(cr, uid, data_id[0]) view_id = data.res_id @@ -2561,6 +2577,7 @@ class wizard_multi_charts_accounts(osv.osv_memory): vals_journal['type'] = 'purchase' vals_journal['code'] = _('EXJ') vals_journal['sequence_id'] = seq_id_purchase + vals_journal['view_id'] = view_id if obj_multi.chart_template_id.property_account_payable: vals_journal['default_credit_account_id'] = acc_template_ref[obj_multi.chart_template_id.property_account_expense_categ.id] diff --git a/addons/account/account_bank_statement.py b/addons/account/account_bank_statement.py index d0d8a8e9458..261807fd036 100644 --- a/addons/account/account_bank_statement.py +++ b/addons/account/account_bank_statement.py @@ -335,6 +335,7 @@ class account_bank_statement(osv.osv): if st.journal_id.entry_posted: account_move_obj.write(cr, uid, [move_id], {'state':'posted'}) + self.log(cr, uid, st.id, 'Statement %s is confirmed and entries are created.' % st.name) done.append(st.id) self.write(cr, uid, done, {'state':'confirm'}, context=context) return True diff --git a/addons/account/account_end_fy.xml b/addons/account/account_end_fy.xml index ee2ad952e6a..fe7b6e682fe 100644 --- a/addons/account/account_end_fy.xml +++ b/addons/account/account_end_fy.xml @@ -8,6 +8,7 @@ form [('state','=','draft')] + After closing a period, you will no longer be able to post entries to the period once it has been closed. + + diff --git a/addons/account/account_invoice_view.xml b/addons/account/account_invoice_view.xml index 7572ae2aa59..e9dee5944d5 100644 --- a/addons/account/account_invoice_view.xml +++ b/addons/account/account_invoice_view.xml @@ -135,6 +135,12 @@ + +