Browse Source

[MRG] porting city addons into better diff:

More complexe name get and name search.
  Completion of country when changing state.
  Zip object is added on company.
  One2many from state to zip
  Security is CSV
pull/2/head
unknown 12 years ago
parent
commit
e5ac19b87e
  1. 6
      better_zip/__init__.py
  2. 15
      better_zip/__openerp__.py
  3. 48
      better_zip/better_zip.py
  4. 14
      better_zip/better_zip_view.xml
  5. 44
      better_zip/company.py
  6. 19
      better_zip/company_view.xml
  7. 39
      better_zip/partner.py
  8. 17
      better_zip/partner_view.xml
  9. 3
      better_zip/security/ir.model.access.csv
  10. 13
      better_zip/security/security.xml
  11. 28
      better_zip/state.py
  12. 26
      better_zip/state_view.xml

6
better_zip/__init__.py

@ -1,7 +1,8 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
############################################################################## ##############################################################################
# #
# Author Nicolas Bessi. Copyright Camptocamp SA
# Author: Nicolas Bessi. Copyright Camptocamp SA
# Contributor: Pedro Manuel Baeza <pedro.baeza@gmail.com>
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as # it under the terms of the GNU Affero General Public License as
@ -18,3 +19,6 @@
# #
############################################################################## ##############################################################################
from . import better_zip from . import better_zip
from . import partner
from . import state
from . import company

15
better_zip/__openerp__.py

@ -1,7 +1,8 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
############################################################################## ##############################################################################
# #
# Author Nicolas Bessi. Copyright Camptocamp SA
# Author: Nicolas Bessi. Copyright Camptocamp SA
# Contributor: Pedro Manuel Baeza <pedro.baeza@gmail.com>
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as # it under the terms of the GNU Affero General Public License as
@ -19,11 +20,17 @@
############################################################################## ##############################################################################
{'name': 'Better zip management', {'name': 'Better zip management',
'version': '0.3', 'version': '0.3',
'depends': ['base',],
'depends': ['base'],
'author': 'Camptocamp', 'author': 'Camptocamp',
'description': """Introduce a better zip/npa management system. Enable partner completion""",
'description': """
Introduces a better zip/npa management system.
It enables zip/city auto-completion on partners""",
'website': 'http://www.camptocamp.com', 'website': 'http://www.camptocamp.com',
'data': ['security/security.xml', 'better_zip_view.xml'],
'data': ['better_zip_view.xml',
'state_view.xml',
'company_view.xml',
'partner_view.xml',
'security/ir.model.access.csv'],
'installable': True, 'installable': True,
'active': False, 'active': False,
} }

48
better_zip/better_zip.py

@ -1,7 +1,8 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
############################################################################## ##############################################################################
# #
# Author Nicolas Bessi. Copyright Camptocamp SA
# Author: Nicolas Bessi. Copyright Camptocamp SA
# Contributor: Pedro Manuel Baeza <pedro.baeza@gmail.com>
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as # it under the terms of the GNU Affero General Public License as
@ -17,11 +18,11 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
############################################################################## ##############################################################################
from openerp.osv.orm import Model, fields
from openerp.osv import orm, fields
class BetterZip(Model):
" Zip/NPA object"
class BetterZip(orm.Model):
" Zip/NPA completion object"
_name = "res.better.zip" _name = "res.better.zip"
_description = __doc__ _description = __doc__
@ -32,6 +33,8 @@ class BetterZip(Model):
'city': fields.char('City', required=True), 'city': fields.char('City', required=True),
'state_id': fields.many2one('res.country.state', 'State'), 'state_id': fields.many2one('res.country.state', 'State'),
'country_id': fields.many2one('res.country', 'Country'), 'country_id': fields.many2one('res.country', 'Country'),
'code': fields.char('City Code', size=64,
help="The official code for the city"),
} }
_defaults = {'priority': 100} _defaults = {'priority': 100}
@ -39,19 +42,30 @@ class BetterZip(Model):
def name_get(self, cursor, uid, ids, context=None): def name_get(self, cursor, uid, ids, context=None):
res = [] res = []
for bzip in self.browse(cursor, uid, ids): for bzip in self.browse(cursor, uid, ids):
res.append((bzip.id, u"%s %s" % (bzip.name, bzip.city)))
name = [bzip.name, bzip.city]
if bzip.state_id:
name.append(bzip.state_id.name)
if bzip.country_id:
name.append(bzip.country_id.name)
res.append((bzip.id, " ".join(name)))
return res return res
def onchange_state_id(self, cr, uid, ids, state_id=False, context={}):
result = {}
if state_id:
state = self.pool['res.country.state'].browse(cr, uid, state_id, context=context)
if state:
result['value'] = {'country_id': state.country_id.id}
return result
class Partner(Model):
_inherit = "res.partner"
_columns = {'zip_id': fields.many2one('res.better.zip', 'ZIP/PN')}
def onchange_zip_id(self, cursor, uid, ids, zip_id, context=None):
if not zip_id:
return {}
if isinstance(zip_id, list):
zip_id = zip_id[0]
bzip = self.pool['res.better.zip'].browse(cursor, uid, zip_id, context=context)
return {'value': {'zip': bzip.name, 'city': bzip.city,
'country_id': bzip.country_id.id, 'state_id': bzip.state_id.id}}
def name_search(self, cr, uid, name, args=None, operator='ilike', context=None, limit=100):
if args is None:
args = []
if context is None:
context = {}
ids = []
if name:
ids = self.search(cr, uid, [('name', 'ilike', name)] + args, limit=limit)
if not ids:
ids = self.search(cr, uid, [('city', operator, name)] + args, limit=limit)
return self.name_get(cr, uid, ids, context=context)

14
better_zip/better_zip_view.xml

@ -1,16 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<openerp> <openerp>
<data> <data>
<record id="view_partner_form" model="ir.ui.view">
<field name="name">res.partner.zip_id.2</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
<field name="city" position="before">
<field name="zip_id" on_change="onchange_zip_id(zip_id)" placeholder="ZIP completion"/>
</field>
</field>
</record>
<record model="ir.ui.view" id="better_zip_form"> <record model="ir.ui.view" id="better_zip_form">
<field name="name">res.better.zip.form</field> <field name="name">res.better.zip.form</field>
@ -19,9 +9,10 @@
<form string="ZIP" version="7.0"> <form string="ZIP" version="7.0">
<group col="4"> <group col="4">
<field name="name"/> <field name="name"/>
<field name="code"/>
<field name="city"/> <field name="city"/>
<field name="priority"/> <field name="priority"/>
<field name="state_id"/>
<field name="state_id" on_change="onchange_state_id(state_id)"/>
<field name="country_id"/> <field name="country_id"/>
</group> </group>
</form> </form>
@ -34,6 +25,7 @@
<field name="arch" type="xml"> <field name="arch" type="xml">
<tree string="ZIP"> <tree string="ZIP">
<field name="name"/> <field name="name"/>
<field name="code"/>
<field name="city"/> <field name="city"/>
<field name="country_id"/> <field name="country_id"/>
<field name="priority"/> <field name="priority"/>

44
better_zip/company.py

@ -0,0 +1,44 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Author: Nicolas Bessi. Copyright Camptocamp SA
# Contributor: Pedro Manuel Baeza <pedro.baeza@gmail.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 ResCompany(orm.Model):
_inherit = 'res.company'
def on_change_city(self, cursor, uid, ids, zip_id):
result = {}
if zip_id:
bzip = self.pool['res.better.zip'].browse(cursor, uid, zip_id)
result = {'value': {'zip': bzip.name,
'country_id': bzip.country_id.id if bzip.country_id else False,
'city': bzip.city,
'state_id': bzip.state_id.id if bzip.state_id else False
}
}
return result
_columns = {
'better_zip_id': fields.many2one('res.better.zip', 'Location', select=1,
help=('Use the city name or the zip code'
' to search the location')),
}

19
better_zip/company_view.xml

@ -0,0 +1,19 @@
<?xml version="1.0"?>
<openerp>
<data>
<!-- Add cities to the company form -->
<record id="view_company_form_city" model="ir.ui.view">
<field name="name">res.company.form.city</field>
<field name="model">res.company</field>
<field name="inherit_id" ref="base.view_company_form"/>
<field name="arch" type="xml">
<field name="street2" position="after">
<field name="better_zip_id"
colspan="4"
on_change="on_change_city(better_zip_id)"
placeholder="ZIP completion" />
</field>
</field>
</record>
</data>
</openerp>

39
better_zip/partner.py

@ -0,0 +1,39 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Author: Nicolas Bessi. Copyright Camptocamp SA
# Contributor: Pedro Manuel Baeza <pedro.baeza@gmail.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 ResPartner(orm.Model):
_inherit = "res.partner"
_columns = {'zip_id': fields.many2one('res.better.zip', 'ZIP/PN')}
def onchange_zip_id(self, cursor, uid, ids, zip_id, context=None):
if not zip_id:
return {}
if isinstance(zip_id, list):
zip_id = zip_id[0]
bzip = self.pool['res.better.zip'].browse(cursor, uid, zip_id, context=context)
return {'value': {'zip': bzip.name,
'city': bzip.city,
'country_id': bzip.country_id.id if bzip.country_id else False,
'state_id': bzip.state_id.id if bzip.state_id else False,
}
}

17
better_zip/partner_view.xml

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<record id="view_partner_form" model="ir.ui.view">
<field name="name">res.partner.zip_id.2</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
<field name="city" position="before">
<field name="zip_id"
on_change="onchange_zip_id(zip_id)"
placeholder="ZIP completion"/>
</field>
</field>
</record>
</data>
</openerp>

3
better_zip/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"
"ir_model_access_betterzip0","res_better_zip group_user_all","model_res_better_zip",base.group_user,1,0,0,0
"ir_model_access_betterzip1","res_better_zip group_user","model_res_better_zip","base.group_partner_manager",1,1,1,1

13
better_zip/security/security.xml

@ -1,13 +0,0 @@
<openerp>
<data>
<record id="ir_model_access_betterzip0" model="ir.model.access">
<field name="model_id" ref="better_zip.model_res_better_zip"/>
<field eval="1" name="perm_read"/>
<field eval="'better_zip'" name="name"/>
<field eval="1" name="perm_unlink"/>
<field eval="1" name="perm_write"/>
<field eval="1" name="perm_create"/>
<field name="group_id" ref="base.group_user"/>
</record>
</data>
</openerp>

28
better_zip/state.py

@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Author: Nicolas Bessi. Copyright Camptocamp SA
# Contributor: Pedro Manuel Baeza <pedro.baeza@gmail.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 ResCountryState(orm.Model):
_inherit = 'res.country.state'
_columns = {'better_zip_ids': fields.one2many('res.better.zip', 'state_id', 'Cities')}

26
better_zip/state_view.xml

@ -0,0 +1,26 @@
<?xml version="1.0"?>
<openerp>
<data>
<!-- Add cities to the State form -->
<record model="ir.ui.view" id="view_country_state_form2">
<field name="name">view_country_state_form2</field>
<field name="model">res.country.state</field>
<field name="inherit_id" ref="base.view_country_state_form"/>
<field name="arch" type="xml">
<field name="country_id" position="after">
<field name="better_zip_ids"
context="{'country_id': country_id}"
colspan="4"
nolabel="1">
<tree editable="top">
<field name="name"/>
<field name="code"/>
<field name="city"/>
<field name="country_id"/>
</tree>
</field>
</field>
</field>
</record>
</data>
</openerp>
Loading…
Cancel
Save