Browse Source

- mail_activity:allow to set an activity of category meeting to done.

- mail_activity_crm: hide old crm.activity menus, add migration scripts
  from crm.activity.
pull/286/head
Jordi Ballester Alomar 6 years ago
parent
commit
ef2c549973
  1. 6
      mail_activity_calendar/models/calendar_event.py
  2. 2
      mail_activity_calendar/views/calendar_event_views.xml
  3. 1
      mail_activity_crm/__init__.py
  4. 4
      mail_activity_crm/__openerp__.py
  5. 102
      mail_activity_crm/hooks.py
  6. 9
      mail_activity_crm/views/crm_action_views.xml
  7. 11
      mail_activity_crm/views/crm_activity_report_view.xml
  8. 11
      mail_activity_crm/views/crm_lead_menu.xml

6
mail_activity_calendar/models/calendar_event.py

@ -89,6 +89,12 @@ class CalendarEvent(models.Model):
def action_close_dialog(self): def action_close_dialog(self):
return {'type': 'ir.actions.act_window_close'} return {'type': 'ir.actions.act_window_close'}
@api.multi
def action_done(self):
for rec in self:
rec.activity_ids.action_feedback()
return {'type': 'ir.actions.act_window_close'}
@api.multi @api.multi
def action_open_calendar_event(self): def action_open_calendar_event(self):
if self.res_model and self.res_id: if self.res_model and self.res_id:

2
mail_activity_calendar/views/calendar_event_views.xml

@ -24,6 +24,8 @@
<footer> <footer>
<button string="Schedule" name="action_close_dialog" <button string="Schedule" name="action_close_dialog"
type="object" class="btn-primary"/> type="object" class="btn-primary"/>
<button string="Mark Activity as Done" name="action_done"
type="object" class="btn-primary"/>
</footer> </footer>
</sheet> </sheet>
</field> </field>

1
mail_activity_crm/__init__.py

@ -1,2 +1,3 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from . import models from . import models
from .hooks import post_init_hook

4
mail_activity_crm/__openerp__.py

@ -17,5 +17,9 @@
], ],
"data": [ "data": [
"views/crm_lead_views.xml", "views/crm_lead_views.xml",
'views/crm_activity_report_view.xml',
'views/crm_lead_menu.xml',
'views/crm_action_views.xml',
], ],
'post_init_hook': 'post_init_hook',
} }

102
mail_activity_crm/hooks.py

@ -0,0 +1,102 @@
# Copyright 2018 Eficent Business and IT Consulting Services S.L.
# Copyright 2018 Tecnativa, S.L.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from openerp import api, SUPERUSER_ID
def convert_crm_activity_types(env):
"""Point default crm.activity.type records to their equivalents now in v11,
and create the rest manually."""
column_name = "crm_activity"
table = 'mail_activity_type'
column = 'crm_activity'
env.cr.execute("""
SELECT column_name
FROM information_schema.columns
WHERE table_name = %s AND column_name = %s""", (table, column))
if not bool(env.cr.fetchall()):
env.cr.execute(
"ALTER TABLE mail_activity_type ADD COLUMN crm_activity INTEGER")
type_mapping = {
'crm.crm_activity_data_email':
'mail_activity.mail_activity_data_email',
'crm.crm_activity_data_call':
'mail_activity.mail_activity_data_call',
'crm.crm_activity_data_meeting':
'mail_activity.mail_activity_data_todo',
}
migrated_ids = []
for old_xml_id, new_xml_id in type_mapping.items():
env.cr.execute(
"SELECT res_id FROM ir_model_data "
"WHERE module = %s and name = %s",
(old_xml_id.split('.')[0], old_xml_id.split('.')[1]),
)
row = env.cr.fetchone()
if row:
old_id = row[0]
migrated_ids.append(old_id)
env.cr.execute(
"UPDATE mail_activity_type "
"SET %s = %s WHERE id = %s"
% (column_name, old_id, env.ref(new_xml_id).id)
)
env.cr.execute("""
INSERT INTO mail_activity_type
(name, sequence, res_model_id, category, days,
create_date, create_uid, write_uid, write_date, %s)
SELECT
mms.name, ca.sequence, im.id, 'default', ca.days,
ca.create_date, ca.create_uid, ca.write_uid, ca.write_date, ca.id
FROM
crm_activity AS ca,
mail_message_subtype AS mms,
ir_model AS im
WHERE
mms.id = ca.subtype_id AND
im.model = 'crm.lead' AND
ca.id NOT IN %s
""" % (column_name, tuple(migrated_ids), )
)
def convert_crm_lead_activities(env):
"""Create mail.activity records for the corresponding activities in v10."""
column_name = 'crm_activity'
env.cr.execute("""
INSERT INTO mail_activity
(res_id, res_model_id, res_model, res_name, summary,
activity_type_id, date_deadline, create_uid, create_date,
write_uid, write_date, user_id)
SELECT
cl.id, im.id, 'crm.lead', cl.name, cl.title_action,
mat.id, cl.date_action, cl.create_uid, cl.create_date,
cl.write_uid, cl.write_date, COALESCE(cl.user_id, cl.create_uid)
FROM
crm_lead AS cl,
mail_activity_type AS mat,
ir_model AS im
WHERE
next_activity_id IS NOT NULL AND
date_action IS NOT NULL AND
im.model = 'crm.lead' AND
mat.%s = cl.next_activity_id
""" % (column_name, )
)
def delete_crm_activities(env):
"""Delete old activities in order to avoid duplicating them
when we transition to v11."""
env.cr.execute("""
DELETE FROM crm_activity
""")
def post_init_hook(cr, registry):
with api.Environment.manage():
env = api.Environment(cr, SUPERUSER_ID, {})
convert_crm_activity_types(env)
convert_crm_lead_activities(env)
delete_crm_activities(env)

9
mail_activity_crm/views/crm_action_views.xml

@ -0,0 +1,9 @@
<?xml version="1.0"?>
<odoo>
<!-- hide -->
<record id="crm.crm_activity_menu" model="ir.ui.menu">
<field name="groups_id" eval="[(6, 0, [ref('base.group_no_one')])]"/>
<field name="name">Activities (obsolete)</field>
</record>
</odoo>

11
mail_activity_crm/views/crm_activity_report_view.xml

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<!-- hide -->
<record id="crm.crm_activity_report_menu" model="ir.ui.menu">
<field name="groups_id" eval="[(6, 0, [ref('base.group_no_one')])]"/>
<field name="name">Activities (obsolete)</field>
</record>
</data>
</openerp>

11
mail_activity_crm/views/crm_lead_menu.xml

@ -0,0 +1,11 @@
<?xml version="1.0"?>
<openerp>
<data>
<!-- hide -->
<record id="crm.crm_lead_menu_activities" model="ir.ui.menu">
<field name="groups_id" eval="[(6, 0, [ref('base.group_no_one')])]"/>
<field name="name">Next Activities (obsolete)</field>
</record>
</data>
</openerp>
Loading…
Cancel
Save