[FIX] Check date not in the period = True is not working while creating journal entri...
authorado <ado@tinyerp.com>
Mon, 14 Nov 2011 10:43:32 +0000 (16:13 +0530)
committerado <ado@tinyerp.com>
Mon, 14 Nov 2011 10:43:32 +0000 (16:13 +0530)
bzr revid: ado@tinyerp.com-20111114104332-r1nods9ic79w52ws

addons/account/account.py

index 1b2ecce..cfc0d7d 100644 (file)
@@ -1166,6 +1166,21 @@ class account_move(osv.osv):
                     return False
         return True
 
+    def _check_date(self, cursor, user, ids, context=None):
+        journal_obj = self.pool.get('account.journal')
+        period_obj = self.pool.get('account.period')
+        for move in self.browse(cursor, user, ids, context=context):
+            journal_id = move.journal_id.id
+            period_id = move.period_id
+            entry_date = move.date
+        if journal_id and period_id and entry_date:
+                journal = journal_obj.browse(cursor, user, journal_id, context=context)
+                if journal.allow_date:
+                    print period_id.id
+                    if not time.strptime(entry_date[:10],'%Y-%m-%d') >= time.strptime(period_id.date_start, '%Y-%m-%d') or not time.strptime(entry_date[:10], '%Y-%m-%d') <= time.strptime(period_id.date_stop, '%Y-%m-%d'):
+                        return False
+        return True
+
     _constraints = [
         (_check_centralisation,
             'You cannot create more than one move per period on centralized journal',
@@ -1173,6 +1188,9 @@ class account_move(osv.osv):
         (_check_period_journal,
             'You cannot create entries on different periods/journals in the same move',
             ['line_id']),
+        (_check_date,
+            'The date of your Journal Entry is not in the defined period!',
+            ['journal_id'])
     ]
 
     def post(self, cr, uid, ids, context=None):