fix bug : 337680
[odoo/odoo.git] / addons / account / wizard / wizard_pay_invoice.py
index 1971a98..2baba87 100644 (file)
@@ -1,29 +1,22 @@
+# -*- encoding: utf-8 -*-
 ##############################################################################
 #
-# Copyright (c) 2004-2008 TINY SPRL. (http://tiny.be) All Rights Reserved.
+#    OpenERP, Open Source Management Solution
+#    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
+#    $Id$
 #
-# $Id$
+#    This program is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License as published by
+#    the Free Software Foundation, either version 3 of the License, or
+#    (at your option) any later version.
 #
-# WARNING: This program as such is intended to be used by professional
-# programmers who take the whole responsability of assessing all potential
-# consequences resulting from its eventual inadequacies and bugs
-# End users who are looking for a ready-to-use solution with commercial
-# garantees and support are strongly adviced to contract a Free Software
-# Service Company
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
 #
-# This program is Free Software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+#    You should have received a copy of the GNU General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 ##############################################################################
 
@@ -47,7 +40,7 @@ pay_fields = {
     'amount': {'string': 'Amount paid', 'type':'float', 'required':True},
     'name': {'string': 'Entry Name', 'type':'char', 'size': 64, 'required':True},
     'date': {'string': 'Payment date', 'type':'date', 'required':True, 'default':lambda *args: time.strftime('%Y-%m-%d')},
-    'journal_id': {'string': 'Journal', 'type': 'many2one', 'relation':'account.journal', 'required':True, 'domain':[('type','=','cash')]},
+    'journal_id': {'string': 'Journal/Payment Mode', 'type': 'many2one', 'relation':'account.journal', 'required':True, 'domain':[('type','=','cash')]},
     'period_id': {'string': 'Period', 'type': 'many2one', 'relation':'account.period', 'required':True},
 }
 
@@ -67,6 +60,12 @@ def _pay_and_reconcile(self, cr, uid, data, context):
         ctx = {'date':data['form']['date']}
         amount = cur_obj.compute(cr, uid, journal.currency.id, invoice.company_id.currency_id.id, amount, context=ctx)
 
+    # Take the choosen date
+    if form.has_key('comment'):
+        context={'date_p':form['date'],'comment':form['comment']}
+    else:
+        context={'date_p':form['date'],'comment':False}
+
     acc_id = journal.default_credit_account_id and journal.default_credit_account_id.id
     if not acc_id:
         raise wizard.except_wizard(_('Error !'), _('Your journal must have a default credit and debit account.'))
@@ -79,7 +78,9 @@ def _wo_check(self, cr, uid, data, context):
     pool = pooler.get_pool(cr.dbname)
     invoice = pool.get('account.invoice').browse(cr, uid, data['id'], context)
     journal = pool.get('account.journal').browse(cr, uid, data['form']['journal_id'], context)
-    if invoice.company_id.currency_id.id<>journal.currency.id:
+    if invoice.company_id.currency_id.id <> invoice.currency_id.id:
+        return 'addendum'
+    if journal.currency and (journal.currency.id <> invoice.currency_id.id):
         return 'addendum'
     if pool.get('res.currency').is_zero(cr, uid, invoice.currency_id,
             (data['form']['amount'] - invoice.amount_total)):
@@ -89,13 +90,15 @@ def _wo_check(self, cr, uid, data, context):
 _transaction_add_form = '''<?xml version="1.0"?>
 <form string="Information addendum">
     <separator string="Write-Off Move" colspan="4"/>
-    <field name="writeoff_acc_id"/>
+    <field name="writeoff_acc_id" domain="[('type','&lt;&gt;','view'),('type','&lt;&gt;','consolidation')]"/>
     <field name="writeoff_journal_id"/>
+    <field name="comment"/>
 </form>'''
 
 _transaction_add_fields = {
     'writeoff_acc_id': {'string':'Write-Off account', 'type':'many2one', 'relation':'account.account', 'required':True},
     'writeoff_journal_id': {'string': 'Write-Off journal', 'type': 'many2one', 'relation':'account.journal', 'required':True},
+    'comment': {'string': 'Entry Name', 'type':'char', 'size': 64, 'required':True},
 }
 
 def _get_value_addendum(self, cr, uid, data, context={}):
@@ -108,11 +111,11 @@ def _get_period(self, cr, uid, data, context={}):
     if len(ids):
         period_id = ids[0]
     invoice = pool.get('account.invoice').browse(cr, uid, data['id'], context)
-    if invoice.state == 'draft':
-        raise wizard.except_wizard(_('Error !'), _('Can not pay draft invoice.'))
+    if invoice.state in ['draft', 'proforma2', 'cancel']:
+        raise wizard.except_wizard(_('Error !'), _('Can not pay draft/proforma/cancel invoice.'))
     return {
         'period_id': period_id,
-        'amount': invoice.amount_total,
+        'amount': invoice.residual,
         'date': time.strftime('%Y-%m-%d')
     }
 
@@ -137,3 +140,6 @@ class wizard_pay_invoice(wizard.interface):
     }
 wizard_pay_invoice('account.invoice.pay')
 
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
+