From 4be4678d8baa041dfd3be6dc6d94c162ab8da879 Mon Sep 17 00:00:00 2001 From: Lionel Sausin Date: Wed, 8 Jul 2015 17:41:19 +0200 Subject: [PATCH] [FIX] stock_account: use all inbound/outbound moves when valuating The valuation wizard is based on stock moves and currently only takes into account the moves which have different companies in source vs destination locations. This is a problem because all user-created locations have a default company set to the user's company, even the "virtual" ones. For example in the demo dataset visible on runbot, some supplier locations have a company set and some don't. So we have to make sure to include every move coming from/going to outside locations based on the locations's type too. Closes #7530 --- .../wizard/stock_valuation_history.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/addons/stock_account/wizard/stock_valuation_history.py b/addons/stock_account/wizard/stock_valuation_history.py index 9a12ff24e1f..6856940c0b6 100644 --- a/addons/stock_account/wizard/stock_valuation_history.py +++ b/addons/stock_account/wizard/stock_valuation_history.py @@ -150,8 +150,11 @@ class stock_history(osv.osv): LEFT JOIN product_template ON product_template.id = product_product.product_tmpl_id WHERE quant.qty>0 AND stock_move.state = 'done' AND dest_location.usage in ('internal', 'transit') AND stock_quant_move_rel.quant_id = quant.id - AND stock_quant_move_rel.move_id = stock_move.id AND ((source_location.company_id is null and dest_location.company_id is not null) or - (source_location.company_id is not null and dest_location.company_id is null) or source_location.company_id != dest_location.company_id) + AND stock_quant_move_rel.move_id = stock_move.id AND ( + (source_location.company_id is null and dest_location.company_id is not null) or + (source_location.company_id is not null and dest_location.company_id is null) or + source_location.company_id != dest_location.company_id or + source_location.usage not in ('internal', 'transit')) ) UNION (SELECT '-' || stock_move.id::text || '-' || quant.id::text AS id, @@ -176,8 +179,11 @@ class stock_history(osv.osv): LEFT JOIN product_template ON product_template.id = product_product.product_tmpl_id WHERE quant.qty>0 AND stock_move.state = 'done' AND source_location.usage in ('internal', 'transit') AND stock_quant_move_rel.quant_id = quant.id - AND stock_quant_move_rel.move_id = stock_move.id AND ((dest_location.company_id is null and source_location.company_id is not null) or - (dest_location.company_id is not null and source_location.company_id is null) or dest_location.company_id != source_location.company_id) + AND stock_quant_move_rel.move_id = stock_move.id AND ( + (dest_location.company_id is null and source_location.company_id is not null) or + (dest_location.company_id is not null and source_location.company_id is null) or + dest_location.company_id != source_location.company_id or + dest_location.usage not in ('internal', 'transit')) )) AS foo GROUP BY move_id, location_id, company_id, product_id, product_categ_id, date, price_unit_on_quant, source