[IMP]: (Work in progress)* Changed demo references according to changes in server...
[odoo/odoo.git] / addons / account / account_bank.py
index 6833946..cbc5a96 100644 (file)
@@ -26,6 +26,8 @@ class bank(osv.osv):
     _inherit = "res.partner.bank"
     _columns = {
         'journal_id': fields.many2one('account.journal', 'Account Journal', help="This journal will be created automatically for this bank account when you save the record"),
+        'currency_id': fields.related('journal_id', 'currency', type="many2one", relation='res.currency', readonly=True,
+            string="Currency", help="Currency of the related account journal."),
     }
     def create(self, cr, uid, data, context={}):
         result = super(bank, self).create(cr, uid, data, context=context)
@@ -42,18 +44,18 @@ class bank(osv.osv):
         return (bank.bank_name or '') + ' ' + bank.acc_number
 
     def post_write(self, cr, uid, ids, context={}):
-        obj_acc = self.pool.get('account.account')
-        obj_data = self.pool.get('ir.model.data')
-
         if isinstance(ids, (int, long)):
           ids = [ids]
 
+        obj_acc = self.pool.get('account.account')
+        obj_data = self.pool.get('ir.model.data')
+
         for bank in self.browse(cr, uid, ids, context):
             if bank.company_id and not bank.journal_id:
                 # Find the code and parent of the bank account to create
                 dig = 6
                 current_num = 1
-                ids = obj_acc.search(cr, uid, [('type','=','liquidity')], context=context)
+                ids = obj_acc.search(cr, uid, [('type','=','liquidity'), ('company_id', '=', bank.company_id.id)], context=context)
                 # No liquidity account exists, no template available
                 if not ids: continue
 
@@ -68,7 +70,6 @@ class bank(osv.osv):
                 name = self._prepare_name(bank)
                 acc = {
                     'name': name,
-                    'currency_id': bank.company_id.currency_id.id,
                     'code': new_code,
                     'type': 'liquidity',
                     'user_type': ref_acc_bank_temp.user_type.id,
@@ -99,7 +100,6 @@ class bank(osv.osv):
                     'type': 'bank',
                     'company_id': bank.company_id.id,
                     'analytic_journal_id': False,
-                    'currency_id': False,
                     'default_credit_account_id': acc_bank_id,
                     'default_debit_account_id': acc_bank_id,
                     'view_id': view_id_cash
@@ -108,3 +108,5 @@ class bank(osv.osv):
 
                 self.write(cr, uid, [bank.id], {'journal_id': journal_id}, context=context)
         return True
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: