Problem saving registers on workflow form

50 views
Skip to first unread message

Francisco Maria Moyano Casco

unread,
Aug 17, 2017, 1:01:18 AM8/17/17
to tryton
Hi,
I'm using tryton 3.8. I'm trying to make a workflow that goes from draft state to request state. I defined the transitions, updates, and buttons:

@classmethod
def __setup__(cls):
super(myClass, cls).__setup__()
cls._transitions |= set((
('draft','request'),
))

cls._buttons.update({
'draft': {
'invisible': Eval('state').in_(['request']),
},
'request': {
'invisible': Eval('state').in_(['draft']),
},
})

@classmethod
@ModelView.button
@Workflow.transition('request')
def draft(cls, myRequests):
..........
cls.write(myRequests,{
'request_date': datetime.now(),
})


The thing is, that I had defined two pair of views for the same model.
On both pair when I clicked on the draft button, doesn't save the register. Only does what it has to do (put the datetime.now() on request_date field).
When I wanted to close the form, one of the form only close after confirm the a save message.
On the other form, it doesn't close. Ask me over and over again to save the register.

When I comment the line cls.write(....), acts normally, but doesn't do what I want it to do.

Cédric Krier

unread,
Aug 17, 2017, 3:00:06 AM8/17/17
to tryton
Is 'request_date' a Date field? Or is it a DateTime?
If it is a Date, you must use date.today() instead of datetime.now()
(and even better to use Pool().get('ir.date').today())

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

Francisco Maria Moyano Casco

unread,
Aug 17, 2017, 3:06:09 AM8/17/17
to tryton
It is a DateTime. But the issue is not there. If I use another field, say a Char, it acts like I just described.

Francisco Maria Moyano Casco

unread,
Aug 18, 2017, 7:47:22 AM8/18/17
to tryton
I try using intermediate functions to do cls.write(...), but the problem isn,t gone. Always ask me to save register in a weird behaviour. Even remove the @Workflow.transition() decorator

Sebastián Marró

unread,
Aug 18, 2017, 7:55:13 AM8/18/17
to try...@googlegroups.com
Hi Francisco


2017-08-17 2:01 GMT-03:00 Francisco Maria Moyano Casco <moyanocasco...@gmail.com>:
Hi,
    I'm using tryton 3.8. I'm trying to make a workflow that goes from draft state to request state. I defined the transitions, updates, and buttons:

     @classmethod
     def __setup__(cls):
       super(myClass, cls).__setup__()
       cls._transitions |= set((
          ('draft','request'),
         ))

       cls._buttons.update({
          'draft': {
              'invisible': Eval('state').in_(['request']),
              },
          'request': {
              'invisible': Eval('state').in_(['draft']),
              },
              })

    @classmethod
    @ModelView.button
    @Workflow.transition('request')
    def draft(cls, myRequests):


I think you have defined wrong the transition decorator or the method name... For the request button should be something like:
    @Workflow.transition('request')
    def request(cls, myRequests):

(You have mixed transition request and method draft in your code... )

Regards

Sebastián Marró

Francisco Maria Moyano Casco

unread,
Aug 21, 2017, 1:34:33 PM8/21/17
to tryton
> (You have mixed transition request and method draft in your code... )
>
>
> Regards
>
>
> Sebastián Marró

Hello Seba,
Thanks for the answer! But, no it isn't that.

I'm using the richtext widget on a text field, and that is the problem. When a take it off, the problem is solved by itself. When I put it back, the problem is on again.

Can anyone confirm this kind of behaviour? Maybe is a bug.

Regards,
Francisco

Francisco Maria Moyano Casco

unread,
Aug 21, 2017, 4:15:45 PM8/21/17
to tryton
I study all the alternatives, and this how to reproduce this issue:

1. Make a fields.Char or a fields.Text. For now, we will call it simple_string:
class MyClass(Workflow, ModelSQL, ModelView):
....
simple_string = fields.Char('My string')
....
2. Add now the transitions and define a button to it:

@classmethod
def __setup__(cls):
super(MyClass, cls).__setup__()
cls._transitions |= set((
('draft','request'),
))

cls._buttons.update({
'draft': {
'invisible': Eval('state').in_(['draft']),
},
'request': {
'invisible': Eval('state').in_(['request']),
},
})

@classmethod
@ModelView.button
@Workflow.transition('request')
def request(cls, myRequests):
..........
cls.write(myRequests,{
'simple_string': 'something something',
})

3. Make a view with a form,menuitem, etc.., and put the field and the button on it, but using the richtext widget on the field
<label name="simple_string"/>
<field name="simple_string" widget="richtext"/>
<button name="request" string="_Request"/>

4. Click on the button, and observe that the form will not be saved as it would be without the richtext widget.

Can anyone confirm this? Thanks

Francisco






Francisco Maria Moyano Casco

unread,
Aug 21, 2017, 5:57:58 PM8/21/17
to tryton
Finally, I get it!!!
On the cls.write(), have to be this way:
cls.write(myRequests,{
'simple_string': '<div>something something</div>',
})

Things get complicated if you want to add some other string, but conserving the one you have. You need to do the following:

for each_request in myRequests:
new_simple_string = simple_string.replace('<div>', '').replace('</div>', '')
cls.write([each_request],{
'simple_string': '<div>'+str(new_simple_string) \
+'somthing else </div>'
})

Regards
Francisco

Sergi Almacellas Abellana

unread,
Aug 22, 2017, 3:18:39 AM8/22/17
to try...@googlegroups.com
El 21/08/17 a les 19:34, Francisco Maria Moyano Casco ha escrit:
This is probably https://bugs.tryton.org/issue6520

Can you confirm?

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

Francisco Maria Moyano Casco

unread,
Aug 25, 2017, 7:57:59 AM8/25/17
to tryton
El martes, 22 de agosto de 2017, 4:18:39 (UTC-3), Sergi Almacellas Abellana escribió:
> El 21/08/17 a les 19:34, Francisco Maria Moyano Casco ha escrit:
> >> (You have mixed transition request and method draft in your code... )
> >>
> >>
> >> Regards
> >>
> >>
> >> Sebastián Marró
> > Hello Seba,
> > Thanks for the answer! But, no it isn't that.
> >
> > I'm using the richtext widget on a text field, and that is the problem. When a take it off, the problem is solved by itself. When I put it back, the problem is on again.
> >
> > Can anyone confirm this kind of behaviour? Maybe is a bug.
> This is probably https://bugs.tryton.org/issue6520
>
> Can you confirm?

Sorry, but I don't understand what is a normalized format.
Anyway, I solved it like I posted it before.

Regards,
Francisco

Reply all
Reply to author
Forward
0 new messages