'''
Created on Apr 10, 2013

@author: egiraldo
'''
from django.forms import widgets
from rest_framework import serializers
from transacciones.models import Transaccion
class TransaccionSerializer(serializers.Serializer):
    id_transaccion = serializers.Field()  # Note: `Field` is an untyped read-only field.
    id_modulo = serializers.Field()  # Note: `Field` is an untyped read-only field.
    nombre = serializers.CharField(widget=widgets.Textarea,max_length=200)
    descripcion = serializers.CharField(widget=widgets.Textarea,max_length=200)
    id_tipo_comprobante = serializers.Field()
    id_tabla = serializers.Field()
    descripcion_conceptos = serializers.CharField(widget=widgets.Textarea,max_length=200)
    codigo_conceptos = serializers.CharField(widget=widgets.Textarea,max_length=200)
    id_cpto = serializers.CharField(widget=widgets.Textarea,max_length=200)
    aplica_concepto = serializers.CharField(widget=widgets.Textarea,max_length=1)
    id_cen_op_con=serializers.Field()
    def restore_object(self, attrs, instance=None):
        if instance:
            # Update existing instance
            instance.id_modulo = attrs.get('id_modulo', instance.id_modulo)
            instance.nombre = attrs.get('nombre', instance.nombre)
            instance.descripcion = attrs.get('descripcion', instance.descripcion)
            instance.id_tipo_comprobante = attrs.get('id_tipo_comprobante', instance.id_tipo_comprobante)
            instance.id_tabla = attrs.get('id_tabla', instance.id_tabla)
            instance.descripcion_conceptos = attrs.get('descripcion_conceptos', instance.descripcion_conceptos)
            instance.codigo_conceptos = attrs.get('codigo_conceptos', instance.codigo_conceptos)
            instance.id_cpto = attrs.get('id_cpto', instance.id_cpto)
            instance.aplica_concepto = attrs.get('aplica_concepto', instance.aplica_concepto)
            instance.id_cen_op_con = attrs.get('id_cen_op_con', instance.id_cen_op_con)
            return instance
        # Create new instance
        return Transaccion(**attrs)
