Browse Source

[ADD] b_shift : attendance sheet possibility to translate terms

pull/125/head
Elouan Le Bars 5 years ago
parent
commit
a5b212cdfb
  1. 67
      beesdoo_shift/models/attendance_sheet.py
  2. 6
      beesdoo_shift/wizard/generate_attendance_sheet.py
  3. 17
      beesdoo_shift/wizard/validate_attendance_sheet.py

67
beesdoo_shift/models/attendance_sheet.py

@ -2,7 +2,7 @@
from lxml import etree from lxml import etree
from openerp import models, exceptions, fields, api
from openerp import models, exceptions, fields, api, _
from openerp.exceptions import UserError, ValidationError from openerp.exceptions import UserError, ValidationError
from datetime import datetime from datetime import datetime
@ -65,7 +65,7 @@ class AttendanceSheetShift(models.AbstractModel):
""" """
if not self.working_mode or not self.stage: if not self.working_mode or not self.stage:
raise UserError( raise UserError(
"Impossible to map task status, all values are not set."
_("Impossible to map task status, all values are not set.")
) )
if self.working_mode == "regular": if self.working_mode == "regular":
if self.stage == "present": if self.stage == "present":
@ -172,9 +172,7 @@ class AttendanceSheet(models.Model):
readonly=True, readonly=True,
help="Indicative maximum number of workers for the shifts.", help="Indicative maximum number of workers for the shifts.",
) )
annotation = fields.Text(
"Annotation", default=""
)
annotation = fields.Text("Annotation", default="")
is_annotated = fields.Boolean( is_annotated = fields.Boolean(
compute="_compute_is_annotated", compute="_compute_is_annotated",
string="Annotation", string="Annotation",
@ -187,9 +185,7 @@ class AttendanceSheet(models.Model):
default=False, default=False,
track_visibility="onchange", track_visibility="onchange",
) )
feedback = fields.Text(
"Feedback"
)
feedback = fields.Text("Feedback")
worker_nb_feedback = fields.Selection( worker_nb_feedback = fields.Selection(
[ [
("not_enough", "Not enough"), ("not_enough", "Not enough"),
@ -221,7 +217,7 @@ class AttendanceSheet(models.Model):
( (
"check_no_annotation_mark_read", "check_no_annotation_mark_read",
"CHECK ((is_annotated=FALSE AND is_read=FALSE) OR is_annotated=TRUE)", "CHECK ((is_annotated=FALSE AND is_read=FALSE) OR is_annotated=TRUE)",
"Non-annotated sheets can't be marked as read. ",
_("Non-annotated sheets can't be marked as read."),
) )
] ]
@ -235,13 +231,13 @@ class AttendanceSheet(models.Model):
def _lock_after_validation(self): def _lock_after_validation(self):
if self.state == "validated": if self.state == "validated":
raise UserError( raise UserError(
"The sheet has already been validated and can't be edited."
_("The sheet has already been validated and can't be edited.")
) )
@api.multi @api.multi
def button_mark_as_read(self): def button_mark_as_read(self):
if self.is_read: if self.is_read:
raise UserError("The sheet has already been marked as read.")
raise UserError(_("The sheet has already been marked as read."))
self.is_read = True self.is_read = True
@api.constrains("expected_shift_ids", "added_shift_ids") @api.constrains("expected_shift_ids", "added_shift_ids")
@ -257,8 +253,10 @@ class AttendanceSheet(models.Model):
if (len(ids) - len(set(ids))) > 0: if (len(ids) - len(set(ids))) > 0:
raise UserError( raise UserError(
_(
"You can't add the same worker more than once to an attendance sheet." "You can't add the same worker more than once to an attendance sheet."
) )
)
# Compute name (not hardcorded to prevent incoherence with timezone) # Compute name (not hardcorded to prevent incoherence with timezone)
@api.depends("start_time", "end_time") @api.depends("start_time", "end_time")
@ -343,20 +341,21 @@ class AttendanceSheet(models.Model):
for added_shift in self.added_shift_ids: for added_shift in self.added_shift_ids:
if not added_shift.worker_id: if not added_shift.worker_id:
raise UserError( raise UserError(
"Worker must be set for shift %s" % added_shift.id
_("Worker must be set for shift %s") % added_shift.id
) )
if not added_shift.stage: if not added_shift.stage:
raise UserError( raise UserError(
"Shift Stage is missing for %s"
_("Shift Stage is missing for %s")
% added_shift.worker_id.name % added_shift.worker_id.name
) )
if not added_shift.task_type_id: if not added_shift.task_type_id:
raise UserError( raise UserError(
"Task Type is missing for %s" % added_shift.worker_id.name
_("Task Type is missing for %s")
% added_shift.worker_id.name
) )
if not added_shift.working_mode: if not added_shift.working_mode:
raise UserError( raise UserError(
"Working mode is missing for %s"
_("Working mode is missing for %s")
% added_shift.worker_id.name % added_shift.worker_id.name
) )
if ( if (
@ -364,14 +363,14 @@ class AttendanceSheet(models.Model):
and not added_shift.regular_task_type and not added_shift.regular_task_type
): ):
raise UserError( raise UserError(
"Regular Task Type is missing for %s"
_("Regular Task Type is missing for %s")
% added_shift.worker_id.name % added_shift.worker_id.name
) )
for expected_shift in self.expected_shift_ids: for expected_shift in self.expected_shift_ids:
if not expected_shift.stage: if not expected_shift.stage:
raise UserError( raise UserError(
"Shift Stage is missing for %s"
_("Shift Stage is missing for %s")
% expected_shift.worker_id.name % expected_shift.worker_id.name
) )
@ -400,8 +399,10 @@ class AttendanceSheet(models.Model):
# Add an annotation if a regular worker is doing its regular shift # Add an annotation if a regular worker is doing its regular shift
if is_regular_shift and is_regular_worker: if is_regular_shift and is_regular_worker:
self.annotation += ( self.annotation += (
_(
"\n\nWarning : %s attended its shift as a normal one but was not expected." "\n\nWarning : %s attended its shift as a normal one but was not expected."
" Something may be wrong in his/her personnal informations.\n" " Something may be wrong in his/her personnal informations.\n"
)
% added_shift.worker_id.name % added_shift.worker_id.name
) )
# Edit a non-assigned shift or create one if none # Edit a non-assigned shift or create one if none
@ -430,7 +431,7 @@ class AttendanceSheet(models.Model):
else: else:
actual_shift = self.env["beesdoo.shift.shift"].create( actual_shift = self.env["beesdoo.shift.shift"].create(
{ {
"name": "[Added Shift] %s" % self.start_time,
"name": _("[Added Shift] %s") % self.start_time,
"task_type_id": added_shift.task_type_id.id, "task_type_id": added_shift.task_type_id.id,
"worker_id": added_shift.worker_id.id, "worker_id": added_shift.worker_id.id,
"start_time": self.start_time, "start_time": self.start_time,
@ -466,23 +467,31 @@ class AttendanceSheet(models.Model):
if self.state == "validated": if self.state == "validated":
raise UserError( raise UserError(
"You cannot modify a validated attendance sheet."
_("You cannot modify a validated attendance sheet.")
) )
worker = self.env["res.partner"].search([("barcode", "=", barcode)]) worker = self.env["res.partner"].search([("barcode", "=", barcode)])
if not len(worker): if not len(worker):
raise UserError("Worker not found (invalid barcode or status).")
raise UserError(_("Worker not found (invalid barcode or status)."))
if len(worker) > 1: if len(worker) > 1:
raise UserError("Multiple workers corresponding to barcode.")
raise UserError(
_("Multiple workers are corresponding this barcode.")
)
if worker.state in ("unsubscribed", "resigning"): if worker.state in ("unsubscribed", "resigning"):
raise UserError("Worker is %s." % worker.state)
raise UserError(_("Worker is %s.") % worker.state)
if worker.working_mode not in ("regular", "irregular"): if worker.working_mode not in ("regular", "irregular"):
raise UserError("Worker is %s and should be regular or irregular." % worker.working_mode)
raise UserError(
_("Worker is %s and should be regular or irregular.")
% worker.working_mode
)
for id in self.expected_shift_ids.ids: for id in self.expected_shift_ids.ids:
shift = self.env["beesdoo.shift.sheet.expected"].browse(id) shift = self.env["beesdoo.shift.sheet.expected"].browse(id)
if shift.worker_id == worker or shift.replacement_worker_id == worker:
if (
shift.worker_id == worker
or shift.replacement_worker_id == worker
):
shift.stage = "present" shift.stage = "present"
return return
@ -493,12 +502,14 @@ class AttendanceSheet(models.Model):
added_ids = map(lambda s: s.worker_id.id, self.added_shift_ids) added_ids = map(lambda s: s.worker_id.id, self.added_shift_ids)
if worker.id in added_ids: if worker.id in added_ids:
raise UserError("Worker is already present.")
raise UserError(_("Worker is already present."))
self.added_shift_ids |= self.added_shift_ids.new({
self.added_shift_ids |= self.added_shift_ids.new(
{
"task_type_id": self.added_shift_ids._default_task_type_id(), "task_type_id": self.added_shift_ids._default_task_type_id(),
"stage": "present", "stage": "present",
"attendance_sheet_id": self._origin.id, "attendance_sheet_id": self._origin.id,
"worker_id": worker.id, "worker_id": worker.id,
"regular_task_type": regular_task_type
})
"regular_task_type": regular_task_type,
}
)

6
beesdoo_shift/wizard/generate_attendance_sheet.py

@ -60,11 +60,13 @@ class GenerateAttendanceSheet(models.TransientModel):
sheets = self.env["beesdoo.shift.sheet"] sheets = self.env["beesdoo.shift.sheet"]
if not self.time_range: if not self.time_range:
raise exceptions.UserError( raise exceptions.UserError(
"Please select a time time_range to generate the sheet."
_("Please select a time time_range to generate the sheet.")
) )
time_range = self.time_range.split("~") time_range = self.time_range.split("~")
if len(time_range) != 2: if len(time_range) != 2:
raise exceptions.ValidationError("Selection key has wrong format.")
raise exceptions.ValidationError(
_("Selection key has wrong format.")
)
sheet = sheets.create( sheet = sheets.create(
{"start_time": time_range[0], "end_time": time_range[1]} {"start_time": time_range[0], "end_time": time_range[1]}
) )

17
beesdoo_shift/wizard/validate_attendance_sheet.py

@ -11,11 +11,10 @@ class ValidateAttendanceSheet(models.TransientModel):
barcode = fields.Char(string="Barcode", required=True) barcode = fields.Char(string="Barcode", required=True)
annotation = fields.Text( annotation = fields.Text(
"Important information requiring permanent member assistance", default=""
)
feedback = fields.Text(
"General feedback"
"Important information requiring permanent member assistance",
default="",
) )
feedback = fields.Text("General feedback")
worker_nb_feedback = fields.Selection( worker_nb_feedback = fields.Selection(
[ [
("not_enough", "Not enough"), ("not_enough", "Not enough"),
@ -23,7 +22,7 @@ class ValidateAttendanceSheet(models.TransientModel):
("too_many", "Too many"), ("too_many", "Too many"),
], ],
string="Number of workers", string="Number of workers",
required=True
required=True,
) )
@api.multi @api.multi
@ -31,16 +30,16 @@ class ValidateAttendanceSheet(models.TransientModel):
sheet_id = self._context.get("active_id") sheet_id = self._context.get("active_id")
sheet_model = self._context.get("active_model") sheet_model = self._context.get("active_model")
sheet = self.env[sheet_model].browse(sheet_id) sheet = self.env[sheet_model].browse(sheet_id)
card = self.env["member.card"].search(
[("barcode", "=", self.barcode)]
)
card = self.env["member.card"].search([("barcode", "=", self.barcode)])
if not len(card): if not len(card):
raise UserError("Please set a correct barcode.")
raise UserError(_("Please set a correct barcode."))
user = card[0].partner_id user = card[0].partner_id
if not user: if not user:
raise UserError( raise UserError(
_(
"Only super-cooperators and administrators can validate attendance sheets." "Only super-cooperators and administrators can validate attendance sheets."
) )
)
sheet.annotation = self.annotation sheet.annotation = self.annotation
sheet.feedback = self.feedback sheet.feedback = self.feedback
sheet.worker_nb_feedback = self.worker_nb_feedback sheet.worker_nb_feedback = self.worker_nb_feedback

Loading…
Cancel
Save