From f6635d02db8d2f45f8e6f097c981f10fcea7f44d Mon Sep 17 00:00:00 2001
From: "RGA(OpenERP)" <>
Date: Mon, 19 Mar 2012 10:41:10 +0530
Subject: [PATCH 1/5] [IMP] Added social chatter notification messages for
incoming shipments and order delivery
bzr revid: rgaopenerp-20120319051110-5yyu30jmrexzjqsx
---
addons/stock/stock.py | 68 ++++++++++++++++++++++++++++++-------
addons/stock/stock_view.xml | 2 ++
2 files changed, 57 insertions(+), 13 deletions(-)
diff --git a/addons/stock/stock.py b/addons/stock/stock.py
index 885f7cd2077..62fe91cf718 100644
--- a/addons/stock/stock.py
+++ b/addons/stock/stock.py
@@ -536,6 +536,7 @@ stock_tracking()
#----------------------------------------------------------
class stock_picking(osv.osv):
_name = "stock.picking"
+ _inherit = 'mail.thread'
_description = "Picking List"
def _set_maximum_date(self, cr, uid, ids, name, value, arg, context=None):
@@ -610,6 +611,8 @@ class stock_picking(osv.osv):
seq_obj_name = 'stock.picking.' + vals['type']
vals['name'] = self.pool.get('ir.sequence').get(cr, user, seq_obj_name)
new_id = super(stock_picking, self).create(cr, user, vals, context)
+ if new_id:
+ self.create_send_note(cr, user, [new_id], context=context)
return new_id
_columns = {
@@ -723,7 +726,6 @@ class stock_picking(osv.osv):
if r.state == 'draft':
todo.append(r.id)
- self.log_picking(cr, uid, ids, context=context)
todo = self.action_explode(cr, uid, todo, context)
if len(todo):
@@ -796,7 +798,6 @@ class stock_picking(osv.osv):
@return: True
"""
self.write(cr, uid, ids, {'state': 'assigned'})
- self.log_picking(cr, uid, ids, context=context)
return True
def test_finished(self, cr, uid, ids):
@@ -837,7 +838,7 @@ class stock_picking(osv.osv):
ids2 = [move.id for move in pick.move_lines]
self.pool.get('stock.move').action_cancel(cr, uid, ids2, context)
self.write(cr, uid, ids, {'state': 'cancel', 'invoice_state': 'none'})
- self.log_picking(cr, uid, ids, context=context)
+ self.ship_cancel_send_note(cr, uid, ids, context)
return True
#
@@ -1310,14 +1311,17 @@ class stock_picking(osv.osv):
wf_service.trg_validate(uid, 'stock.picking', new_picking, 'button_done', cr)
wf_service.trg_write(uid, 'stock.picking', pick.id, cr)
delivered_pack_id = new_picking
+ back_order_name = self.browse(cr, uid, delivered_pack_id, context=context).name
+ self.back_order_send_note(cr, uid, ids, back_order_name, context)
else:
self.action_move(cr, uid, [pick.id])
wf_service.trg_validate(uid, 'stock.picking', pick.id, 'button_done', cr)
delivered_pack_id = pick.id
+ self.ship_done_send_note(cr, uid, ids, context)
delivered_pack = self.browse(cr, uid, delivered_pack_id, context=context)
res[pick.id] = {'delivered_picking': delivered_pack.id or False}
-
+
return res
def log_picking(self, cr, uid, ids, context=None):
@@ -1358,8 +1362,53 @@ class stock_picking(osv.osv):
res = data_obj.get_object_reference(cr, uid, 'stock', view_list.get(pick.type, 'view_picking_form'))
context.update({'view_id': res and res[1] or False})
message += state_list[pick.state]
- self.log(cr, uid, pick.id, message, context=context)
return True
+
+
+ # -----------------------------
+ # OpenChatter and notifications
+ # -----------------------------
+ def _get_document_type(self, type):
+ type_dict = {
+ 'out': 'Delivery order',
+ 'in': 'Shipment',
+ 'internal': 'Internal picking',
+ }
+ return type_dict[type]
+
+ def create_send_note(self, cr, uid, ids, context=None):
+ for obj in self.browse(cr, uid, ids, context=context):
+ self.message_append_note(cr, uid, ids, _('System notification'),
+ _("""%s created.""") % (self._get_document_type(obj.type)),
+ type='notification', context=context)
+
+ def scrap_send_note(self, cr, uid, ids, quantity, name, context=None):
+ self.message_append_note(cr, uid, ids, _('System notification'),
+ _("""%s %s moved to scrap.""")
+ % (quantity, name), type='notification', context=context)
+
+ def back_order_send_note(self, cr, uid, ids, back_name, context=None):
+ self.message_append_note(cr, uid, ids, _('System notification'),
+ _("""Back order %s created.""")
+ % (back_name), type='notification', context=context)
+
+ def ship_done_send_note(self, cr, uid, ids, context=None):
+ type_dict = {
+ 'out': 'delivered',
+ 'in': 'received',
+ 'internal': 'moved',
+ }
+ for obj in self.browse(cr, uid, ids, context=context):
+ self.message_append_note(cr, uid, ids, _('System notification'),
+ _("""Product %s.""") % (type_dict[obj.type]),
+ type='notification', context=context)
+
+ def ship_cancel_send_note(self, cr, uid, ids, context=None):
+ for obj in self.browse(cr, uid, ids, context=context):
+ self.message_append_note(cr, uid, ids, _('System notification'),
+ _("""%s cancelled.""") % (self._get_document_type(obj.type)),
+ type='notification', context=context)
+
stock_picking()
@@ -2361,7 +2410,7 @@ class stock_move(osv.osv):
res += [new_move]
product_obj = self.pool.get('product.product')
for (id, name) in product_obj.name_get(cr, uid, [move.product_id.id]):
- self.log(cr, uid, move.id, "%s x %s %s" % (quantity, name, _("were scrapped")))
+ move.picking_id.scrap_send_note(quantity, name)
self.action_done(cr, uid, res, context=context)
return res
@@ -2483,11 +2532,6 @@ class stock_move(osv.osv):
}
self.write(cr, uid, [move.id], update_val)
- product_obj = self.pool.get('product.product')
- for new_move in self.browse(cr, uid, res, context=context):
- for (id, name) in product_obj.name_get(cr, uid, [new_move.product_id.id]):
- message = _("Product '%s' is consumed with '%s' quantity.") %(name, new_move.product_qty)
- self.log(cr, uid, new_move.id, message)
self.action_done(cr, uid, res, context=context)
return res
@@ -2697,8 +2741,6 @@ class stock_inventory(osv.osv):
'location_dest_id': location_id,
})
move_ids.append(self._inventory_line_hook(cr, uid, line, value))
- message = _("Inventory '%s' is done.") %(inv.name)
- self.log(cr, uid, inv.id, message)
self.write(cr, uid, [inv.id], {'state': 'confirm', 'move_ids': [(6, 0, move_ids)]})
self.pool.get('stock.move').action_confirm(cr, uid, move_ids, context=context)
return True
diff --git a/addons/stock/stock_view.xml b/addons/stock/stock_view.xml
index 4264a488436..51d77b6557c 100644
--- a/addons/stock/stock_view.xml
+++ b/addons/stock/stock_view.xml
@@ -1010,6 +1010,7 @@
+
@@ -1227,6 +1228,7 @@
+
From 26b97bcd0223fd26c407c9af5a4532a8f2ab56a5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?=
Date: Tue, 20 Mar 2012 16:13:50 +0100
Subject: [PATCH 2/5] [FIX] stock: fixed error in some notifications: browsing
on obj but sending notofications to all records (ids). Added protection for
dict accesses.
bzr revid: tde@openerp.com-20120320151350-rs309a5pdpbfvqz0
---
addons/stock/stock.py | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/addons/stock/stock.py b/addons/stock/stock.py
index 62fe91cf718..9e0aece81b9 100644
--- a/addons/stock/stock.py
+++ b/addons/stock/stock.py
@@ -1364,21 +1364,21 @@ class stock_picking(osv.osv):
message += state_list[pick.state]
return True
+ # -----------------------------------------
+ # OpenChatter notifications and need_action
+ # -----------------------------------------
- # -----------------------------
- # OpenChatter and notifications
- # -----------------------------
def _get_document_type(self, type):
type_dict = {
'out': 'Delivery order',
'in': 'Shipment',
'internal': 'Internal picking',
}
- return type_dict[type]
+ return type_dict.get(type, 'Stock picking')
def create_send_note(self, cr, uid, ids, context=None):
for obj in self.browse(cr, uid, ids, context=context):
- self.message_append_note(cr, uid, ids, _('System notification'),
+ self.message_append_note(cr, uid, [obj.id], _('System notification'),
_("""%s created.""") % (self._get_document_type(obj.type)),
type='notification', context=context)
@@ -1399,13 +1399,13 @@ class stock_picking(osv.osv):
'internal': 'moved',
}
for obj in self.browse(cr, uid, ids, context=context):
- self.message_append_note(cr, uid, ids, _('System notification'),
- _("""Product %s.""") % (type_dict[obj.type]),
+ self.message_append_note(cr, uid, [obj.id], _('System notification'),
+ _("""Product %s.""") % (type_dict.get(obj.type, 'move done')),
type='notification', context=context)
def ship_cancel_send_note(self, cr, uid, ids, context=None):
for obj in self.browse(cr, uid, ids, context=context):
- self.message_append_note(cr, uid, ids, _('System notification'),
+ self.message_append_note(cr, uid, [obj.id], _('System notification'),
_("""%s cancelled.""") % (self._get_document_type(obj.type)),
type='notification', context=context)
From e440e402acbca8078d977634f31ed5e8c0ac205f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?=
Date: Thu, 22 Mar 2012 11:08:05 +0100
Subject: [PATCH 3/5] [FIX] Temporary fix for picking_id making crash the
runbot. TODO: check were the error comes from.
bzr revid: tde@openerp.com-20120322100805-ljqbieyqcg9spmhb
---
addons/stock/stock.py | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/addons/stock/stock.py b/addons/stock/stock.py
index 9e0aece81b9..1b63a193414 100644
--- a/addons/stock/stock.py
+++ b/addons/stock/stock.py
@@ -2410,7 +2410,8 @@ class stock_move(osv.osv):
res += [new_move]
product_obj = self.pool.get('product.product')
for (id, name) in product_obj.name_get(cr, uid, [move.product_id.id]):
- move.picking_id.scrap_send_note(quantity, name)
+ if move.picking_id:
+ move.picking_id.scrap_send_note(quantity, name, context=context)
self.action_done(cr, uid, res, context=context)
return res
From d42b55a3a714d9ee203cf2b70f7677591aa1cdb0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?=
Date: Mon, 2 Apr 2012 17:12:51 +0200
Subject: [PATCH 4/5] [IMP] Message spelling harmonization.
bzr revid: tde@openerp.com-20120402151251-6wgr068h96z979mq
---
addons/stock/stock.py | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/addons/stock/stock.py b/addons/stock/stock.py
index 4cf4b081b00..f88c94c2e68 100644
--- a/addons/stock/stock.py
+++ b/addons/stock/stock.py
@@ -1378,17 +1378,17 @@ class stock_picking(osv.osv):
def create_send_note(self, cr, uid, ids, context=None):
for obj in self.browse(cr, uid, ids, context=context):
self.message_append_note(cr, uid, [obj.id], _('System notification'),
- _("""%s created.""") % (self._get_document_type(obj.type)),
+ _("""%s has been created.""") % (self._get_document_type(obj.type)),
type='notification', context=context)
def scrap_send_note(self, cr, uid, ids, quantity, name, context=None):
self.message_append_note(cr, uid, ids, _('System notification'),
- _("""%s %s moved to scrap.""")
+ _("""%s %s have been moved to scrap.""")
% (quantity, name), type='notification', context=context)
def back_order_send_note(self, cr, uid, ids, back_name, context=None):
self.message_append_note(cr, uid, ids, _('System notification'),
- _("""Back order %s created.""")
+ _("""Back order has been %s created.""")
% (back_name), type='notification', context=context)
def ship_done_send_note(self, cr, uid, ids, context=None):
@@ -1399,13 +1399,13 @@ class stock_picking(osv.osv):
}
for obj in self.browse(cr, uid, ids, context=context):
self.message_append_note(cr, uid, [obj.id], _('System notification'),
- _("""Product %s.""") % (type_dict.get(obj.type, 'move done')),
+ _("""Products have been %s.""") % (type_dict.get(obj.type, 'move done')),
type='notification', context=context)
def ship_cancel_send_note(self, cr, uid, ids, context=None):
for obj in self.browse(cr, uid, ids, context=context):
self.message_append_note(cr, uid, [obj.id], _('System notification'),
- _("""%s cancelled.""") % (self._get_document_type(obj.type)),
+ _("""%s has been cancelled.""") % (self._get_document_type(obj.type)),
type='notification', context=context)
From e0b7a4436ffa74c3a68f14e90d6132e78ab17c06 Mon Sep 17 00:00:00 2001
From: "RGA(OpenERP)" <>
Date: Tue, 3 Apr 2012 15:16:42 +0530
Subject: [PATCH 5/5] [IMP] added UOM in scrap move message
bzr revid: rgaopenerp-20120403094642-yz53ivp5vvmfjek3
---
addons/stock/stock.py | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/addons/stock/stock.py b/addons/stock/stock.py
index f88c94c2e68..6b02aa4e499 100644
--- a/addons/stock/stock.py
+++ b/addons/stock/stock.py
@@ -1381,10 +1381,10 @@ class stock_picking(osv.osv):
_("""%s has been created.""") % (self._get_document_type(obj.type)),
type='notification', context=context)
- def scrap_send_note(self, cr, uid, ids, quantity, name, context=None):
+ def scrap_send_note(self, cr, uid, ids, quantity, uom, name, context=None):
self.message_append_note(cr, uid, ids, _('System notification'),
- _("""%s %s have been moved to scrap.""")
- % (quantity, name), type='notification', context=context)
+ _("""%s %s %s has been moved to scrap.""")
+ % (quantity, uom, name), type='notification', context=context)
def back_order_send_note(self, cr, uid, ids, back_name, context=None):
self.message_append_note(cr, uid, ids, _('System notification'),
@@ -2406,9 +2406,8 @@ class stock_move(osv.osv):
res += [new_move]
product_obj = self.pool.get('product.product')
- for (id, name) in product_obj.name_get(cr, uid, [move.product_id.id]):
- if move.picking_id:
- move.picking_id.scrap_send_note(quantity, name, context=context)
+ for product in product_obj.browse(cr, uid, [move.product_id.id], context=context):
+ move.picking_id.scrap_send_note(quantity, product.uom_id.name, product.name, context=context)
self.action_done(cr, uid, res, context=context)
return res