Skip to content

Commit

Permalink
[MIG] crm_sector: Migrated to V10
Browse files Browse the repository at this point in the history
  • Loading branch information
luismontalba authored and pedrobaeza committed Jun 6, 2017
1 parent f478330 commit f3d613e
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 38 deletions.
3 changes: 2 additions & 1 deletion crm_sector/README.rst
Expand Up @@ -12,7 +12,7 @@ This module adds the concept of economic sector for leads and opportunities.

.. 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/10.0


Bug Tracker
Expand All @@ -38,6 +38,7 @@ Contributors
* Rafael Blasco <rafabn@antiun.com>
* Antonio Espinosa <antonioea@antiun.com>
* Javier Iniesta <javieria@antiun.com>
* Luis M. Ontalba <luis.martinez@tecnativa.com>

Maintainer
----------
Expand Down
1 change: 0 additions & 1 deletion crm_sector/__init__.py
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
# © 2015 Antiun Ingenieria S.L. - Antonio Espinosa
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from . import models
2 changes: 1 addition & 1 deletion crm_sector/__openerp__.py → crm_sector/__manifest__.py
Expand Up @@ -5,7 +5,7 @@
{
"name": "CRM Sector",
"summary": "Link leads/opportunities to sectors",
"version": "8.0.1.0.0",
"version": "10.0.1.0.0",
"category": "Customer Relationship Management",
"website": "http://www.antiun.com",
"author": "Antiun Ingeniería, "
Expand Down
1 change: 0 additions & 1 deletion crm_sector/models/__init__.py
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
# © 2015 Antiun Ingenieria S.L. - Javier Iniesta
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from . import crm_lead
27 changes: 13 additions & 14 deletions crm_sector/models/crm_lead.py
Expand Up @@ -2,14 +2,14 @@
# © 2015 Antiun Ingenieria S.L. - Javier Iniesta
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from openerp import models, fields, api, exceptions, _
from odoo import _, api, exceptions, fields, models


class CrmLead(models.Model):
_inherit = 'crm.lead'

sector_id = fields.Many2one(comodel_name='res.partner.sector',
string='Main Sector', oldname='sector')
string='Main Sector')

secondary_sector_ids = fields.Many2many(
comodel_name='res.partner.sector', string="Secondary Sectors",
Expand All @@ -19,19 +19,18 @@ class CrmLead(models.Model):
@api.constrains('sector_id', 'secondary_sector_ids')
def _check_sectors(self):
if self.sector_id in self.secondary_sector_ids:
raise exceptions.Warning(_('The secondary sectors must be '
raise exceptions.UserError(_('The secondary sectors must be '
'different from the main sector.'))

@api.model
def _lead_create_contact(self, lead, name, is_company, parent_id=False):
@api.multi
def _lead_create_contact(self, name, is_company,
parent_id=False):
"""Propagate sector to created partner.
"""
partner_id = super(CrmLead, self)._lead_create_contact(
lead, name, is_company, parent_id)
secondary_sector_ids = []
for sector in lead.secondary_sector_ids:
secondary_sector_ids.append((4, sector.id, 0))
self.env['res.partner'].browse(partner_id).write(
{'sector_id': lead.sector_id.id,
'secondary_sector_ids': secondary_sector_ids})
return partner_id
partner = super(CrmLead, self)._lead_create_contact(
name, is_company, parent_id)
partner.write({
'sector_id': self.sector_id.id,
'secondary_sector_ids': [(6, 0, self.secondary_sector_ids.ids)],
})
return partner
1 change: 0 additions & 1 deletion crm_sector/tests/__init__.py
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
# © 2015 Antiun Ingenieria S.L. - Javier Iniesta
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from . import test_crm_lead
17 changes: 8 additions & 9 deletions crm_sector/tests/test_crm_lead.py
Expand Up @@ -2,8 +2,8 @@
# © 2015 Antiun Ingenieria S.L. - Javier Iniesta
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from openerp.tests.common import TransactionCase
from openerp.exceptions import ValidationError
from odoo.tests.common import TransactionCase
from odoo.exceptions import ValidationError


class TestCrmLead(TransactionCase):
Expand All @@ -26,12 +26,11 @@ def test_lead_create_contact(self):
'name': 'test',
'partner_name': 'test',
'sector_id': sector_1.id,
'secondary_sector_ids': [(4, sector_2.id, 0), (4, sector_3.id, 0)]
'secondary_sector_ids': [(4, sector_2.id, 0), (4, sector_3.id, 0)],
}
lead = self.env['crm.lead'].create(lead_vals)
partner_id = self.env['crm.lead']._lead_create_contact(
lead, lead.partner_name, True)
partner = self.env['res.partner'].browse(partner_id)
self.assertEqual(partner.sector_id.id, lead.sector_id.id)
self.assertListEqual(partner.secondary_sector_ids.ids,
lead.secondary_sector_ids.ids)
partner = lead._lead_create_contact(
lead.partner_name, True, False)
self.assertEqual(partner.sector_id, lead.sector_id)
self.assertEqual(
partner.secondary_sector_ids, lead.secondary_sector_ids)
18 changes: 8 additions & 10 deletions crm_sector/views/crm_lead_view.xml
@@ -1,8 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- © 2015 Antiun Ingenieria S.L. - Javier Iniesta
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -->
<openerp>
<data>
<odoo>

<record model="ir.ui.view" id="crm_case_form_view_leads">
<field name="name">Add sector field</field>
Expand All @@ -22,7 +21,7 @@
<field name="model">crm.lead</field>
<field name="inherit_id" ref="crm.crm_case_tree_view_leads"/>
<field name="arch" type="xml">
<field name="section_id" position="after">
<field name="partner_id" position="after">
<field name="sector_id"/>
</field>
</field>
Expand All @@ -33,10 +32,10 @@
<field name="model">crm.lead</field>
<field name="inherit_id" ref="crm.view_crm_case_leads_filter"/>
<field name="arch" type="xml">
<field name="section_id" position="after">
<field name="country_id" position="after">
<field name="sector_id"/>
</field>
<filter string="Sales Team" position="after">
<filter name="unassigned" position="after">
<filter string="Sector"
domain="[]"
context="{'group_by': 'sector_id'}"/>
Expand All @@ -62,7 +61,7 @@
<field name="model">crm.lead</field>
<field name="inherit_id" ref="crm.crm_case_tree_view_oppor"/>
<field name="arch" type="xml">
<field name="section_id" position="after">
<field name="partner_id" position="after">
<field name="sector_id"/>
</field>
</field>
Expand All @@ -73,16 +72,15 @@
<field name="model">crm.lead</field>
<field name="inherit_id" ref="crm.view_crm_case_opportunities_filter"/>
<field name="arch" type="xml">
<field name="section_id" position="after">
<field name="partner_id" position="after">
<field name="sector_id"/>
</field>
<filter string="Sales Team" position="after">
<filter name="stage" position="after">
<filter string="Sector"
domain="[]"
context="{'group_by': 'sector_id'}"/>
</filter>
</field>
</record>

</data>
</openerp>
</odoo>
2 changes: 2 additions & 0 deletions oca_dependencies.txt
@@ -0,0 +1,2 @@
partner-contact

0 comments on commit f3d613e

Please sign in to comment.