[IMP] Added notification for purchase order

bzr revid: rgaopenerp-20120313100726-e01a0bbrxw05kmw0
This commit is contained in:
RGA(OpenERP) 2012-03-13 15:37:26 +05:30
parent debad43b1c
commit a67ecbaaae
3 changed files with 74 additions and 5 deletions

View File

@ -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 <b>created</b>."""),
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 <em>%s</em> <b>converted</b> 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 <em>%s</em> <b>scheduled</b> 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 <b>waiting for validation</b>.""")
% (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 <b>received</b>.""")
,type='notification', context=context)
def invoice_paid_notificate(self, cr, uid, ids, context=None):
self.message_append_note(cr, uid, ids, _('System notification'),
_("""Invoice <b>paid</b>.""")
,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 <em>%s</em> <b>cancelled</b>.""")
% (obj.partner_id.name), type='notification', context=context)
purchase_order()

View File

@ -231,6 +231,7 @@
<field colspan="4" name="notes" nolabel="1"/>
</page>
</notebook>
<field name="message_ids_social" colspan="4" widget="ThreadView" nolabel="1"/>
</form>
</field>
</record>

View File

@ -55,7 +55,7 @@
<record id="act_invoice_done" model="workflow.activity">
<field name="wkf_id" ref="purchase_order"/>
<field name="name">invoice_done</field>
<field name="action">write({'state':'approved'})</field>
<field name="action">invoice_done()</field>
<field name="kind">function</field>
</record>
<record id="act_invoice_end" model="workflow.activity">
@ -72,7 +72,7 @@
<record id="act_picking_done" model="workflow.activity">
<field name="wkf_id" ref="purchase_order"/>
<field name="name">picking_done</field>
<field name="action">write({'shipped':1,'state':'approved'})</field>
<field name="action">picking_done()</field>
<field name="kind">function</field>
<field name="signal_send">subflow.delivery_done</field>
</record>