From ccd78ad74520f706bbfda7d8889158172a2959a9 Mon Sep 17 00:00:00 2001 From: "Sanjay Gohel (Open ERP)" Date: Mon, 26 Nov 2012 11:25:41 +0530 Subject: [PATCH 1/4] [IMP] remove message post for stage change and implement subtype on changed stage bzr revid: sgo@tinyerp.com-20121126055541-nh8wjs35wviiybks --- addons/crm/crm.py | 1 + addons/crm/crm_lead.py | 15 --------------- addons/crm/crm_lead_data.xml | 8 ++++++++ addons/crm/crm_view.xml | 1 + addons/mail/mail_thread.py | 9 ++++++--- addons/project/project.py | 26 ++------------------------ addons/project/project_data.xml | 9 +++++++++ addons/project/project_view.xml | 1 + 8 files changed, 28 insertions(+), 42 deletions(-) diff --git a/addons/crm/crm.py b/addons/crm/crm.py index 368656224ac..d53f416a8eb 100644 --- a/addons/crm/crm.py +++ b/addons/crm/crm.py @@ -78,6 +78,7 @@ class crm_case_stage(osv.osv): 'state': fields.selection(AVAILABLE_STATES, 'Related Status', required=True, help="The status of your document will automatically change regarding the selected stage. " \ "For example, if a stage is related to the status 'Close', when your document reaches this stage, it is automatically closed."), + 'subtype': fields.char('Related Subtype', size=64), 'case_default': fields.boolean('Common to All Teams', help="If you check this field, this stage will be proposed by default on each sales team. It will not assign this stage to existing teams."), 'fold': fields.boolean('Hide in Views when Empty', diff --git a/addons/crm/crm_lead.py b/addons/crm/crm_lead.py index d3795c39d34..4ee26fde712 100644 --- a/addons/crm/crm_lead.py +++ b/addons/crm/crm_lead.py @@ -382,7 +382,6 @@ class crm_lead(base_stage, format_address, osv.osv): stage_id = self.stage_find(cr, uid, [lead], lead.section_id.id or False, [('probability', '=', 0.0)], context=context) if stage_id: self.case_set(cr, uid, [lead.id], values_to_update={'probability': 0.0}, new_stage_id=stage_id, context=context) - self.case_mark_lost_send_note(cr, uid, ids, context=context) return True def case_mark_won(self, cr, uid, ids, context=None): @@ -391,7 +390,6 @@ class crm_lead(base_stage, format_address, osv.osv): stage_id = self.stage_find(cr, uid, [lead], lead.section_id.id or False, [('probability', '=', 100.0)], context=context) if stage_id: self.case_set(cr, uid, [lead.id], values_to_update={'probability': 100.0}, new_stage_id=stage_id, context=context) - self.case_mark_won_send_note(cr, uid, ids, context=context) return True def set_priority(self, cr, uid, ids, priority): @@ -843,11 +841,6 @@ class crm_lead(base_stage, format_address, osv.osv): # OpenChatter methods and notifications # ---------------------------------------- - def stage_set_send_note(self, cr, uid, ids, stage_id, context=None): - """ Override of the (void) default notification method. """ - stage_name = self.pool.get('crm.case.stage').name_get(cr, uid, [stage_id], context=context)[0][1] - return self.message_post(cr, uid, ids, body=_("Stage changed to %s.") % (stage_name), subtype="mt_crm_stage", context=context) - def case_get_note_msg_prefix(self, cr, uid, lead, context=None): if isinstance(lead, (int, long)): lead = self.browse(cr, uid, [lead], context=context)[0] @@ -859,14 +852,6 @@ class crm_lead(base_stage, format_address, osv.osv): self.message_post(cr, uid, [id], body=message, context=context) return True - def case_mark_lost_send_note(self, cr, uid, ids, context=None): - message = _("Opportunity has been lost.") - return self.message_post(cr, uid, ids, body=message, subtype="mt_crm_lost", context=context) - - def case_mark_won_send_note(self, cr, uid, ids, context=None): - message = _("Opportunity has been won.") - return self.message_post(cr, uid, ids, body=message, subtype="mt_crm_won", context=context) - def schedule_phonecall_send_note(self, cr, uid, ids, phonecall_id, action, context=None): phonecall = self.pool.get('crm.phonecall').browse(cr, uid, [phonecall_id], context=context)[0] if action == 'log': prefix = 'Logged' diff --git a/addons/crm/crm_lead_data.xml b/addons/crm/crm_lead_data.xml index b7541b6daf0..5490f590855 100644 --- a/addons/crm/crm_lead_data.xml +++ b/addons/crm/crm_lead_data.xml @@ -7,6 +7,7 @@ New draft + mail.mt_crm_stage both @@ -15,6 +16,7 @@ Opportunity open + mail.mt_crm_stage lead @@ -23,6 +25,7 @@ Qualification open + mail.mt_crm_stage opportunity @@ -31,6 +34,7 @@ Proposition open + mail.mt_crm_stage opportunity @@ -39,6 +43,7 @@ Negotiation open + mail.mt_crm_stage opportunity @@ -47,6 +52,7 @@ Won done + mail.mt_crm_won @@ -57,6 +63,7 @@ cancel + mail.mt_crm_stage lead @@ -66,6 +73,7 @@ cancel + mail.mt_crm_lost opportunity diff --git a/addons/crm/crm_view.xml b/addons/crm/crm_view.xml index 99d3752529e..d6731f8f0bd 100644 --- a/addons/crm/crm_view.xml +++ b/addons/crm/crm_view.xml @@ -203,6 +203,7 @@ + diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py index 4d98ecbdc97..cc19e9d6007 100644 --- a/addons/mail/mail_thread.py +++ b/addons/mail/mail_thread.py @@ -296,7 +296,7 @@ class mail_thread(osv.AbstractModel): if f._type == 'many2one': if not isinstance(v, browse_record): v = self.pool[f._obj].browse(cr, SUPERUSER_ID, v) - return v.name_get()[0][1] + return v if f._type == 'selection': # TODO get translated value pass @@ -327,17 +327,20 @@ class mail_thread(osv.AbstractModel): for record, changed_fields in changes.items(): # TODO tpl changed_fields + subtype = False chg = [] for f in changed_fields: ci = tracked[f] from_ = convert_for_display(record[f], ci.column) to = convert_for_display(values[f], ci.column) - chg.append((_t(ci), from_, to)) + if to.__hasattr__('subtype'): + subtype = to.subtype + chg.append((_t(ci), from_.name_get()[0][1], to.name_get()[0][1])) message = MakoTemplate(self._TRACK_TEMPLATE).render_unicode(updated_fields=updated_fields, changes=chg) - record.message_post(message) + record.message_post(message,subtype=subtype) return result diff --git a/addons/project/project.py b/addons/project/project.py index 7beef9e1050..e8e22e5fb09 100644 --- a/addons/project/project.py +++ b/addons/project/project.py @@ -46,6 +46,7 @@ class project_task_type(osv.osv): 'state': fields.selection(_TASK_STATE, 'Related Status', required=True, help="The status of your document is automatically changed regarding the selected stage. " \ "For example, if a stage is related to the status 'Close', when your document reaches this stage, it is automatically closed."), + 'subtype': fields.char('Related Subtype', size=64), 'fold': fields.boolean('Hide in views if empty', help="This stage is not visible, for example in status bar or kanban view, when there are no records in that stage to display."), } @@ -993,14 +994,12 @@ class task(base_stage, osv.osv): if not task.date_end: vals['date_end'] = fields.datetime.now() self.case_set(cr, uid, [task.id], 'done', vals, context=context) - self.case_close_send_note(cr, uid, [task.id], context=context) return True def do_reopen(self, cr, uid, ids, context=None): for task in self.browse(cr, uid, ids, context=context): project = task.project_id self.case_set(cr, uid, [task.id], 'open', {}, context=context) - self.case_open_send_note(cr, uid, [task.id], context) return True def do_cancel(self, cr, uid, ids, context=None): @@ -1012,7 +1011,6 @@ class task(base_stage, osv.osv): self._check_child_task(cr, uid, ids, context=context) for task in tasks: self.case_set(cr, uid, [task.id], 'cancelled', {'remaining_hours': 0.0}, context=context) - self.case_cancel_send_note(cr, uid, [task.id], context=context) return True def do_open(self, cr, uid, ids, context=None): @@ -1022,7 +1020,6 @@ class task(base_stage, osv.osv): def case_open(self, cr, uid, ids, context=None): if not isinstance(ids,list): ids = [ids] self.case_set(cr, uid, ids, 'open', {'date_start': fields.datetime.now()}, context=context) - self.case_open_send_note(cr, uid, ids, context) return True def do_draft(self, cr, uid, ids, context=None): @@ -1031,7 +1028,6 @@ class task(base_stage, osv.osv): def case_draft(self, cr, uid, ids, context=None): self.case_set(cr, uid, ids, 'draft', {}, context=context) - self.case_draft_send_note(cr, uid, ids, context=context) return True def do_pending(self, cr, uid, ids, context=None): @@ -1039,8 +1035,7 @@ class task(base_stage, osv.osv): return self.case_pending(cr, uid, ids, context=context) def case_pending(self, cr, uid, ids, context=None): - self.case_set(cr, uid, ids, 'pending', {}, context=context) - return self.case_pending_send_note(cr, uid, ids, context=context) + return self.case_set(cr, uid, ids, 'pending', {}, context=context) def _delegate_task_attachments(self, cr, uid, task_id, delegated_task_id, context=None): attachment = self.pool.get('ir.attachment') @@ -1160,7 +1155,6 @@ class task(base_stage, osv.osv): self._subscribe_project_followers_to_task(cr, uid, task_id, context=context) self._store_history(cr, uid, [task_id], context=context) - self.create_send_note(cr, uid, [task_id], context=context) return task_id # Overridden to reset the kanban_state to normal whenever @@ -1288,24 +1282,8 @@ class task(base_stage, osv.osv): res = super(task, self).message_get_monitored_follower_fields(cr, uid, ids, context=context) return res + ['user_id', 'manager_id'] - def stage_set_send_note(self, cr, uid, ids, stage_id, context=None): - """ Override of the (void) default notification method. """ - stage_name = self.pool.get('project.task.type').name_get(cr, uid, [stage_id], context=context)[0][1] - return self.message_post(cr, uid, ids, body=_("Stage changed to %s.") % (stage_name), - context=context) - - def create_send_note(self, cr, uid, ids, context=None): - return self.message_post(cr, uid, ids, body=_("Task has been created."), context=context) - - def case_draft_send_note(self, cr, uid, ids, context=None): return self.message_post(cr, uid, ids, body=_('Task has been set as draft.'), context=context) - def do_delegation_send_note(self, cr, uid, ids, context=None): - for task in self.browse(cr, uid, ids, context=context): - msg = _('Task has been delegated to %s.') % (task.user_id.name) - self.message_post(cr, uid, [task.id], body=msg, context=context) - return True - def project_task_reevaluate(self, cr, uid, ids, context=None): if self.pool.get('res.users').has_group(cr, uid, 'project.group_time_work_estimation_tasks'): return { diff --git a/addons/project/project_data.xml b/addons/project/project_data.xml index 08981bd126a..ee88595956a 100644 --- a/addons/project/project_data.xml +++ b/addons/project/project_data.xml @@ -30,30 +30,35 @@ 1 Analysis draft + project.mt_task_new 2 Specification draft + project.mt_task_change 2 Design open + project.mt_task_change 3 Negotiation pending + project.mt_task_change 4 Development + project.mt_task_change open @@ -61,12 +66,14 @@ 5 Testing open + project.mt_task_change 6 Merge open + project.mt_task_change @@ -74,12 +81,14 @@ 7 Done done + project.mt_task_closed 7 Cancelled cancelled + project.mt_task_canceled diff --git a/addons/project/project_view.xml b/addons/project/project_view.xml index 8bb45ca6738..df2188be6b6 100644 --- a/addons/project/project_view.xml +++ b/addons/project/project_view.xml @@ -750,6 +750,7 @@ + From 9adb2e1eb142ff40ad3763836446c2165ae72001 Mon Sep 17 00:00:00 2001 From: "Sanjay Gohel (Open ERP)" Date: Mon, 26 Nov 2012 18:27:33 +0530 Subject: [PATCH 2/4] [IMP]improve code bzr revid: sgo@tinyerp.com-20121126125733-av712p9bixk20ew9 --- addons/mail/mail_thread.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py index cc19e9d6007..e78e2574e49 100644 --- a/addons/mail/mail_thread.py +++ b/addons/mail/mail_thread.py @@ -291,16 +291,19 @@ class mail_thread(osv.AbstractModel): return v def convert_for_display(v, f): + subtype = False if not v: return false_value(f) if f._type == 'many2one': if not isinstance(v, browse_record): v = self.pool[f._obj].browse(cr, SUPERUSER_ID, v) - return v + if v.__hasattr__('subtype'): + subtype = v.subtype + return (v.name_get()[0][1],subtype) if f._type == 'selection': # TODO get translated value pass - return v + return (v,subtype) tracked = dict((n, f) for n, f in self._all_columns.items() if getattr(f.column, 'tracked', False)) to_log = [k for k in values if k in tracked] @@ -327,20 +330,17 @@ class mail_thread(osv.AbstractModel): for record, changed_fields in changes.items(): # TODO tpl changed_fields - subtype = False chg = [] for f in changed_fields: ci = tracked[f] - from_ = convert_for_display(record[f], ci.column) + from_ = convert_for_display(record[f], ci.column)[0] to = convert_for_display(values[f], ci.column) - if to.__hasattr__('subtype'): - subtype = to.subtype - chg.append((_t(ci), from_.name_get()[0][1], to.name_get()[0][1])) + chg.append((_t(ci), from_, to[0])) message = MakoTemplate(self._TRACK_TEMPLATE).render_unicode(updated_fields=updated_fields, changes=chg) - record.message_post(message,subtype=subtype) + record.message_post(message,subtype=to[1]) return result From 766cad2f029f0c0524ea1d6764020de6e2b6afab Mon Sep 17 00:00:00 2001 From: "Sanjay Gohel (Open ERP)" Date: Wed, 28 Nov 2012 17:18:23 +0530 Subject: [PATCH 3/4] [IMP]improve code for subtype implementation and if remove record then string shows as removed bzr revid: sgo@tinyerp.com-20121128114823-whnokm2a1j9m3ddk --- addons/mail/mail_thread.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py index e78e2574e49..cf8dc453867 100644 --- a/addons/mail/mail_thread.py +++ b/addons/mail/mail_thread.py @@ -291,19 +291,16 @@ class mail_thread(osv.AbstractModel): return v def convert_for_display(v, f): - subtype = False if not v: return false_value(f) if f._type == 'many2one': if not isinstance(v, browse_record): v = self.pool[f._obj].browse(cr, SUPERUSER_ID, v) - if v.__hasattr__('subtype'): - subtype = v.subtype - return (v.name_get()[0][1],subtype) + return v.name_get()[0][1] if f._type == 'selection': # TODO get translated value pass - return (v,subtype) + return v tracked = dict((n, f) for n, f in self._all_columns.items() if getattr(f.column, 'tracked', False)) to_log = [k for k in values if k in tracked] @@ -327,20 +324,32 @@ class mail_thread(osv.AbstractModel): model = c.parent_model or self._name lang = context.get('lang') return Trans._get_source(cr, uid, '{0},{1}'.format(model, c.name), 'field', lang, ci.column.string) + + def get_subtype(model, record): + record_model = self.pool[model].browse(cr, SUPERUSER_ID, record) + if record_model.__hasattr__('subtype'): + return record_model.subtype + return False for record, changed_fields in changes.items(): # TODO tpl changed_fields chg = [] + subtype = False for f in changed_fields: ci = tracked[f] - from_ = convert_for_display(record[f], ci.column)[0] + from_ = convert_for_display(record[f], ci.column) to = convert_for_display(values[f], ci.column) - chg.append((_t(ci), from_, to[0])) + if to is None: + to = "Removed" + if ci.column._type == "many2one": + subtype = get_subtype(ci.column._obj,values[f]) + + chg.append((_t(ci), from_, to)) message = MakoTemplate(self._TRACK_TEMPLATE).render_unicode(updated_fields=updated_fields, changes=chg) - record.message_post(message,subtype=to[1]) + record.message_post(message,subtype=subtype) return result From 4080fc712cca0a750f4379c4adba96e22a70d55f Mon Sep 17 00:00:00 2001 From: "Sanjay Gohel (Open ERP)" Date: Wed, 28 Nov 2012 17:41:26 +0530 Subject: [PATCH 4/4] [IMP]remove unused messge post bzr revid: sgo@tinyerp.com-20121128121126-s9n0910qjcgc66pt --- addons/project/project.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/addons/project/project.py b/addons/project/project.py index e8e22e5fb09..7dff3fa28f5 100644 --- a/addons/project/project.py +++ b/addons/project/project.py @@ -1075,7 +1075,6 @@ class task(base_stage, osv.osv): self.do_pending(cr, uid, [task.id], context=context) elif delegate_data['state'] == 'done': self.do_close(cr, uid, [task.id], context=context) - self.do_delegation_send_note(cr, uid, [task.id], context) delegated_tasks[task.id] = delegated_task_id return delegated_tasks @@ -1172,7 +1171,6 @@ class task(base_stage, osv.osv): #raise osv.except_osv(_('Warning!'), _('Stage is not defined in the project.')) write_vals = vals_reset_kstate if t.stage_id != new_stage else vals super(task, self).write(cr, uid, [t.id], write_vals, context=context) - self.stage_set_send_note(cr, uid, [t.id], new_stage, context=context) result = True else: result = super(task, self).write(cr, uid, ids, vals, context=context)