From 5d29a27a5fdfd86dd6f7f468cea1656c97cacf28 Mon Sep 17 00:00:00 2001 From: "RGA(OpenERP)" <> Date: Tue, 13 Mar 2012 15:00:45 +0530 Subject: [PATCH 1/7] [IMP] Added notification for sale bzr revid: rgaopenerp-20120313093045-x8tsaxjqwts113jz --- addons/sale/sale.py | 83 ++++++++++++++++++++++++++++++++++----- addons/sale/sale_view.xml | 6 +-- 2 files changed, 74 insertions(+), 15 deletions(-) diff --git a/addons/sale/sale.py b/addons/sale/sale.py index 82bfda7b580..d8d25e213d6 100644 --- a/addons/sale/sale.py +++ b/addons/sale/sale.py @@ -48,7 +48,9 @@ sale_shop() class sale_order(osv.osv): _name = "sale.order" + _inherit = 'mail.thread' _description = "Sales Order" + def copy(self, cr, uid, id, default=None, context=None): if not default: @@ -321,9 +323,6 @@ class sale_order(osv.osv): # Deleting the existing instance of workflow for SO wf_service.trg_delete(uid, 'sale.order', inv_id, cr) wf_service.trg_create(uid, 'sale.order', inv_id, cr) - for (id,name) in self.name_get(cr, uid, ids): - message = _("The sales order '%s' has been set in draft state.") %(name,) - self.log(cr, uid, id, message) return True def onchange_pricelist_id(self, cr, uid, ids, pricelist_id, order_lines, context={}): @@ -391,7 +390,10 @@ class sale_order(osv.osv): vals.update({'invoice_quantity': 'order'}) if vals['order_policy'] == 'picking': vals.update({'invoice_quantity': 'procurement'}) - return super(sale_order, self).create(cr, uid, vals, context=context) + order = super(sale_order, self).create(cr, uid, vals, context=context) + if order: + self.create_notificate(cr, uid, [order], context=context) + return order def button_dummy(self, cr, uid, ids, context=None): return True @@ -487,7 +489,6 @@ class sale_order(osv.osv): res = mod_obj.get_object_reference(cr, uid, 'account', 'invoice_form') res_id = res and res[1] or False, - return { 'name': _('Customer Invoices'), 'view_type': 'form', @@ -556,6 +557,8 @@ class sale_order(osv.osv): if order.order_policy == 'picking': picking_obj.write(cr, uid, map(lambda x: x.id, order.picking_ids), {'invoice_state': 'invoiced'}) cr.execute('insert into sale_order_invoice_rel (order_id,invoice_id) values (%s,%s)', (order.id, res)) + if res: + self.invoice_notificate(cr, uid, ids, res, context) return res def action_invoice_cancel(self, cr, uid, ids, context=None): @@ -607,6 +610,7 @@ class sale_order(osv.osv): # if order.state == 'invoice_except': self.write(cr, uid, [order.id], {'state': 'progress'}, context=context) + self.invoice_paid_notificate(cr, uid, ids, context=None) return True def action_cancel(self, cr, uid, ids, context=None): @@ -640,8 +644,7 @@ class sale_order(osv.osv): wf_service.trg_validate(uid, 'account.invoice', inv, 'invoice_cancel', cr) sale_order_line_obj.write(cr, uid, [l.id for l in sale.order_line], {'state': 'cancel'}) - message = _("The sales order '%s' has been cancelled.") % (sale.name,) - self.log(cr, uid, sale.id, message) + self.cancel_notificate(cr, uid, [sale.id], context=None) self.write(cr, uid, ids, {'state': 'cancel'}) return True @@ -654,8 +657,7 @@ class sale_order(osv.osv): else: self.write(cr, uid, [o.id], {'state': 'progress', 'date_confirm': fields.date.context_today(self, cr, uid, context=context)}) self.pool.get('sale.order.line').button_confirm(cr, uid, [x.id for x in o.order_line]) - message = _("The quotation '%s' has been converted to a sales order.") % (o.name,) - self.log(cr, uid, o.id, message) + self.confirm_notificate(cr, uid, ids, context) return True def procurement_lines_get(self, cr, uid, ids, *args): @@ -840,6 +842,8 @@ class sale_order(osv.osv): wf_service = netsvc.LocalService("workflow") if picking_id: wf_service.trg_validate(uid, 'stock.picking', picking_id, 'button_confirm', cr) + self.delivery_notificate(cr, uid, [order.id], picking_id, context) + for proc_id in proc_ids: wf_service.trg_validate(uid, 'procurement.order', proc_id, 'button_confirm', cr) @@ -878,7 +882,9 @@ class sale_order(osv.osv): towrite.append(line.id) if towrite: self.pool.get('sale.order.line').write(cr, uid, towrite, {'state': 'done'}, context=context) - self.write(cr, uid, [order.id], val) + res = self.write(cr, uid, [order.id], val) + if res: + self.delivery_end_notificate(cr, uid, [order.id], context=context) return True def _log_event(self, cr, uid, ids, factor=0.7, name='Open Order'): @@ -910,6 +916,63 @@ class sale_order(osv.osv): if order_line.product_id and order_line.product_id.product_tmpl_id.type in ('product', 'consu'): return True return False + + # ----------------------------- + # OpenChatter and notifications + # ----------------------------- + def get_needaction_user_id(self, cr, uid, ids, name, arg, context=None): + result = {} + for obj in self.browse(cr, uid, ids, context=context): + result[obj.id] = False + if (obj.state == 'manual' or obj.state == 'progress'): + result[obj.id] = obj.user_id.id + return result + + def create_notificate(self, cr, uid, ids, context=None): + for obj in self.browse(cr, uid, ids, context=context): + self.message_subscribe(cr, uid, ids, [obj.user_id.id], context=context) + self.message_append_note(cr, uid, ids, _('System notification'), + _("""Quotation for %s created.""") + % (obj.partner_id.name), 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_append_note(cr, uid, ids, _('System notification'), + _("""Quotation %s converted to a Sale Order of %s %s.""") + % (obj.partner_id.name, obj.amount_total, obj.pricelist_id.currency_id.symbol), 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'), + _("""Sale Order for %s cancelled.""") + % (obj.partner_id.name), type='notification', context=context) + + def delivery_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'), + _("""Delivery Order %s scheduled for %s.""") + % (picking.name, pck_date), type='notification', context=context) + + def delivery_end_notificate(self, cr, uid, ids, context=None): + self.message_append_note(cr, uid, ids, _('System notification'), + _("""Order delivered.""") + ,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 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) + + sale_order() # TODO add a field price_unit_uos diff --git a/addons/sale/sale_view.xml b/addons/sale/sale_view.xml index 90d3838f5a0..2e3fdeb49c5 100644 --- a/addons/sale/sale_view.xml +++ b/addons/sale/sale_view.xml @@ -235,11 +235,6 @@ - - - - - @@ -250,6 +245,7 @@ + From 15bdffe237a1aab2de3973a73adbc045a61759b0 Mon Sep 17 00:00:00 2001 From: "RGA(OpenERP)" <> Date: Fri, 16 Mar 2012 19:15:01 +0530 Subject: [PATCH 2/7] [IMP] change method name _notificate to _send_note and use new api of need action bzr revid: rgaopenerp-20120316134501-83xvlo0xwoiqhod0 --- addons/sale/sale.py | 55 ++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/addons/sale/sale.py b/addons/sale/sale.py index d8d25e213d6..31a52205eb3 100644 --- a/addons/sale/sale.py +++ b/addons/sale/sale.py @@ -392,7 +392,7 @@ class sale_order(osv.osv): vals.update({'invoice_quantity': 'procurement'}) order = super(sale_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 button_dummy(self, cr, uid, ids, context=None): @@ -558,7 +558,7 @@ class sale_order(osv.osv): picking_obj.write(cr, uid, map(lambda x: x.id, order.picking_ids), {'invoice_state': 'invoiced'}) cr.execute('insert into sale_order_invoice_rel (order_id,invoice_id) values (%s,%s)', (order.id, res)) if res: - self.invoice_notificate(cr, uid, ids, res, context) + self.invoice_send_note(cr, uid, ids, res, context) return res def action_invoice_cancel(self, cr, uid, ids, context=None): @@ -610,7 +610,7 @@ class sale_order(osv.osv): # if order.state == 'invoice_except': self.write(cr, uid, [order.id], {'state': 'progress'}, context=context) - self.invoice_paid_notificate(cr, uid, ids, context=None) + self.invoice_paid_send_note(cr, uid, ids, context=None) return True def action_cancel(self, cr, uid, ids, context=None): @@ -644,7 +644,7 @@ class sale_order(osv.osv): wf_service.trg_validate(uid, 'account.invoice', inv, 'invoice_cancel', cr) sale_order_line_obj.write(cr, uid, [l.id for l in sale.order_line], {'state': 'cancel'}) - self.cancel_notificate(cr, uid, [sale.id], context=None) + self.cancel_send_note(cr, uid, [sale.id], context=None) self.write(cr, uid, ids, {'state': 'cancel'}) return True @@ -657,7 +657,7 @@ class sale_order(osv.osv): else: self.write(cr, uid, [o.id], {'state': 'progress', 'date_confirm': fields.date.context_today(self, cr, uid, context=context)}) self.pool.get('sale.order.line').button_confirm(cr, uid, [x.id for x in o.order_line]) - self.confirm_notificate(cr, uid, ids, context) + self.confirm_send_note(cr, uid, ids, context) return True def procurement_lines_get(self, cr, uid, ids, *args): @@ -842,7 +842,7 @@ class sale_order(osv.osv): wf_service = netsvc.LocalService("workflow") if picking_id: wf_service.trg_validate(uid, 'stock.picking', picking_id, 'button_confirm', cr) - self.delivery_notificate(cr, uid, [order.id], picking_id, context) + self.delivery_send_note(cr, uid, [order.id], picking_id, context) for proc_id in proc_ids: @@ -884,7 +884,7 @@ class sale_order(osv.osv): self.pool.get('sale.order.line').write(cr, uid, towrite, {'state': 'done'}, context=context) res = self.write(cr, uid, [order.id], val) if res: - self.delivery_end_notificate(cr, uid, [order.id], context=context) + self.delivery_end_send_note(cr, uid, [order.id], context=context) return True def _log_event(self, cr, uid, ids, factor=0.7, name='Open Order'): @@ -920,55 +920,54 @@ class sale_order(osv.osv): # ----------------------------- # OpenChatter and notifications # ----------------------------- - def get_needaction_user_id(self, cr, uid, ids, name, arg, context=None): - result = {} + 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): - result[obj.id] = False if (obj.state == 'manual' or obj.state == 'progress'): - result[obj.id] = obj.user_id.id + result[obj.id] = [obj.user_id.id] return result - - def create_notificate(self, cr, uid, ids, context=None): + + def create_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.user_id.id], context=context) - self.message_append_note(cr, uid, ids, _('System notification'), - _("""Quotation for %s created.""") - % (obj.partner_id.name), type='notification', context=context) + self.message_subscribe(cr, uid, [obj.id], [obj.user_id.id], context=context) + self.message_append_note(cr, uid, [obj.id], _('System notification'), + _("""Quotation for %s created.""") + % (obj.partner_id.name), 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_append_note(cr, uid, ids, _('System notification'), - _("""Quotation %s converted to a Sale Order of %s %s.""") + self.message_append_note(cr, uid, [obj.id], _('System notification'), + _("""Quotation %s converted to Sale Order of %s %s.""") % (obj.partner_id.name, obj.amount_total, obj.pricelist_id.currency_id.symbol), 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'), _("""Sale Order for %s cancelled.""") % (obj.partner_id.name), type='notification', context=context) - def delivery_notificate(self, cr, uid, ids, picking_id, context=None): + def delivery_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'), _("""Delivery Order %s scheduled for %s.""") % (picking.name, pck_date), type='notification', context=context) - def delivery_end_notificate(self, cr, uid, ids, context=None): + def delivery_end_send_note(self, cr, uid, ids, context=None): self.message_append_note(cr, uid, ids, _('System notification'), _("""Order delivered.""") ,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 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) From 606e3755400517d41539e0bfb3975c46a1aba978 Mon Sep 17 00:00:00 2001 From: "RGA(OpenERP)" <> Date: Thu, 22 Mar 2012 19:49:49 +0530 Subject: [PATCH 3/7] [FIX] inherited view could not find 'date_create' which is remove from sale_order form view bzr revid: rgaopenerp-20120322141949-oghbmf2v8y68m2bx --- addons/sale/sale_view.xml | 2 +- addons/sale_order_dates/sale_order_dates_view.xml | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/addons/sale/sale_view.xml b/addons/sale/sale_view.xml index 2e3fdeb49c5..4f3acc2185a 100644 --- a/addons/sale/sale_view.xml +++ b/addons/sale/sale_view.xml @@ -229,7 +229,7 @@ - + diff --git a/addons/sale_order_dates/sale_order_dates_view.xml b/addons/sale_order_dates/sale_order_dates_view.xml index c6544d5238f..3340b94006c 100644 --- a/addons/sale_order_dates/sale_order_dates_view.xml +++ b/addons/sale_order_dates/sale_order_dates_view.xml @@ -8,13 +8,13 @@ form - - - - - - - + + + + + + + From bf879014b73655a51ac556c1ef56ec17d479eef4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Thu, 22 Mar 2012 15:57:27 +0100 Subject: [PATCH 4/7] [IMP] Better code indentation; added a forgotten field; reset group to the good one. bzr revid: tde@openerp.com-20120322145727-hknudtr5t82ds832 --- addons/sale_order_dates/sale_order_dates_view.xml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/addons/sale_order_dates/sale_order_dates_view.xml b/addons/sale_order_dates/sale_order_dates_view.xml index 3340b94006c..6ce54e798d3 100644 --- a/addons/sale_order_dates/sale_order_dates_view.xml +++ b/addons/sale_order_dates/sale_order_dates_view.xml @@ -9,14 +9,15 @@ - - - - + + + + + - \ No newline at end of file + From ab5a577438041334b75b9ea7d3037aec1653508b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Thu, 22 Mar 2012 16:08:04 +0100 Subject: [PATCH 5/7] [IMP] Indentation problem bzr revid: tde@openerp.com-20120322150804-0azu6vu6e4afsiue --- addons/sale_order_dates/sale_order_dates_view.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/sale_order_dates/sale_order_dates_view.xml b/addons/sale_order_dates/sale_order_dates_view.xml index 6ce54e798d3..672a1cadd0e 100644 --- a/addons/sale_order_dates/sale_order_dates_view.xml +++ b/addons/sale_order_dates/sale_order_dates_view.xml @@ -9,12 +9,12 @@ - + - + From 5a08aaddd4c35530ee7af4d4cac4cd055b212e9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Mon, 2 Apr 2012 17:33:03 +0200 Subject: [PATCH 6/7] [IMP] Small improvement of messages bzr revid: tde@openerp.com-20120402153303-5r5v1nvemj29vh9l --- addons/sale/sale.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/sale/sale.py b/addons/sale/sale.py index 73fa3d40e20..0b7805c1b75 100644 --- a/addons/sale/sale.py +++ b/addons/sale/sale.py @@ -932,7 +932,7 @@ class sale_order(osv.osv): def confirm_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'), - _("""Quotation %s converted to Sale Order of %s %s.""") + _("""Quotation for %s converted to Sale Order of %s %s.""") % (obj.partner_id.name, obj.amount_total, obj.pricelist_id.currency_id.symbol), type='notification', context=context) def cancel_send_note(self, cr, uid, ids, context=None): From 81003b68eda789a44dd8dd6bf9d948ecd6495740 Mon Sep 17 00:00:00 2001 From: "RGA(OpenERP)" <> Date: Tue, 3 Apr 2012 11:35:43 +0530 Subject: [PATCH 7/7] [IMP] Small improvement of messages bzr revid: rgaopenerp-20120403060543-9sym6trb0tqvavl8 --- addons/sale/sale.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/sale/sale.py b/addons/sale/sale.py index 0b7805c1b75..b46b2f84b5a 100644 --- a/addons/sale/sale.py +++ b/addons/sale/sale.py @@ -926,7 +926,7 @@ class sale_order(osv.osv): for obj in self.browse(cr, uid, ids, context=context): self.message_subscribe(cr, uid, [obj.id], [obj.user_id.id], context=context) self.message_append_note(cr, uid, [obj.id], _('System notification'), - _("""Quotation for %s created.""") + _("""Quotation for %s has been created.""") % (obj.partner_id.name), type='notification', context=context) def confirm_send_note(self, cr, uid, ids, context=None):