Browse Source

[7.0] port base_address_category to 7.0

This is not a real port as this module is not useful in 7.0: the res.partner.address is not longer there. 

I've kept the model definitions and removed the views from the model. The
migration process should convert res.partner.address.category records to
res.partner.category records.
pull/2/head
Alexandre Fayolle 12 years ago
parent
commit
d597948c0d
  1. 30
      base_address_category/__init__.py
  2. 60
      base_address_category/__openerp__.py
  3. 74
      base_address_category/base_address.py
  4. 152
      base_address_category/base_address_view.xml

30
base_address_category/__init__.py

@ -1,31 +1,23 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2010 Camptocamp SA (http://www.camptocamp.com)
# Copyright (c) 2010-2013 Camptocamp SA (http://www.camptocamp.com)
# All Right Reserved
#
# Author : Nicolas Bessi (Camptocamp), Joel Grand-Guillaume
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
# 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 Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# 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.
#
# 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# 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 base_address

60
base_address_category/__openerp__.py

@ -1,38 +1,41 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2010 Camptocamp SA (http://www.camptocamp.com)
# Copyright (c) 2010-2013 Camptocamp SA (http://www.camptocamp.com)
# All Right Reserved
#
# Author : Nicolas Bessi (Camptocamp), Joel Grand-Guillaume
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
# 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 Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# 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.
#
# 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# 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" : "Partner Adress Category",
"description" : """Add categories on Address like there is on Partner. This is interesting for managing mailling list based on address
for example.
"name" : "Partner Address Category",
"description" : """\
res.partner.address.category
----------------------------
This module is deprecated as of OpenERP 7.0, because that version
deprecated res.partner.address, and res.partner already has multi
category support (visible as Tags in the user interface).
The port of this module to OpenERP 7 keeps the model definitions, but
removes the views (for which the base views are no longer
available). The migration process should ensure that the
res.partner.address.category records are migrated to
res.partner.category records.
""",
"version" : "1.2",
"author" : "Camptocamp",
@ -41,13 +44,10 @@
"depends" : [
"base",
],
"init_xml" : [
"security/security.xml"
],
"update_xml" : [
"base_address_view.xml",
'security/ir.model.access.csv',
],
"data" : [
"security/security.xml"
'security/ir.model.access.csv',
],
"active": False,
"installable": False
"installable": True
}

74
base_address_category/base_address.py

@ -1,59 +1,54 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2010 Camptocamp SA (http://www.camptocamp.com)
# Copyright (c) 2010-2013 Camptocamp SA (http://www.camptocamp.com)
# All Right Reserved
#
# Author : Nicolas Bessi (Camptocamp), Joel Grand-Guillaume
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
# 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 Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# 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.
#
# 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 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/>.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
from osv import osv, fields
from openerp.osv import osv, fields, orm
class ResPartnerAdressCategory(osv.osv):
def name_get(self, cr, uid, ids, context={}):
class ResPartnerAdressCategory(orm.Model):
def name_get(self, cr, uid, ids, context=None):
if not len(ids):
return []
reads = self.read(cr, uid, ids, ['name','parent_id'], context)
reads = self.read(cr, uid, ids, ['name', 'parent_id'], context)
res = []
for record in reads:
name = record['name']
if record['parent_id']:
name = record['parent_id'][1]+' / '+name
name = '%s / %s ' % (record['parent_id'][1], name)
res.append((record['id'], name))
return res
def _name_get_fnc(self, cr, uid, ids, prop, unknow_none, unknow_dict):
res = self.name_get(cr, uid, ids)
return dict(res)
def _check_recursion(self, cr, uid, ids):
level = 100
while len(ids):
cr.execute('select distinct parent_id from res_partner_address_category\
where id in ('+','.join(map(unicode,ids))+')')
ids = filter(None, map(lambda x:x[0], cr.fetchall()))
cr.execute('select distinct parent_id '
'from res_partner_address_category '
'where id in (%s)' % ','.join(unicode(id) for id in ids))
ids = [parent_id for (parent_id,) in cr.fetchall() if parent_id]
if not level:
return False
level -= 1
@ -65,27 +60,36 @@ class ResPartnerAdressCategory(osv.osv):
_name = 'res.partner.address.category'
_columns = {
'name': fields.char('Category Name', required=True, size=64),
'parent_id': fields.many2one('res.partner.address.category', 'Parent Category', select=True),
'complete_name': fields.function(_name_get_fnc, method=True, type="char", string='Name'),
'child_ids': fields.one2many('res.partner.address.category', 'parent_id', 'Childs Category'),
'parent_id': fields.many2one('res.partner.address.category',
'Parent Category',
select=True),
'complete_name': fields.function(_name_get_fnc,
type="char",
string='Name'),
'child_ids': fields.one2many('res.partner.address.category',
'parent_id',
'Children Category'),
'active' : fields.boolean('Active'),
}
_constraints = [
(_check_recursion, 'Error ! You can not create recursive categories.', ['parent_id'])
(_check_recursion,
'Error: you can not create recursive categories.',
['parent_id'])
]
_defaults = {
'active' : lambda *a: 1,
}
_order = 'parent_id,name'
ResPartnerAdressCategory()
class ResPartnerAddress(osv.osv):
class ResPartnerAddress(orm.Model):
_inherit = "res.partner.address"
_columns = {
'category_id': fields.many2many('res.partner.address.category', 'res_partner_address_category_rel', 'adress_id', 'category_id', 'Adress categories'),
'category_id': fields.many2many('res.partner.address.category',
'res_partner_address_category_rel',
'adress_id',
'category_id',
'Address categories'),
}
ResPartnerAddress()

152
base_address_category/base_address_view.xml

@ -1,154 +1,4 @@
<openerp>
<data>
#---------------------------------------------------------------------------------------------------------
# Search Address
#---------------------------------------------------------------------------------------------------------
<record id="view_res_partner_address_filter" model="ir.ui.view">
<field name="name">res.partner.address.select</field>
<field name="model">res.partner.address</field>
<field name="inherit_id" ref="base.view_res_partner_address_filter" />
<field name="type">search</field>
<field name="arch" type="xml">
<field name="country_id" position="after" >
<field name="category_id" />
</field>
</field>
</record>
#---------------------------------------------------------------------------------------------------------
# Partner form->contact and view of address
#---------------------------------------------------------------------------------------------------------
<record model="ir.ui.view" id="view_partner_address_categ_form1_inherit">
<field name="name">res.partner.address.form1.c2c_partner_adress</field>
<field name="model">res.partner.address</field>
<field name="type">form</field>
<field name="inherit_id" ref="base.view_partner_address_form1" />
<field name="priority" eval="17" />
<field name="arch" type="xml">
<xpath expr="/form/group[3]" position="after">
<group colspan="4">
<separator string="Address Categories" colspan="4"/>
<field name="category_id" nolabel="1"/>
</group>
</xpath>
</field>
</record>
<!--
=========================================
the short form used in the partner form
=========================================
-->
<record model="ir.ui.view" id="view_partner_address_form2_inerit_categ">
<field name="name">res.partner.address.form2_c2c_partner_address</field>
<field name="model">res.partner.address</field>
<field name="type">form</field>
<field name="inherit_id" ref="base.view_partner_address_form2" />
<field name="priority" eval="17" />
<field name="arch" type="xml">
<xpath expr="/form/field[@name='email']" position="after">
<newline/>
<separator string="Address Categories" colspan="4"/>
<field name="category_id" nolabel="1"/>
</xpath>
</field>
</record>
<!--
=========================================
the short form used in the res_partner stdandard form
=========================================
-->
<record model="ir.ui.view" id="view_partner_form_inherite_categ_infos">
<field name="name">res.partner.form_partner</field>
<field name="model">res.partner</field>
<field name="type">form</field>
<field name="inherit_id" ref="base.view_partner_form" />
<field name="arch" type="xml">
<xpath expr="/form/notebook/page[@string='General']/field[@name='address']/form[@string='Partner Contacts']/group[3]" position="after">
<group colspan="4" >
<separator string="Address Categories" colspan="4"/>
<field name="category_id" nolabel="1"/>
</group>
</xpath>
</field>
</record>
<!--
======================
Adresses categories
======================
-->
<record model="ir.ui.view" id="view_partner_address_category_form">
<field name="name">res.partner.address.category.form</field>
<field name="model">res.partner.address.category</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Partner categories">
<field name="name" select="1"/>
<field name="active" select="1" />
<field name="parent_id"/>
</form>
</field>
</record>
<record model="ir.ui.view" id="view_partner_address_category_list">
<field name="name">res.partner.address.category.list</field>
<field name="model">res.partner.address.category</field>
<field name="type">tree</field>
<field name="priority" eval="6"/>
<field name="arch" type="xml">
<tree string="Partner categories">
<field name="complete_name"/>
</tree>
</field>
</record>
<record model="ir.ui.view" id="view_partner_address_category_tree">
<field name="name">res.partner.address.category.tree</field>
<field name="model">res.partner.address.category</field>
<field name="type">tree</field>
<field name="field_parent">child_ids</field>
<field name="arch" type="xml">
<tree string="Partner Categories">
<field name="name"/>
</tree>
</field>
</record>
<record model="ir.actions.act_window" id="action_partner_address_category">
<field name="name">Address categories</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">res.partner.address.category</field>
<field name="view_type">tree</field>
<field name="view_id" ref="view_partner_address_category_tree"/>
<field name="domain">[('parent_id','=',False)]</field>
</record>
<menuitem parent="base.menu_address_book" action="action_partner_address_category" id="menu_partner_address_category"/>
<record model="ir.actions.act_window" id="action_partner_by_category">
<field name="res_model">res.partner.address</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="domain">[('category_id','child_of', [active_id])]</field>
</record>
<record model="ir.values" id="ir_action_partner_by_category">
<field name="key2" eval="'tree_but_open'"/>
<field name="model" eval="'res.partner.address.category'"/>
<field name="name">Open partners</field>
<field name="value" eval="'ir.actions.act_window,%d'%action_partner_by_category"/>
<field name="object" eval="True"/>
</record>
<record model="ir.actions.act_window" id="action_partner_address_category_form">
<field name="name">Address categories</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">res.partner.address.category</field>
<field name="view_type">form</field>
</record>
<menuitem parent="base.menu_config_address_book" action="action_partner_address_category_form" id="menu_partner_address_category_form"/>
</data>
</openerp>
</openerp>
Loading…
Cancel
Save