[IMP] account: added constraint on account_journal currency + changed default value...
authorQuentin (OpenERP) <qdp-launchpad@openerp.com>
Tue, 22 Nov 2011 10:13:38 +0000 (11:13 +0100)
committerQuentin (OpenERP) <qdp-launchpad@openerp.com>
Tue, 22 Nov 2011 10:13:38 +0000 (11:13 +0100)
bzr revid: qdp-launchpad@openerp.com-20111122101338-44k60vjsnmf3khud

addons/account/account.py

index 630735c..c8895fa 100644 (file)
@@ -461,7 +461,7 @@ class account_account(osv.osv):
     }
 
     _defaults = {
-        'type': 'view',
+        'type': 'other',
         'reconcile': False,
         'active': True,
         'currency_mode': 'current',
@@ -716,6 +716,19 @@ class account_journal(osv.osv):
 
     _order = 'code'
 
+    def _check_currency(self, cr, uid, ids, context=None):
+        for journal in self.browse(cr, uid, ids, context=context):
+            if journal.currency:
+                if journal.default_credit_account_id and not journal.default_credit_account_id.currency_id.id == journal.currency.id:
+                    return False
+                if journal.default_debit_account_id and not journal.default_debit_account_id.currency_id.id == journal.currency.id:
+                    return False
+        return True
+
+    _constraints = [
+        (_check_currency, 'Configuration error! The currency chosen should be shared by the default accounts too.', ['currency','default_debit_account_id','default_credit_account_id']),
+    ]
+
     def copy(self, cr, uid, id, default={}, context=None, done_list=[], local=False):
         journal = self.browse(cr, uid, id, context=context)
         if not default: