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()
self.Move.click(moves, '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?
Thanks for your prompt reply, I have added the implementation of __lt__ in proteus/__init__.py, 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:
self.Move.click(moves, 'do')
except trytond.modules.stock.exceptions.MoveOriginWarning as e:
print(f"raised {e.name} so we are saving this before retrying")
self.Warning(user=self.admin_user, name=e.name, always=True).save()
self.Move.click(moves, 'do') # This call will succeed
This works actually, but did you have anything better?