diff --git a/addons/account/account_analytic_line.py b/addons/account/account_analytic_line.py index 2117f6e49ea..f0a420f7496 100644 --- a/addons/account/account_analytic_line.py +++ b/addons/account/account_analytic_line.py @@ -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' diff --git a/addons/analytic/analytic.py b/addons/analytic/analytic.py index 65505a2884e..39506c63958 100644 --- a/addons/analytic/analytic.py +++ b/addons/analytic/analytic.py @@ -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 } diff --git a/addons/hr_timesheet/hr_timesheet.py b/addons/hr_timesheet/hr_timesheet.py index 56f71d624e2..a28508be4db 100644 --- a/addons/hr_timesheet/hr_timesheet.py +++ b/addons/hr_timesheet/hr_timesheet.py @@ -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: diff --git a/addons/hr_timesheet_sheet/hr_timesheet_sheet.py b/addons/hr_timesheet_sheet/hr_timesheet_sheet.py index e62134ee38a..03f4443c235 100644 --- a/addons/hr_timesheet_sheet/hr_timesheet_sheet.py +++ b/addons/hr_timesheet_sheet/hr_timesheet_sheet.py @@ -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: diff --git a/addons/hr_timesheet_sheet/hr_timesheet_sheet_view.xml b/addons/hr_timesheet_sheet/hr_timesheet_sheet_view.xml index fc35a17377f..741b59d4393 100644 --- a/addons/hr_timesheet_sheet/hr_timesheet_sheet_view.xml +++ b/addons/hr_timesheet_sheet/hr_timesheet_sheet_view.xml @@ -94,7 +94,7 @@ - +