From 5c9897a83f79834b5c54a79b944262556e3f87ee Mon Sep 17 00:00:00 2001 From: Nicolas Seinlet Date: Thu, 22 Oct 2015 15:37:06 +0200 Subject: [PATCH] [IMP] stock_account: rework on stock_history view joins - Replace `LEFT JOIN` by simple `JOIN` for required fields - Use `JOIN ... ON (...)` syntax instead of implicit join `A.X = B.Y` - Remove of unused column quant_id Closes #9197 opw-650598 --- .../wizard/stock_valuation_history.py | 38 +++++++++++-------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/addons/stock_account/wizard/stock_valuation_history.py b/addons/stock_account/wizard/stock_valuation_history.py index e6218dbf036..71ff9950a2d 100644 --- a/addons/stock_account/wizard/stock_valuation_history.py +++ b/addons/stock_account/wizard/stock_valuation_history.py @@ -130,7 +130,6 @@ class stock_history(osv.osv): FROM ((SELECT stock_move.id AS id, - quant.id AS quant_id, stock_move.id AS move_id, dest_location.id AS location_id, dest_location.company_id AS company_id, @@ -141,17 +140,21 @@ class stock_history(osv.osv): quant.cost as price_unit_on_quant, stock_move.origin AS source FROM - stock_quant as quant, stock_quant_move_rel, stock_move - LEFT JOIN + stock_move + JOIN + stock_quant_move_rel on stock_quant_move_rel.move_id = stock_move.id + JOIN + stock_quant as quant on stock_quant_move_rel.quant_id = quant.id + JOIN stock_location dest_location ON stock_move.location_dest_id = dest_location.id - LEFT JOIN + JOIN stock_location source_location ON stock_move.location_id = source_location.id - LEFT JOIN + JOIN product_product ON product_product.id = stock_move.product_id - LEFT JOIN + 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 ( + WHERE quant.qty>0 AND stock_move.state = 'done' AND dest_location.usage in ('internal', 'transit') + 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 @@ -159,7 +162,6 @@ class stock_history(osv.osv): ) UNION ALL (SELECT (-1) * stock_move.id AS id, - quant.id AS quant_id, stock_move.id AS move_id, source_location.id AS location_id, source_location.company_id AS company_id, @@ -170,17 +172,21 @@ class stock_history(osv.osv): quant.cost as price_unit_on_quant, stock_move.origin AS source FROM - stock_quant as quant, stock_quant_move_rel, stock_move - LEFT JOIN + stock_move + JOIN + stock_quant_move_rel on stock_quant_move_rel.move_id = stock_move.id + JOIN + stock_quant as quant on stock_quant_move_rel.quant_id = quant.id + JOIN stock_location source_location ON stock_move.location_id = source_location.id - LEFT JOIN + JOIN stock_location dest_location ON stock_move.location_dest_id = dest_location.id - LEFT JOIN + JOIN product_product ON product_product.id = stock_move.product_id - LEFT JOIN + 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 ( + WHERE quant.qty>0 AND stock_move.state = 'done' AND source_location.usage in ('internal', 'transit') + 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