from otree.api import * c = cu doc = 'Declaracion del Impuesto, control y grupos tratados' class C(BaseConstants): # built-in constants NAME_IN_URL = 'Segunda_ronda' PLAYERS_PER_GROUP = None NUM_ROUNDS = 1 # user-defined constants TASA_TX = 0.2 TASA_TX2 = 0.4 TASA1 = '20%' TASA2 = '40%' SANCION = 0.15 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): Income_2 = models.IntegerField(label='¿Cuál fue el su ingreso a declarar?', min=0) class Defensa_Ronda1(Page): form_model = 'player' form_fields = ['Income_2'] @staticmethod def is_displayed(player: Player): participant = player.participant return participant.random==2 @staticmethod def error_message(player: Player, values): participant = player.participant if values['Income_2'] > participant.task_payment2: return "El Ingreso Declarado NO puede ser mayor al Ingreso Ganado" class Salud_Ronda1(Page): form_model = 'player' form_fields = ['Income_2'] @staticmethod def is_displayed(player: Player): participant = player.participant return participant.random==1 @staticmethod def error_message(player: Player, values): participant = player.participant if values['Income_2'] > participant.task_payment2: return "El Ingreso Declarado NO puede ser mayor al Ingreso Ganado" class Resultados(Page): form_model = 'player' @staticmethod def vars_for_template(player: Player): return dict( tx_2= int (player.Income_2 * C.TASA_TX) ) @staticmethod def before_next_page(player: Player, timeout_happened): participant = player.participant participant.Income_declarado2= player.Income_2 participant.CTX2= C.TASA_TX participant.TX2= player.Income_2 * C.TASA_TX participant.subdeclara_r2=participant.task_payment2-player.Income_2 if participant.prob_audit == 10: participant.sancion_r2 =int( 1.5 *0.2* participant.subdeclara_r2) else: participant.sancion_r2 = 0 class Auditoria2(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): participant = player.participant return participant.prob_audit==10 @staticmethod def vars_for_template(player: Player): participant = player.participant return dict( sancion_r2= int(1.5* C.TASA_TX * participant.subdeclara_r2) ) @staticmethod def before_next_page(player: Player, timeout_happened): pass class No_Auditoria2(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): participant = player.participant return participant.prob_audit!=10 page_sequence = [Defensa_Ronda1, Salud_Ronda1, Resultados, Auditoria2, No_Auditoria2]