From e7e4283a57441e33012c6c57f8ae70fe0245f7c2 Mon Sep 17 00:00:00 2001 From: odoo-tac Date: Tue, 4 Aug 2015 15:27:46 +0200 Subject: [PATCH] [FIX] hr_timesheet: magic values when is_timesheet Timesheets entries could only be created with the help of the magic default_is_timesheet=1 set in the context, thus in views. To allow manual creation or import of timesheets by setting is_timesheet=True directly, the values of invisible but required fields will be computed at create insted of default_get. --- addons/hr_timesheet/hr_timesheet.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/addons/hr_timesheet/hr_timesheet.py b/addons/hr_timesheet/hr_timesheet.py index d6687976657..2877dabd8f4 100644 --- a/addons/hr_timesheet/hr_timesheet.py +++ b/addons/hr_timesheet/hr_timesheet.py @@ -22,19 +22,6 @@ class HrEmployee(models.Model): class account_analytic_line(models.Model): _inherit = 'account.analytic.line' - def default_get(self, cr, uid, fields, context=None): - values = super(account_analytic_line, self).default_get(cr, uid, fields, context=context) - if values.get('is_timesheet'): - if 'product_id' in fields: - values['product_id'] = self._get_employee_product(cr, uid, context=context) - if 'product_uom_id' in fields: - values['product_uom_id'] = self._get_employee_unit(cr, uid, context=context) - if 'general_account_id' in fields: - values['general_account_id'] = self._get_general_account(cr, uid, context=context) - if 'journal_id' in fields: - values['journal_id'] = self._get_analytic_journal(cr, uid, context=context) - return values - is_timesheet = fields.Boolean() @api.model @@ -115,6 +102,19 @@ class account_analytic_line(models.Model): if self.is_timesheet and self._origin.date and (self._origin.date != self.date): raise exceptions.Warning(_('Changing the date will let this entry appear in the timesheet of the new date.')) + @api.model + def create(self, values): + if values.get('is_timesheet'): + if not values.get('product_id'): + values['product_id'] = self._get_employee_product() + if not values.get('product_uom_id'): + values['product_uom_id'] = self._get_employee_unit() + if not values.get('general_account_id'): + values['general_account_id'] = self._get_general_account() + if not values.get('journal_id'): + values['journal_id'] = self._get_analytic_journal() + return super(account_analytic_line, self).create(values) + class account_analytic_account(models.Model): _inherit = 'account.analytic.account'