Filtering outgoing moves and using domain on function field

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 ?

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

    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:

...
            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 :slight_smile:

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

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

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

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

 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 ?

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

Ok. So, why using a domain on field “outgoing_moves” ?

To have domain inversion at creation.

Thanks for explanations :slight_smile: