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 @@ +