Skip to content

Commit

Permalink
[MIG] crm_phonecall_summary_predefined: Migration to 9.0
Browse files Browse the repository at this point in the history
* Updated views
* Updated README

[9.0][MIG] crm_phonecall_summary_predefined module
  • Loading branch information
cubells authored and pedrobaeza committed Apr 1, 2017
1 parent 3ca7a9d commit 8b06740
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 68 deletions.
24 changes: 13 additions & 11 deletions crm_phonecall_summary_predefined/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
Restricted Summary for Phone Calls
==================================

This module extends the functionality of CRM phonecalls to support setting a
limited list of possible phonecall summaries, that only the sales manager can
This module extends the functionality of CRM phone calls to support setting a
limited list of possible phone call summaries, that only the sales manager can
edit.

Configuration
Expand All @@ -25,28 +25,30 @@ Usage

.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/111/8.0
:target: https://runbot.odoo-community.org/runbot/111/9.0

Bug Tracker
===========

Bugs are tracked on `GitHub Issues
<https://github.com/OCA/crm/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smashing it by providing a detailed and welcomed `feedback
<https://github.com/OCA/
crm/issues/new?body=module:%20
crm_phonecall_summary_predefined%0Aversion:%20
8.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Bugs are tracked on `GitHub Issues <https://github.com/OCA/crm/issues>`_. In
case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smash it by providing detailed and welcomed
feedback.

Credits
=======

Images
------

* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.

Contributors
------------

* Rafael Blasco <rafabn@antiun.com>
* Jairo Llopis <yajo.sk8@gmail.com>
* Vicent Cubells <vicent.cubells@tecnativa.com>

Maintainer
----------
Expand Down
4 changes: 3 additions & 1 deletion crm_phonecall_summary_predefined/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# -*- coding: utf-8 -*-
# © 2016 Antiun Ingeniería S.L. - Jairo Llopis
# Copyright 2016 Antiun Ingeniería S.L. - Jairo Llopis
# Copyright 2017 Tecnativa - Vicent Cubells
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from . import models
from .hooks import convert_names_to_many2one
13 changes: 8 additions & 5 deletions crm_phonecall_summary_predefined/__openerp__.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
# -*- coding: utf-8 -*-
# © 2016 Antiun Ingeniería S.L. - Jairo Llopis
# Copyright 2016 Antiun Ingeniería S.L. - Jairo Llopis
# Copyright 2017 Tecnativa - Vicent Cubells
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "Restricted Summary for Phone Calls",
"summary": "Allows to choose from a defined summary list",
"version": "8.0.1.0.0",
"version": "9.0.1.0.0",
"category": "Customer Relationship Management",
"website": "http://www.antiun.com",
"author": "Antiun Ingeniería S.L., Odoo Community Association (OCA)",
"website": "http://www.tecnativa.com",
"author": "Tecnativa, "
"Odoo Community Association (OCA)",
"license": "AGPL-3",
"application": False,
"installable": True,
"post_init_hook": "convert_names_to_many2one",
"depends": [
"crm",
"crm_phonecall",
],
"data": [
"security/ir.model.access.csv",
Expand Down
23 changes: 23 additions & 0 deletions crm_phonecall_summary_predefined/hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Vicent Cubells <vicent.cubells@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from psycopg2 import IntegrityError

from openerp import api, SUPERUSER_ID


def convert_names_to_many2one(cr, registry):
"""Convert old string names to new Many2one."""
with api.Environment.manage():
env = api.Environment(cr, SUPERUSER_ID, {})
summary = env["crm.phonecall.summary"]
phone_call = env["crm.phonecall"]
for s in phone_call.search([("summary_id", "=", False)]):
try:
with env.cr.savepoint():
s.summary_id = summary.create({
"name": s.name,
})
except IntegrityError:
s.summary_id = summary.search([("name", "=", s.name)])
2 changes: 1 addition & 1 deletion crm_phonecall_summary_predefined/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# © 2016 Antiun Ingeniería S.L. - Jairo Llopis
# COpyright 2016 Antiun Ingeniería S.L. - Jairo Llopis
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from . import crm_phonecall
48 changes: 12 additions & 36 deletions crm_phonecall_summary_predefined/models/crm_phonecall.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-
# © 2016 Antiun Ingeniería S.L. - Jairo Llopis
# Copyright 2016 Antiun Ingeniería S.L. - Jairo Llopis
# Copyright 2017 Tecnativa - Vicent Cubells
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from psycopg2 import IntegrityError
from openerp import api, fields, models, SUPERUSER_ID
from openerp import fields, models


class CRMPhonecall(models.Model):
Expand All @@ -13,39 +13,14 @@ class CRMPhonecall(models.Model):
related="summary_id.name",
store=True,
required=False,
readonly=True)
readonly=True,
)
summary_id = fields.Many2one(
comodel_name="crm.phonecall.summary",
string="Summary",
required=True,
ondelete="restrict")

def _set_default_value_on_column(self, cr, column_name, context=None):
"""Default values when creating the field."""
if column_name != "summary_id":
return super(CRMPhonecall, self)._set_default_value_on_column(
cr, column_name, context)

# Ensure crm.phonecall.summary is installed before continuing
summary = self.pool["crm.phonecall.summary"]
if not summary._table_exist(cr):
summary._auto_init(cr, context)

# Proper default value per row
self._init_summary_id(cr, SUPERUSER_ID)

@api.model
def _init_summary_id(self):
"""Convert old string names to new Many2one."""
summary = self.env["crm.phonecall.summary"]
for s in self.search([("summary_id", "=", False)]):
try:
with self.env.cr.savepoint():
s.summary_id = summary.create({
"name": s.name,
})
except IntegrityError:
s.summary_id = summary.search([("name", "=", s.name)])
ondelete="restrict",
)


class CRMPhonecallSummary(models.Model):
Expand All @@ -56,7 +31,8 @@ class CRMPhonecallSummary(models.Model):

name = fields.Char()
phonecall_ids = fields.One2many(
"crm.phonecall",
"summary_id",
"Phonecalls",
help="Phonecalls with this summary.")
comodel_name="crm.phonecall",
inverse_name="summary_id",
string="Phonecalls",
help="Phonecalls with this summary.",
)
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- © 2016 Antiun Ingeniería S.L. - Jairo Llopis
<!-- Copyright 2016 Antiun Ingeniería S.L. - Jairo Llopis
Copyright 2017 Tecnativa - Vicent Cubells
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -->

<openerp>
<data>
<odoo>

<record id="summary_form" model="ir.ui.view">
<field name="name">CRM Phonecall Summary Form</field>
Expand Down Expand Up @@ -51,7 +51,6 @@
id="summary_menu"
action="summary_action"
groups="base.group_sale_manager"
parent="crm.menu_crm_config_phonecall"/>
parent="crm_phonecall.menu_crm_config_phonecall"/>

</data>
</openerp>
</odoo>
15 changes: 7 additions & 8 deletions crm_phonecall_summary_predefined/views/crm_phonecall_view.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- © 2016 Antiun Ingeniería S.L. - Jairo Llopis
<!-- Copyright 2016 Antiun Ingeniería S.L. - Jairo Llopis
Copyright 2017 Tecnativa - Vicent Cubells
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -->

<openerp>
<data>
<odoo>

<record id="crm_case_inbound_phone_tree_view" model="ir.ui.view">
<field name="name">Replace name by summary_id</field>
<field name="model">crm.phonecall</field>
<field name="inherit_id" ref="crm.crm_case_inbound_phone_tree_view"/>
<field name="inherit_id" ref="crm_phonecall.crm_case_inbound_phone_tree_view"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='name']" position="attributes">
<attribute name="invisible">True</attribute>
Expand All @@ -22,7 +22,7 @@
<record id="crm_case_phone_form_view" model="ir.ui.view">
<field name="name">Replace name by summary_id</field>
<field name="model">crm.phonecall</field>
<field name="inherit_id" ref="crm.crm_case_phone_form_view"/>
<field name="inherit_id" ref="crm_phonecall.crm_case_phone_form_view"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='name']" position="attributes">
<attribute name="invisible">True</attribute>
Expand All @@ -36,7 +36,7 @@
<record id="crm_case_phone_calendar_view" model="ir.ui.view">
<field name="name">Replace name by summary_id</field>
<field name="model">crm.phonecall</field>
<field name="inherit_id" ref="crm.crm_case_phone_calendar_view"/>
<field name="inherit_id" ref="crm_phonecall.crm_case_phone_calendar_view"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='name']" position="attributes">
<attribute name="invisible">True</attribute>
Expand All @@ -47,5 +47,4 @@
</field>
</record>

</data>
</openerp>
</odoo>

0 comments on commit 8b06740

Please sign in to comment.