Commit 5894327c authored by Gabriel Davini's avatar Gabriel Davini 🕺🏻

[FIX] Fix depends on _get_duration(): don't recompute on labour_contract change!

[MOD] Some code-styling mods.
parent 74e57959
......@@ -23,7 +23,6 @@ import datetime
from openerp import _, api, exceptions, fields, models
from openerp.addons import decimal_precision as dp
from openerp.exceptions import ValidationError, Warning
STATE_COLOR_MAP = {
'template': 1,
......@@ -349,7 +348,7 @@ class ProjectWorkTeam(models.Model):
# if work_order.state not in ('project',):
# err = _('You cannot delete an work order which is not project. You should cancel \
# it instead.')
# raise Warning(err)
# raise exceptions.Warning(err)
# return super(project_order_work, self).unlink()
#
#
......@@ -378,7 +377,7 @@ class ProjectOrderWorkTransient(models.Model):
# date_end = fields.Datetime.from_string(order.planned_date_end)
# if date_start >= date_end:
# err = _("Planned Ending Date must be > Planned Starting Date!")
# raise ValidationError(err)
# raise exceptions.ValidationError(err)
@api.constrains("date_start", "date_end")
def check_dates(self):
......@@ -390,7 +389,7 @@ class ProjectOrderWorkTransient(models.Model):
date_end = fields.Datetime.from_string(order.date_end)
if order.date_start and order.date_end and date_start >= date_end:
err = _("Ending Date must be > Starting Date!")
raise ValidationError(err)
raise exceptions.ValidationError(err)
@api.returns("res.users")
def _default_solicited_by(self):
......@@ -505,7 +504,7 @@ class ProjectOrderWorkTransient(models.Model):
@api.multi
def set_planning(self):
if not self.task_ids:
raise Warning(_('You cannot send order to planning without task.'))
raise exceptions.Warning(_('You cannot send order to planning without task.'))
return self.write({'state': 'planning'})
......@@ -527,7 +526,7 @@ class ProjectOrderWorkTransient(models.Model):
@api.multi
def set_done(self):
if not self.task_ids or not self.work_ids:
raise Warning(_('You cannot close an work order without works.'))
raise exceptions.Warning(_('You cannot close an work order without works.'))
return self.write({'state': 'done', 'responsible_for_execution_id': self.env.uid})
......@@ -580,7 +579,7 @@ class ProjectOrderWorkTransient(models.Model):
if work_order.state not in ('project',):
err = _('You cannot delete an work order which is not project. You should cancel '
'it instead.')
raise Warning(err)
raise exceptions.Warning(err)
return super(ProjectOrderWorkTransient, self).unlink()
......@@ -693,19 +692,21 @@ class ProjectWorkOffice(models.Model):
end_date = fields.Date.from_string(pwo.end_date)
if start_date and end_date and start_date > end_date:
raise ValidationError(_("Start Date must be before End Date"))
raise exceptions.ValidationError(_("Start Date must be before End Date"))
if pwo.start_date[5:7] != pwo.end_date[5:7]:
raise ValidationError(_("Start Date and End Date must be in the same Month"))
raise exceptions.ValidationError(
_("Start Date and End Date must be in the same Month"))
#start_date_count = self.get_attendances_on_date(pwo.start_date, pwo.user_id.id)
#if start_date_count <= 0:
# err = _("User %s has no attendances on %s")
# raise ValidationError(err % (pwo.user_id.name, start_date.strftime(fmt)))
# raise exceptions.ValidationError(err % (pwo.user_id.name,
# start_date.strftime(fmt)))
#end_date_count = self.get_attendances_on_date(pwo.end_date, pwo.user_id.id)
#if end_date_count <= 0:
# err = _("User %s has no attendances on %s")
# raise ValidationError(err % (pwo.user_id.name, end_date.strftime(fmt)))
# raise exceptions.ValidationError(err % (pwo.user_id.name, end_date.strftime(fmt)))
def get_day_perc_in_range(self, start_date, end_date, user_id, pwo_id=False):
query = """
......@@ -736,7 +737,7 @@ class ProjectWorkOffice(models.Model):
day_perc_selection = self._fields["day_perc"].selection
valid_day_perc = [key for key, __ in day_perc_selection]
if day_perc not in valid_day_perc:
raise ValidationError(_("This Employee is fully busy on this dates!"))
raise exceptions.ValidationError(_("This Employee is fully busy on this dates!"))
return True
......@@ -777,7 +778,7 @@ class ProjectWorkOffice(models.Model):
return True
def calc_closing_date(self, user, last_date):
employee = user.employee_ids and user.employee_ids[-1] or False
employee = user.employee_ids and user.employee_ids[-1]
if not employee:
return False
......@@ -844,7 +845,7 @@ class ProjectWorkOffice(models.Model):
return worked_hours
@api.depends('start_date', 'end_date', 'day_perc', 'user_id.employee_ids.labour_contract')
@api.depends('start_date', 'end_date', 'day_perc', 'user_id')
def _get_duration(self):
for pwo in self:
if pwo.start_date and pwo.end_date:
......@@ -853,7 +854,6 @@ class ProjectWorkOffice(models.Model):
pwo.end_date,
pwo.user_id,
)
duration = worked_hours * float(pwo.day_perc)
else:
duration = 0
......
......@@ -31,7 +31,7 @@ class WizardAddWorkToWorkOrder(models.TransientModel):
@api.multi
def button_accept(self):
pass
return None
def reopen(self):
return self.env["ir.actions.act_window"].for_xml_id(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment