[IMP]project_timesheet:implemented method for setting default values.
authorKhushboo Bhatt (Open ERP) <kbh@tinyerp.com>
Mon, 15 Oct 2012 07:20:14 +0000 (12:50 +0530)
committerKhushboo Bhatt (Open ERP) <kbh@tinyerp.com>
Mon, 15 Oct 2012 07:20:14 +0000 (12:50 +0530)
bzr revid: kbh@tinyerp.com-20121015072014-st4aavfgw4pve3ad

addons/project_timesheet/project_timesheet.py

index 724944d..bc3e764 100644 (file)
@@ -272,50 +272,39 @@ res_partner()
 class account_analytic_line(osv.osv):
    _inherit = "account.analytic.line"
 
-   def on_change_account_id(self, cr, uid, ids, account_id):
-       res = {}
-       if not account_id:
-           return res
-       res.setdefault('value',{})
-       acc = self.pool.get('account.analytic.account').browse(cr, uid, account_id)
-       st = acc.to_invoice.id
-       res['value']['to_invoice'] = st or False
-       if acc.state == 'close' or acc.state == 'cancelled':
-           raise osv.except_osv(_('Invalid Analytic Account !'), _('You cannot select a Analytic Account which is in Close or Cancelled state.'))
-       return res
-
-   def _default_product(self, cr, uid, context=None):
-        proxy = self.pool.get('hr.employee')
+   def _default_account_id(self, cr, uid, context=None):
+        proxy = self.pool.get('account.analytic.account')
         record_ids = proxy.search(cr, uid, [('user_id', '=', uid)], context=context)
-        print "record_ids",record_ids
         employee = proxy.browse(cr, uid, record_ids[0], context=context)
-        if employee.product_id:
-            return employee.product_id.id
+        if employee:
+            return employee.id
         return False
 
-   def _default_product_uom(self, cr, uid, context=None):
+   def _default_product(self, cr, uid, context=None):
         proxy = self.pool.get('hr.employee')
         record_ids = proxy.search(cr, uid, [('user_id', '=', uid)], context=context)
-        print "record_ids",record_ids
         employee = proxy.browse(cr, uid, record_ids[0], context=context)
-        if employee.product_id and employee.product_id.uom_id:
-            return employee.product_id.uom_id.id
-        return False
-
-   def _default_invoice(self, cr, uid, context=None):
-        proxy = self.pool.get('hr_timesheet_invoice.factor')
-        record_ids = proxy.search(cr, uid, [('customer_name', '=', '100%')], context=context)
-        invoice = proxy.browse(cr, uid, record_ids[0], context=context)
-        if invoice:
-            return invoice.id
+        if employee.product_id:
+            return employee.product_id.id
         return False
 
    _defaults = {
         'product_id': _default_product,
-        'product_uom_id': _default_product_uom,
-        'to_invoice': _default_invoice
+        'account_id': _default_account_id
         }
 
+   def on_change_account_id(self, cr, uid, ids, account_id):
+       res = {}
+       if not account_id:
+           return res
+       res.setdefault('value',{})
+       acc = self.pool.get('account.analytic.account').browse(cr, uid, account_id)
+       st = acc.to_invoice.id
+       res['value']['to_invoice'] = st or False
+       if acc.state == 'close' or acc.state == 'cancelled':
+           raise osv.except_osv(_('Invalid Analytic Account !'), _('You cannot select a Analytic Account which is in Close or Cancelled state.'))
+       return res
+
 account_analytic_line()
 
 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: