Prefilling fields with the values of last writed record

31 views
Skip to first unread message

Guzmán Olivera

unread,
May 2, 2016, 3:05:04 PM5/2/16
to tryton
Hello everybody, basically I want to pre fill Formulario's fields with some specific values. Formulario is a class which is related with other class called "Paciente". With specific values I mean I want to create a new Formulario with the last entered values of a Formulario's record. Supose you have this case:

1 - Create a new Paciente
2 - Create a new Formulario and fill some fields
3 - Create other Formulario. Here I am trying to get the already filled fields filled. This is what I want to achieve.

That classes are defined as follows:

class Formulario(Workflow, ModelSQL,ModelView):
'Formulario'
_name = 'cefiro.formulario'
_description = __doc__
_rec_name = 'fecha'

paciente = fields.Many2One('cefiro.paciente','Paciente') # Don't understand why here is Many2One and the other was One2One
## Here I have more fields but I only put one here in order to simplify:
motivoPaciente1 = fields.Char(u'Motivo según el paciente (1)')

...

Formulario()

And the related class "Paciente" is declared as follows:

class Paciente(Persona,Workflow):
'Paciente'
_name = 'cefiro.paciente'
_description = __doc__

formularioInicial = fields.One2Many('cefiro.formulario', 'paciente', 'Formulario Inicial') 

I was looking at this https://groups.google.com/forum/#!msg/tryton-dev/Kwwp-SHdP0M/tBXT1gKhrOIJ and trying to adapt to my situation field by field. I don't know if you can get this easier. Any suggestions are welcomed!

Thank you in advance

Cédric Krier

unread,
May 3, 2016, 3:00:04 AM5/3/16
to tryton
On 2016-05-02 11:20, Guzmán Olivera wrote:
> I was looking at this
> https://groups.google.com/forum/#!msg/tryton-dev/Kwwp-SHdP0M/tBXT1gKhrOIJ
> and trying to adapt to my situation field by field. I don't know if you can
> get this easier. Any suggestions are welcomed!

I guess you have to write a default function for each field and this
method will search the last created record and return the value of the
corresponding field.

--
Cédric Krier - B2CK SPRL
Email/Jabber: cedric...@b2ck.com
Tel: +32 472 54 46 59
Website: http://www.b2ck.com/
Reply all
Reply to author
Forward
0 new messages