from otree.api import * c = cu doc = 'Declaracion del Impuesto, control y grupos tratados' class C(BaseConstants): # built-in constants NAME_IN_URL = 'Primera_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_R1 = models.IntegerField(label='¿Cuál fue el su ingreso a declarar?', min=0) class Ronda1(Page): form_model = 'player' form_fields = ['Income_R1'] @staticmethod def error_message(player: Player, values): participant = player.participant if values['Income_R1'] > participant.task_payment1: 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( tx1= int(player.Income_R1 * C.TASA_TX) ) @staticmethod def before_next_page(player: Player, timeout_happened): participant = player.participant participant.Income_declarado1= player.Income_R1 participant.CTX1= C.TASA_TX participant.TX1= player.Income_R1 * C.TASA_TX participant.subdeclara_r1=participant.task_payment1-player.Income_R1 if participant.prob_audit == 4: participant.sancion_r1 = int(1.5*0.2 * participant.subdeclara_r1) else: participant.sancion_r1 = 0 class Auditoria1(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): participant = player.participant return participant.prob_audit==4 @staticmethod def vars_for_template(player: Player): participant = player.participant return dict( sancion_r1=int(1.5* C.TASA_TX * participant.subdeclara_r1) ) @staticmethod def before_next_page(player: Player, timeout_happened): pass class No_auditoria(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): participant = player.participant return participant.prob_audit!=4 page_sequence = [Ronda1, Resultados, Auditoria1, No_auditoria]