diff --git a/partner_rank/__init__.py b/partner_rank/__init__.py new file mode 100644 index 000000000..96a8b0e47 --- /dev/null +++ b/partner_rank/__init__.py @@ -0,0 +1,26 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# This module copyright (C) 2014 Savoir-faire Linux +# (). +# +# 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 . +# +############################################################################## + +from . import ( + res_rank, + res_partner, +) diff --git a/partner_rank/__openerp__.py b/partner_rank/__openerp__.py new file mode 100644 index 000000000..de6f06459 --- /dev/null +++ b/partner_rank/__openerp__.py @@ -0,0 +1,70 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# This module copyright (C) 2014 Savoir-faire Linux +# (). +# +# 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 . +# +############################################################################## + +{ + 'name': 'Partner Rank', + 'version': '0.1', + 'author': 'Savoir-faire Linux', + 'maintainer': 'Savoir-faire Linux', + 'website': 'http://www.savoirfairelinux.com', + 'license': 'AGPL-3', + 'category': 'Customer Relationship Management', + 'summary': "Manage partner's priority", + 'description': """ +Manage partner's priority +========================= + +This module allow to setup a rank between partners, manually defined. +It adds : + +1) a new field 'Rank' on the partner form +2) the ability to group the partners per rank +3) a new menu 'Sales -> Configuration -> Address Book -> Ranks' + to define the available Ranks. + +Each Rank is defined as : + +* a priority (integer) : the lower the most important +* a name +* a description +* the name_get is defined as 'Priority - Name' + +Contributors +------------ +* El Hadji Dem (elhadji.dem@savoirfairelinux.com) +""", + 'depends': [ + 'base', + ], + 'external_dependencies': { + 'python': [], + }, + 'data': [ + 'res_partner_view.xml', + 'res_rank_view.xml', + 'security/ir.model.access.csv', + ], + 'demo': [], + 'test': [], + 'installable': True, + 'auto_install': False, +} diff --git a/partner_rank/res_partner.py b/partner_rank/res_partner.py new file mode 100644 index 000000000..dadd85bbd --- /dev/null +++ b/partner_rank/res_partner.py @@ -0,0 +1,29 @@ +############################################################################## +# +# OpenERP, Open Source Management Solution +# This module copyright (C) 2014 Savoir-faire Linux +# (). +# +# 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 . +# +############################################################################## + +from openerp.osv import fields, orm + + +class res_partner(orm.Model): + _inherit = 'res.partner' + _columns = { + 'rank_id': fields.many2one('res.rank', 'Partner rank'), + } diff --git a/partner_rank/res_partner_view.xml b/partner_rank/res_partner_view.xml new file mode 100644 index 000000000..e1b5028a5 --- /dev/null +++ b/partner_rank/res_partner_view.xml @@ -0,0 +1,31 @@ + + + + + + + res.partner + + + + + + + + + + + res.partner..rank.select + + res.partner + + + + + + + + + + + diff --git a/partner_rank/res_rank.py b/partner_rank/res_rank.py new file mode 100644 index 000000000..85e1f9af3 --- /dev/null +++ b/partner_rank/res_rank.py @@ -0,0 +1,53 @@ +############################################################################## +# +# OpenERP, Open Source Management Solution +# This module copyright (C) 2014 Savoir-faire Linux +# (). +# +# 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 . +# +############################################################################## + +from openerp.osv import fields, orm + + +class res_rank(orm.Model): + _description = 'Rank' + _name = 'res.rank' + + _columns = { + 'name': fields.char( + 'Name', help='Rank name.'), + 'description': fields.text( + 'Description', help='Rank description.'), + 'priority': fields.integer( + 'Priority', help='Rank priority (the lower the most important).'), + 'partner_ids': fields.one2many( + 'res.partner', 'rank_id', 'Partner'), + } + + _sql_constraints = [ + ('priority_uniq', 'UNIQUE(priority)', 'The priority must be unique!'), + ] + + def name_get(self, cr, uid, ids, context=None): + if context is None: + context = {} + if type(ids) in (int, long): + ids = [ids] + res = [] + for record in self.browse(cr, uid, ids, context): + res.append((record.id, str(record.priority) + + ' - ' + record.name)) + return res diff --git a/partner_rank/res_rank_view.xml b/partner_rank/res_rank_view.xml new file mode 100644 index 000000000..8c4bda4a2 --- /dev/null +++ b/partner_rank/res_rank_view.xml @@ -0,0 +1,48 @@ + + + + + + Rank Tree View + res.rank + tree + + + + + + + + + + + + Rank Form View + res.rank + form + +
+ + + + + +
+
+
+ + + + Partner's rank + res.rank + form + tree,form + + + +
+
diff --git a/partner_rank/security/ir.model.access.csv b/partner_rank/security/ir.model.access.csv new file mode 100644 index 000000000..b2fa3a088 --- /dev/null +++ b/partner_rank/security/ir.model.access.csv @@ -0,0 +1,2 @@ +"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink" +"access_res_rank","res_rank_user","model_res_rank","base.group_user",1,1,1,1 diff --git a/partner_rank/tests/__init__.py b/partner_rank/tests/__init__.py new file mode 100644 index 000000000..e3e2179ad --- /dev/null +++ b/partner_rank/tests/__init__.py @@ -0,0 +1,27 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# This module copyright (C) 2013 Savoir-faire Linux +# (). +# +# 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 . +# +############################################################################## + +from . import test_rank + +checks = [ + test_rank, +] diff --git a/partner_rank/tests/test_rank.py b/partner_rank/tests/test_rank.py new file mode 100644 index 000000000..df317eac4 --- /dev/null +++ b/partner_rank/tests/test_rank.py @@ -0,0 +1,67 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# This module copyright (C) 2014 Savoir-faire Linux +# (). +# +# 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 . +# +############################################################################## + +from openerp.tests.common import TransactionCase +from openerp.osv.orm import browse_record + + +class Base_Test_rank(TransactionCase): + """ + Simple test creating a rank + This is a base class for rank test cases. + Inherit from this and setup values. + """ + + def setUp(self, vals={}): + """ + Setting up rank. + """ + # Default test values + self.vals = {'name': 'This is a test rank', + 'priority': 1, + 'description': 'Description for rank', + } + super(Base_Test_rank, self).setUp() + # Overwrite vals if needed + self.vals = dict(self.vals.items() + vals.items()) + # Create the rank object; we will be testing this, so store in self + res_rank = self.registry('res.rank') + self.rank_id = res_rank.create( + self.cr, self.uid, self.vals, context=None) + + def test_rank(self): + """ + Checking the rank creation. + """ + res_rank = self.registry('res.rank') + rank_obj = res_rank.browse( + self.cr, self.uid, self.rank_id, context=None) + for field in self.vals: + val = rank_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(str(self.vals[field]), str(val), + "Values for %s don't match: (%s != %s)" % + (field, str(self.vals[field]), str(val)))