default for selection field for a state

64 views
Skip to first unread message

Vincent Bastos

unread,
Feb 13, 2016, 5:20:32 AM2/13/16
to tryton
Hey,

I am getting the following error for a state field:

The value "None" of field "State" on "..." is not in the selection.

However I do have the default method in the class:

    @staticmethod
    def default_state():
        return 'draft'

The only thing I am uncertain about is that I have seen this method defined as a class method rather than a static method, but even changing this does nothing.

Just not sure how to troubleshoot at this stage.

Cédric Krier

unread,
Feb 13, 2016, 9:15:04 AM2/13/16
to tryton
On 2016-02-13 02:20, Vincent Bastos wrote:
> Hey,
>
> I am getting the following error for a state field:
>
> The value "None" of field "State" on "..." is not in the selection.
>
> However I do have the default method in the class:
>
> @staticmethod
> def default_state():
> return 'draft'

This means that you are creating a record with the value 'None' for the
state field. The default value method is only used if there is no key
for the field in the dictionary.

> The only thing I am uncertain about is that I have seen this method defined
> as a class method rather than a static method, but even changing this does
> nothing.

staticmethod or classmethod at this point doesn't change but it is
semantically more correct to use a classmethod.

--
Cédric Krier - B2CK SPRL
Email/Jabber: cedric...@b2ck.com
Tel: +32 472 54 46 59
Website: http://www.b2ck.com/

Vincent Bastos

unread,
Feb 13, 2016, 5:44:56 PM2/13/16
to tryton


On Sunday, February 14, 2016 at 12:15:04 AM UTC+10, Cédric Krier wrote:
On 2016-02-13 02:20, Vincent Bastos wrote:
> Hey,
>
> I am getting the following error for a state field:
>
> The value "None" of field "State" on "..." is not in the selection.
>
> However I do have the default method in the class:
>
>     @staticmethod
>     def default_state():
>         return 'draft'

This means that you are creating a record with the value 'None' for the
state field. The default value method is only used if there is no key
for the field in the dictionary.

Tryton is telling me that I am trying to save a record with the field state with a value None, but this field is required, so this is wrong. Right?

How can that be if the selection dictionary does not have any keys with None values, and there is even a default method?

Also, even the client displays the value 'draft' in that field before save button is pressed.

Cédric Krier

unread,
Feb 14, 2016, 5:00:03 AM2/14/16
to tryton
On 2016-02-13 14:44, Vincent Bastos wrote:
>
>
> On Sunday, February 14, 2016 at 12:15:04 AM UTC+10, Cédric Krier wrote:
> >
> > On 2016-02-13 02:20, Vincent Bastos wrote:
> > > Hey,
> > >
> > > I am getting the following error for a state field:
> > >
> > > The value "None" of field "State" on "..." is not in the selection.
> > >
> > > However I do have the default method in the class:
> > >
> > > @staticmethod
> > > def default_state():
> > > return 'draft'
> >
> > This means that you are creating a record with the value 'None' for the
> > state field. The default value method is only used if there is no key
> > for the field in the dictionary.
> >
>
> Tryton is telling me that I am trying to save a record with the field state
> with a value None, but this field is required, so this is wrong. Right?

No, the field is not required but the value None is not in the selection
list.

> How can that be if the selection dictionary does not have any keys with
> None values, and there is even a default method?

I don't understand what you are talking about. What are you calling
"selection dictionary"?
As I said default method is only used if you don't specify a value. Here
it is pretty sure that you put 'None' as value.

> Also, even the client displays the value 'draft' in that field before save
> button is pressed.

You can not trust the client to display the erroneous value because it
is limited to display only value from the selection.

Vincent Bastos

unread,
Feb 15, 2016, 1:15:06 AM2/15/16
to tryton


On Sunday, February 14, 2016 at 8:00:03 PM UTC+10, Cédric Krier wrote:
On 2016-02-13 14:44, Vincent Bastos wrote:
>
>
> On Sunday, February 14, 2016 at 12:15:04 AM UTC+10, Cédric Krier wrote:
> >
> > On 2016-02-13 02:20, Vincent Bastos wrote:
> > > Hey,
> > >
> > > I am getting the following error for a state field:
> > >
> > > The value "None" of field "State" on "..." is not in the selection.
> > >
> > > However I do have the default method in the class:
> > >
> > >     @staticmethod
> > >     def default_state():
> > >         return 'draft'
> >
> > This means that you are creating a record with the value 'None' for the
> > state field. The default value method is only used if there is no key
> > for the field in the dictionary.
> >
>
> Tryton is telling me that I am trying to save a record with the field state
> with a value None, but this field is required, so this is wrong. Right?

No, the field is not required but the value None is not in the selection
list. 

> How can that be if the selection dictionary does not have any keys with
> None values, and there is even a default method?

I don't understand what you are talking about. What are you calling
"selection dictionary"?
As I said default method is only used if you don't specify a value. Here
it is pretty sure that you put 'None' as value.

The available choices for this selection field does not include an option with the value None.
 

> Also, even the client displays the value 'draft' in that field before save
> button is pressed.

You can not trust the client to display the erroneous value because it
is limited to display only value from the selection.


So somehow the client sends the value 'None' for the field State... 

Cédric Krier

unread,
Feb 15, 2016, 3:10:06 AM2/15/16
to tryton
I doubt about that. This is probably your code that does that.

Vincent Bastos

unread,
Feb 15, 2016, 4:25:31 AM2/15/16
to try...@googlegroups.com
--
You received this message because you are subscribed to a topic in the Google Groups "tryton" group.
To view this discussion on the web visit https://groups.google.com/d/msgid/tryton/20160215080812.GE11535%40tetsuo.



--
Vincent Bastos
Lava Lab Software

Vincent Bastos

unread,
Feb 15, 2016, 4:26:07 AM2/15/16
to try...@googlegroups.com
On Mon, Feb 15, 2016 at 6:08 PM, Cédric Krier <cedric...@b2ck.com> wrote:
On 2016-02-14 22:15, Vincent Bastos wrote:
> On Sunday, February 14, 2016 at 8:00:03 PM UTC+10, Cédric Krier wrote:
> >
> > On 2016-02-13 14:44, Vincent Bastos wrote:
> > > Also, even the client displays the value 'draft' in that field before
> > save
> > > button is pressed.
> >
> > You can not trust the client to display the erroneous value because it
> > is limited to display only value from the selection.
> >
>
>
> So somehow the client sends the value 'None' for the field State...

I doubt about that. This is probably your code that does that.

yes, somehow my code tells the client to send that :) ... 

Guillem Barba Domingo

unread,
Feb 18, 2016, 12:10:08 PM2/18/16
to try...@googlegroups.com
It's hard to say without see the code. Can you post the state field definition?

--

Vincent Bastos

unread,
Feb 18, 2016, 4:41:00 PM2/18/16
to try...@googlegroups.com
 Thanks for trying to help Guillem, but I fixed my error. I was missing a field dependency.
Reply all
Reply to author
Forward
0 new messages