[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.
This commit is contained in:
odoo-tac
2015-08-04 22:48:58 +02:00
committed by Antony Lesuisse
parent a7dee722cc
commit e7e4283a57
+13 -13
View File
@@ -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'