Discussion:
[tryton-es] herencia en tryton super() no tiene atributo (AttributeError)
Maicoly Guerrero
2018-09-28 15:03:24 UTC
Permalink
Buenos dias ***@s,
tengo un problema en una herencia:

Clase Padre:


class CreatePurchase(Wizard):
__name__ = 'first.something1'
// data

@staticmethod
def _group_purchase_key(requests, request):
return (
('company', request.company),
/// mas data
)

y en otro archivo tengo

class CreatePurchase:
__metaclass__ = PoolMeta
__name__ = 'first.something1'

@staticmethod
def _group_purchase_key(requests, request):
result =
super(CreatePurchase,CreatePurchase)._group_purchase_key(
requests,request)
result += (('poa', request.poa), ('department',
request.department))
return result

y me arroja esto en consola:

AttributeError: 'super' object has no attribute '_group_purchase_key'
Sergi Almacellas Abellana
2018-09-28 17:04:18 UTC
Permalink
        __name__ = 'first.something1'
       // data
              return (
                ('company', request.company),
                /// mas data
              )
y en otro archivo tengo
        __metaclass__ = PoolMeta
        __name__ = 'first.something1'
          result =
         super(CreatePurchase,CreatePurchase)._group_purchase_key(
         requests,request)
         result += (('poa', request.poa), ('department',
         request.department))
         return result
    AttributeError: 'super' object has no attribute '_group_purchase_key'
Para heredar un método estatico lo tiense que hacer convertir a
classmethod (de hecho en python ambos son equivalentes).

Tu código deberia ser:

@classmethod
def _group_purchase_key(cls, requests, request):
result =
super(CreatePurchase, cls)._group_purchase_key(
requests,request)
result += (('poa', request.poa), ('department',
request.department))
return result

Si estas en python3 usando super() te deberia funcionar sin problemas.

Un saludo,
--
Sergi Almacellas Abellana
www.koolpi.com
Twitter: @pokoli_srk
Maicoly Guerrero
2018-09-28 18:02:09 UTC
Permalink
Si, se pudo realizar.
Muchas gracias Sergi, lo tendré en cuenta a futuro.

Además se solucionó de otra manera con ayuda de @perilla
se observa que no se importa 'CreatePurchase' es decir:
from trytond.modules.purchase_request import CreatePurchase

Un saludo!!

El vie., 28 sept. 2018 a las 12:04, Sergi Almacellas Abellana (<
Post by Maicoly Guerrero
Post by Maicoly Guerrero
__name__ = 'first.something1'
// data
@staticmethod
return (
('company', request.company),
/// mas data
)
y en otro archivo tengo
__metaclass__ = PoolMeta
__name__ = 'first.something1'
@staticmethod
result =
super(CreatePurchase,CreatePurchase)._group_purchase_key(
requests,request)
result += (('poa', request.poa), ('department',
request.department))
return result
AttributeError: 'super' object has no attribute
'_group_purchase_key'
Para heredar un método estatico lo tiense que hacer convertir a
classmethod (de hecho en python ambos son equivalentes).
@classmethod
result =
super(CreatePurchase, cls)._group_purchase_key(
requests,request)
result += (('poa', request.poa), ('department',
request.department))
return result
Si estas en python3 usando super() te deberia funcionar sin problemas.
Un saludo,
--
Sergi Almacellas Abellana
www.koolpi.com
Sergi Almacellas Abellana
2018-10-01 07:27:15 UTC
Permalink
Post by Maicoly Guerrero
from trytond.modules.purchase_request import CreatePurchase
No debes importar la misma classe para hacer herencia de ella misma en
el pool, sinó que lo debes registrar con el mismo __name__ y Tryton se
encarga de construir la classe final

Saludos,
--
Sergi Almacellas Abellana
www.koolpi.com
Twitter: @pokoli_srk
Maicoly Guerrero
2018-10-01 20:48:22 UTC
Permalink
Si, muchas gracias Sergi.
Al final seguimos tu consejo.
Saludos!!

El lun., 1 oct. 2018 a las 2:30, Sergi Almacellas Abellana (<
Post by Sergi Almacellas Abellana
Post by Maicoly Guerrero
from trytond.modules.purchase_request import CreatePurchase
No debes importar la misma classe para hacer herencia de ella misma en
el pool, sinó que lo debes registrar con el mismo __name__ y Tryton se
encarga de construir la classe final
Saludos,
--
Sergi Almacellas Abellana
www.koolpi.com
Loading...