diff --git a/addons/mrp/mrp.py b/addons/mrp/mrp.py index 1f70f55e505..8e550ba4119 100644 --- a/addons/mrp/mrp.py +++ b/addons/mrp/mrp.py @@ -130,6 +130,7 @@ class mrp_bom(osv.osv): """ _name = 'mrp.bom' _description = 'Bill of Material' + _inherit = ['mail.thread'] def _child_compute(self, cr, uid, ids, name, arg, context=None): """ Gets child bom. @@ -358,6 +359,18 @@ class mrp_bom(osv.osv): default.update({'name': bom_data['name'] + ' ' + _('Copy'), 'bom_id':False}) return super(mrp_bom, self).copy_data(cr, uid, id, default, context=context) + def create(self, cr, uid, vals, context=None): + obj_id = super(mrp_bom, self).create(cr, uid, vals, context=context) + self.create_send_note(cr, uid, [obj_id], context=context) + return obj_id + + def create_send_note(self, cr, uid, ids, context=None): + prod_obj = self.pool.get('product.product') + for obj in self.browse(cr, uid, ids, context=context): + for prod in prod_obj.browse(cr, uid, [obj.product_id], context=context): + self.message_append_note(cr, uid, [obj.id], body=_("Bill of Material has been created for %s product.") % (prod.id.name_template), context=context) + return True + mrp_bom() class mrp_bom_revision(osv.osv): @@ -393,6 +406,7 @@ class mrp_production(osv.osv): _name = 'mrp.production' _description = 'Manufacturing Order' _date_name = 'date_planned' + _inherit = ['ir.needaction', 'mail.thread'] def _production_calc(self, cr, uid, ids, prop, unknow_none, context=None): """ Calculates total hours and total no. of cycles for a production order. @@ -497,6 +511,11 @@ class mrp_production(osv.osv): (_check_qty, 'Order quantity cannot be negative or zero!', ['product_qty']), ] + def create(self, cr, uid, vals, context=None): + obj_id = super(mrp_production, self).create(cr, uid, vals, context=context) + self.create_send_note(cr, uid, [obj_id], context=context) + return obj_id + def unlink(self, cr, uid, ids, context=None): for production in self.browse(cr, uid, ids, context=context): if production.state not in ('draft', 'cancel'): @@ -629,9 +648,10 @@ class mrp_production(osv.osv): move_obj.action_cancel(cr, uid, [x.id for x in production.move_created_ids]) move_obj.action_cancel(cr, uid, [x.id for x in production.move_lines]) self.write(cr, uid, ids, {'state': 'cancel'}) + self.action_cancel_send_note(cr, uid, ids, context) return True - def action_ready(self, cr, uid, ids): + def action_ready(self, cr, uid, ids, context=None): """ Changes the production state to Ready and location id of stock move. @return: True """ @@ -643,18 +663,18 @@ class mrp_production(osv.osv): if production.move_prod_id: move_obj.write(cr, uid, [production.move_prod_id.id], {'location_id': production.location_dest_id.id}) - - message = _("Manufacturing order '%s' is ready to produce.") % ( name,) - self.log(cr, uid, production_id, message) + self.action_ready_send_note(cr, uid, [production_id], context) return True - def action_production_end(self, cr, uid, ids): + def action_production_end(self, cr, uid, ids, context=None): """ Changes production state to Finish and writes finished date. @return: True """ for production in self.browse(cr, uid, ids): self._costs_generate(cr, uid, production) - return self.write(cr, uid, ids, {'state': 'done', 'date_finished': time.strftime('%Y-%m-%d %H:%M:%S')}) + write_res = self.write(cr, uid, ids, {'state': 'done', 'date_finished': time.strftime('%Y-%m-%d %H:%M:%S')}) + self.action_done_send_note(cr, uid, ids, context) + return write_res def test_production_done(self, cr, uid, ids): """ Tests whether production is done or not. @@ -698,7 +718,6 @@ class mrp_production(osv.osv): if (produced_product.scrapped) or (produced_product.product_id.id <> production.product_id.id): continue produced_qty += produced_product.product_qty - if production_mode in ['consume','consume_produce']: consumed_data = {} @@ -819,11 +838,12 @@ class mrp_production(osv.osv): } ) return amount - def action_in_production(self, cr, uid, ids): + def action_in_production(self, cr, uid, ids, context=None): """ Changes state to In Production and writes starting date. @return: True """ self.write(cr, uid, ids, {'state': 'in_production', 'date_start': time.strftime('%Y-%m-%d %H:%M:%S')}) + self.action_in_production_send_note(cr, uid, ids, context) return True def test_if_product(self, cr, uid, ids): @@ -997,11 +1017,7 @@ class mrp_production(osv.osv): wf_service.trg_validate(uid, 'stock.picking', shipment_id, 'button_confirm', cr) production.write({'state':'confirmed'}, context=context) - message = _("Manufacturing order '%s' is scheduled for the %s.") % ( - production.name, - datetime.strptime(production.date_planned,'%Y-%m-%d %H:%M:%S').strftime('%m/%d/%Y'), - ) - self.log(cr, uid, production.id, message) + self.action_confirm_send_note(cr, uid, [production.id], context); return shipment_id def force_production(self, cr, uid, ids, *args): @@ -1012,6 +1028,55 @@ class mrp_production(osv.osv): pick_obj = self.pool.get('stock.picking') pick_obj.force_assign(cr, uid, [prod.picking_id.id for prod in self.browse(cr, uid, ids)]) return True + + # --------------------------------------------------- + # 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' and obj.user_id: + result[obj.id] = [obj.user_id.id] + return result + + def message_get_subscribers(self, cr, uid, ids, context=None): + sub_ids = self.message_get_subscribers_ids(cr, uid, ids, context=context); + for obj in self.browse(cr, uid, ids, context=context): + if obj.user_id: + sub_ids.append(obj.user_id.id) + return self.pool.get('res.users').read(cr, uid, sub_ids, context=context) + + def create_send_note(self, cr, uid, ids, context=None): + self.message_append_note(cr, uid, ids, body=_("Manufacturing order has been created."), context=context) + return True + + def action_cancel_send_note(self, cr, uid, ids, context=None): + message = _("Manufacturing order has been canceled.") + self.message_append_note(cr, uid, ids, body=message, context=context) + return True + + def action_ready_send_note(self, cr, uid, ids, context=None): + message = _("Manufacturing order is ready to produce.") + self.message_append_note(cr, uid, ids, body=message, context=context) + return True + + def action_in_production_send_note(self, cr, uid, ids, context=None): + message = _("Manufacturing order is in production.") + self.message_append_note(cr, uid, ids, body=message, context=context) + return True + + def action_done_send_note(self, cr, uid, ids, context=None): + message = _("Manufacturing order has been done.") + self.message_append_note(cr, uid, ids, body=message, context=context) + return True + + def action_confirm_send_note(self, cr, uid, ids, context=None): + for obj in self.browse(cr, uid, ids, context=context): + message = _("Manufacturing order has been confirmed and is scheduled for the %s.") % (obj.date_planned) + self.message_append_note(cr, uid, [obj.id], body=message, context=context) + return True + mrp_production() @@ -1019,6 +1084,7 @@ class mrp_production_workcenter_line(osv.osv): _name = 'mrp.production.workcenter.line' _description = 'Work Order' _order = 'sequence' + _inherit = ['mail.thread'] _columns = { 'name': fields.char('Work Order', size=64, required=True), diff --git a/addons/mrp/mrp_view.xml b/addons/mrp/mrp_view.xml index f96147e9344..ef8645a6081 100644 --- a/addons/mrp/mrp_view.xml +++ b/addons/mrp/mrp_view.xml @@ -410,6 +410,8 @@ + + @@ -644,6 +646,7 @@