Odoo Mindscape. Understand Odoo faster. Explore modules, fields, dependencies and version differences in one place instead of digging through the source code.

Module: Stock Release Channels

Entity: stock.release.channel

Compute Method: _compute_picking_chain

Inputs Method Outputs
self.env["stock.move"].flush_model(
            ["move_dest_ids", "move_orig_ids", "picking_id"]
        )
self.env["stock.picking"].flush_model(["state"])
domain = self._field_picking_domains()["released"]
domain += [("release_channel_id", "in", self.ids)]
released = self.env["stock.picking"].search(domain)
if not released:
            for channel in self:
                channel.picking_chain_ids = False
                channel.count_picking_chain = 0
                channel.count_picking_chain_in_progress = 0
                channel.count_picking_chain_done = 0
            return
self.env.cr.execute(*self._query_get_chain(released))
rows = self.env.cr.dictfetchall()
rows_by_channel = dict(groupby(rows, key=itemgetter("release_channel_id")))
for channel in self:
            rows = rows_by_channel.get(channel.id, [])
            channel.picking_chain_ids = [row["picking_id"] for row in rows]
            channel.count_picking_chain_in_progress = sum(
                [1 for row in rows if row["state"] not in ("cancel", "done")]
            )
            channel.count_picking_chain_done = sum(
                [1 for row in rows if row["state"] == "done"]
            )
            channel.count_picking_chain = (
                channel.count_picking_chain_done
                + channel.count_picking_chain_in_progress
            )

Back to entity