Better Warning Message when employee misconfigured for timesheet
authorFabien Pinckaers <fp@tinyerp.com>
Tue, 19 Aug 2008 22:38:20 +0000 (00:38 +0200)
committerFabien Pinckaers <fp@tinyerp.com>
Tue, 19 Aug 2008 22:38:20 +0000 (00:38 +0200)
lp bug: https://launchpad.net/bugs/259465 fixed

bzr revid: fp@tinyerp.com-20080819223820-znehuxw9ikxo9qqs

addons/account/account_analytic_line.py
addons/hr_timesheet/hr_timesheet.py

index 8e8a20e..68559fd 100644 (file)
@@ -46,9 +46,9 @@ class account_analytic_line(osv.osv):
         'product_uom_id' : fields.many2one('product.uom', 'UoM'),
         'product_id' : fields.many2one('product.product', 'Product'),
         'account_id' : fields.many2one('account.analytic.account', 'Analytic Account', required=True, ondelete='cascade', select=True),
-        'general_account_id' : fields.many2one('account.account', 'General account', required=True, ondelete='cascade'),
-        'move_id' : fields.many2one('account.move.line', 'General entry', ondelete='cascade', select=True),
-        'journal_id' : fields.many2one('account.analytic.journal', 'Analytic journal', required=True, ondelete='cascade', select=True),
+        'general_account_id' : fields.many2one('account.account', 'General Account', required=True, ondelete='cascade'),
+        'move_id' : fields.many2one('account.move.line', 'Move Line', ondelete='cascade', select=True),
+        'journal_id' : fields.many2one('account.analytic.journal', 'Analytic Journal', required=True, ondelete='cascade', select=True),
         'code' : fields.char('Code', size=8),
         'user_id' : fields.many2one('res.users', 'User',),
         'ref': fields.char('Ref.', size=32),
index 7d0d4e8..6c26b7f 100644 (file)
@@ -31,6 +31,7 @@
 import time
 from osv import fields
 from osv import osv
+from osv.orm import except_orm
 
 
 class hr_employee(osv.osv):
@@ -116,7 +117,16 @@ class hr_analytic_timesheet(osv.osv):
         'date' : lambda self,cr,uid,ctx: ctx.get('date', time.strftime('%Y-%m-%d')),
         'user_id' : lambda obj, cr, uid, ctx : ctx.get('user_id', uid),
     }
-
+    def create(self, cr, uid, vals, context={}):
+        try:
+            res = super(hr_analytic_timesheet, self).create(cr, uid, vals, context)
+            return res
+        except Exception,e:
+            if 'journal_id' in e.args[0]:
+                raise except_orm(_('ValidateError'),
+                     _('No analytic journal available for this employee.\nDefine an employee for the selected user and assign an analytic journal.'))
+            else:
+                raise
 
     def on_change_user_id(self, cr, uid, ids, user_id):
         if not user_id:
@@ -126,10 +136,7 @@ class hr_analytic_timesheet(osv.osv):
             'product_uom_id' : self._getEmployeeUnit(cr, user_id, context= {}),
             'general_account_id' :self. _getGeneralAccount(cr, user_id, context= {}),
             'journal_id' : self._getAnalyticJournal(cr, user_id, context= {}),
-                           }}
-
-
-
+        }}
 hr_analytic_timesheet()
 
 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: