# Create initial stock moves with proteus

**URL:** <https://discuss.tryton.org/t/create-initial-stock-moves-with-proteus/5293>\
**Category:** Developer\
**Tags:** stock\
**Created:** [May 25, 2022, 10:24pm UTC](https://discuss.tryton.org/t/create-initial-stock-moves-with-proteus/5293 "2022-05-25T22:24:21Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![DancesWithHaggises](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/d/71e660/32.png) [@DancesWithHaggises](https://discuss.tryton.org/u/DancesWithHaggises)\
**Post date:** [May 25, 2022, 10:24pm UTC](https://discuss.tryton.org/t/create-initial-stock-moves-with-proteus/5293/1 "2022-05-25T22:24:22Z")

</div>

Hi,

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

> [@Create initial stock moves with proteus on a remote server](https://discuss.tryton.org/t/create-initial-stock-moves-with-proteus-on-a-remote-server/4545):
>
> Hi, We use Tryton 5.6 to manage our stocks. We planned to migrate to Tryton 6.0 with a clean database. So i made some proteus scripts to import specific data (product, lots, stocks). I’m using a postgresql database to store temporary data’s. I’m following this procedure to set initial stock levels from postgresql database: [https://docs.tryton.org/projects/modules-stock/en/latest/setup.html#setting-initial-stock-levels](https://docs.tryton.org/projects/modules-stock/en/latest/setup.html#setting-initial-stock-levels) When doing such stock moves, Tryton is raising a warning about “Moves witho…

I am running tryton 6.4, and I am trying to setup initial stock as detailed in [Setup — Tryton module for stock and inventory](https://docs.tryton.org/projects/modules-stock/en/latest/setup.html#setting-initial-stock-levels)

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?

Please could someone assist?

---

<div class="post-metadata">

**Author:** ![maxx](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/maxx/32/2320_2.png) [@maxx](https://discuss.tryton.org/u/maxx)\
**Post date:** [May 26, 2022, 7:29am UTC](https://discuss.tryton.org/t/create-initial-stock-moves-with-proteus/5293/2 "2022-05-26T07:29:40Z")

</div>

Hi,

Following my post [Create initial stock moves with proteus on a remote server](https://discuss.tryton.org/t/create-initial-stock-moves-with-proteus-on-a-remote-server/4545)  
It was working with the resolution of issue: [Format warning name indepentently of the platform (#10672) · Issues · Tryton / Tryton · GitLab](https://bugs.tryton.org/issue10672)  
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](https://discuss.tryton.org/t/create-initial-stock-moves-with-proteus-on-a-remote-server/4545/2)

---

<div class="post-metadata">

**Author:** ![DancesWithHaggises](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/d/71e660/32.png) [@DancesWithHaggises](https://discuss.tryton.org/u/DancesWithHaggises)\
**Post date:** [May 26, 2022, 8:37am UTC](https://discuss.tryton.org/t/create-initial-stock-moves-with-proteus/5293/3 "2022-05-26T08:37:01Z")

</div>

Hi Maxime,

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?

---

<div class="post-metadata">

**Author:** ![pokoli](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/pokoli/32/22_2.png) [@pokoli](https://discuss.tryton.org/u/pokoli)\
**Post date:** [May 26, 2022, 9:01am UTC](https://discuss.tryton.org/t/create-initial-stock-moves-with-proteus/5293/4 "2022-05-26T09:01:26Z")

</div>

> [@DancesWithHaggises](#):
>
> What mechanism can I use to prevent the MoveOriginWarning from firing?

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.

> [@DancesWithHaggises](#):
>
> ```auto
> warning_name = '%s.done' % hashlib.md5(str(movesw).encode('utf-8')) .hexdigest()
> 
> ```

Note that on 6.4 the [format code has been updated](https://hg.tryton.org/trytond/rev/3a1b5de38374), so you should adapt your script to generate exactly the same string for moves.

---

<div class="post-metadata">

**Author:** ![DancesWithHaggises](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/d/71e660/32.png) [@DancesWithHaggises](https://discuss.tryton.org/u/DancesWithHaggises)\
**Post date:** [May 26, 2022, 9:36am UTC](https://discuss.tryton.org/t/create-initial-stock-moves-with-proteus/5293/5 "2022-05-26T09:36:35Z")

</div>

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=Move()
> move.from_location = supplier_loc
> move.quantity = 10
> ... complete the rest of the move
> moves.append(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()
> self.Move.click(moves, 'do')
> 
> ```

---

<div class="post-metadata">

**Author:** ![system](https://discuss-cdn.tryton.org/uploads/default/original/1X/c6f8ec0a40525cdcd50058c734283450a4b3d38b.png) [@system](https://discuss.tryton.org/u/system)\
**Post date:** [June 25, 2022, 9:37am UTC](https://discuss.tryton.org/t/create-initial-stock-moves-with-proteus/5293/6 "2022-06-25T09:37:11Z")

</div>

Closed on June 25, 2022, 9:37am UTC

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