Browse Source

[ADD] base_contact_function module

Allow to manage contacts by function
pull/20/head
Sandy Carter 10 years ago
parent
commit
b43d2e2f82
  1. 28
      base_contact_function/__init__.py
  2. 51
      base_contact_function/__openerp__.py
  3. 265
      base_contact_function/i18n/base_contact_function.pot
  4. 290
      base_contact_function/i18n/fr.po
  5. 97
      base_contact_function/res_partner.py
  6. 57
      base_contact_function/res_partner_category.py
  7. 47
      base_contact_function/res_partner_category_function.py
  8. 54
      base_contact_function/res_partner_category_view.xml
  9. 51
      base_contact_function/res_partner_function.py
  10. 43
      base_contact_function/res_partner_function_view.xml
  11. 526
      base_contact_function/res_partner_view.xml
  12. 3
      base_contact_function/security/ir.model.access.csv
  13. 31
      base_contact_function/tests/__init__.py
  14. 105
      base_contact_function/tests/test_functions.py
  15. 193
      base_contact_function/tests/test_partner_category.py

28
base_contact_function/__init__.py

@ -0,0 +1,28 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# This module copyright (C) 2013 Savoir-faire Linux
# (<http://www.savoirfairelinux.com>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from . import (
res_partner,
res_partner_function,
res_partner_category,
res_partner_category_function,
)

51
base_contact_function/__openerp__.py

@ -0,0 +1,51 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# This module copyright (C) 2013 Savoir-faire Linux
# (<http://www.savoirfairelinux.com>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
{
'name': 'Contact by Function',
'version': '1.0',
'author': 'Savoir-faire Linux',
'maintainer': 'Savoir-faire Linux',
'website': 'http://www.savoirfairelinux.com',
'category': 'Customer Relationship Management',
'description': """
Contacts by Functions
=====================
This module allows you to manage contacts by functions
Contributors
------------
* El Hadji Dem (elhadji.dem@savoirfairelinux.com)
* Sandy Carter (sandy.carter@savoirfairelinux.com)
""",
'depends': [
'base_contact',
],
'data': [
'res_partner_function_view.xml',
'res_partner_category_view.xml',
'res_partner_view.xml',
'security/ir.model.access.csv',
],
'installable': True,
}

265
base_contact_function/i18n/base_contact_function.pot

@ -0,0 +1,265 @@
# Translation of OpenERP Server.
# This file contains the translation of the following modules:
# * base_contact_function
#
msgid ""
msgstr ""
"Project-Id-Version: OpenERP Server 7.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2014-10-31 16:24+0000\n"
"PO-Revision-Date: 2014-10-31 16:24+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: base_contact_function
#: field:res.partner.category.function,category_id:0
msgid "Category"
msgstr ""
#. module: base_contact_function
#: view:res.partner:0
msgid "City"
msgstr ""
#. module: base_contact_function
#: model:ir.actions.act_window,name:base_contact_function.action_function_tree_list
#: view:res.partner:0
#: field:res.partner,function_ids:0
#: view:res.partner.category:0
#: field:res.partner.category,category_function_ids:0
#: field:res.partner.category.function,function_id:0
#: view:res.partner.function:0
#: field:res.partner.function,partner_ids:0
msgid "Functions"
msgstr ""
#. module: base_contact_function
#: model:ir.model,name:base_contact_function.model_res_partner_category_function
msgid "Partner Category Function"
msgstr ""
#. module: base_contact_function
#: model:ir.actions.act_window,name:base_contact_function.action_partner_contact_form
msgid "Contacts"
msgstr ""
#. module: base_contact_function
#: view:res.partner:0
msgid "Street..."
msgstr ""
#. module: base_contact_function
#: view:res.partner:0
msgid "State"
msgstr ""
#. module: base_contact_function
#: view:res.partner:0
msgid "e.g. Sales Director"
msgstr ""
#. module: base_contact_function
#: model:ir.model,name:base_contact_function.model_res_partner_function
msgid "Partner Function"
msgstr ""
#. module: base_contact_function
#: view:res.partner:0
msgid "Tags..."
msgstr ""
#. module: base_contact_function
#: field:res.partner,start_date:0
msgid "Start date"
msgstr ""
#. module: base_contact_function
#: view:res.partner:0
msgid "Parent Organism"
msgstr ""
#. module: base_contact_function
#: view:res.partner:0
msgid "Fax:"
msgstr ""
#. module: base_contact_function
#: view:res.partner:0
#: view:res.partner.category:0
#: view:res.partner.function:0
msgid "Function"
msgstr ""
#. module: base_contact_function
#: view:res.partner:0
msgid "Fax"
msgstr ""
#. module: base_contact_function
#: field:res.partner.function,acronym:0
msgid "Acronym"
msgstr ""
#. module: base_contact_function
#: field:res.partner,other_contact_history_ids:0
msgid "unknown"
msgstr ""
#. module: base_contact_function
#: model:ir.actions.act_window,name:base_contact_function.action_partner_customer_form
msgid "Company"
msgstr ""
#. module: base_contact_function
#: view:res.partner:0
msgid "History (Functions)"
msgstr ""
#. module: base_contact_function
#: view:res.partner:0
msgid "Tag"
msgstr ""
#. module: base_contact_function
#: view:res.partner:0
msgid "Address"
msgstr ""
#. module: base_contact_function
#: view:res.partner:0
msgid "Use Organisation Address"
msgstr ""
#. module: base_contact_function
#: view:res.partner:0
msgid "have the same form for contact and other postions"
msgstr ""
#. module: base_contact_function
#: view:res.partner:0
msgid "Phone:"
msgstr ""
#. module: base_contact_function
#: field:res.partner.function,name:0
msgid "Name"
msgstr ""
#. module: base_contact_function
#: view:res.partner:0
msgid "ZIP"
msgstr ""
#. module: base_contact_function
#: view:res.partner:0
msgid "Country"
msgstr ""
#. module: base_contact_function
#: view:res.partner:0
msgid "Select Functions for this Organisation"
msgstr ""
#. module: base_contact_function
#: view:res.partner:0
msgid "Is an Organism"
msgstr ""
#. module: base_contact_function
#: field:res.partner,function_id:0
msgid "Position Occupied"
msgstr ""
#. module: base_contact_function
#: view:res.partner:0
msgid "Contact"
msgstr ""
#. module: base_contact_function
#: view:res.partner:0
msgid "Parent Organisation"
msgstr ""
#. module: base_contact_function
#: view:res.partner:0
msgid "Mobile:"
msgstr ""
#. module: base_contact_function
#: model:ir.model,name:base_contact_function.model_res_partner_category
msgid "Partner Categories"
msgstr ""
#. module: base_contact_function
#: view:res.partner:0
msgid "Organism"
msgstr ""
#. module: base_contact_function
#: help:res.partner,naming:0
msgid "Naming."
msgstr ""
#. module: base_contact_function
#: view:res.partner:0
msgid "History"
msgstr ""
#. module: base_contact_function
#: field:res.partner,end_date:0
msgid "End date"
msgstr ""
#. module: base_contact_function
#: view:res.partner.category:0
msgid "Add function"
msgstr ""
#. module: base_contact_function
#: view:res.partner:0
msgid "Bank Details"
msgstr ""
#. module: base_contact_function
#: field:res.partner.category.function,sequence:0
msgid "Sequence"
msgstr ""
#. module: base_contact_function
#: view:res.partner:0
msgid "Bank Accounts"
msgstr ""
#. module: base_contact_function
#: view:res.partner:0
msgid "No, Street, Apartment/Office"
msgstr ""
#. module: base_contact_function
#: help:res.partner.category.function,sequence:0
msgid "Used to order"
msgstr ""
#. module: base_contact_function
#: help:res.partner.function,acronym:0
msgid "Acronym of function."
msgstr ""
#. module: base_contact_function
#: help:res.partner.function,name:0
msgid "Name of function."
msgstr ""
#. module: base_contact_function
#: model:ir.model,name:base_contact_function.model_res_partner
msgid "Partner"
msgstr ""
#. module: base_contact_function
#: field:res.partner,naming:0
msgid "Naming"
msgstr ""

290
base_contact_function/i18n/fr.po

@ -0,0 +1,290 @@
# Translation of OpenERP Server.
# This file contains the translation of the following modules:
# * base_contact_function
#
msgid ""
msgstr ""
"Project-Id-Version: OpenERP Server 7.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2014-10-31 16:24+0000\n"
"PO-Revision-Date: 2014-10-31 12:25-0500\n"
"Last-Translator: Sandy Carter <sandy.carter@savoirfairelinux.com>\n"
"Language-Team: \n"
"Language: fr\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: \n"
"X-Generator: Poedit 1.6.10\n"
#. module: base_contact_function
#: field:res.partner.category.function,category_id:0
msgid "Category"
msgstr "Catégorie"
#. module: base_contact_function
#: view:res.partner:0
msgid "City"
msgstr "Ville"
#. module: base_contact_function
#: model:ir.actions.act_window,name:base_contact_function.action_function_tree_list
#: view:res.partner:0 field:res.partner,function_ids:0
#: view:res.partner.category:0
#: field:res.partner.category,category_function_ids:0
#: field:res.partner.category.function,function_id:0
#: view:res.partner.function:0 field:res.partner.function,partner_ids:0
msgid "Functions"
msgstr "Fonctions"
#. module: base_contact_function
#: model:ir.model,name:base_contact_function.model_res_partner_category_function
msgid "Partner Category Function"
msgstr "Fonction de la catégorie du partenaire"
#. module: base_contact_function
#: model:ir.actions.act_window,name:base_contact_function.action_partner_contact_form
msgid "Contacts"
msgstr "Contacts"
#. module: base_contact_function
#: view:res.partner:0
msgid "Street..."
msgstr "Rue..."
#. module: base_contact_function
#: view:res.partner:0
msgid "State"
msgstr "Etat"
#. module: base_contact_function
#: view:res.partner:0
msgid "e.g. Sales Director"
msgstr "ex: Directeur de vente"
#. module: base_contact_function
#: model:ir.model,name:base_contact_function.model_res_partner_function
msgid "Partner Function"
msgstr "Fonction du partenaire"
#. module: base_contact_function
#: view:res.partner:0
msgid "Tags..."
msgstr "Etiquettes..."
#. module: base_contact_function
#: field:res.partner,start_date:0
msgid "Start date"
msgstr "Date de début"
#. module: base_contact_function
#: view:res.partner:0
msgid "Parent Organism"
msgstr "Organisme parent"
#. module: base_contact_function
#: view:res.partner:0
msgid "Fax:"
msgstr "Télécopie :"
#. module: base_contact_function
#: view:res.partner:0 view:res.partner.category:0 view:res.partner.function:0
msgid "Function"
msgstr "Fonction"
#. module: base_contact_function
#: view:res.partner:0
msgid "Fax"
msgstr "Télécopie"
#. module: base_contact_function
#: field:res.partner.function,acronym:0
msgid "Acronym"
msgstr "Acronyme"
#. module: base_contact_function
#: field:res.partner,other_contact_history_ids:0
msgid "unknown"
msgstr "inconnu"
#. module: base_contact_function
#: model:ir.actions.act_window,name:base_contact_function.action_partner_customer_form
msgid "Company"
msgstr "Organisme"
#. module: base_contact_function
#: view:res.partner:0
msgid "History (Functions)"
msgstr "Historique (Fonctions)"
#. module: base_contact_function
#: view:res.partner:0
msgid "Tag"
msgstr "Etiquette"
#. module: base_contact_function
#: view:res.partner:0
msgid "Address"
msgstr "Adresse"
#. module: base_contact_function
#: view:res.partner:0
msgid "Use Organisation Address"
msgstr "Utiliser l'adresse de l'organisme"
#. module: base_contact_function
#: view:res.partner:0
msgid "have the same form for contact and other postions"
msgstr "Avoir le même formulaire de contact et d'autres postions"
#. module: base_contact_function
#: view:res.partner:0
msgid "Phone:"
msgstr "Téléphone:"
#. module: base_contact_function
#: field:res.partner.function,name:0
msgid "Name"
msgstr "Nom"
#. module: base_contact_function
#: view:res.partner:0
msgid "ZIP"
msgstr "Code postal"
#. module: base_contact_function
#: view:res.partner:0
msgid "Country"
msgstr "Pays"
#. module: base_contact_function
#: view:res.partner:0
msgid "Select Functions for this Organisation"
msgstr "Sélectionner les fonctions de cet organisme"
#. module: base_contact_function
#: view:res.partner:0
msgid "Is an Organism"
msgstr "Est un Organisme"
#. module: base_contact_function
#: field:res.partner,function_id:0
msgid "Position Occupied"
msgstr "Fonction Occupée"
#. module: base_contact_function
#: view:res.partner:0
msgid "Contact"
msgstr "Contact"
#. module: base_contact_function
#: view:res.partner:0
msgid "Parent Organisation"
msgstr "Organisme parent"
#. module: base_contact_function
#: view:res.partner:0
msgid "Mobile:"
msgstr "Portable :"
#. module: base_contact_function
#: model:ir.model,name:base_contact_function.model_res_partner_category
msgid "Partner Categories"
msgstr "Catégories de partenaires"
#. module: base_contact_function
#: view:res.partner:0
msgid "Organism"
msgstr "Organisme"
#. module: base_contact_function
#: help:res.partner,naming:0
msgid "Naming."
msgstr "Appellation"
#. module: base_contact_function
#: view:res.partner:0
msgid "History"
msgstr "Historique"
#. module: base_contact_function
#: field:res.partner,end_date:0
msgid "End date"
msgstr "Date de fin"
#. module: base_contact_function
#: view:res.partner.category:0
msgid "Add function"
msgstr "Ajouter fonction"
#. module: base_contact_function
#: view:res.partner:0
msgid "Bank Details"
msgstr "Coordonnées bancaires"
#. module: base_contact_function
#: field:res.partner.category.function,sequence:0
msgid "Sequence"
msgstr "Séquence"
#. module: base_contact_function
#: view:res.partner:0
msgid "Bank Accounts"
msgstr "Comptes bancaires"
#. module: base_contact_function
#: view:res.partner:0
msgid "No, Street, Apartment/Office"
msgstr "No, Rue, Appartement/Bureau"
#. module: base_contact_function
#: help:res.partner.category.function,sequence:0
msgid "Used to order"
msgstr "Permet d'ordonner"
#. module: base_contact_function
#: help:res.partner.function,acronym:0
msgid "Acronym of function."
msgstr "Acronyme de la fonction."
#. module: base_contact_function
#: help:res.partner.function,name:0
msgid "Name of function."
msgstr "Nom de la fonction."
#. module: base_contact_function
#: model:ir.model,name:base_contact_function.model_res_partner
msgid "Partner"
msgstr "Partenaire"
#. module: base_contact_function
#: field:res.partner,naming:0
msgid "Naming"
msgstr "Appellation"
#~ msgid "institution"
#~ msgstr "institution"
#~ msgid "Add functions for this institution"
#~ msgstr "Ajouter des fonctions de cette institution"
#~ msgid "Name already exists"
#~ msgstr "Le nom existe déjà"
#~ msgid "InstitutionsForm"
#~ msgstr "InstitutionsForm"
#~ msgid "Name of institution."
#~ msgstr "Nom de l'institution."
#~ msgid "Institution"
#~ msgstr "Institution"
#~ msgid "Used to order the institutions"
#~ msgstr "Permet d'ordonner les institutions"
#~ msgid "Institution Function"
#~ msgstr "Fonction de l'institution"
#~ msgid "Institutions"
#~ msgstr "Institutions"

97
base_contact_function/res_partner.py

@ -0,0 +1,97 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# This module copyright (C) 2013 Savoir-faire Linux
# (<http://www.savoirfairelinux.com>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import time
from openerp.osv import orm, fields
class res_partner(orm.Model):
"""
Inherits partner and adds function_ids : List of functions
"""
_inherit = 'res.partner'
def onchange_partner_function(self, cr, uid, ids, part, context=None):
partner_pool = self.pool['res.partner']
if not part:
return {'value': None}
partner_ids = partner_pool.search(cr, uid, [('id', '=', part)])
function_ids = partner_pool.browse(
cr, uid, partner_ids, context=context)[0].function_ids
result = []
if function_ids:
for line in function_ids:
result.append(line.id)
dom = {'function_id': [('id', 'in', result)]}
return {'domain': dom}
def _get_history_lines(self, cr, uid, ids, name, arg, context=None):
res = {}
res_partner_pool = self.pool.get('res.partner')
for record in self.browse(cr, uid, ids, context=context):
if record.is_company:
return res
contact_ids = res_partner_pool.search(
cr, uid, [
('contact_id', '=', record.id),
('active', '=', False),
], context=context
)
res[record.id] = [
x.id for x in res_partner_pool.browse(cr, uid, contact_ids)
if x.end_date and x.end_date <= time.strftime('%Y-%m-%d')
]
return res
_columns = {
'function_ids': fields.many2many(
'res.partner.function',
'function_partner_rel',
'partner_id',
'function_id',
'Functions',
),
'start_date': fields.date('Start date'),
'end_date': fields.date('End date'),
'naming': fields.char(
'Naming',
help="Naming.",
),
'function_id': fields.many2one(
'res.partner.function',
'Position Occupied',
),
'other_contact_history_ids': fields.function(
_get_history_lines,
relation="res.partner",
method=True,
type="one2many",
),
# Replace company by Organisation
'use_parent_address': fields.boolean(
'Use Organisation Address',
help="Select this if you want to set organisation's address "
"information for this contact",
),
}

57
base_contact_function/res_partner_category.py

@ -0,0 +1,57 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# This module copyright (C) 2013 Savoir-faire Linux
# (<http://www.savoirfairelinux.com>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp.osv import orm, fields
class res_partner_category(orm.Model):
"""
Inherits partner_category
"""
_inherit = 'res.partner.category'
_columns = {
'category_function_ids': fields.one2many(
'res.partner.category.function',
'category_id',
'Functions'
),
}
def name_search(self, cr, user, name='', args=None, operator='ilike',
context=None, limit=100):
if not args:
args = []
if not context:
context = {}
if name:
name = name.split(' / ')[-1]
ids = self.search(cr, user, [('name', operator, name)] + args,
limit=limit, context=context)
if ids:
child_ids = self.search(
cr, user, [('parent_id', 'child_of', ids)],
context=context)
if child_ids:
ids.extend(child_ids)
else:
ids = self.search(cr, user, args, limit=limit, context=context)
return self.name_get(cr, user, ids, context)

47
base_contact_function/res_partner_category_function.py

@ -0,0 +1,47 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# This module copyright (C) 2013 Savoir-faire Linux
# (<http://www.savoirfairelinux.com>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp.osv import orm, fields
class res_partner_category_function(orm.Model):
"""
Adds this class to link category and functions
"""
_description = 'Partner Category Function'
_name = 'res.partner.category.function'
_order = 'sequence asc'
_columns = {
'function_id': fields.many2one(
'res.partner.function',
'Functions',
required='True',
),
'sequence': fields.integer(
'Sequence',
help="Used to order",
),
'category_id': fields.many2one(
'res.partner.category',
'Category',
),
}

54
base_contact_function/res_partner_category_view.xml

@ -0,0 +1,54 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="view_partner_category_form_admin" model="ir.ui.view">
<field name="name">List Form</field>
<field name="model">res.partner.category</field>
<field name="arch" type="xml">
<tree string="List">
<field name="complete_name"/>
</tree>
</field>
</record>
<record id="view_partner_category_list_admin" model="ir.ui.view">
<field name="name">List Tree</field>
<field name="model">res.partner.category</field>
<field name="field_parent">child_ids</field>
<field name="arch" type="xml">
<tree string="List">
<field name="name"/>
</tree>
</field>
</record>
<record id="partner_category_action" model="ir.actions.act_window">
<field name="name">List</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">res.partner.category</field>
<field name="domain">[('parent_id','=',False)]</field>
<field name="view_type">tree</field>
<field name="view_mode">tree</field>
<field name="view_id" ref="view_partner_category_list_admin"/>
<field name="help" type="html">
<p>
Here is a list of all your partners classified by category.
</p>
</field>
</record>
<menuitem id="menu_partner_category_list_form"
name="Category Lists"
parent="mail.mail_my_stuff"
sequence="30"
action="base.action_partner_category_form"/>
<menuitem id="menu_partner_category"
name="Category Lists Tree"
action="partner_category_action"
parent="mail.mail_my_stuff"
sequence="40" />
</data>
</openerp>

51
base_contact_function/res_partner_function.py

@ -0,0 +1,51 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# This module copyright (C) 2013 Savoir-faire Linux
# (<http://www.savoirfairelinux.com>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp.osv import fields, orm
class res_partner_function(orm.Model):
_description = 'Partner Function'
_name = 'res.partner.function'
_columns = {
'name': fields.char(
'Name',
required=True,
select=True,
translate=True,
help='Name of function.',
),
'acronym': fields.char(
'Acronym',
size=50,
select=True,
translate=True,
help='Acronym of function.',
),
'partner_ids': fields.many2many(
'res.partner',
'function_partner_rel',
'function_id',
'partner_id',
'Functions',
),
}

43
base_contact_function/res_partner_function_view.xml

@ -0,0 +1,43 @@
<?xml version="1.0" ?>
<openerp>
<data>
<!-- Tree Views functions-->
<record id="function_tree_view" model="ir.ui.view">
<field name="name">Function Tree View</field>
<field name="model">res.partner.function</field>
<field name="arch" type="xml">
<tree string="Functions" version="7.0">
<field name="name"/>
<field name="acronym"/>
</tree>
</field>
</record>
<!-- Form Views functions-->
<record id="function_form_view" model="ir.ui.view">
<field name="name">Function Form View</field>
<field name="model">res.partner.function</field>
<field name="arch" type="xml">
<form string="Function" version="7.0" >
<group col="4">
<field name="name"/>
<field name="acronym"/>
</group>
</form>
</field>
</record>
<!-- Actions -->
<record id="action_function_tree_list" model="ir.actions.act_window">
<field name="name">Functions</field>
<field name="view_id" ref="function_tree_view"/>
<field name="res_model">res.partner.function</field>
<field name="view_mode">tree,form</field>
</record>
</data>
</openerp>

526
base_contact_function/res_partner_view.xml

@ -0,0 +1,526 @@
<?xml version = "1.0" encoding="utf-8"?>
<openerp>
<data>
<!--Add list of functions in partner view-->
<record id="view_contact_by_function_form" model="ir.ui.view">
<field name="name">contact.functions.form.inherit</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
<field name="use_parent_address" position="replace">
<field name="use_parent_address"
class="oe_edit_only oe_inline"
on_change="onchange_address(use_parent_address, parent_id)"
attrs="{'invisible': [('parent_id','=', False),('use_parent_address','=',False)]}"
string="Use Organisation Address"/>
</field>
<label for="use_parent_address" position="replace">
<label for="use_parent_address"
class="oe_edit_only"
attrs="{'invisible': [('parent_id','=', False),('use_parent_address','=',False)]}"
string="Use Organisation Address"/>
</label>
<!--Add ')' at the end of 'Is an Organism?'-->
<label for="is_company" position="replace">
<label for="is_company" string="Is an Organism"/>)
</label>
<!--Replace Street placeholder by No, Street, Apartment/Office-->
<field name="street" position="attributes">
<attribute name="placeholder">No, Street, Apartment/Office</attribute>
</field>
<field name="fax" position="attributes">
<attribute name="string">Fax</attribute>
</field>
<notebook position="inside">
<page string="Functions"
attrs="{'invisible': [('is_company','=',False), ('child_ids', '=', [])]}"
autofocus="autofocus">
<separator string="Select Functions for this Organisation"/>
<field name="function_ids"/>
</page>
<page string="History (Functions)" attrs="{'invisible': ['|','|',('is_company','=',True),('contact_id','!=',False),('other_contact_history_ids','=',[])]}">
<separator string="History"/>
<field name="other_contact_history_ids" mode="kanban"
attrs="{'invisible': [('other_contact_history_ids','=',False)]}">
<kanban>
<field name="color"/>
<field name="name"/>
<field name="title"/>
<field name="email"/>
<field name="parent_id" string="Organism"/>
<field name="is_company"/>
<field name="function_id" string="Function"/>
<field name="phone"/>
<field name="street"/>
<field name="street2"/>
<field name="zip"/>
<field name="city"/>
<field name="country_id"/>
<field name="mobile"/>
<field name="fax"/>
<field name="state_id"/>
<field name="has_image"/>
<templates>
<t t-name="kanban-box">
<div class="oe_kanban_vignette oe_semantic_html_override">
<a type="open">
<t t-if="record.has_image.raw_value === true">
<img t-att-src="kanban_image('res.partner', 'image_small', record.id.value)"
class="oe_kanban_image"/>
</t>
<t t-if="record.has_image.raw_value === false">
<t t-if="record.is_company.raw_value === true">
<img t-att-src='_s + "/base/static/src/img/company_image.png"'
class="oe_kanban_image"/>
</t>
<t t-if="record.is_company.raw_value === false">
<img t-att-src='_s + "/base/static/src/img/avatar.png"'
class="oe_kanban_image"/>
</t>
</t>
</a>
<div class="oe_kanban_details">
<h4 class="oe_partner_heading">
<a type="open">
<field name="name"/>
</a>
</h4>
<div class="oe_kanban_partner_categories"/>
<div class="oe_kanban_partner_links"/>
<ul>
<li t-if="!record.parent_id.raw_value and record.function_id.raw_value">
<field name="function_id"/>
</li>
<li t-if="record.parent_id.raw_value and record.function_id.raw_value">
<field name="function_id"/>
,
<field name="parent_id"/>
</li>
<li t-if="record.city.raw_value and !record.country.raw_value">
<field name="city"/>
</li>
<li t-if="!record.city.raw_value and record.country.raw_value">
<field name="country"/>
</li>
<li t-if="record.city.raw_value and record.country.raw_value">
<field name="city"/>
,
<field name="country"/>
</li>
<li t-if="record.email.raw_value">
<a t-attf-href="mailto:#{record.email.raw_value}">
<field name="email"/>
</a>
</li>
</ul>
</div>
</div>
</t>
</templates>
</kanban>
<form string="Contact" version="7.0">
<sheet>
<field name="image" widget='image' class="oe_avatar oe_left"
options='{"preview_image": "image_medium"}'/>
<div class="oe_title">
<label for="name" class="oe_edit_only"/>
<h1>
<field name="name" style="width: 70%%"/>
</h1>
</div>
<group>
<!-- inherited part -->
<field name="category_id" widget="many2many_tags"
placeholder="Tags..." style="width: 70%%" string="Tag"/>
<field name="parent_id"
placeholder="Organism"
domain="[('is_company','=',True)]"
string="Parent Organism"/>
<!-- inherited part end -->
<field name="function_id" placeholder="e.g. Sales Director"/>
<group colspan="4">
<field name="start_date" />
<field name="end_date"/>
<field name="naming"/>
</group>
<field name="email"/>
<field name="phone"/>
<field name="mobile"/>
</group>
<div>
<field name="use_parent_address"/>
<label for="use_parent_address" string="Use Organisation Address"/>
</div>
<group>
<label for="type"/>
<div name="div_type">
<field class="oe_inline" name="type"/>
</div>
<label for="street" string="Address"
attrs="{'invisible': [('use_parent_address','=', True)]}"/>
<div attrs="{'invisible': [('use_parent_address','=', True)]}"
name="div_address">
<field name="street" placeholder="Street..."/>
<field name="street2"/>
<div class="address_format">
<field name="city" placeholder="City" style="width: 40%%"/>
<field name="state_id" class="oe_no_button"
placeholder="State" style="width: 37%%"
options='{"no_open": True}' on_change="onchange_state(state_id)"/>
<field name="zip" placeholder="ZIP" style="width: 20%%"/>
</div>
<field name="country_id" placeholder="Country"
class="oe_no_button" options='{"no_open": True}'/>
</div>
</group>
<field name="supplier" invisible="True"/>
<group string="Bank Accounts">
<field name="bank_ids" nolabel="1">
<tree string="Bank Details">
<field name="state" invisible="1"/>
<field name="sequence" invisible="1"/>
<field name="acc_number"/>
<field name="bank_name"/>
<field name="owner_name"/>
</tree>
</field>
</group>
</sheet>
</form>
</field>
</page>
</notebook>
<!--Replace function by function_id defined by Organisation-->
<field name="function" position="replace"/>
</field>
</record>
<!--Add start_date, end_date, naming and account bank in partner view-->
<record id="view_position_info_form" model="ir.ui.view">
<field name="name">position.info.form.inherit</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base_contact.view_partner_form_inherit"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='other_contact_ids']/form//field[@name='category_id']"
position="attributes">
<attribute name="string">Tag</attribute>
</xpath>
<xpath expr="//field[@name='other_contact_ids']/form//field[@name='function']"
position="after">
<group colspan="4">
<field name="start_date" />
<field name="end_date"/>
<field name="naming"/>
</group>
</xpath>
<xpath expr="//field[@name='other_contact_ids']/form//field[@name='supplier']"
position="after">
<group string="Bank Accounts">
<field name="bank_ids" nolabel="1"/>
</group>
</xpath>
<xpath expr="//field[@name='other_contact_ids']/form//field[@name='parent_id']"
position="replace">
<group colspan="4">
<field name="parent_id" placeholder="Organism"
domain="[('is_company','=',True)]"
on_change="onchange_partner_function(parent_id)"
string="Parent Organism"/>
</group>
</xpath>
<xpath expr="//field[@name='other_contact_ids']/form//field[@name='function']"
position="replace">
<group colspan="4">
<field name="function_id" string="Function"/>
</group>
</xpath>
<xpath expr="//field[@name='other_contact_ids']/form//label[@for='use_parent_address']"
position="replace">
<label for="use_parent_address"/>
</xpath>
<xpath expr="//field[@name='other_contact_ids']/kanban//field[@name='function']"
position="replace">
<group colspan="4">
<field name="function_id" string="Function"/>
</group>
</xpath>
<xpath expr="//field[@name='other_contact_ids']/kanban//field[@name='has_image']"
position="after">
<templates>
<t t-name="kanban-box">
<t t-set="color" t-value="kanban_color(record.color.raw_value)"/>
<div t-att-class="color + (record.title.raw_value == 1 ? ' oe_kanban_color_alert' : '')"
style="position: relative">
<a t-if="! read_only_mode" type="delete"
style="position: absolute; right: 0; padding: 4px; diplay: inline-block">
X
</a>
<div class="oe_module_vignette">
<a type="open">
<t t-if="record.has_image.raw_value === true">
<img t-att-src="kanban_image('res.partner', 'image',
record.id.value, {'preview_image': 'image_small'})"
class="oe_avatar oe_kanban_avatar_smallbox"/>
</t>
<t t-if="record.image and record.image.raw_value !== false">
<img t-att-src="'data:image/png;base64,'+record.image.raw_value"
class="oe_avatar oe_kanban_avatar_smallbox"/>
</t>
<t t-if="record.has_image.raw_value === false
and (!record.image or record.image.raw_value === false)">
<t t-if="record.is_company.raw_value === true">
<img t-att-src='_s + "/base/static/src/img/company_image.png"'
class="oe_kanban_image oe_kanban_avatar_smallbox"/>
</t>
<t t-if="record.is_company.raw_value === false">
<img t-att-src='_s + "/base/static/src/img/avatar.png"'
class="oe_kanban_image oe_kanban_avatar_smallbox"/>
</t>
</t>
</a>
<div class="oe_module_desc">
<div class="oe_kanban_box_content oe_kanban_color_bglight oe_kanban_color_border">
<table class="oe_kanban_table">
<tr>
<td class="oe_kanban_title1" align="left" valign="middle">
<h4>
<a type="open">
<field name="name"/>
</a>
</h4>
<i>
<t t-if="record.parent_id.raw_value and !record.function_id.raw_value">
<field name="parent_id"/>
</t>
<t t-if="!record.parent_id.raw_value and record.function_id.raw_value">
<field name="function_id"/>
</t>
<t t-if="record.parent_id.raw_value and record.function_id.raw_value">
<field name="function_id"/>
,
<field name="parent_id"/>
</t>
</i>
<div>
<a t-if="record.email.raw_value" title="Mail"
t-att-href="'mailto:'+record.email.value">
<field name="email"/>
</a>
</div>
<div t-if="record.phone.raw_value">
Phone: <field name="phone"/>
</div>
<div t-if="record.mobile.raw_value">
Mobile: <field name="mobile"/>
</div>
<div t-if="record.fax.raw_value">
Fax: <field name="fax"/>
</div>
</td>
</tr>
</table>
</div>
</div>
</div>
</div>
</t>
</templates>
</xpath>
have the same form for contact and other postions
<field name="parent_id" position="replace">
<field name="parent_id" placeholder="Parent Organisation"
domain="[('is_company','=',True)]"
attrs="{'invisible': [('is_company','=', False)]}"/>
</field>
<xpath expr="//field[@name='child_ids']/form//field[@name='supplier']"
position="after">
<group string="Bank Accounts">
<field name="bank_ids" nolabel="1"/>
</group>
</xpath>
<xpath expr="//field[@name='child_ids']/form//field[@name='function']"
position="after">
<group colspan="4">
<field name="start_date" />
<field name="end_date"/>
<field name="naming"/>
</group>
</xpath>
<xpath expr="//field[@name='child_ids']/form//field[@name='function']"
position="replace">
<group colspan="4">
<field name="parent_id"
placeholder="Organism"
domain="[('is_company','=',True)]"
string="Parent Organisation" />
<field name="function_id"
readonly="False"
domain="[('id', 'in', parent.function_ids[0][2])]"
string="Function"/>
</group>
</xpath>
<xpath expr="//field[@name='child_ids']/form//label[@for='use_parent_address']"
position="replace">
<label for="use_parent_address"/>
</xpath>
<xpath expr="//field[@name='child_ids']/kanban//field[@name='function']"
position="replace">
<group colspan="4">
<field name="function_id" string="Function"/>
</group>
</xpath>
<xpath expr="//field[@name='other_contact_ids']/kanban//field[@name='has_image']"
position="after">
<templates>
<t t-name="kanban-box">
<div class="oe_kanban_vignette oe_semantic_html_override">
<a type="open">
<t t-if="record.has_image.raw_value === true">
<img t-att-src="kanban_image('res.partner', 'image_small', record.id.value)"
class="oe_kanban_image"/>
</t>
<t t-if="record.has_image.raw_value === false">
<t t-if="record.is_company.raw_value === true">
<img t-att-src='_s + "/base/static/src/img/company_image.png"'
class="oe_kanban_image"/>
</t>
<t t-if="record.is_company.raw_value === false">
<img t-att-src='_s + "/base/static/src/img/avatar.png"'
class="oe_kanban_image"/>
</t>
</t>
</a>
<div class="oe_kanban_details">
<h4 class="oe_partner_heading">
<a type="open">
<field name="name"/>
</a>
</h4>
<div class="oe_kanban_partner_categories"/>
<div class="oe_kanban_partner_links"/>
<ul>
<li t-if="record.parent_id.raw_value and !record.function_id.raw_value">
<field name="parent_id"/>
</li>
<li t-if="!record.parent_id.raw_value and record.function_id.raw_value">
<field name="function_id"/>
</li>
<li t-if="record.parent_id.raw_value and record.function_id.raw_value">
<field name="function_id"/>
,
<field name="parent_id"/>
</li>
<li t-if="record.city.raw_value and !record.country.raw_value">
<field name="city"/>
</li>
<li t-if="!record.city.raw_value and record.country.raw_value">
<field name="country"/>
</li>
<li t-if="record.city.raw_value and record.country.raw_value">
<field name="city"/>
,
<field name="country"/>
</li>
<li t-if="record.email.raw_value">
<a t-attf-href="mailto:#{record.email.raw_value}">
<field name="email"/>
</a>
</li>
</ul>
</div>
</div>
</t>
</templates>
</xpath>
</field>
</record>
<!-- Actions for Organisation -->
<record id="action_partner_customer_form" model="ir.actions.act_window">
<field name="name">Company</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">res.partner</field>
<field name="view_type">form</field>
<field name="view_mode">kanban,tree,form</field>
<field name="domain">[('is_company','=',1)]</field>
<field name="context" eval="{'default_is_company': True}"/>
<field name="filter" eval="True"/>
</record>
<!-- Actions for Contacts -->
<record id="action_partner_contact_form" model="ir.actions.act_window">
<field name="name">Contacts</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">res.partner</field>
<field name="view_type">form</field>
<field name="view_mode">kanban,tree,form</field>
<field name="domain">[('is_company','=',0)]</field>
<field name="filter" eval="True"/>
</record>
<!--Add country,street fields in tree partner view-->
<record model="ir.ui.view" id="view_partner_tree_country_address">
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_tree"/>
<field name="arch" type="xml">
<field name="country_id" position="replace"/>
<field name="name" position="after">
<field name="country_id"/>
</field>
<field name="email" position="after">
<field name="street" string="Address"/>
</field>
</field>
</record>
<!-- Inherit Categories adding functions -->
<record id="view_partner_category_functions_form" model="ir.ui.view">
<field name="name">Partner Categories Functions</field>
<field name="model">res.partner.category</field>
<field name="inherit_id" ref="base.view_partner_category_form"/>
<field name="arch" type="xml">
<xpath expr="//form[@string='Partner Category']/group[1]"
position="after">
<notebook position="inside">
<page string="Functions">
<separator string="Add function"/>
<group col="2" colspan="4">
<field name="category_function_ids" nolabel="1">
<tree string="Functions">
<field name="sequence"/>
<field name="function_id"/>
</tree>
<form string="Function">
<field name="function_id"/>
<field name="sequence"/>
</form>
</field>
</group>
</page>
</notebook>
</xpath>
</field>
</record>
<!--Replace company by Organisation-->
<record id="view_partner_simple_form" model="ir.ui.view">
<field name="name">res.partner.simplified.form</field>
<field name="model">res.partner</field>
<field name="arch" type="xml">
<label for="is_company" position="replace">
<label for="is_company" string="Is an Organism"/>
</label>
<field name="parent_id" position="replace">
<field name="parent_id"
placeholder="Organism"
domain="[('is_company', '=', True)]"
context="{'default_is_company': True, 'default_supplier': supplier}"
attrs="{'invisible': [('is_company','=', True),('parent_id', '=', False)]}"
on_change="onchange_address(use_parent_address, parent_id)"/>
</field>
</field>
</record>
</data>
</openerp>

3
base_contact_function/security/ir.model.access.csv

@ -0,0 +1,3 @@
"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink"
"access_res_partner_function","access_res_partner_function_user","model_res_partner_function","base.group_user",1,1,1,1
"access_res_partner_category_function","access_res_partner_category_function_user","model_res_partner_category_function","base.group_user",1,1,1,1

31
base_contact_function/tests/__init__.py

@ -0,0 +1,31 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# This module copyright (C) 2013 Savoir-faire Linux
# (<http://www.savoirfairelinux.com>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from . import (
test_functions,
test_partner_category,
)
checks = [
test_functions,
test_partner_category
]

105
base_contact_function/tests/test_functions.py

@ -0,0 +1,105 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# This module copyright (C) 2013 Savoir-faire Linux
# (<http://www.savoirfairelinux.com>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp.tests.common import TransactionCase
from openerp.osv.orm import browse_record
from openerp.tools import ustr
class Base_Test_function(TransactionCase):
"""
Simple test creating a function
This is a base class for function test cases.
Inherit from this and setup values.
"""
def setUp(self, vals=None):
"""
Setting up function.
"""
if not vals:
vals = {}
# Default test values
self.vals = {
'name': u'This is a test function name with uniödé',
'acronym': u'This is a test function acronym with uniödé',
}
super(Base_Test_function, self).setUp()
self.vals = dict(self.vals.items() + vals.items())
# Create the function object; we will be testing this, so store in self
function_pool = self.registry('res.partner.function')
self.function_id = function_pool.create(
self.cr, self.uid, self.vals, context=None
)
def test_function(self):
"""
Checking the function creation.
"""
function_function = self.registry('res.partner.function')
function_obj = function_function.browse(
self.cr, self.uid, self.function_id, context=None
)
for field in self.vals:
val = function_obj[field]
if type(val) == browse_record:
self.assertEquals(self.vals[field], val.id,
"IDs for %s don't match: (%i != %i)" %
(field, self.vals[field], val.id))
else:
self.assertEquals(ustr(self.vals[field]), ustr(val),
"Values for %s don't match: (%s != %s)" %
(field, ustr(self.vals[field]), ustr(val)))
class Test_function_bad(Base_Test_function):
"""
Simple test creating a function, test against bad values
"""
def setUp(self):
"""
Setting up function, then changing the values to test against.
"""
super(Test_function_bad, self).setUp()
# Change vals to something wrong
self.vals = {'name': 'This is the wrong function name',
'acronym': 'This is the wrong function acronym',
}
def test_function(self):
"""
Checking the function creation, assertions should all be false.
"""
function_function = self.registry('res.partner.function')
function_obj = function_function.browse(
self.cr, self.uid, self.function_id, context=None
)
for field in self.vals:
val = function_obj[field]
if type(val) == browse_record:
self.assertNotEqual(self.vals[field], val.id,
"IDs for %s don't match: (%i != %i)" %
(field, self.vals[field], val.id))
else:
self.assertNotEqual(ustr(self.vals[field]), ustr(val),
"Values for %s don't match: (%s != %s)" %
(field, ustr(self.vals[field]), ustr(val)))

193
base_contact_function/tests/test_partner_category.py

@ -0,0 +1,193 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# This module copyright (C) 2013 Savoir-faire Linux
# (<http://www.savoirfairelinux.com>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp.tests.common import TransactionCase
from openerp.osv.orm import browse_record
from openerp.tools import ustr
class Base_Test_partner_category(TransactionCase):
"""
Simple test creating a partner_category
This is a base class for partner_category test cases.
Inherit from this and setup values.
"""
def setUp(self, vals=None):
"""
Setting up partner_category.
"""
if not vals:
vals = {}
# Default test values
self.vals = {
'name': 'This is a test partner_category name with unicödé',
'active': True,
}
super(Base_Test_partner_category, self).setUp()
# Create the parent
partner_category_partner = self.registry('res.partner.category')
self.vals['parent_id'] = partner_category_partner.create(
self.cr, self.uid, {
'name': 'Test parent',
'active': True,
}, context=None
)
self.vals = dict(self.vals.items() + vals.items())
# Create the partner_category object; we will be testing this,
# so store in self
self.partner_category_id = partner_category_partner.create(
self.cr, self.uid, self.vals, context=None
)
def test_partner_category(self):
"""
Checking the partner_category creation.
"""
partner_category = self.registry('res.partner.category')
partner_category_obj = partner_category.browse(
self.cr, self.uid, self.partner_category_id, context=None
)
for field in self.vals:
val = partner_category_obj[field]
if type(val) == browse_record:
self.assertEquals(self.vals[field], val.id,
"IDs for %s don't match: (%i != %i)" %
(field, self.vals[field], val.id))
else:
self.assertEquals(ustr(self.vals[field]), ustr(val),
"Values for %s don't match: (%s != %s)" %
(field, ustr(self.vals[field]), ustr(val)))
class Test_partner_category_bad(Base_Test_partner_category):
"""
Simple test creating a partner_category, test against bad values
"""
def setUp(self):
"""
Setting up partner_category, then changing the values to test against.
"""
super(Test_partner_category_bad, self).setUp()
# Change vals to something wrong
self.vals = {'name': 'This is the wrong partner_category name',
'active': False,
}
def test_partner_category(self):
"""
Checking the partner_category creation, assertions should all be false.
"""
partner_category_partner_category = self.registry(
'res.partner.category'
)
partner_category_obj = partner_category_partner_category.browse(
self.cr, self.uid, self.partner_category_id, context=None
)
for field in self.vals:
val = partner_category_obj[field]
if type(val) == browse_record:
self.assertNotEqual(self.vals[field], val.id,
"IDs for %s don't match: (%i != %i)" %
(field, self.vals[field], val.id))
else:
self.assertNotEqual(ustr(self.vals[field]), ustr(val),
"Values for %s don't match: (%s != %s)" %
(field, ustr(self.vals[field]), ustr(val)))
class test_partner_category(TransactionCase):
def setUp(self):
super(test_partner_category, self).setUp()
# Clean up registries
self.registry('ir.model').clear_caches()
self.registry('ir.model.data').clear_caches()
# Get registries
self.user_model = self.registry("res.users")
self.partner_cat_model = self.registry("res.partner.category")
# Get context
self.context = self.user_model.context_get(self.cr, self.uid)
# Create parent partner category
self.test_parent_id = self.partner_cat_model.create(
self.cr, self.uid, {
'name': 'test_parent',
}, context=self.context)
self.test_child_id = self.partner_cat_model.create(
self.cr, self.uid, {
'name': 'test_child',
'parent_id': self.test_parent_id,
}, context=self.context)
self.test_grandchild_id = self.partner_cat_model.create(
self.cr, self.uid, {
'name': 'test_grandchild',
'parent_id': self.test_child_id,
}, context=self.context)
self.test_orphan_id = self.partner_cat_model.create(
self.cr, self.uid, {
'name': 'test_orphan',
}, context=self.context)
def test_name_search(self):
self.assertListEqual(
self.partner_cat_model.name_search(
self.cr, self.uid, name='test_parent', context=self.context
),
[
(self.test_child_id, 'test_parent / test_child'),
(self.test_grandchild_id,
'test_parent / test_child / test_grandchild'),
(self.test_parent_id, 'test_parent'),
]
)
self.assertListEqual(
self.partner_cat_model.name_search(
self.cr, self.uid, name='test_child', context=self.context
),
[
(self.test_child_id, 'test_parent / test_child'),
(self.test_grandchild_id,
'test_parent / test_child / test_grandchild'),
]
)
self.assertListEqual(
self.partner_cat_model.name_search(
self.cr, self.uid, name='test_grandchild', context=self.context
),
[
(self.test_grandchild_id,
'test_parent / test_child / test_grandchild'),
]
)
self.assertListEqual(
self.partner_cat_model.name_search(
self.cr, self.uid, name='test_orphan', context=self.context
),
[
(self.test_orphan_id, 'test_orphan'),
]
)
Loading…
Cancel
Save