[FIX] improve new employee for timesheet
authorFabien Pinckaers <fp@tinyerp.com>
Tue, 12 Oct 2010 17:27:25 +0000 (19:27 +0200)
committerFabien Pinckaers <fp@tinyerp.com>
Tue, 12 Oct 2010 17:27:25 +0000 (19:27 +0200)
bzr revid: fp@tinyerp.com-20101012172725-5zo9c43yezol5woj

addons/hr_timesheet/hr_timesheet.py
addons/hr_timesheet/hr_timesheet_data.xml
addons/hr_timesheet/hr_timesheet_demo.xml

index b117563..84e7db4 100644 (file)
@@ -35,25 +35,23 @@ class hr_employee(osv.osv):
     }
     
     def _getAnalyticJournal(self, cr, uid, context=None):
-        if context is None:
-            context = {}
-        id = self.search(cr, uid, [('user_id', '=', context.get('user_id', uid))], context=context)
-        if id:
-            journal = self.browse(cr, uid, id[0], context=context)
-            if journal.journal_id:
-                return journal.journal_id.id
+        md = self.pool.get('ir.model.data')
+        try:
+            result = md.get_object_reference(cr, uid, 'hr_timesheet', 'analytic_journal')
+            return result[1]
+        except ValueError, e:
+            pass
         return False
-    
+
     def _getEmployeeProduct(self, cr, uid, context=None):
-        if context is None:
-            context = {}
-        id = self.search(cr, uid, [('user_id', '=', context.get('user_id', uid))], context=context)
-        if id:
-            prod = self.browse(cr, uid, id[0], context=context)
-            if prod.product_id:
-                return prod.product_id.id
+        md = self.pool.get('ir.model.data')
+        try:
+            result = md.get_object_reference(cr, uid, 'hr_timesheet', 'product_consultant')
+            return result[1]
+        except ValueError, e:
+            pass
         return False
-        
+
     _defaults = {
         'journal_id' : _getAnalyticJournal,
         'product_id' : _getEmployeeProduct    
index 08a769d..e7cb3d5 100644 (file)
@@ -6,5 +6,17 @@
             <field name="name">Timesheet Journal</field>
             <field name="type">general</field>
         </record>
+
+        <record id="product_consultant" model="product.product">
+            <field name="list_price">75.0</field>
+            <field name="standard_price">30.0</field>
+            <field name="uom_id" ref="product.uom_hour"/>
+            <field name="uom_po_id" ref="product.uom_hour"/>
+            <field name="name">Service on Timesheet</field>
+            <field name="categ_id" ref="product.cat0"/>
+            <field name="type">service</field>
+            <field eval="False" name="purchase_ok"/>
+        </record>
+
     </data>
 </openerp>
index f344b60..e7ba5c9 100644 (file)
@@ -2,20 +2,6 @@
 <openerp>
     <data noupdate="1">
 
-        <record id="product_consultant" model="product.product">
-            <field name="default_code">DEV</field>
-            <field name="list_price">75.0</field>
-            <field name="standard_price">30.0</field>
-            <field name="uom_id" ref="product.uom_hour"/>
-            <field name="uom_po_id" ref="product.uom_hour"/>
-            <field name="name">Consultancy - Senior Developer</field>
-            <field name="categ_id" ref="product.product_category_10"/>
-            <field name="type">service</field>
-            <field name="supply_method">produce</field>
-            <field name="procure_method">make_to_order</field>
-            <field eval="False" name="purchase_ok"/>
-        </record>
-
         <!-- complete our example employee -->
         <record id="hr.employee1" model="hr.employee">
             <field name="product_id" ref="product_consultant"/>