diff --git a/addons/account/account.py b/addons/account/account.py index 9aadf24b7dd..b01f659a70d 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) @@ -1018,7 +1030,6 @@ class account_move(osv.osv): res.append((move.id, name)) return res - def _get_period(self, cr, uid, context): periods = self.pool.get('account.period').find(cr, uid) if periods: @@ -1066,24 +1077,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, } @@ -1116,6 +1116,7 @@ class account_move(osv.osv): 'You cannot create entries on different periods/journals in the same move', ['line_id']), ] + def post(self, cr, uid, ids, context=None): if self.validate(cr, uid, ids, context) and len(ids): for move in self.browse(cr, uid, ids): @@ -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..e5581f3f05d 100644 --- a/addons/account/account_bank_statement.py +++ b/addons/account/account_bank_statement.py @@ -160,6 +160,32 @@ class account_bank_statement(osv.osv): 'period_id': _get_period, } + def onchange_date(self, cr, user, ids, date, context={}): + """ + 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 + """ + res = {} + period_pool = self.pool.get('account.period') + pids = period_pool.search(cr, user, [('date_start','<=',date), ('date_stop','>=',date)]) + if pids: + res.update({ + 'period_id':pids[0] + }) + context.update({ + 'period_id':pids[0] + }) + + return { + 'value':res, + 'context':context, + } + def button_confirm_bank(self, cr, uid, ids, context={}): done = [] res_currency_obj = self.pool.get('res.currency') @@ -335,6 +361,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_cash_statement.py b/addons/account/account_cash_statement.py index b6c36dd3337..9cf14295be2 100644 --- a/addons/account/account_cash_statement.py +++ b/addons/account/account_cash_statement.py @@ -174,6 +174,17 @@ class account_cash_statement(osv.osv): return company_id + def _get_cash_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(dct) + return res + _columns = { 'company_id':fields.many2one('res.company', 'Company', required=False), 'journal_id': fields.many2one('account.journal', 'Journal', required=True), @@ -197,24 +208,23 @@ class account_cash_statement(osv.osv): '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 + 'company_id': _get_company, + 'starting_details_ids':_get_cash_box_lines, + 'ending_details_ids':_get_cash_box_lines } def create(self, cr, uid, vals, context=None): company_id = vals and vals.get('company_id',False) if company_id: - open_jrnl = self.search(cr, uid, [('company_id', '=', vals['company_id']), ('journal_id', '=', vals['journal_id']), ('state', '=', 'open')]) + sql = [ + ('company_id', '=', vals['company_id']), + ('journal_id', '=', vals['journal_id']), + ('state', '=', 'open') + ] + open_jrnl = self.search(cr, uid, sql) if open_jrnl: - raise osv.except_osv('Error', u'Une caisse de type espèce est déjà ouverte') - if 'starting_details_ids' in vals: - vals['starting_details_ids'] = starting_details_ids = map(list, vals['starting_details_ids']) - for i in starting_details_ids: - if i and i[0] and i[1]: - i[0], i[1] = 0, 0 + raise osv.except_osv('Error', _('You can not have two open register for the same journal')) res_id = super(account_cash_statement, self).create(cr, uid, vals, context=context) - res = self._get_starting_balance(cr, uid, [res_id]) - for rs in res: - super(account_cash_statement, self).write(cr, uid, rs, res.get(rs)) return res_id def write(self, cr, uid, ids, vals, context=None): @@ -284,27 +294,26 @@ class account_cash_statement(osv.osv): number = self.pool.get('ir.sequence').get(cr, uid, statement.journal_id.sequence_id.code) - if len(statement.starting_details_ids) > 0: - sid = [] - for line in statement.starting_details_ids: - sid.append(line.id) - - cash_pool.unlink(cr, uid, sid) - - cr.execute("select id from account_bank_statement where journal_id=%s and user_id=%s and state=%s order by id desc limit 1", (statement.journal_id.id, uid, 'confirm')) - rs = cr.fetchone() - rs = rs and rs[0] or None - if rs: - statement = statement_pool.browse(cr, uid, rs) - balance_start = statement.balance_end_real or 0.0 - open_ids = cash_pool.search(cr, uid, [('ending_id','=',statement.id)]) - for sid in open_ids: - default = { - 'ending_id': False, - 'starting_id':ids[0] - } - cash_pool.copy(cr, uid, sid, default) - +# if len(statement.starting_details_ids) > 0: +# sid = [] +# for line in statement.starting_details_ids: +# sid.append(line.id) +# cash_pool.unlink(cr, uid, sid) +# +# cr.execute("select id from account_bank_statement where journal_id=%s and user_id=%s and state=%s order by id desc limit 1", (statement.journal_id.id, uid, 'confirm')) +# rs = cr.fetchone() +# rs = rs and rs[0] or None +# if rs: +# statement = statement_pool.browse(cr, uid, rs) +# balance_start = statement.balance_end_real or 0.0 +# open_ids = cash_pool.search(cr, uid, [('ending_id','=',statement.id)]) +# for sid in open_ids: +# default = { +# 'ending_id': False, +# 'starting_id':ids[0] +# } +# cash_pool.copy(cr, uid, sid, default) +# vals = { 'date':time.strftime("%Y-%m-%d %H:%M:%S"), 'state':'open', diff --git a/addons/account/account_invoice_view.xml b/addons/account/account_invoice_view.xml index ddd2cc2dabe..e9dee5944d5 100644 --- a/addons/account/account_invoice_view.xml +++ b/addons/account/account_invoice_view.xml @@ -135,6 +135,12 @@ + +