1
# -*- coding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2004-2010 ISA srl (<http://www.isa.it>).
7
# This program is free software: you can redistribute it and/or modify
8
# it under the terms of the GNU Affero General Public License as
9
# published by the Free Software Foundation, either version 3 of the
10
# License, or (at your option) any later version.
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU Affero General Public License for more details.
17
# You should have received a copy of the GNU Affero General Public License
18
# along with this program. If not, see <http://www.gnu.org/licenses/>.
20
##############################################################################
23
from osv import fields, osv, orm
24
from tools.translate import _
25
from datetime import datetime
27
class account_invoice(osv.osv):
29
_inherit = 'account.invoice'
31
'registration_date':fields.date('Registration Date', states={'paid':[('readonly',True)], 'open':[('readonly',True)], 'close':[('readonly',True)]}, select=True, help="Keep empty to use the current date"),
34
def action_move_create(self, cr, uid, ids, *args):
36
super(account_invoice,self).action_move_create(cr, uid, ids,*args)
38
for inv in self.browse(cr, uid, ids):
40
date_invoice=inv.date_invoice
42
reg_date = inv.registration_date
43
if not inv.registration_date :
44
if not inv.date_invoice:
45
reg_date = time.strftime('%Y-%m-%d')
46
else : reg_date = inv.date_invoice
48
if date_invoice and reg_date :
49
if (date_invoice > reg_date) :
50
raise osv.except_osv(_('Error date !'), _('The invoice date cannot be later than the date of registration!'))
53
date_start = inv.registration_date or inv.date_invoice or time.strftime('%Y-%m-%d')
54
date_stop = inv.registration_date or inv.date_invoice or time.strftime('%Y-%m-%d')
56
period_ids = self.pool.get('account.period').search(cr, uid, [('date_start','<=',date_start),('date_stop','>=',date_stop), ('company_id', '=', inv.company_id.id)])
58
period_id = period_ids[0]
60
self.write(cr, uid, [inv.id], {'registration_date':reg_date,'period_id':period_id,})
62
mov_date = reg_date or inv.date_invoice or time.strftime('%Y-%m-%d')
64
self.pool.get('account.move').write(cr, uid, [inv.move_id.id], {'state':'draft'})
66
sql="update account_move_line set period_id="+str(period_id)+",date='"+mov_date+"' where move_id = "+str(inv.move_id.id)
70
self.pool.get('account.move').write(cr, uid, [inv.move_id.id], {'period_id':period_id,'date':mov_date})
72
self.pool.get('account.move').write(cr, uid, [inv.move_id.id], {'state':'posted'})
74
self._log_event(cr, uid, ids)