This question has been flagged
2 Replies
120 Views

I'm working with v15. When order which requires resupply order is cancelled the stock that was initially reserved from subcontracting location stay reserved (the available quantity doesn't go up) which creates an overstocking of components on the supplier side. Cancelling the PO, MO and SO doesn't change it at all. On hand quantity doesn't change. How can the stock be unreserved when order is cancelled?

Avatar
Discard

To ensure understanding, is the reference to subcontract orders, that have been cancelled after the material has been transferred to supplier or prior to validating transfer?

Author

We keep some stock in the subcontracting location, available for the supplier to use when orders come in, so when it's available the resupply order isn't raised and the stock is taken from that location. So when the order is raised that stock is reserved and when cancelled it stays reserved, but the On hand quantity stays the same. Hope this explains.

Best Answer

Actually odoo have some resevation issues still they are not rectified. We are in Odoo 16 EE.

Whenever reservation issues are coming we need to run the server actions given by Odoo as temporoy solution.

There is no reply after that..!

Component Reservation Issue

------------------------------------

# Available variables:
#  - env: Odoo Environment on which the action is triggered
#  - model: Odoo Model of the record on which the action is triggered; is a void recordset
#  - record: record on which the action is triggered; may be void
#  - records: recordset of all records on which the action is triggered in multi-mode; may be void
#  - time, datetime, dateutil, timezone: useful Python libraries
#  - float_compare: Odoo function to compare floats based on specific precisions
#  - log: log(message, level='info'): logging function to record debug information in ir.logging table
#  - UserError: Warning Exception to use with raise
#  - Command: x2Many commands namespace
# To return an action, assign: action = {...}

quants = env["stock.quant"].search([])

move_line_ids = []

warning = ""

for quant in quants:

    move_lines = env["stock.move.line"].search(

        [

            ("product_id", "=", quant.product_id.id),

            ("location_id", "=", quant.location_id.id),

            ("lot_id", "=", quant.lot_id.id),

            ("package_id", "=", quant.package_id.id),

            ("owner_id", "=", quant.owner_id.id),

            ("reserved_qty", "!=", 0),

        ]

    )

    move_line_ids += move_lines.ids

    reserved_on_move_lines = sum(move_lines.mapped("reserved_qty"))

    move_line_str = str.join(

        ", ", [str(move_line_id) for move_line_id in move_lines.ids]

    )



    if quant.location_id.should_bypass_reservation():

        # If a quant is in a location that should bypass the reservation, its `reserved_quantity` field

        # should be 0.

        if quant.reserved_quantity != 0:

            quant.write({"reserved_quantity": 0})

    else:

        # If a quant is in a reservable location, its `reserved_quantity` should be exactly the sum

        # of the `reserved_qty` of all the partially_available / assigned move lines with the same

        # characteristics.

        if quant.reserved_quantity == 0:

            if move_lines:

                move_lines.with_context(bypass_reservation_update=True).write(

                    {"reserved_uom_qty": 0}

                )

        elif quant.reserved_quantity
            quant.write({"reserved_quantity": 0})

            if move_lines:

                move_lines.with_context(bypass_reservation_update=True).write(

                    {"reserved_uom_qty": 0}

                )

        else:

            if reserved_on_move_lines != quant.reserved_quantity:

                move_lines.with_context(bypass_reservation_update=True).write(

                    {"reserved_uom_qty": 0}

                )

                quant.write({"reserved_quantity": 0})

            else:

                if any(move_line.reserved_qty
                    move_lines.with_context(bypass_reservation_update=True).write(

                        {"reserved_uom_qty": 0}

                    )

                    quant.write({"reserved_quantity": 0})



move_lines = env["stock.move.line"].search(

    [

        ("product_id.type", "=", "product"),

        ("reserved_qty", "!=", 0),

        ("id", "not in", move_line_ids),

    ]

)



move_lines_to_unreserve = []



for move_line in move_lines:

    if not move_line.location_id.should_bypass_reservation():

        move_lines_to_unreserve.append(move_line.id)



if len(move_lines_to_unreserve) > 1:

    env.cr.execute(

        """

            UPDATE stock_move_line SET reserved_uom_qty = 0, reserved_qty = 0 WHERE id in %s ;

        """

        % (tuple(move_lines_to_unreserve),)

    )

elif len(move_lines_to_unreserve) == 1:

    env.cr.execute(

        """

        UPDATE stock_move_line SET reserved_uom_qty = 0, reserved_qty = 0 WHERE id = %s ;

        """

        % (move_lines_to_unreserve[0])

    )



Unreserve Quont

---------------------

# Available variables:
#  - env: Odoo Environment on which the action is triggered
#  - model: Odoo Model of the record on which the action is triggered; is a void recordset
#  - record: record on which the action is triggered; may be void
#  - records: recordset of all records on which the action is triggered in multi-mode; may be void
#  - time, datetime, dateutil, timezone: useful Python libraries
#  - float_compare: Odoo function to compare floats based on specific precisions
#  - log: log(message, level='info'): logging function to record debug information in ir.logging table
#  - UserError: Warning Exception to use with raise
#  - Command: x2Many commands namespace
# To return an action, assign: action = {...}

for record in records:
  if record.reserved_quantity > 0:
    record.write({'reserved_quantity':0})


FG Lot Generation Issue

--------------------------

# Available variables:
#  - env: Odoo Environment on which the action is triggered
#  - model: Odoo Model of the record on which the action is triggered; is a void recordset
#  - record: record on which the action is triggered; may be void
#  - records: recordset of all records on which the action is triggered in multi-mode; may be void
#  - time, datetime, dateutil, timezone: useful Python libraries
#  - float_compare: Odoo function to compare floats based on specific precisions
#  - log: log(message, level='info'): logging function to record debug information in ir.logging table
#  - UserError: Warning Exception to use with raise
#  - Command: x2Many commands namespace
# To return an action, assign: action = {...}

env.cr.execute("""UPDATE stock_move_line sml SET reserved_uom_qty = 0, reserved_qty = 0 WHERE sml.move_id in (select a.move_id from (select production_id,sm.id as move_id from stock_move sm JOIN mrp_production mp on mp.id = sm.production_id where mp.state in ('to_close','progress','confirmed'))a) ;""")



Avatar
Discard
Author

That's very interesting so it could not be related to our setup after all. I'll try this and see if it helps. Thanks a lot.

Best Answer

Did create  use case and tested, it seems to work as intended. 

Created 2 PO's for subcontract product and then validated the component transfers to subcontract location. Post that went out to cancel one of the orders (the PO and also ensured the associated Inventory receipt were cancelled). 




The products (components) in sub-contract location were no longer reserved. The on-hand qty wouldn't change as the component didn't get consumed, however the available qty were updated.


From your post it seems the expectation is for on hand Qty to increase. Could you confirm if you mean the on-hand qty in WH/Stock or Sub-contract location to increase? On cancelling an order there are no transfers generated only reservation is impacted.


Could you also confirm if you are using odoo default routes and locations or they have been modified? With default routes, the resupply route is always triggered irrespective of available component stocks in subcontract location.

Avatar
Discard
Author

Thank you for your answer. I'm referring to the Available qty, the On Hand qty stay the same as it should. The routes were modified quite a lot by a person who worked here before and I'm trying to bring them back to the default settings as it's causing other problems as well. It's very helpful to know that this works fine with default routes. From what I can see comparing our current setup to runbot, Resupply Subcontractor on Order supply method was changed to 'Take from Stock, if unavailable trigger another rule' and Resupply Subcontractor Source location was changed from WH/Stock to WH/Output. Possibly one of them changes is the source of the issue.

If the available qty does not update in subcontract location then I would look at the receipt operation (for the finished product from sub contractor), this is the operation that is reserving the components.

If the available qty does not update in WH/ Stock location (in the event order was cancelled prior to components being transferred to subcontractor) then I would look at re-supply subcontractor operation. Additionally since your modified route is output and in the event of unavailability at output location it is likely another operation is triggered Stock to Output.

Change of supply method and source location on the resupply route still doesn't explain how an operation is not triggered if components are available at subcontract location.
- The rule
>>> When products are needed in Physical Locations/Subcontracting Location, Resupply Subcontractor are created from WH/Stock to fulfill the need.
If the products are not available in WH/Stock, a rule will be triggered to bring products in this location.<<<

Each time a subcontract order is created this route would be triggered, to reserve product in WH/stock. If you wish Odoo to reserve the component already at subcontract location, then the source location needs to be Physical Locations/Subcontracting Location and if unavailable trigger another rule.