_name = "procurement.order"
_description = "Procurement"
_order = 'priority,date_planned desc'
+ _inherit = ['ir.needaction_mixin', 'mail.thread']
_log_create = False
_columns = {
'name': fields.char('Reason', size=64, required=True, help='Procurement name.'),
\nAfter confirming the state is set to \'Running\'.\n If any exception arises in the order then the state is set to \'Exception\'.\n Once the exception is removed the state becomes \'Ready\'.\n It is in \'Waiting\'. state when the procurement is waiting for another one to finish.'),
'note': fields.text('Note'),
'company_id': fields.many2one('res.company','Company',required=True),
+ 'user_id': fields.many2one('res.users', 'Salesman'),
}
_defaults = {
'state': 'draft',
'date_planned': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'),
'close_move': 0,
'procure_method': 'make_to_order',
+ 'user_id': lambda obj, cr, uid, context: uid,
'company_id': lambda self, cr, uid, c: self.pool.get('res.company')._company_default_get(cr, uid, 'procurement.order', context=c)
}
move_obj.action_confirm(cr, uid, [id], context=context)
self.write(cr, uid, [procurement.id], {'move_id': id, 'close_move': 1})
self.write(cr, uid, ids, {'state': 'confirmed', 'message': ''})
+ self.confirm_send_note(cr, uid, ids, context)
return True
def action_move_assigned(self, cr, uid, ids, context=None):
"""
self.write(cr, uid, ids, {'state': 'running',
'message': _('from stock: products assigned.')})
+ self.running_send_note(cr, uid, ids, context)
return True
def _check_make_to_stock_service(self, cr, uid, procurement, context=None):
if len(todo):
move_obj.write(cr, uid, todo, {'state': 'assigned'})
self.write(cr, uid, ids, {'state': 'cancel'})
+ self.cancel_send_note(cr, uid, ids, context=None)
wf_service = netsvc.LocalService("workflow")
for id in ids:
wf_service.trg_trigger(uid, 'procurement.order', id, cr)
@return: True
"""
res = self.write(cr, uid, ids, {'state': 'ready'})
+ self.ready_send_note(cr, uid, ids, context)
return res
def action_done(self, cr, uid, ids):
if procurement.close_move and (procurement.move_id.state <> 'done'):
move_obj.action_done(cr, uid, [procurement.move_id.id])
res = self.write(cr, uid, ids, {'state': 'done', 'date_close': time.strftime('%Y-%m-%d')})
+ self.done_send_note(cr, uid, ids, context)
wf_service = netsvc.LocalService("workflow")
for id in ids:
wf_service.trg_trigger(uid, 'procurement.order', id, cr)
return res
+ # ----------------------------------------
+ # OpenChatter methods and notifications
+ # ----------------------------------------
+
+ 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 == 'draft' or obj.state == 'waiting'):
+ result[obj.id] = [obj.user_id.id]
+ return result
+
+ def create(self, cr, uid, vals, context=None):
+ obj_id = super(procurement_order, self).create(cr, uid, vals, context)
+ self.create_send_note(cr, uid, [obj_id], context=context)
+ return obj_id
+
+ 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, [obj.id], [obj.user_id.id], context=context)
+ self.message_append_note(cr, uid, [obj.id], body=_("Procurement has been <b>created</b>."), context=context)
+
+ 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, [obj.id], [obj.user_id.id], context=context)
+ self.message_append_note(cr, uid, [obj.id], body=_("Procurement has been <b>confirmed</b>."), context=context)
+
+ def running_send_note(self, cr, uid, ids, context=None):
+ 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], body=_("Procurement has been <b>run</b>."), context=context)
+
+ def ready_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], body=_("Procurement has been <b>redy</b>."), context=context)
+
+ 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, [obj.id], body=_("Procurement has been <b>cancelled</b>."), context=context)
+
+ def done_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], body=_("Procurement has been <b>done</b>."), context=context)
+
procurement_order()
class StockPicking(osv.osv):