[FIX] working urls
[odoo/odoo.git] / addons / l10n_ch / invoice.py
index 1057fc3..9e8d3f0 100644 (file)
@@ -1,37 +1,25 @@
-# -*- coding: utf-8 -*-
-#
-#  bank.py
-#  invoice.py
-#
-#  Created by Nicolas Bessi based on Credric Krier contribution
-#
-#  Copyright (c) 2009 CamptoCamp. All rights reserved.
+# -*- encoding: utf-8 -*-
 ##############################################################################
-# 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 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.
+#    Author: Nicolas Bessi. Copyright Camptocamp SA
+#    Donors: Hasa Sàrl, Open Net Sàrl and Prisme Solutions Informatique SA
+#
+#    This program is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU Affero General Public License as
+#    published by the Free Software Foundation, either version 3 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.
+#    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 Affero 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 Affero General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 ##############################################################################
 
-from mx import DateTime
-
+from datetime import datetime
 from osv import fields, osv
 from tools import mod10r
 
@@ -71,8 +59,8 @@ class account_invoice(osv.osv):
             if invoice.move_id:
                 for line in invoice.move_id.line_id:
                     if not line.date_maturity or \
-                            DateTime.strptime(line.date_maturity, '%Y-%m-%d') \
-                            < DateTime.now():
+                            datetime.strptime(line.date_maturity, '%Y-%m-%d') \
+                            < datetime.now():
                         res[invoice.id] += line.amount_to_pay
         return res
 
@@ -85,8 +73,9 @@ class account_invoice(osv.osv):
             help='The partner bank account to pay\nKeep empty to use the default'
             ),
         ### Amount to pay
-        'amount_to_pay': fields.function(_amount_to_pay, method=True,
-            type='float', string='Amount to be paid',
+        'amount_to_pay': fields.function(_amount_to_pay,
+            type='float', 
+            string='Amount to be paid',
             help='The amount which should be paid at the current date\n' \
                     'minus the amount which is already in payment order'),
     }
@@ -96,7 +85,7 @@ class account_invoice(osv.osv):
     ## @param user res.user.id that is currently loged
     ## @parma ids invoices id
     ## @return a boolean True if valid False if invalid
-    def _check_bvr(self, cr, uid, ids):
+    def _check_bvr(self, cr, uid, ids, context=None):
         """
         Function to validate a bvr reference like :
         0100054150009>132000000000000000000000014+ 1300132412>
@@ -123,7 +112,7 @@ class account_invoice(osv.osv):
     ## @param user res.user.id that is currently loged
     ## @parma ids invoices id
     ## @return a boolean True if valid False if invalid
-    def _check_reference_type(self, cursor, user, ids):
+    def _check_reference_type(self, cursor, user, ids, context=None):
         """Check the customer invoice reference type depending
         on the BVR reference type and the invoice partner bank type"""
         for invoice in self.browse(cursor, user, ids):
@@ -132,7 +121,7 @@ class account_invoice(osv.osv):
                         invoice.partner_bank_id.state in \
                         ('bvrbank', 'bvrpost') and \
                         invoice.reference_type != 'bvr':
-                            return False
+                    return False
         return True
 
     _constraints = [
@@ -155,24 +144,34 @@ class account_invoice(osv.osv):
     def onchange_partner_id(self, cr, uid, ids, type, partner_id,
             date_invoice=False, payment_term=False, partner_bank_id=False, company_id=False):
         """ Function that is call when the partner of the invoice is changed
-        it will retriev and set the good bank partner bank"""
-        res = super(account_invoice, self).onchange_partner_id(
-                                                                cr,
-                                                                 uid,
-                                                                 ids,
-                                                                 type,
-                                                                 partner_id,
-                                                                 date_invoice,
-                                                                 payment_term
-                                                            )
+        it will retrieve and set the good bank partner bank"""
+        #context not define in signature of function in account module
+        context = {}
+        res = super(account_invoice, self).onchange_partner_id(cr,
+                                                               uid,
+                                                               ids,
+                                                               type,
+                                                               partner_id,
+                                                               date_invoice,
+                                                               payment_term,
+                                                               partner_bank_id,
+                                                               company_id)
         bank_id = False
         if partner_id:
-            p = self.pool.get('res.partner').browse(cr, uid, partner_id)
-            if p.bank_ids:
-                bank_id = p.bank_ids[0].id
-
-        if type in ('in_invoice', 'in_refund'):
-            res['value']['partner_bank_id'] = bank_id
+            if type in ('in_invoice', 'in_refund'):
+                p = self.pool.get('res.partner').browse(cr, uid, partner_id, context)
+                if p.bank_ids:
+                    bank_id = p.bank_ids[0].id
+                res['value']['partner_bank_id'] = bank_id
+            else:
+                user = self.pool.get('res.users').browse(cr, uid, uid, context)
+                bank_ids = user.company_id.partner_id.bank_ids
+                if bank_ids:
+                    #How to order bank ?
+                    for bank in bank_ids:
+                        if bank.my_bank:
+                            bank_id = bank.id
+                res['value']['partner_bank_id'] = bank_id
 
         if partner_bank_id != bank_id:
             to_update = self.onchange_partner_bank(cr, uid, ids, bank_id)
@@ -203,10 +202,9 @@ class account_tax_code(osv.osv):
     _name = 'account.tax.code'
     _inherit = "account.tax.code"
     _columns = {
-        ### The case code of the taxt code
         'code': fields.char('Case Code', size=512),
     }
 
 account_tax_code()
 
-# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
\ No newline at end of file
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: