Comment 4 for bug 1174650

Revision history for this message
Carlos Pueyo (cpueyo) wrote :

Ok. I do too a patch for create method.

Write Method:

Same of comment #2

Create Method Override:

    def _check_estado_hoja(self, cr, uid, ids, context=None):
        osv.logging.log(100, "[Alca] _check_estado_hoja:hr_analytic_timesheet:hr_timesheet_project")
        if context is None:
            context = {}
        bSheet = self.pool.get("hr_timesheet_sheet.sheet").browse(cr, uid, ids[0], context=context)
        if hasattr(bSheet, 'state') and bSheet.state not in ('draft', 'new'):
            return False
        return True

    def create(self, cr, uid, vals, *args, **argv):
        osv.logging.log(100, "[Alca] create:hr_analytic_timesheet:hr_timesheet_project" + str(vals))
        id_hr = super(hr_analytic_timesheet, self).create(cr, uid, vals, *args, **argv)

        sheet = self._sheet(cr, uid, [id_hr], None, None)

        if sheet:
            sheet_id = sheet.values()[0][0]
        # Comprobamos el estado de la hoja
        estado = self._check_estado_hoja(cr, uid, [sheet_id])
        # Si el estado es False, significa que esta cerrada
        if estado is False:
            # Comprobamos si hay valores modificados
            if vals:
                raise osv.except_osv(_('Error!'),
                    _('You cannot create an entry in a Confirmed/Done timesheet!'))
            else:
                # Si no hay valores modificados, limpiamos los identificadores, para poder saltarnos la comprobacion
                ids = []

        return id_hr