From a67ecbaaaefd22da58834e472bbb81b55dda3b25 Mon Sep 17 00:00:00 2001 From: "RGA(OpenERP)" <> Date: Tue, 13 Mar 2012 15:37:26 +0530 Subject: [PATCH 1/3] [IMP] Added notification for purchase order bzr revid: rgaopenerp-20120313100726-e01a0bbrxw05kmw0 --- addons/purchase/purchase.py | 74 +++++++++++++++++++++++++-- addons/purchase/purchase_view.xml | 1 + addons/purchase/purchase_workflow.xml | 4 +- 3 files changed, 74 insertions(+), 5 deletions(-) diff --git a/addons/purchase/purchase.py b/addons/purchase/purchase.py index 3d909c1085e..2a0be38b773 100644 --- a/addons/purchase/purchase.py +++ b/addons/purchase/purchase.py @@ -223,9 +223,16 @@ class purchase_order(osv.osv): ('name_uniq', 'unique(name, company_id)', 'Order Reference must be unique per Company!'), ] _name = "purchase.order" + _inherit = "mail.thread" _description = "Purchase Order" _order = "name desc" - + + def create(self, cr, uid, vals, context=None): + order = super(purchase_order, self).create(cr, uid, vals, context=context) + if order: + self.create_notificate(cr, uid, [order], context=context) + return order + def unlink(self, cr, uid, ids, context=None): purchase_orders = self.read(cr, uid, ids, ['state'], context=context) unlink_ids = [] @@ -292,6 +299,7 @@ class purchase_order(osv.osv): self.pool.get('purchase.order.line').action_confirm(cr, uid, todo, context) for id in ids: self.write(cr, uid, [id], {'state' : 'confirmed', 'validator' : uid}) + self.confirm_notificate(cr, uid, ids, context) return True def _prepare_inv_line(self, cr, uid, account_id, order_line, context=None): @@ -393,8 +401,15 @@ class purchase_order(osv.osv): # Link this new invoice to related purchase order order.write({'invoice_ids': [(4, inv_id)]}, context=context) res = inv_id + if res: + self.invoice_notificate(cr, uid, ids, res, context) return res - + + def invoice_done(self, cr, uid, ids, context=None): + self.write(cr, uid, ids, {'state':'approved'}, context=context) + self.invoice_paid_notificate(cr, uid, ids, context=context) + return True + def has_stockable_product(self,cr, uid, ids, *args): for order in self.browse(cr, uid, ids): for order_line in order.order_line: @@ -497,7 +512,7 @@ class purchase_order(osv.osv): stock_move.force_assign(cr, uid, todo_moves) wf_service.trg_validate(uid, 'stock.picking', picking_id, 'button_confirm', cr) return [picking_id] - + def action_picking_create(self,cr, uid, ids, context=None): picking_ids = [] for order in self.browse(cr, uid, ids): @@ -507,8 +522,15 @@ class purchase_order(osv.osv): # In case of multiple (split) pickings, we should return the ID of the critical one, i.e. the # one that should trigger the advancement of the purchase workflow. # By default we will consider the first one as most important, but this behavior can be overridden. + if picking_ids: + self.shipment_notificate(cr, uid, ids, picking_ids[0], context=context) return picking_ids[0] if picking_ids else False + def picking_done(self, cr, uid, ids, context=None): + self.write(cr, uid, ids, {'shipped':1,'state':'approved'}, context=context) + self.shipment_done_notificate(cr, uid, ids, context=context) + return True + def copy(self, cr, uid, id, default=None, context=None): if not default: default = {} @@ -633,6 +655,52 @@ class purchase_order(osv.osv): wf_service.trg_redirect(uid, 'purchase.order', old_id, neworder_id, cr) wf_service.trg_validate(uid, 'purchase.order', old_id, 'purchase_cancel', cr) return orders_info + + # ----------------------------- + # OpenChatter and notifications + # ----------------------------- + def create_notificate(self, cr, uid, ids, context=None): + self.message_append_note(cr, uid, ids, _('System notification'), + _("""Request for quotation created."""), + type='notification', context=context) + + def confirm_notificate(self, cr, uid, ids, context=None): + for obj in self.browse(cr, uid, ids, context=context): + self.message_subscribe(cr, uid, ids, [obj.validator.id], context=context) + self.message_append_note(cr, uid, ids, _('System notification'), + _("""Quotation %s converted to a Purchase Order of %s %s.""") + % (obj.partner_id.name, obj.amount_total, obj.pricelist_id.currency_id.symbol), type='notification', context=context) + + def shipment_notificate(self, cr, uid, ids, picking_id, context=None): + for order in self.browse(cr, uid, ids, context=context): + for picking in (pck for pck in order.picking_ids if pck.id == picking_id): + pck_date = datetime.strptime(picking.min_date, '%Y-%m-%d %H:%M:%S').strftime('%m/%d/%Y') + self.message_append_note(cr, uid, ids, _('System notification'), + _("""Shipment %s scheduled for %s.""") + % (picking.name, pck_date), type='notification', context=context) + + def invoice_notificate(self, cr, uid, ids, invoice_id, context=None): + for order in self.browse(cr, uid, ids, context=context): + for invoice in (inv for inv in order.invoice_ids if inv.id == invoice_id): + self.message_append_note(cr, uid, ids, _('System notification'), + _("""Draft Invoice of %s %s waiting for validation.""") + % (invoice.amount_total, invoice.currency_id.symbol), type='notification', context=context) + + def shipment_done_notificate(self, cr, uid, ids, context=None): + self.message_append_note(cr, uid, ids, _('System notification'), + _("""Shipment received.""") + ,type='notification', context=context) + + def invoice_paid_notificate(self, cr, uid, ids, context=None): + self.message_append_note(cr, uid, ids, _('System notification'), + _("""Invoice paid.""") + ,type='notification', context=context) + + def cancel_notificate(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'), + _("""Purchase Order for %s cancelled.""") + % (obj.partner_id.name), type='notification', context=context) purchase_order() diff --git a/addons/purchase/purchase_view.xml b/addons/purchase/purchase_view.xml index 1c936055aff..4e6ebc45c37 100644 --- a/addons/purchase/purchase_view.xml +++ b/addons/purchase/purchase_view.xml @@ -231,6 +231,7 @@ + diff --git a/addons/purchase/purchase_workflow.xml b/addons/purchase/purchase_workflow.xml index c978712c0a1..b26363a02f2 100644 --- a/addons/purchase/purchase_workflow.xml +++ b/addons/purchase/purchase_workflow.xml @@ -55,7 +55,7 @@ invoice_done - write({'state':'approved'}) + invoice_done() function @@ -72,7 +72,7 @@ picking_done - write({'shipped':1,'state':'approved'}) + picking_done() function subflow.delivery_done From d5411712d9e3757694392069dda3b4505bca05b1 Mon Sep 17 00:00:00 2001 From: "RGA(OpenERP)" <> Date: Fri, 16 Mar 2012 20:27:04 +0530 Subject: [PATCH 2/3] [IMP] hange method name _notificate to _send_note and add need action bzr revid: rgaopenerp-20120316145704-e87uo2rqz1ppitnl --- addons/purchase/purchase.py | 44 +++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/addons/purchase/purchase.py b/addons/purchase/purchase.py index 2a0be38b773..4ed3524575a 100644 --- a/addons/purchase/purchase.py +++ b/addons/purchase/purchase.py @@ -151,7 +151,6 @@ class purchase_order(osv.osv): ('done', 'Done'), ('cancel', 'Cancelled') ] - _columns = { 'name': fields.char('Order Reference', size=64, required=True, select=True, help="unique number of the purchase order,computed automatically when the purchase order is created"), 'origin': fields.char('Source Document', size=64, @@ -230,7 +229,7 @@ class purchase_order(osv.osv): def create(self, cr, uid, vals, context=None): order = super(purchase_order, self).create(cr, uid, vals, context=context) if order: - self.create_notificate(cr, uid, [order], context=context) + self.create_send_note(cr, uid, [order], context=context) return order def unlink(self, cr, uid, ids, context=None): @@ -299,7 +298,7 @@ class purchase_order(osv.osv): self.pool.get('purchase.order.line').action_confirm(cr, uid, todo, context) for id in ids: self.write(cr, uid, [id], {'state' : 'confirmed', 'validator' : uid}) - self.confirm_notificate(cr, uid, ids, context) + self.confirm_send_note(cr, uid, ids, context) return True def _prepare_inv_line(self, cr, uid, account_id, order_line, context=None): @@ -402,12 +401,12 @@ class purchase_order(osv.osv): order.write({'invoice_ids': [(4, inv_id)]}, context=context) res = inv_id if res: - self.invoice_notificate(cr, uid, ids, res, context) + self.invoice_send_note(cr, uid, ids, res, context) return res def invoice_done(self, cr, uid, ids, context=None): self.write(cr, uid, ids, {'state':'approved'}, context=context) - self.invoice_paid_notificate(cr, uid, ids, context=context) + self.invoice_paid_send_note(cr, uid, ids, context=context) return True def has_stockable_product(self,cr, uid, ids, *args): @@ -523,12 +522,12 @@ class purchase_order(osv.osv): # one that should trigger the advancement of the purchase workflow. # By default we will consider the first one as most important, but this behavior can be overridden. if picking_ids: - self.shipment_notificate(cr, uid, ids, picking_ids[0], context=context) + self.shipment_send_note(cr, uid, ids, picking_ids[0], context=context) return picking_ids[0] if picking_ids else False def picking_done(self, cr, uid, ids, context=None): self.write(cr, uid, ids, {'shipped':1,'state':'approved'}, context=context) - self.shipment_done_notificate(cr, uid, ids, context=context) + self.shipment_done_send_note(cr, uid, ids, context=context) return True def copy(self, cr, uid, id, default=None, context=None): @@ -659,46 +658,53 @@ class purchase_order(osv.osv): # ----------------------------- # OpenChatter and notifications # ----------------------------- - def create_notificate(self, cr, uid, ids, context=None): + def get_needaction_user_ids(self, cr, uid, ids, context=None): + result = dict.fromkeys(ids, []) + for obj in self.browse(cr, uid, ids, context=context): + if obj.state == 'approved': + result[obj.id] = [obj.validator.id] + return result + + def create_send_note(self, cr, uid, ids, context=None): self.message_append_note(cr, uid, ids, _('System notification'), _("""Request for quotation created."""), type='notification', context=context) - def confirm_notificate(self, cr, uid, ids, context=None): + def confirm_send_note(self, cr, uid, ids, context=None): for obj in self.browse(cr, uid, ids, context=context): - self.message_subscribe(cr, uid, ids, [obj.validator.id], context=context) - self.message_append_note(cr, uid, ids, _('System notification'), + self.message_subscribe(cr, uid, [obj.id], [obj.validator.id], context=context) + self.message_append_note(cr, uid, [obj.id], _('System notification'), _("""Quotation %s converted to a Purchase Order of %s %s.""") % (obj.partner_id.name, obj.amount_total, obj.pricelist_id.currency_id.symbol), type='notification', context=context) - def shipment_notificate(self, cr, uid, ids, picking_id, context=None): + def shipment_send_note(self, cr, uid, ids, picking_id, context=None): for order in self.browse(cr, uid, ids, context=context): for picking in (pck for pck in order.picking_ids if pck.id == picking_id): pck_date = datetime.strptime(picking.min_date, '%Y-%m-%d %H:%M:%S').strftime('%m/%d/%Y') - self.message_append_note(cr, uid, ids, _('System notification'), + self.message_append_note(cr, uid, [order.id], _('System notification'), _("""Shipment %s scheduled for %s.""") % (picking.name, pck_date), type='notification', context=context) - def invoice_notificate(self, cr, uid, ids, invoice_id, context=None): + def invoice_send_note(self, cr, uid, ids, invoice_id, context=None): for order in self.browse(cr, uid, ids, context=context): for invoice in (inv for inv in order.invoice_ids if inv.id == invoice_id): - self.message_append_note(cr, uid, ids, _('System notification'), + self.message_append_note(cr, uid, [order.id], _('System notification'), _("""Draft Invoice of %s %s waiting for validation.""") % (invoice.amount_total, invoice.currency_id.symbol), type='notification', context=context) - def shipment_done_notificate(self, cr, uid, ids, context=None): + def shipment_done_send_note(self, cr, uid, ids, context=None): self.message_append_note(cr, uid, ids, _('System notification'), _("""Shipment received.""") ,type='notification', context=context) - def invoice_paid_notificate(self, cr, uid, ids, context=None): + def invoice_paid_send_note(self, cr, uid, ids, context=None): self.message_append_note(cr, uid, ids, _('System notification'), _("""Invoice paid.""") ,type='notification', context=context) - def cancel_notificate(self, cr, uid, ids, context=None): + def 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'), _("""Purchase Order for %s cancelled.""") % (obj.partner_id.name), type='notification', context=context) From fad5c86dc9ff0c367a08ced2c7784e08a6b42680 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Mon, 2 Apr 2012 17:30:02 +0200 Subject: [PATCH 3/3] [IMP] Small improvement of messages bzr revid: tde@openerp.com-20120402153002-b96t8bfus3ham5cs --- addons/purchase/purchase.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/purchase/purchase.py b/addons/purchase/purchase.py index 0feb605de9d..e30bb94f356 100644 --- a/addons/purchase/purchase.py +++ b/addons/purchase/purchase.py @@ -668,7 +668,7 @@ class purchase_order(osv.osv): for obj in self.browse(cr, uid, ids, context=context): self.message_subscribe(cr, uid, [obj.id], [obj.validator.id], context=context) self.message_append_note(cr, uid, [obj.id], _('System notification'), - _("""Quotation %s converted to a Purchase Order of %s %s.""") + _("""Quotation for %s converted to a Purchase Order of %s %s.""") % (obj.partner_id.name, obj.amount_total, obj.pricelist_id.currency_id.symbol), type='notification', context=context) def shipment_send_note(self, cr, uid, ids, picking_id, context=None): @@ -683,7 +683,7 @@ class purchase_order(osv.osv): for order in self.browse(cr, uid, ids, context=context): for invoice in (inv for inv in order.invoice_ids if inv.id == invoice_id): self.message_append_note(cr, uid, [order.id], _('System notification'), - _("""Draft Invoice of %s %s waiting for validation.""") + _("""Draft Invoice of %s %s is waiting for validation.""") % (invoice.amount_total, invoice.currency_id.symbol), type='notification', context=context) def shipment_done_send_note(self, cr, uid, ids, context=None):