important MRP bug: wrong virtual stock after cancelling production/purchase generated by MTS procurement

Bug #356697 reported by Raphaël Valyi - http://www.akretion.com
6
Affects Status Importance Assigned to Milestone
Odoo Addons (MOVED TO GITHUB)
Fix Released
Undecided
Fabien (Open ERP)

Bug Description

https://bugs.launchpad.net/openobject-addons/+filebug#form-start

Hi,

this bug is reproducible on trunk with a fresh manufacturing database.

Configure a product with:
- procurement method: MTS
- procurement: buy or produce

Make sure you define a minimum order point rule for that product and the current warehouse.

Now make a customer sale order so that you don't have enough product in stock and you should produce or buy the product.
validate the sale order.

Look the product virtual stock level: it's lower than before because of the order.
Now run the scheduler.
The scheduler create a purchase (or production order) to for the product, as a result, the virtual stock level
just increased just like it was before the customer order.

The trouble is that if you open the related purchase (or production) order and cancel it, then
the virtual stock level remains as high as before.
This is a bug because you just cancelled the planned purchase or production!

Here is what happened:
when you validated the sale order, a MTS procurement has been generated to put products again in Stock.
But, at the beginning of the procurement workflow, the procurement had no move, so a confirmed move
form procurement to stock has been created. It is because of that move creation after you run the scheduler that the
virtual stock level has been increased. Indeed, the MRP egine used that move to artifially increase the virtual
stock level in order to reflect our plan to buy/produce the product.

The move creation happens in addons/mrp.py#mrp_procurement#action_confirm arround line 961:
                if not procurement.move_id:
                    source = procurement.location_id.id
                    if procurement.procure_method=='make_to_order':
                        source = procurement.product_id.product_tmpl_id.property_stock_procurement.id
                    id = self.pool.get('stock.move').create(cr, uid, {...

The problem is that this move will stay here foreever; cancelling the related purchase/production order will NOT
cancel that confirmed move. As a consequence, virtual stock level are wrong; they are too optimistic.

What should be done instead?
the confirmed procurement -> Stock move should stop increasing the virtual stock level.
A case when it happens is when you actually validade the related purchase order instead of cancelling it. In this case,
a new move suppliers -> Stock is created and the previous procurement -> Stock move is voided. The way it's voided
is it is transformed into a Stock -> Stock move so it has no effect. I'm not sure if that is better than cancelling the move
but it's the way it's done currently.

So, at least for the MTS+buy case, I'm proposing a patch (attached) doing something similar: I change the purchase workflow so thatwhen the purchase is cancelled right after it's creation, now we run a full server action. And that existing action (which is doing a bit more but without any risk) is now extended to change the procurement -> Stock move into a Stock -> Stock move so the virtual stock won't take it into account anymore.

I think my patch is correct but it only fixes the MTS + buy case.
A similar patch should be done to fix the MTS + produce case, probably using the production workflow but I had no time to elaborate it sorry.

Hope this helps,

Raphaël Valyi

Revision history for this message
Raphaël Valyi - http://www.akretion.com (rvalyi) wrote :
Revision history for this message
Fabien (Open ERP) (fp-tinyerp) wrote :

I think the MTS+produce case is correct. Because if you cancel a production, it cancels moves, which cancels the procurement too. The purchase is different because you don't have the moves before having confirmed the po.

Changed in openobject-addons:
assignee: nobody → fp-tinyerp
Revision history for this message
Fabien (Open ERP) (fp-tinyerp) wrote :

fixed in branches 5.0.
Your patch is not correct, I suggest you to take if from the rev 2280 in branches/5.0

Changed in openobject-addons:
status: New → Fix Released
Revision history for this message
Raphaël Valyi - http://www.akretion.com (rvalyi) wrote :

I'm sorry, but I just tested that on trunk and it doesn't seem to be fixed. I try cancelling the purchase order generated by the automatic order point rule and the virtual stock keep being over-optimistic still taking into account a move from Procurement to Stock generated by the MRP that is not canceled or voided.

So I'm re-opening the bug.

Changed in openobject-addons:
status: Fix Released → Confirmed
Revision history for this message
Raphaël Valyi - http://www.akretion.com (rvalyi) wrote :

Also notice that it has been reported here also:
https://bugs.launchpad.net/openobject-addons/+bug/378624

Not sure that's a duplicate or one should be closed, but for sure we should look for a resolution that satisfies both bug reports.

Revision history for this message
Fabien (Open ERP) (fp-tinyerp) wrote :

seems fixed in branch/5. Please test on branch5, not trunk.
branch5 is not yet pushed to trunk.

Changed in openobject-addons:
status: Confirmed → Fix Released
Revision history for this message
Raphaël Valyi - http://www.akretion.com (rvalyi) wrote :

I confirmed it's fixed on 5-0 at least, you rocks, thanks a lot.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.