From e28904b96fd226ef45bc19f59b0de2c3637c5c67 Mon Sep 17 00:00:00 2001 From: "Ajay Chauhan (OpenERP)" Date: Fri, 21 Sep 2012 18:54:31 +0530 Subject: [PATCH 1/2] [IMP] stock: solve the issue of openchatter for Incoming shipment, delivery order bzr revid: cha@tinyerp.com-20120921132431-p5jv6tdfi5lug584 --- addons/stock/stock.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/addons/stock/stock.py b/addons/stock/stock.py index 30bd70b9728..295cee2c583 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -723,6 +723,8 @@ class stock_picking(osv.osv): self.write(cr, uid, ids, {'state': 'confirmed'}) todo = [] for picking in self.browse(cr, uid, ids, context=context): + if picking.state == 'confirmed': + self.confirm_send_note(cr, uid, ids, context=context) for r in picking.move_lines: if r.state == 'draft': todo.append(r.id) @@ -1376,6 +1378,12 @@ class stock_picking(osv.osv): # OpenChatter methods and notifications # ----------------------------------------- + def _get_thread_model(self, cr, uid, ids, context=None): + for obj in self.browse(cr, uid, ids, context=context): + if obj.type in ('out', 'in'): + context.update({'thread_model': 'stock.picking.' + obj.type}) + return True + def _get_document_type(self, type): type_dict = { 'out': 'Delivery order', @@ -1385,13 +1393,25 @@ class stock_picking(osv.osv): return type_dict.get(type, 'Stock picking') def create_send_note(self, cr, uid, ids, context=None): + context = context or {} + self._get_thread_model(cr, uid, ids, context=context) for obj in self.browse(cr, uid, ids, context=context): self.message_post(cr, uid, [obj.id], body=_("%s has been created.") % (self._get_document_type(obj.type)), context=context) + def confirm_send_note(self, cr, uid, ids, context=None): + context = context or {} + self._get_thread_model(cr, uid, ids, context=context) + for obj in self.browse(cr, uid, ids, context=context): + self.message_post(cr, uid, [obj.id], body=_("%s has been confirmed.") % (self._get_document_type(obj.type)), context=context) + def scrap_send_note(self, cr, uid, ids, quantity, uom, name, context=None): + context = context or {} + self._get_thread_model(cr, uid, ids, context=context) return self.message_post(cr, uid, ids, body= _("%s %s %s has been moved to scrap.") % (quantity, uom, name), context=context) def back_order_send_note(self, cr, uid, ids, back_name, context=None): + context = context or {} + self._get_thread_model(cr, uid, ids, context=context) return self.message_post(cr, uid, ids, body=_("Back order %s has been created.") % (back_name), context=context) def ship_done_send_note(self, cr, uid, ids, context=None): @@ -1400,10 +1420,14 @@ class stock_picking(osv.osv): 'in': 'received', 'internal': 'moved', } + context = context or {} + self._get_thread_model(cr, uid, ids, context=context) for obj in self.browse(cr, uid, ids, context=context): self.message_post(cr, uid, [obj.id], body=_("Products have been %s.") % (type_dict.get(obj.type, 'move done')), context=context) def ship_cancel_send_note(self, cr, uid, ids, context=None): + context = context or {} + self._get_thread_model(cr, uid, ids, context=context) for obj in self.browse(cr, uid, ids, context=context): self.message_post(cr, uid, [obj.id], body=_("%s has been cancelled.") % (self._get_document_type(obj.type)), context=context) From 21f2f7c1128668fb6d2a15b054340bea66d71668 Mon Sep 17 00:00:00 2001 From: "Ajay Chauhan (OpenERP)" Date: Mon, 24 Sep 2012 11:09:44 +0530 Subject: [PATCH 2/2] [IMP] stock: add if condition to check context bzr revid: cha@tinyerp.com-20120924053944-l2mwyuijvzr9ot0w --- addons/stock/stock.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/addons/stock/stock.py b/addons/stock/stock.py index 295cee2c583..96cabbf1cce 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -1393,24 +1393,28 @@ class stock_picking(osv.osv): return type_dict.get(type, 'Stock picking') def create_send_note(self, cr, uid, ids, context=None): - context = context or {} + if context is None: + context = {} self._get_thread_model(cr, uid, ids, context=context) for obj in self.browse(cr, uid, ids, context=context): self.message_post(cr, uid, [obj.id], body=_("%s has been created.") % (self._get_document_type(obj.type)), context=context) def confirm_send_note(self, cr, uid, ids, context=None): - context = context or {} + if context is None: + context = {} self._get_thread_model(cr, uid, ids, context=context) for obj in self.browse(cr, uid, ids, context=context): self.message_post(cr, uid, [obj.id], body=_("%s has been confirmed.") % (self._get_document_type(obj.type)), context=context) def scrap_send_note(self, cr, uid, ids, quantity, uom, name, context=None): - context = context or {} + if context is None: + context = {} self._get_thread_model(cr, uid, ids, context=context) return self.message_post(cr, uid, ids, body= _("%s %s %s has been moved to scrap.") % (quantity, uom, name), context=context) def back_order_send_note(self, cr, uid, ids, back_name, context=None): - context = context or {} + if context is None: + context = {} self._get_thread_model(cr, uid, ids, context=context) return self.message_post(cr, uid, ids, body=_("Back order %s has been created.") % (back_name), context=context) @@ -1420,13 +1424,15 @@ class stock_picking(osv.osv): 'in': 'received', 'internal': 'moved', } - context = context or {} + if context is None: + context = {} self._get_thread_model(cr, uid, ids, context=context) for obj in self.browse(cr, uid, ids, context=context): self.message_post(cr, uid, [obj.id], body=_("Products have been %s.") % (type_dict.get(obj.type, 'move done')), context=context) def ship_cancel_send_note(self, cr, uid, ids, context=None): - context = context or {} + if context is None: + context = {} self._get_thread_model(cr, uid, ids, context=context) for obj in self.browse(cr, uid, ids, context=context): self.message_post(cr, uid, [obj.id], body=_("%s has been cancelled.") % (self._get_document_type(obj.type)), context=context)