Skip to content

[stock_inventory 17.0]: BUG - Wrong stock.move.line is selected on _apply_inventory() method #2499

Description

After yearly inventory i have a lot of mowes with reference to inventory but they are not paired wit it (inventory_adjustment_id on stock.move.lines is Null.

The problem is that filtered changes orders

eg:

            moves = record_moves.search(
                [
                    ("product_id", "=", rec.product_id.id),
                    ("lot_id", "=", rec.lot_id.id),
                    "|",
                    ("location_id", "=", rec.location_id.id),
                    ("location_dest_id", "=", rec.location_id.id),
                ],
                order="create_date asc",
            )

returns
stock.move.line(64837, 483782, 653681, 655690, 661947, 1176881)

and after filtered it gives
stock.move.line(64837, 483782, 1176881, 653681, 655690, 661947)

move 1176881 is proper one but to write it takes inventory_adjustment_id 661947 which is in some cases it is (but not always) 'Product Quantity Confirmed' with 0 quantity.

can You modify it and add .sorted at the end

                moves = record_moves.search(
                    [
                        ("product_id", "=", rec.product_id.id),
                        ("lot_id", "=", rec.lot_id.id),
                        "|",
                        ("location_id", "=", rec.location_id.id),
                        ("location_dest_id", "=", rec.location_id.id),
                    ],
                    order="create_date asc",
                ).filtered(
                    lambda x, rec=rec: not x.company_id.id
                    or not rec.company_id.id
                    or rec.company_id.id == x.company_id.id
                ).sorted(key=lambda m: (m.create_date or fields.Datetime.now(), m.id))

Metadata

Metadata

Assignees

No one assigned

    Labels

    stalePR/Issue without recent activity, it'll be soon closed automatically.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions