From 7ca9a1294a30c3691478ca0c1b68111df406810c Mon Sep 17 00:00:00 2001 From: "Khushboo Bhatt (Open ERP)" Date: Mon, 15 Oct 2012 12:50:14 +0530 Subject: [PATCH] [IMP]project_timesheet:implemented method for setting default values. bzr revid: kbh@tinyerp.com-20121015072014-st4aavfgw4pve3ad --- addons/project_timesheet/project_timesheet.py | 51 ++++++++++--------------- 1 file changed, 20 insertions(+), 31 deletions(-) diff --git a/addons/project_timesheet/project_timesheet.py b/addons/project_timesheet/project_timesheet.py index 724944d..bc3e764 100644 --- a/addons/project_timesheet/project_timesheet.py +++ b/addons/project_timesheet/project_timesheet.py @@ -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: -- 1.7.10.4