On Tuesday, June 2, 2009 12:28:31 PM UTC-3, Cédric Krier wrote:
>
> On 02/06/09 08:11 -0700, dbrenck wrote:
> > 
> > class Party(ModelSQL, ModelView):
> >     """Class: Party(ModelSQL, ModelView)
> >     This class inherits party.party model and adds...
> >     """
> >     _name = "party.party"
> > 
> >     dummy = fields.Function("get_dummy", type="one2many",
> >             relation="dummy.model", string="Dummy",
> >             context="{'id': id}" )
> > 
> >     def get_dummy(...)
> > 
> > This fails with a socket error (displayed by the client, but nothing
> > to see serverside).
> > If I change it to context="{'id': 'id'}" it works nicely - but, of
> > cause, using the string 'id' instead of the partys id.
>
> id is a Python function so you have a socket error because you try to send 
> to
> the server a function which is not marshable.
> You should use active_id
>
>
> > Obviously model inheritance by _name is no real python/class
> > inheritance. But how can I access the model-inherited fields at this 
>
> point?
>
> In fact, it ends with a real Python inheritance.
> But I don't understand what you mean by 'access the model-inherited 
> fields'?
>
> --
>

at which point exactly this happens? Im using gnuhealth which has 
PartyPatient and I just need to add a custom validator, to keep the code 
separated I created a new module installed it and create a new model which 
the only thing in common with PartyPatient (and Party) is the __name__ 
attribute. I can understand dbrenk's point and I still fail to understand 
how extending/inheriting models work. the validate method is not being 
called in my new class.

I could achieve this by monkey patching, but afaik is better to avoid that, 
right?
anyway here is my file, any help will be greatly appreciated:

from trytond.model import ModelView, ModelSQL

__all__ = ['CustomPartyPatient']

class CustomPartyPatient(ModelSQL, ModelView):
    'Party'
    __name__ = 'party.party'

    @classmethod
    def __setup__(cls):
        super(CustomPartyPatient, cls).__setup__()

    @classmethod
    def validate(cls, parties):
        import pdb; pdb.set_trace()
        super(CustomPartyPatient, cls).validate(parties)
        print parties      
        for party in parties:

            party.custom_check_person()

    def custom_check_person(self):
        if self.ref == "someid":
            self.raise_user_error("no puede usar someid como id")



    def __register__(cls, module_name):
        super(CustomPartyPatient, cls).__register__(module_name)



Saludos,
Mariano.

Reply via email to