-1

The objective is to take the sale date and create a plan for automatic visits, 2 visits per year for three years, and i can do it in older version of odoo but now i get this error.

that worked in openerp 7, but now i want to do it in Odoo 11.0 Python 3, really i don't get it what i missed


    class garantias(models.Model):
        _name = 'itriplee.garantias'

        equipo = fields.Many2one('itriplee.equipos', 'Equipo')
        fecha_de_venta = fields.Date('Fecha de Venta', related='equipo.venta', readonly=True)

     @api.model
        def create(self, vals):
            obj_visita = self.pool.get('itriplee.servicio')
            obj = self.env['itriplee.garantias']
            cliente = obj.cliente.id
            fecha_compra = obj.fecha_de_venta
            fm = ('%Y-%m-%d')
            cantidad_meses = 6
            ind = 0
            now = datetime.now()
            now_str = now.strftime(fm)
            now_int = datetime.strptime(now_str, fm)
            # fecha_compra_original = datetime.strptime(fecha_compra, fm)
            fecha_compra_inicial = datetime.strptime(fecha_compra, fm)
            while ind < cantidad_meses:
                fecha_6_meses = fecha_compra_inicial + relativedelta(months=6)
                if fecha_6_meses >= now_int:
                    obj_visita.create({'cliente':cliente,'visita':fecha_6_meses,'estado':'confirmar','visitas':obj.id},context=None)
                ind = ind + 1
                fecha_compra_inicial = fecha_6_meses
            return True

and get this error:

Traceback (most recent call last):
  File "/home/openerp/odoo-dev/odoo/odoo/http.py", line 651, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/home/openerp/odoo-dev/odoo/odoo/http.py", line 310, in _handle_exception
    raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])
  File "/home/openerp/odoo-dev/odoo/odoo/tools/pycompat.py", line 87, in reraise
    raise value
  File "/home/openerp/odoo-dev/odoo/odoo/http.py", line 693, in dispatch
    result = self._call_function(**self.params)
  File "/home/openerp/odoo-dev/odoo/odoo/http.py", line 342, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/home/openerp/odoo-dev/odoo/odoo/service/model.py", line 97, in wrapper
    return f(dbname, *args, **kwargs)
  File "/home/openerp/odoo-dev/odoo/odoo/http.py", line 335, in checked_call
    result = self.endpoint(*a, **kw)
  File "/home/openerp/odoo-dev/odoo/odoo/http.py", line 937, in __call__
    return self.method(*args, **kw)
  File "/home/openerp/odoo-dev/odoo/odoo/http.py", line 515, in response_wrap
    response = f(*args, **kw)
  File "/home/openerp/odoo-dev/odoo/addons/web/controllers/main.py", line 934, in call_kw
    return self._call_kw(model, method, args, kwargs)
  File "/home/openerp/odoo-dev/odoo/addons/web/controllers/main.py", line 926, in _call_kw
    return call_kw(request.env[model], method, args, kwargs)
  File "/home/openerp/odoo-dev/odoo/odoo/api.py", line 687, in call_kw
    return call_kw_model(method, model, args, kwargs)
  File "/home/openerp/odoo-dev/odoo/odoo/api.py", line 672, in call_kw_model
    result = method(recs, *args, **kwargs)
  File "/home/openerp/odoo-dev/odoo/addons/itriplee/models/garantias.py", line 53, in create
    fecha_compra_inicial = datetime.strptime(fecha_compra, fm).date()
TypeError: strptime() argument 1 must be str, not bool
deceze
  • 510,633
  • 85
  • 743
  • 889
  • Hacve you tried removing the brackets at fm =? – Nathan Jul 17 '19 at 22:54
  • That missing ending apostrophe in `_name = 'itriplee.garantias`, is that in your code too? – ipaleka Jul 17 '19 at 22:57
  • So apparently `obj.fecha_de_venta` is a bool, not a date string. – deceze Jul 17 '19 at 22:58
  • you nedd to add this `if obj.fecha_de_venta:` to assure you can get date value.To Prevent none value cause that error. – Terrence Poe Jul 18 '19 at 00:43
  • The field 'fecha_de_venta' is related to 'equipo.venta' , are you sure the field 'venta' in the model 'itriplee.equipos' , is a date field ? – Ajmal JK Jul 18 '19 at 07:17
  • Thanks for your help. but the problem persist: Nathan I tried but it does not make a difference. Ipaleka there's the apostrophe. Deceze: i know but in theory is a date string. Ajmal JK: try to change the field to one where I enter the value directly but I still give the same error. Terrence Poe: i tried put the "if" after while but the problem persist. – Miguel Zamora Garcia Jul 18 '19 at 15:50

1 Answers1

1

This error occurs when that field is not date string or it contains null value, so it returns False value when it is called.So first make sure that field contains date str when function is called.strptime method requires date string value.

You can use if condition to check whether data is present in field continue strptime method or if you're using pycharm you can add breakpoint to check values

Thayif kabir
  • 715
  • 5
  • 20