herencia en tryton super() no tiene atributo (AttributeError)

22 views
Skip to first unread message

Maicoly Guerrero

unread,
Sep 28, 2018, 11:03:25 AM9/28/18
to tryton-es
Buenos dias amig@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

unread,
Sep 28, 2018, 1:04:22 PM9/28/18
to tryt...@googlegroups.com
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

unread,
Sep 28, 2018, 2:02:22 PM9/28/18
to tryt...@googlegroups.com
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!!

Sergi Almacellas Abellana

unread,
Oct 1, 2018, 3:30:19 AM10/1/18
to tryt...@googlegroups.com
On 9/28/18 8:02 PM, Maicoly Guerrero wrote:
>
> 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
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,

Maicoly Guerrero

unread,
Oct 1, 2018, 4:48:35 PM10/1/18
to tryt...@googlegroups.com
Si, muchas gracias Sergi.
Al final seguimos tu consejo.
Saludos!!
Reply all
Reply to author
Forward
0 new messages