Hello I'm making a module ( I'm newbie on odoo), i want add or delete fields depending if a checkbox field value is yes or no, i have this code on my model:
# -*- coding: utf-8 -*-
from odoo import models, fields, api
import time
import requests
class Modulo2(models.Model):
_name = 'modulo2.modulo2'
urlApi = 'http://localhost:8000/api/persons/'
actualYear = time.strftime('%Y')
newPerson = fields.Selection([('yes', 'Yes'), ('no', 'No')], string='Nueva Persona (Si/No)')
if newPerson == 'yes':
nombre = fields.Char(string="Nombre", required=True)
else:
nombre = fields.Char(string="Nombre", required=True)
anioNacimiento = fields.Integer(string="Año de Nacimiento", compute="_obtener_datos", store=True)
edad = fields.Integer(compute="_calcular_edad", store=True)
@api.depends('nombre')
def _obtener_datos(self):
response = requests.get(str(self.urlApi) + str(self.nombre))
if response.text != "not found":
self.anioNacimiento = response.json()['year']
@api.depends('anioNacimiento')
def _calcular_edad(self):
self.edad = int(self.actualYear) - int(self.anioNacimiento)
But this doesn't work, any idea? i use odoo 10 community version, ( sorry for my bad english ), thanks !