Esempio n. 1
0
    def add_new_timesheet(self, task_id, redirect=None, **post):
        try:
            task_sudo = self._document_check_access('project.task', task_id,
                                                    None)
        except (AccessError, MissingError):
            return request.render("website.403")

        if post and task_sudo.user_id == request.env.user:
            # START PROCESSING DATA
            error = CustomerPortal.check_timesheet(post)
            if not error:
                project = task_sudo.project_id
                if not project:
                    error += [
                        _('PLease ask the website administrator to link this task to a project'
                          )
                    ]
                else:
                    values = {
                        'date': datetime.strptime(post['date'], '%Y-%m-%d'),
                        'project_id': project.id,
                        'task_id': task_sudo.id,
                        'unit_amount': post['unit_amount'],
                        'name': post['name'],
                    }
                    analytic_line = request.env['account.analytic.line'].sudo(
                    ).create(values)
                    analytic_line._link_portal_analytic_line_purchase(
                        request.env.user)
                    # END OF PROCESSING DATA
            return self.portal_my_task(task_id, error=error)
        else:
            return request.render("website.403")
Esempio n. 2
0
    def edit_timesheet(self, task_id, timesheet_id, redirect=None, **post):
        try:
            task_sudo = self._document_check_access('project.task', task_id, None)
        except (AccessError, MissingError):
            return request.render("website.403")

        if post and task_sudo.user_id == request.env.user:
            # START PROCESSING DATA
            error = CustomerPortal.check_timesheet(post)
            if len(error) == 0:
                values = post.copy()
                values['date'] = datetime.strptime(values['date'], '%Y-%m-%d')
                #values['stage_id'] = 'draft'
                timesheet = request.env['account.analytic.line'].sudo().search([('id', '=', timesheet_id)])
                if timesheet and not timesheet.validated:
                    timesheet.write(values)
            return self.portal_my_task(task_id, error=error)
        else:
            return request.render("website.403")
Esempio n. 3
0
    def add_new_timesheet(self, task_id, redirect=None, **post):
        try:
            project_sudo = self._document_check_access('project.task', task_id,
                                                       None)
        except (AccessError, MissingError):
            return request.render("website.403")

        if post:
            # START PROCESSING DATA
            error = CustomerPortal.check_timesheet(post)
            if len(error) == 0:
                vals = post
                vals['date'] = datetime.strptime(vals['date'], '%Y-%m-%d')
                vals['project_id'] = request.env['project.task'].sudo().search(
                    [('id', '=', task_id)]).project_id.id
                vals['task_id'] = task_id
                request.env['account.analytic.line'].create(vals)
            # END OF PROCESSING DATA
            return self.portal_my_task(task_id, error=error)
        else:
            return request.render("website.403")
Esempio n. 4
0
    def edit_timesheet(self, task_id, timesheet_id, redirect=None, **post):
        try:
            task_sudo = self._document_check_access('project.task', task_id,
                                                    None)
        except (AccessError, MissingError):
            return request.render("website.403")

        if post and task_sudo.user_id == request.env.user:
            # START PROCESSING DATA
            error = CustomerPortal.check_timesheet(post)
            if len(error) == 0:
                vals = post
                vals['date'] = datetime.strptime(vals['date'], '%Y-%m-%d')
                vals['stage_id'] = 'draft'
                request.env['account.analytic.line'].sudo().search([
                    ('id', '=', timesheet_id)
                ]).write(vals)
            task_url = '/my/task/{}'.format(task_id)
            return request.redirect(task_url)
        else:
            return request.render("website.403")
Esempio n. 5
0
    def add_new_timesheet(self, task_id, redirect=None, **post):
        try:
            task_sudo = self._document_check_access('project.task', task_id, None)
        except (AccessError, MissingError):
            return request.render("website.403")

        if post and task_sudo.user_id == request.env.user:
            # START PROCESSING DATA
            error = CustomerPortal.check_timesheet(post)
            if not error:

                project = task_sudo.project_id
                if not project:
                    error += [_('Please ask the website administrator to link this task to a project')]

                employee = request.env['hr.employee'].sudo().search([('user_id','=',request.env.user.id)])
                if not employee:
                    error += [_("No external employee found for {}").format(request.env.user.name)]
                
                #Over budget error
                if task_sudo.total_hours_spent + float(post['unit_amount']) > task_sudo.planned_hours:
                    error += [_('Overbudget error, only {} hours remaing in this task. Please contact your lead consultant.').format(task_sudo.planned_hours-task_sudo.total_hours_spent)]

                if not error:
                    values = {
                        'date': datetime.strptime(post['date'], '%Y-%m-%d'),
                        'project_id': project.id,
                        'task_id': task_sudo.id,
                        'employee_id': employee.id,
                        'unit_amount': float(post['unit_amount']),
                        'name': post['name'],
                        'time_category_id': post['time_category_id'],
                    }
                    analytic_line = request.env['account.analytic.line'].sudo().create(values)
                    analytic_line._link_portal_analytic_line_purchase(request.env.user)
                    # END OF PROCESSING DATA
            return self.portal_my_task(task_id, error=error)
        else:
            return request.render("website.403")