stock inventory - wrong stock_moves if moves with prodlots and without exists for one product and location

Bug #1008099 reported by Ferdinand
20
This bug affects 4 people
Affects Status Importance Assigned to Milestone
Odoo Addons (MOVED TO GITHUB)
Fix Released
Low
OpenERP Publisher's Warranty Team

Bug Description

the following code in
stock/product.py
does not distinguish between
* select all move_lines without prodlots
* select all move_lines with prodlot = null

a query without prodlot returns all moves regardless if these have lots and not

this gives very wrong results for inventory postings

the fix is complex and for now I put in into the module
http://bazaar.launchpad.net/~c2c/c2c-rd-addons/trunk/files/head:/c2c_stock_accounting/
stock.py
wizard/stock_fill_inventory.py

I didn't want to patch stock/product.py because it might break some applications which rely on exaclty this behavior.

257 # TODO: perhaps merge in one query.
258 if date_values:
259 where.append(tuple(date_values))
260 if 'in' in what:
261 # all moves from a location out of the set to a location in the set
262 cr.execute(
263 'select sum(product_qty), product_id, product_uom '\
264 'from stock_move '\
265 'where location_dest_id IN %s '\
266 'and product_id IN %s '\
267 '' + (prodlot_id and ('and prodlot_id = ' + str(prodlot_id)) or '') + ' '\
268 'and state IN %s ' + (date_str and 'and '+date_str+' ' or '') +' '\
269 'group by product_id,product_uom',tuple(where))
270 results = cr.fetchall()
271 if 'out' in what:
272 # all moves from a location in the set to a location out of the set
273 cr.execute(
274 'select sum(product_qty), product_id, product_uom '\
275 'from stock_move '\
276 'where location_id IN %s '\
277 'and product_id IN %s '\
278 '' + (prodlot_id and ('and prodlot_id = ' + str(prodlot_id)) or '') + ' '\
279 'and state in %s ' + (date_str and 'and '+date_str+' ' or '') + ' '\
280 'group by product_id,product_uom',tuple(where))
281 results2 = cr.fetchall()

Tags: maintenance

Related branches

Revision history for this message
Numérigraphe (numerigraphe) wrote :

WMS experts can you please confirm this bug?
Lionel Sausin.

Revision history for this message
Numérigraphe (numerigraphe) wrote :

I can confirm this bug in v6 :
- enter an inventory for a location with 2 lines for the same product : line 1 without lot ; line 2 with a lot number ; validate the inventory
- enter the exact same inventory again and validate it
No move should be created , but one will be.
Lionel.

Changed in openobject-addons:
status: New → Confirmed
Changed in openobject-addons:
assignee: nobody → OpenERP Publisher's Warranty Team (openerp-opw)
tags: added: maintenance
Revision history for this message
Amit Parik (amit-parik) wrote :

Hello Lionel,

I am not able to understand your last point exactly "- enter the exact same inventory again and validate it
No move should be created , but one will be." . You mean we have to create a new inventory for same product with same qty or update previously created.

So would you please elaborate more on this issue.

@Ferdinand : Please provide a precious steps on this.

Thanks and waiting for your reply!

Revision history for this message
Ferdinand (office-chricar) wrote :

@Amit
please look at the code I provided which solves the problem

Revision history for this message
Numérigraphe (numerigraphe) wrote : Re: [Openerp-wms-expert] [Bug 1008099] Re: stock inventory - wrong stock_moves if moves with prodlots and without exists for one product and location

Amit, yes you can see the problem when you enter a new inventory with
the same lines.
And from what I understand of it, it will happen as soon as you have
move lines with prodlots and move lines without (for the same product,
same location).
Lionel.

Revision history for this message
Rifakat Husen (OpenERP) (rha-openerp) wrote :

I see,
'' + (prodlot_id and ('and prodlot_id = ' + str(prodlot_id)) or '') + ' '\
adds prodlot_id and filter it but doesn't add in query when there is null value.

Ferdinand, I agree with you that it may affect at many places and can cause problem in stable!

Changed in openobject-addons:
status: Confirmed → In Progress
importance: Undecided → Low
Revision history for this message
Numérigraphe (numerigraphe) wrote :

The patch in the branch you linked seems to fix the problem and it applies cleanly to v6.0.
Does it have bad known side-effects?
Lionel.

Revision history for this message
Rifakat Husen (OpenERP) (rha-openerp) wrote :

Hi Dr Ferdinand,

I have fixed this issue in following branch,
lp:~openerp-dev/openobject-addons/6.1-opw-575875-rha
Revision ID: <email address hidden>
Revision 6841 & 6842

Could you please test the fix and confirm if it works for you?

Thanks you very much,
Rifakat Haradwala

Revision history for this message
Rifakat Husen (OpenERP) (rha-openerp) wrote :

Hi Lionel,

I have checked all the possible ways and I confirm that it does not have any side effect.
I request you to check it again with all possibilities and let me know if you face any problem.

Thanks!

Changed in openobject-addons:
status: In Progress → Fix Committed
Revision history for this message
Numérigraphe (numerigraphe) wrote :

Dear Rafikat,
Unfortunately I got mixed up between several bugs I was following, and sadly I have to say that your patch does NOT apply cleanly to 6.0.
Also, as I stated in the MP review, you must not impose production lots in inventory lines (this was confirmed by Olivier Dony in another bug report).
Can you please provide a solution for 6.0?
Lionel.

Changed in openobject-addons:
status: Fix Committed → Confirmed
Revision history for this message
Rifakat Husen (OpenERP) (rha-openerp) wrote :

Hello Lionel,

You are not able to apply the patch on 6.0 due to recent changes occured in the very same method,
see r5261 of v6.0
Anyway, I will propose a clean merge again for 6.0 and 6.1

Regards,
Rifakat Haradwala

Changed in openobject-addons:
status: Confirmed → Fix Committed
Revision history for this message
Xavier ALT (dex-phx) wrote :

Hi,

Fix released with following revision ids:

* v6.0: <email address hidden>
* v6.1: <email address hidden>

Regards,
Xavier

Changed in openobject-addons:
status: Fix Committed → Fix Released
Revision history for this message
bruno bottacini (bruno-bottacini) wrote :

same problem is on 7.0.

Revision history for this message
Lionel Sausin - Initiatives/Numérigraphe (ls-initiatives) wrote :

the patch that was merged in v6.1 merged cleanly in v7, I'll make a PR in a moment.

Revision history for this message
Lionel Sausin - Initiatives/Numérigraphe (ls-initiatives) wrote :

Pull request here: https://github.com/odoo/odoo/pull/1658, please test and review

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.