Instantiate a model object

18 views
Skip to first unread message

Khurram Shahzad

unread,
Mar 29, 2018, 4:50:10 AM3/29/18
to try...@googlegroups.com
Dear All,

I have defined a model class with some attributes, methods for setting default values and on_change() event listener. How can I instantiate it so that I can have its attributes initialized automatically by default_??? methods and when user make some change to fields, the on_change() event gets fired.

In fact, I will show a list of such objects to user and when user is done with entering data, and save them when he clicks 'Process' button of wizard.

--
 
Regards,
Khurram.

Sergi Almacellas Abellana

unread,
Mar 29, 2018, 5:30:13 AM3/29/18
to try...@googlegroups.com
El 29/03/18 a les 09:19, Khurram Shahzad ha escrit:
> Dear All,
>
> I have defined a model class with some attributes, methods for setting
> default values and on_change() event listener. How can I instantiate it
> so that I can have its attributes initialized automatically by
> default_??? methods and when user make some change to fields, the
> on_change() event gets fired.

When you instantiate a model from code default values and on_change are
not applied. This is done on client side.

>
> In fact, I will show a list of such objects to user and when user is
> done with entering data, and save them when he clicks 'Process' button
> of wizard.

What is the user behavior here? It has to create the records or it has
to update some data?

Best way is to show a One2Many field on the wizard. If the user has to
create the records just leave it empty an let them fill the records. If
you have to modify some existing records, just return the ids of the
records as default value and the client will show the record with all
the values of the view.

In both cases the client will automatically call the defaults and
on_change required for user actions.

Hope it helps.

--
Sergi Almacellas Abellana
www.koolpi.com
Twitter: @pokoli_srk

Khurram Shahzad

unread,
Mar 29, 2018, 6:30:09 AM3/29/18
to try...@googlegroups.com
Dear Sergi,

Thanks for the response.

On Thu, Mar 29, 2018 at 2:30 PM, Sergi Almacellas Abellana <se...@koolpi.com> wrote:
El 29/03/18 a les 09:19, Khurram Shahzad ha escrit:
> Dear All,
>
> I have defined a model class with some attributes, methods for setting
> default values and on_change() event listener. How can I instantiate it
> so that I can have its attributes initialized automatically by
> default_??? methods and when user make some change to fields, the
> on_change() event gets fired.

When you instantiate a model from code default values and on_change are
not applied. This is done on client side.

>
> In fact, I will show a list of such objects to user and when user is
> done with entering data, and save them when he clicks 'Process' button
> of wizard.

What is the user behavior here? It has to create the records or it has
to update some data?
 
In fact, we are working on duty roster management. I run a wizard, which shows list of employees and months. The user selects a month and an employee. When employee changes, I fill a One2Many field which contains as many records as days. Here I want default values for every day, like default shift. I also want that when user changes a shift for a day, its time is displayed in next column.

Best way is to show a One2Many field on the wizard. If the user has to
create the records just leave it empty an let them fill the records. If
you have to modify some existing records, just return the ids of the
records as default value and the client will show the record with all
the values of the view.

I am doing the same; but I can not leave the records empty. Moreover, I also want to respond to change events of each record.
 

In both cases the client will automatically call the defaults and
on_change required for user actions.

Hope it helps.

Thanks again.
 
 
Regards,
Khurram.

Sergi Almacellas Abellana

unread,
Mar 29, 2018, 7:04:11 AM3/29/18
to try...@googlegroups.com
El 29/03/18 a les 12:01, Khurram Shahzad ha escrit:
> In fact, we are working on duty roster management. I run a wizard, which
> shows list of employees and months. The user selects a month and an
> employee. When employee changes, I fill a One2Many field which contains
> as many records as days. Here I want default values for every day, like
> default shift.

Then I will probably ask the employee and the month in a state, generate
the records and then use a StateAction to show the created records so
the user can modify whatever they wants.

If you create the records default values will be automatically applied.

I also want that when user changes a shift for a day, its
> time is displayed in next column.
If you need to re-process the records after some action, you can display
the created records on a One2Many and add another transition to do
whatever you need with them.

Khurram Shahzad

unread,
Mar 29, 2018, 11:06:26 PM3/29/18
to try...@googlegroups.com
Thanks a lot. That's perfect.
Reply all
Reply to author
Forward
0 new messages