İçereği Atla
Menü
Bu soru işaretlendi
3 Cevaplar
16838 Görünümler

Hi, i have this problem with this code that worked in past versions of Odoo:

The objetive is take the sale's date and create visitthe objective is to take the sale date and create a plan for automatic visits, 2 visits per year for three years

class garantias(models.Model):

_name = 'itriplee.garantias'
_rec_name = 'folio'

folio = fields.Integer('Folio', required=True)
cliente = fields.Many2one('res.partner', 'Cliente')
equipo = fields.Many2one('itriplee.equipos', 'Equipo')
serie = fields.Char('Numero de Serie', related='equipo.name', readonly=True)
factura = fields.Char('Numero de Factura', related='equipo.factura', readonly=True)
modelo = fields.Char('Modelo', related='equipo.modelo.name', readonly=True)
marca = fields.Char('Marca', related='equipo.marca', readonly=True)
tipo = fields.Char('Tipo', related='equipo.tipo', readonly=True)
fecha_de_venta = fields.Date('Fecha de Venta', related='equipo.venta', readonly=True)
visitas = fields.One2many('itriplee.servicio', 'garantia_asociada', 'Visitas')
observaciones = fields.Text('Observaciones')
valoracion = fields.Text('Valoración para Poliza')

@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.equipo.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 that gave me 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 83, in create
    fecha_compra_inicial = datetime.strptime(fecha_compra, fm)
TypeError: strptime() argument 1 must be str, not bool

i don't get it, can you help me?

Avatar
Vazgeç
En İyi Yanıt

Hi,

The error is due to the field/variable you have passed will not contain the value, so it will return null/False. So make sure that the variable you passed to strptime hold contains value or not by putting a IF statement.

Thanks

Avatar
Vazgeç
Üretici

You have right, thanks.

En İyi Yanıt

Hello, 

you can add IF condition maybe in your case return value False. So add one condition in your code if now_int and fecha_compra_inicial before fecha_6_meses = fecha_compra_inicial + relativedelta(months=6).

Thanks

Avatar
Vazgeç
Üretici

ok, thanks for the tip

En İyi Yanıt

Hi,

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


Avatar
Vazgeç
Üretici

thanks i see you in stack overflow too. Pycharm is really useful, i didn't know it.

So, my ask was wrong, because the problem is that i can't get the information of a related field of my model. You know how can i do it?

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

that is the field that gave me the False value

İlgili Gönderiler Cevaplar Görünümler Aktivite
2
Şub 24
16266
1
Ara 22
5522
2
Ara 22
15211
2
Haz 22
7251
2
Haz 22
5332