# Filtering outgoing moves and using domain on function field

**URL:** https://discuss.tryton.org/t/filtering-outgoing-moves-and-using-domain-on-function-field/6941
**Category:** Developer
**Tags:** stock
**Created:** [February 1, 2024, 8:52am UTC](https://discuss.tryton.org/t/filtering-outgoing-moves-and-using-domain-on-function-field/6941 "2024-02-01T08:52:11Z")
**Posts on this page:** 9
**Page:** 1

<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: [February 1, 2024, 8:52am UTC](https://discuss.tryton.org/t/filtering-outgoing-moves-and-using-domain-on-function-field/6941/1 "2024-02-01T08:52:12Z")

</div>

Hi,

I think the question was already asked but i don’t find where. Why is is necessary to have outgoing moves with quantity 0 in picked state on customer shipments ?

 ![2024-02-01_09-27](https://discuss-cdn.tryton.org/uploads/default/original/2X/8/840296799bf8df3f218c9be15dc39dfc48fa0981.png)

So i tried to make a custo.  
The field “outgoing\_moves” is a Function field on One2Many field.

```auto
    outgoing_moves = fields.Function(fields.One2Many('stock.move', 'shipment',
            'Outgoing Moves',
            domain=[
                If(Eval('warehouse_output') == Eval('warehouse_storage'),
                    ('from_location', 'child_of',
                        [Eval('warehouse_output', -1)], 'parent'),
                    ('from_location', '=', Eval('warehouse_output'))),
                If(~Eval('state').in_(['done', 'cancelled']),
                    ('to_location', '=', Eval('customer_location')),
                    ()),
                ('company', '=', Eval('company')),
                ],
            order=[
                ('product', 'ASC'),
                ('id', 'ASC'),
                ],
            states={
                'readonly': (Eval('state').in_(
                        If(Eval('warehouse_storage')
                            == Eval('warehouse_output'),
                            ['done', 'cancelled'],
                            ['waiting', 'packed', 'done', 'cancelled'],
                            ))
                    | ~Eval('warehouse') | ~Eval('customer')),
                },
            help="The moves that send the stock to the customer."),
        'get_outgoing_moves', setter='set_outgoing_moves')

```

To remove moves with quantity =0, I did with adding such line in the domain:

```auto
...
            domain=[
                ...
                ('company', '=', Eval('company')),
                ('quantity', '!=', 0),
                ],

```

But this is not working. It’s seems domain is useless when using Function field. (???)  
The only way I found was to limit the results in the method ‘get\_outgoing\_moves’.  
Thanks for help 🙂

---

<div class="post-metadata">

### Author: ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)
#### Post date: [February 1, 2024, 8:54am UTC](https://discuss.tryton.org/t/filtering-outgoing-moves-and-using-domain-on-function-field/6941/2 "2024-02-01T08:54:46Z")

</div>

Because deleting them before doing the shipment will trigger the sale workflow earlier before the shipment being actually done.

---

<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: [February 1, 2024, 9:01am UTC](https://discuss.tryton.org/t/filtering-outgoing-moves-and-using-domain-on-function-field/6941/3 "2024-02-01T09:01:24Z")

</div>

Ok, but it’s not needed to display them.

---

<div class="post-metadata">

### Author: ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)
#### Post date: [February 1, 2024, 9:02am UTC](https://discuss.tryton.org/t/filtering-outgoing-moves-and-using-domain-on-function-field/6941/4 "2024-02-01T09:02:38Z")

</div>

It is needed to be in the fields otherwise the code is broken.

---

<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: [February 1, 2024, 9:09am UTC](https://discuss.tryton.org/t/filtering-outgoing-moves-and-using-domain-on-function-field/6941/5 "2024-02-01T09:09:07Z")

</div>

> [@ced](#):
>
> Because deleting them before doing the shipment will trigger the sale workflow earlier before the shipment being actually done.

Ok.

So, for my case, I’ve defined another field called ‘outgoing\_moves\_display’ without moves with quantity = 0.  
What about the use of the domain when using a Function field on One2Many field ?

I tried such thing to test the domain: (‘id’, ‘in’, Eval(‘inventory\_moves’)),  
and it seems useless: displayed moves are moves returned by the “get\_outgoing\_moves\_display” method

```auto
 outgoing_moves_display = fields.Function(fields.One2Many('stock.move', 'shipment',
            'Outgoing Moves Display',
            domain=[
                ('id', 'in', Eval('inventory_moves')),
                ],
            order=[
                ('product', 'ASC'),
                ('id', 'ASC'),
                ],
            states={
                'readonly': (Eval('state').in_(
                        If(Eval('warehouse_storage')
                            == Eval('warehouse_output'),
                            ['done', 'cancelled'],
                            ['waiting', 'packed', 'done', 'cancelled'],
                            ))
                    | ~Eval('warehouse') | ~Eval('customer')),
                },
            help="The moves that send the stock to the customer."),
        'get_outgoing_moves_display', setter='set_outgoing_moves_display')

```

Is it a bug ?

---

<div class="post-metadata">

### Author: ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)
#### Post date: [February 1, 2024, 9:24am UTC](https://discuss.tryton.org/t/filtering-outgoing-moves-and-using-domain-on-function-field/6941/6 "2024-02-01T09:24:10Z")

</div>

The content of a Function field is only defined by its `getter`.

---

<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: [February 1, 2024, 9:27am UTC](https://discuss.tryton.org/t/filtering-outgoing-moves-and-using-domain-on-function-field/6941/7 "2024-02-01T09:27:36Z")

</div>

Ok. So, why using a domain on field “outgoing\_moves” ?

---

<div class="post-metadata">

### Author: ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)
#### Post date: [February 1, 2024, 9:28am UTC](https://discuss.tryton.org/t/filtering-outgoing-moves-and-using-domain-on-function-field/6941/8 "2024-02-01T09:28:36Z")

</div>

To have domain inversion at creation.

---

<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: [February 1, 2024, 9:29am UTC](https://discuss.tryton.org/t/filtering-outgoing-moves-and-using-domain-on-function-field/6941/9 "2024-02-01T09:29:26Z")

</div>

Thanks for explanations 🙂
