Create initial stock moves with proteus


I am hitting the exact problem as described in this post:

I am running tryton 6.4, and I am trying to setup initial stock as detailed in Setup — trytond_stock latest documentation

Unfortunately the post doesn’t detail the solution to the problem.

What mechanism can I use to prevent the MoveOriginWarning from firing?

I tried the exact code from the post, but that still leads to MoveOriginWarning being raised.

The code looks like this:

           types = {'customer', 'supplier'}

              def no_origin(move):
                  return ((move.from_location.type in types) ^ (move.to_location.  type in types) and not move.origin)

              movesw = sorted(filter(no_origin, moves))

              warning_name = '%s.done' % hashlib.md5(str(movesw).encode('utf-8'))  .hexdigest()

              self.Warning(user=self.admin_user, name=warning_name, always=True).  save()

    , 'do')

Perhaps you would need to implement a mechanism in trytond to mute such warnings when commands are issued from proteus. Here I could patch trytond, but that would be very inelegant. Is there another way that would work?

Please could someone assist?


Following my post Create initial stock moves with proteus on a remote server
It was working with the resolution of issue: Issue 10672: Format warning name indepentently of the platform - Tryton issue tracker
One missing thing, is to add ‘__lt__’ method in proteus script to allow sorting moves: Create initial stock moves with proteus on a remote server - #2 by maxx

Hi Maxime,

Thanks for your prompt reply, I have added the implementation of __lt__ in proteus/, however if I am not mistaken that alone doesn’t fix the fact that a different warning key is generated, so I am still getting the Warning raised as you mentioned in the post, is there something else needed to complete the solution?

The one thing I can do is catch the Warning, get the name and save the warning before issuing the “do” command again.

Like so:

    try:, 'do')
    except trytond.modules.stock.exceptions.MoveOriginWarning as e:
        print(f"raised {} so we are saving this before retrying")
        self.Warning(user=self.admin_user,, always=True).save(), 'do')  # This call will succeed

This works actually, but did you have anything better?

You should save a record on the warning table that has exactly the same warning_name as the one that should be raised on the server side.

Note that on 6.4 the format code has been updated, so you should adapt your script to generate exactly the same string for moves.

Brilliant, exactly what I was missing. Thank you very much.

For anyone needing this the code that works looks like this:

   types = {'customer', 'supplier'}
   admin_user, = self.User.find([('login', '=', 'admin')])

   def no_origin(move):
       return ((move.from_location.type in types)
           ^ (move.to_location.type in types)
               and not move.origin)

   moves = []
   move.from_location = supplier_loc
   move.quantity = 10
   ... complete the rest of the move

   movesw = sorted(filter(no_origin, moves))

   key = '|'.join(map(str, movesw)).encode('utf-8')
   warning_name = "%s.done" % (hashlib.md5(key).hexdigest())

   self.Warning(user=admin_user, name=warning_name, always=True).save(), 'do')

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.