From 49d549bb392a37cd2d9e7b968a339a56ae4afd22 Mon Sep 17 00:00:00 2001
From: Josse Colpaert
Date: Fri, 24 Jan 2014 17:30:32 +0100
Subject: [PATCH] [IMP] New traceability button instead of down/upstream
buttons
bzr revid: jco@openerp.com-20140124163032-6g24pwusfla9z00n
---
addons/stock/res_config.py | 2 +-
addons/stock/stock.py | 39 +++++++++++++++++++++++++++++++++++++
addons/stock/stock_data.xml | 2 +-
addons/stock/stock_view.xml | 7 +++----
4 files changed, 44 insertions(+), 6 deletions(-)
diff --git a/addons/stock/res_config.py b/addons/stock/res_config.py
index 338e9728f66..952407f59b3 100644
--- a/addons/stock/res_config.py
+++ b/addons/stock/res_config.py
@@ -69,7 +69,7 @@ This installs the module product_expiry."""),
help="""Allows you to create and manage your packaging dimensions and types you want to be maintained in your system."""),
'group_stock_tracking_lot': fields.boolean("Track serial number on products",
implied_group='stock.group_tracking_lot',
- help="""This allows you to manage products by using serial numbers. When you select a serial number on product moves, you can get the upstream or downstream traceability of that product."""),
+ help="""This allows you to manage products by using serial numbers. When you select a serial number on product moves, you can get the traceability of that product."""),
'group_stock_tracking_owner': fields.boolean("Manage owner on stock",
implied_group='stock.group_tracking_owner',
help="""This way you can receive products attributed to a certain owner. """),
diff --git a/addons/stock/stock.py b/addons/stock/stock.py
index 3e32eddd640..ae8db2950be 100644
--- a/addons/stock/stock.py
+++ b/addons/stock/stock.py
@@ -1162,6 +1162,45 @@ class stock_production_lot(osv.osv):
('name_ref_uniq', 'unique (name, ref)', 'The combination of Serial Number and internal reference must be unique !'),
]
+ def action_traceability(self, cr, uid, ids, context=None):
+ """ It traces the information of a product
+ @param self: The object pointer.
+ @param cr: A database cursor
+ @param uid: ID of the user currently logged in
+ @param ids: List of IDs selected
+ @param context: A standard dictionary
+ @return: A dictionary of values
+ """
+ if not ids or len(ids) == 0:
+ return False #TODO give warning instead
+ quant_obj = self.pool.get("stock.quant")
+ move_obj = self.pool.get("stock.move")
+ quants = quant_obj.search(cr, uid, [('lot_id', 'in', ids)], context=context)
+ moves = set()
+ for quant in quant_obj.browse(cr, uid, quants, context=context):
+ for move in quant.history_ids:
+ moves.add(move.id)
+# import pdb
+# pdb.set_trace()
+ if moves:
+# ir_model_data = self.pool.get('ir.model.data')
+# try:
+# template_id = ir_model_data.get_object_reference(cr, uid, 'stock', 'view_move_tree')[1]
+# except:
+# template_id = False
+ return {
+ 'domain': "[('id','in',["+','.join(map(str, list(moves)))+"])]",
+ 'name': 'Traceability',
+ 'view_mode': 'tree, form',
+ 'view_type': 'tree',
+ 'res_model': 'stock.move',
+ 'type': 'ir.actions.act_window',
+ 'nodestroy':True,
+ }
+ else:
+ return False
+
+
# ----------------------------------------------------
# Move
diff --git a/addons/stock/stock_data.xml b/addons/stock/stock_data.xml
index 432e015600a..332c2130d05 100644
--- a/addons/stock/stock_data.xml
+++ b/addons/stock/stock_data.xml
@@ -78,7 +78,7 @@
Warehouse Management application installed!
Manage your product inventoy and stock locations: you can control stock moves history and planning,
-watch your stock valuation, and track production lots upstream and downstream (based on serial numbers).
]]>
+watch your stock valuation, and track production lots (based on serial numbers).]]>
diff --git a/addons/stock/stock_view.xml b/addons/stock/stock_view.xml
index 9ec583f89ff..ff542762c38 100644
--- a/addons/stock/stock_view.xml
+++ b/addons/stock/stock_view.xml
@@ -191,8 +191,7 @@