[FIX] hr_timesheet_sheet: default date on timehseet lines should be the date_from of the timesheet if today isn't included in the date_from and date_to

bzr revid: qdp-launchpad@openerp.com-20121025145443-5iuohn57h6uxn04t
This commit is contained in:
Quentin (OpenERP) 2012-10-25 16:54:43 +02:00
parent fb9af9f8bb
commit 149451bdf5
5 changed files with 23 additions and 28 deletions

View File

@ -39,7 +39,6 @@ class account_analytic_line(osv.osv):
}
_defaults = {
'date': fields.date.context_today,
'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'account.analytic.line', context=c),
}
_order = 'date desc'

View File

@ -306,14 +306,14 @@ class account_analytic_line(osv.osv):
}
def _get_default_datum(self, cr, uid, context=None):
import pprint; PP = pprint.PrettyPrinter()
import pdb; pdb.set_trace()
print 'dans analytic'
return fields.date.context_today()
def _get_default_date(self, cr, uid, context=None):
return fields.date.context_today(self, cr, uid, context=context)
def __get_default_date(self, cr, uid, context=None):
return self._get_default_date(cr, uid, context=context)
_defaults = {
'date': _get_default_datum,
'date': __get_default_date,
'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'account.analytic.line', context=c),
'amount': 0.00
}

View File

@ -210,15 +210,4 @@ class account_analytic_account(osv.osv):
account_analytic_account()
class account_analytic_line(osv.osv):
_inherit = 'account.analytic.line'
def _get_default_date(self, cr, uid, context=None):
print 'not called'
if context is None:
context = {}
if context.get('timesheet_date'):
return context.get('timesheet_date')
return super(account_analytic_line, self)._get_default_date(cr, uid, context=context)
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -304,16 +304,26 @@ class hr_timesheet_sheet(osv.osv):
hr_timesheet_sheet()
class hr_timesheet_line(osv.osv):
_inherit = "hr.analytic.timesheet"
class account_analytic_line(osv.osv):
_inherit = "account.analytic.line"
def _get_default_date(self, cr, uid, context=None):
if context is None:
context = {}
if 'date' in context:
return context['date']
return time.strftime('%Y-%m-%d')
#get the default date (should be: today)
res = super(account_analytic_line, self)._get_default_date(cr, uid, context=context)
#if we got the dates from and to from the timesheet and if the default date is in between, we use the default
#but if the default isn't included in those dates, we use the date start of the timesheet as default
if context.get('timesheet_date_from') and context.get('timesheet_date_to'):
if context['timesheet_date_from'] <= res <= context['timesheet_date_to']:
return res
return context.get('timesheet_date_from')
#if we don't get the dates from the timesheet, we return the default value from super()
return res
class hr_timesheet_line(osv.osv):
_inherit = "hr.analytic.timesheet"
def _sheet(self, cursor, user, ids, name, args, context=None):
sheet_obj = self.pool.get('hr_timesheet_sheet.sheet')
@ -359,9 +369,6 @@ class hr_timesheet_line(osv.osv):
},
),
}
_defaults = {
'date': _get_default_date,
}
def _check_sheet_state(self, cr, uid, ids, context=None):
if context is None:

View File

@ -94,7 +94,7 @@
<group col="4">
<field name="state_attendance" groups="base.group_hr_attendance"/>
</group>
<field colspan="4" context="{'user_id':user_id}" name="timesheet_ids" nolabel="1">
<field colspan="4" context="{'user_id': user_id, 'timesheet_date_from': date_from, 'timesheet_date_to': date_to}" name="timesheet_ids" nolabel="1">
<tree editable="top" string="Timesheet Lines">
<field name="date"/>
<field domain="[('type','in',['normal', 'contract']), ('state', '&lt;&gt;', 'close'),('use_timesheets','=',1)]" name="account_id" on_change="on_change_account_id(account_id, user_id)" context="{'default_use_timesheets': 1}"/>