Browse Source

[IMP+ partner_sector: Test and check recursion

pull/342/head
Pedro M. Baeza 8 years ago
parent
commit
e0e012b0c6
  1. 1
      partner_sector/README.rst
  2. 2
      partner_sector/__openerp__.py
  3. 0
      partner_sector/i18n/.gitkeep
  4. 106
      partner_sector/i18n/partner_sector.pot
  5. 9
      partner_sector/models/res_partner_sector.py
  6. 2
      partner_sector/tests/__init__.py
  7. 17
      partner_sector/tests/test_res_partner.py
  8. 40
      partner_sector/tests/test_res_partner_sector.py

1
partner_sector/README.rst

@ -54,6 +54,7 @@ Contributors
* Antonio Espinosa <antonioea@antiun.com>
* Javier Iniesta <javieria@antiun.com>
* Vicent Cubells <vicent.cubells@tecnativa.com>
* Pedro M. Baeza <pedro.baeza@tecnativa.com>
Maintainer
----------

2
partner_sector/__openerp__.py

@ -6,7 +6,7 @@
{
"name": "Partner Sector",
"summary": "Add partner sectors",
"version": "9.0.1.0.0",
"version": "9.0.1.0.1",
"category": "Customer Relationship Management",
"website": "http://www.tecnativa.com",
"author": "Tecnativa, Odoo Community Association (OCA)",

0
partner_sector/i18n/.gitkeep

106
partner_sector/i18n/partner_sector.pot

@ -1,106 +0,0 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * partner_sector
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 8.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2015-12-17 13:49+0000\n"
"PO-Revision-Date: 2015-12-17 13:49+0000\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"
#. module: partner_sector
#: field:res.partner.sector,child_ids:0
msgid "Children"
msgstr ""
#. module: partner_sector
#: field:res.partner.sector,create_uid:0
msgid "Created by"
msgstr ""
#. module: partner_sector
#: field:res.partner.sector,create_date:0
msgid "Created on"
msgstr ""
#. module: partner_sector
#: field:res.partner.sector,id:0
msgid "ID"
msgstr ""
#. module: partner_sector
#: field:res.partner.sector,write_uid:0
msgid "Last Updated by"
msgstr ""
#. module: partner_sector
#: field:res.partner.sector,write_date:0
msgid "Last Updated on"
msgstr ""
#. module: partner_sector
#: field:res.partner,sector_id:0
msgid "Main Sector"
msgstr ""
#. module: partner_sector
#: field:res.partner.sector,name:0
msgid "Name"
msgstr ""
#. module: partner_sector
#: field:res.partner.sector,parent_left:0
msgid "Parent Left"
msgstr ""
#. module: partner_sector
#: field:res.partner.sector,parent_right:0
msgid "Parent Right"
msgstr ""
#. module: partner_sector
#: field:res.partner.sector,parent_id:0
msgid "Parent id"
msgstr ""
#. module: partner_sector
#: model:ir.model,name:partner_sector.model_res_partner
msgid "Partner"
msgstr ""
#. module: partner_sector
#: view:res.partner:partner_sector.view_res_partner_filter_sector
msgid "Salesperson"
msgstr ""
#. module: partner_sector
#: field:res.partner,secondary_sector_ids:0
msgid "Secondary Sectors"
msgstr ""
#. module: partner_sector
#: model:ir.model,name:partner_sector.model_res_partner_sector
#: view:res.partner:partner_sector.view_partner_form_sector
#: view:res.partner:partner_sector.view_res_partner_filter_sector
msgid "Sector"
msgstr ""
#. module: partner_sector
#: model:ir.actions.act_window,name:partner_sector.res_partner_sector_action
#: model:ir.ui.menu,name:partner_sector.menu_res_partner_sector
#: view:res.partner.sector:partner_sector.res_partner_sector_tree_view
msgid "Sectors"
msgstr ""
#. module: partner_sector
#: code:addons/partner_sector/models/res_partner.py:21
#, python-format
msgid "The main sector must be different from the secondary sectors."
msgstr ""

9
partner_sector/models/res_partner_sector.py

@ -1,9 +1,10 @@
# -*- coding: utf-8 -*-
# © 2015 Antiun Ingenieria S.L. - Javier Iniesta
# © 2016 Tecnativa S.L. - Vicent Cubells
# © 2016 Tecnativa S.L. - Pedro M. Baeza
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp import models, fields, api
from openerp import _, api, fields, exceptions, models
class ResPartnerSector(models.Model):
@ -33,3 +34,9 @@ class ResPartnerSector(models.Model):
return res
return [(cat.id, " / ".join(reversed(get_names(cat)))) for cat in self]
@api.constrains('parent_id')
def _check_parent_id(self):
if not self._check_recursion():
raise exceptions.ValidationError(
_('Error! You cannot create recursive sectors.'))

2
partner_sector/tests/__init__.py

@ -3,4 +3,4 @@
# © 2016 Tecnativa S.L. - Vicent Cubells
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import test_res_partner
from . import test_res_partner_sector

17
partner_sector/tests/test_res_partner.py

@ -1,17 +0,0 @@
# -*- coding: utf-8 -*-
# © 2015 Antiun Ingenieria S.L. - Javier Iniesta
# © 2016 Tecnativa S.L. - Vicent Cubells
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp.tests.common import TransactionCase
from openerp.exceptions import ValidationError
class TestResPartner(TransactionCase):
def test_check_sectors(self):
sector = self.env['res.partner.sector'].create({'name': 'Test'})
with self.assertRaises(ValidationError):
self.env['res.partner'].create(
{'name': 'Test', 'sector_id': sector.id,
'secondary_sector_ids': [(4, sector.id)]})

40
partner_sector/tests/test_res_partner_sector.py

@ -0,0 +1,40 @@
# -*- coding: utf-8 -*-
# © 2015 Antiun Ingenieria S.L. - Javier Iniesta
# © 2016 Tecnativa S.L. - Vicent Cubells
# © 2016 Tecnativa S.L. - Pedro M. Baeza
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp.tests import common
from openerp.exceptions import ValidationError
class TestResPartnerSector(common.SavepointCase):
@classmethod
def setUpClass(cls):
super(TestResPartnerSector, cls).setUpClass()
cls.Sector = cls.env['res.partner.sector']
cls.sector_main = cls.Sector.create({
'name': 'Test',
})
cls.sector_child = cls.Sector.create({
'name': 'Test child',
'parent_id': cls.sector_main.id,
})
def test_check_sectors(self):
with self.assertRaises(ValidationError):
self.env['res.partner'].create({
'name': 'Test',
'sector_id': self.sector_main.id,
'secondary_sector_ids': [(4, self.sector_main.id)],
})
def test_check_recursion(self):
with self.assertRaises(ValidationError):
self.sector_main.parent_id = self.sector_child.id
def test_name(self):
self.assertEqual(
self.sector_child.name_get()[0][1],
"Test / Test child",
)
Loading…
Cancel
Save