From 9605bb2948bdbfe91ccbb5acab801e627b999dc5 Mon Sep 17 00:00:00 2001 From: Fabien Pinckaers Date: Sun, 14 Dec 2008 20:37:38 +0100 Subject: [PATCH] modifs bzr revid: fp@tinyerp.com-20081214193738-779o940ai8slj34n --- addons/account/account.py | 2 ++ addons/account/account_move_line.py | 26 ++++++++++++++++++++++++-- addons/account/account_view.xml | 15 ++++++++------- addons/account/invoice.py | 25 +++++-------------------- 4 files changed, 39 insertions(+), 29 deletions(-) diff --git a/addons/account/account.py b/addons/account/account.py index 004b6610cf2..997fe2b3c59 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -722,6 +722,7 @@ class account_move(osv.osv): 'to_check': fields.boolean('To Be Verified'), '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=(16,2)), + 'date': fields.date('Date', required=True), 'type': fields.selection([ ('pay_voucher','Cash Payment'), ('bank_pay_voucher','Bank Payment'), @@ -738,6 +739,7 @@ class account_move(osv.osv): 'state': lambda *a: 'draft', 'period_id': _get_period, 'type' : lambda *a : 'journal_voucher', + 'date': lambda *a:time.strftime('%Y-%m-%d'), } def _check_centralisation(self, cursor, user, ids): diff --git a/addons/account/account_move_line.py b/addons/account/account_move_line.py index 16537a4b6ae..ffef364ae37 100644 --- a/addons/account/account_move_line.py +++ b/addons/account/account_move_line.py @@ -310,6 +310,13 @@ class account_move_line(osv.osv): return [('id', '=', '0')] return [('id', 'in', [x[0] for x in res])] + def _get_move_lines(self, cr, uid, ids, context={}): + result = [] + for move in self.pool.get('account.move').browse(cr, uid, ids, context=context): + for line in move.line_id: + result.append(line.id) + return result + _columns = { 'name': fields.char('Name', size=64, required=True), 'quantity': fields.float('Quantity', digits=(16,2), help="The optional quantity expressed by this line, eg: number of product sold. The quantity is not a legal requirement but is very usefull for some reports."), @@ -333,7 +340,10 @@ class account_move_line(osv.osv): 'partner_id': fields.many2one('res.partner', 'Partner Ref.'), 'date_maturity': fields.date('Maturity date', help="This field is used for payable and receivable entries. You can put the limit date for the payment of this entry line."), - 'date': fields.date('Effective date', required=True), + 'date': fields.related('move_id','date', string='Effective date', type='date', required=True, + store={ + 'account.move': (_get_move_lines, ['date'], 20) + }), 'date_created': fields.date('Creation date'), 'analytic_lines': fields.one2many('account.analytic.line', 'move_id', 'Analytic lines'), 'centralisation': fields.selection([('normal','Normal'),('credit','Credit Centralisation'),('debit','Debit Centralisation')], 'Centralisation', size=6), @@ -714,6 +724,11 @@ class account_move_line(osv.osv): if ('account_id' in vals) or ('journal_id' in vals) or ('period_id' in vals) or ('move_id' in vals) or ('debit' in vals) or ('credit' in vals) or ('date' in vals): self._update_check(cr, uid, ids, context) + todo_date = None + if vals.get('date', False): + todo_date = vals['date'] + del vals['date'] + print 'Writing', vals, 'to move_line', ids result = super(account_move_line, self).write(cr, uid, ids, vals, context) if check: @@ -722,6 +737,8 @@ class account_move_line(osv.osv): if line.move_id.id not in done: done.append(line.move_id.id) self.pool.get('account.move').validate(cr, uid, [line.move_id.id], context) + if todo_date: + self.pool.get('account.move').write(cr, uid, [line.move_id.id], {'date': todo_date}, context=context) return result def _update_journal_check(self, cr, uid, journal_id, period_id, context={}): @@ -789,6 +806,7 @@ class account_move_line(osv.osv): if journal.sequence_id: #name = self.pool.get('ir.sequence').get_id(cr, uid, journal.sequence_id.id) v = { + 'date': vals.get('date', time.strftime('%Y-%m-%d')), 'period_id': context['period_id'], 'journal_id': context['journal_id'] } @@ -796,6 +814,10 @@ class account_move_line(osv.osv): vals['move_id'] = move_id else: raise osv.except_osv(_('No piece number !'), _('Can not create an automatic sequence for this piece !\n\nPut a sequence in the journal definition for automatic numbering or create a sequence manually for this piece.')) + else: + if 'date' in vals: + self.pool.get('account.move').write(cr, uid, [move_id], {'date':vals['date']}, context=context) + del vals['date'] ok = not (journal.type_control_ids or journal.account_control_ids) if ('account_id' in vals): @@ -828,7 +850,7 @@ class account_move_line(osv.osv): if journal.analytic_journal_id: vals['analytic_lines'] = [(0,0, { 'name': vals['name'], - 'date': vals['date'], + 'date': vals.get('date', time.strftime('%Y-%m-%d')), 'account_id': vals['analytic_account_id'], 'unit_amount':'quantity' in vals and vals['quantity'] or 1.0, 'amount': vals['debit'] or vals['credit'], diff --git a/addons/account/account_view.xml b/addons/account/account_view.xml index 1cc773ef2ee..319431615f7 100644 --- a/addons/account/account_view.xml +++ b/addons/account/account_view.xml @@ -468,8 +468,9 @@ tree - + + @@ -800,6 +801,7 @@ + @@ -822,8 +824,9 @@ - - + + + @@ -833,9 +836,8 @@
- - + @@ -855,9 +857,8 @@ - - + diff --git a/addons/account/invoice.py b/addons/account/invoice.py index 7f8f1bbb1d0..7307a2fbd3b 100644 --- a/addons/account/invoice.py +++ b/addons/account/invoice.py @@ -602,15 +602,11 @@ class account_invoice(osv.osv): journal_id = inv.journal_id.id #self._get_journal(cr, uid, {'type': inv['type']}) journal = self.pool.get('account.journal').browse(cr, uid, journal_id) - if journal.sequence_id and not inv.move_name: - name = self.pool.get('ir.sequence').get_id(cr, uid, journal.sequence_id.id) - else: - name = inv.move_name if journal.centralisation: raise osv.except_osv(_('UserError'), _('Can not create invoice move on centralized journal')) - move = {'name': name, 'line_id': line, 'journal_id': journal_id} + move = {'ref': inv.number, 'line_id': line, 'journal_id': journal_id, 'date': date} period_id=inv.period_id and inv.period_id.id or False if not period_id: period_ids= self.pool.get('account.period').search(cr,uid,[('date_start','<=',inv.date_invoice or time.strftime('%Y-%m-%d')),('date_stop','>=',inv.date_invoice or time.strftime('%Y-%m-%d'))]) @@ -630,7 +626,6 @@ class account_invoice(osv.osv): def line_get_convert(self, cr, uid, x, part, date, context={}): return { - 'date':date, 'date_maturity': x.get('date_maturity', False), 'partner_id':part, 'name':x['name'][:64], @@ -663,6 +658,9 @@ class account_invoice(osv.osv): ref = self._convert_ref(cr, uid, number) cr.execute('UPDATE account_invoice SET number=%s ' \ 'WHERE id=%s', (number, id)) + cr.execute('UPDATE account_move SET ref=%s ' \ + 'WHERE id=%s AND (ref is null OR ref = \'\')', + (ref, move_id)) cr.execute('UPDATE account_move_line SET ref=%s ' \ 'WHERE move_id=%s AND (ref is null OR ref = \'\')', (ref, move_id)) @@ -814,16 +812,7 @@ class account_invoice(osv.osv): assert len(ids)==1, "Can only pay one invoice at a time" invoice = self.browse(cr, uid, ids[0]) src_account_id = invoice.account_id.id - journal = self.pool.get('account.journal').browse(cr, uid, pay_journal_id) - if journal.sequence_id: - name = self.pool.get('ir.sequence').get_id(cr, uid, journal.sequence_id.id) - else: - raise osv.except_osv(_('No piece number !'), _('Can not create an automatic sequence for this piece !\n\nPut a sequence in the journal definition for automatic numbering or create a sequence manually for this piece.')) # Take the seq as name for move - if journal.sequence_id: - seq = self.pool.get('ir.sequence').get_id(cr, uid, journal.sequence_id.id) - else: - raise osv.except_osv('No piece number !', 'Can not create an automatic sequence for this piece !\n\nPut a sequence in the journal definition for automatic numbering or create a sequence manually for this piece.') types = {'out_invoice': -1, 'in_invoice': 1, 'out_refund': 1, 'in_refund': -1} direction = types[invoice.type] #take the choosen date @@ -832,26 +821,22 @@ class account_invoice(osv.osv): else: date=time.strftime('%Y-%m-%d') l1 = { - 'name': name, 'debit': direction * pay_amount>0 and direction * pay_amount, 'credit': direction * pay_amount<0 and - direction * pay_amount, 'account_id': src_account_id, 'partner_id': invoice.partner_id.id, - 'date': date, 'ref':invoice.number, } l2 = { - 'name':name, 'debit': direction * pay_amount<0 and - direction * pay_amount, 'credit': direction * pay_amount>0 and direction * pay_amount, 'account_id': pay_account_id, 'partner_id': invoice.partner_id.id, - 'date': date, 'ref':invoice.number, } lines = [(0, 0, l1), (0, 0, l2)] - move = {'name': seq, 'line_id': lines, 'journal_id': pay_journal_id, 'period_id': period_id} + move = {'ref': inv.number, 'line_id': lines, 'journal_id': pay_journal_id, 'period_id': period_id, 'date': date} move_id = self.pool.get('account.move').create(cr, uid, move) line_ids = []