Browse Source

Fix pep8

pull/4/head
Sandy Carter 10 years ago
parent
commit
43f85b72d9
  1. 5
      account_partner_merge/partner_merge.py
  2. 1
      base_address_category/__openerp__.py
  3. 8
      base_address_category/base_address.py
  4. 4
      base_continent/__openerp__.py
  5. 29
      base_partner_merge/base_partner_merge.py
  6. 71
      base_partner_merge/validate_email.py
  7. 12
      firstname_display_name_trigger/__openerp__.py
  8. 1
      firstname_display_name_trigger/res_partner.py
  9. 2
      firstname_display_name_trigger/tests/__init__.py
  10. 20
      firstname_display_name_trigger/tests/test_display_name.py
  11. 26
      partner_address_ldap/__openerp__.py
  12. 72
      partner_address_ldap/address.py
  13. 19
      partner_address_ldap/company.py
  14. 7
      partner_address_ldap/partner.py
  15. 64
      partner_address_ldap/wizard/wiz_import_adresses.py
  16. 1
      partner_contact_address_detailed/__init__.py
  17. 5
      partner_contact_address_detailed/__openerp__.py
  18. 3
      partner_firstname/__openerp__.py
  19. 4
      partner_firstname/partner.py
  20. 4
      partner_firstname/res_user.py
  21. 2
      partner_firstname/tests/__init__.py
  22. 20
      partner_firstname/tests/test_partner_firstname.py
  23. 7
      portal_partner_merge/wizard/portal_wizard.py
  24. 17
      res_partner_affiliate/__openerp__.py
  25. 2
      res_partner_affiliate/res_partner.py

5
account_partner_merge/partner_merge.py

@ -18,9 +18,10 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp.osv import osv
from openerp.osv import orm
class MergePartnerAutomatic(osv.TransientModel):
class MergePartnerAutomatic(orm.TransientModel):
_inherit = 'base.partner.merge.automatic.wizard'
def _update_values(self, cr, uid, src_partners, dst_partner, context=None):

1
base_address_category/__openerp__.py

@ -48,6 +48,5 @@
"security/security.xml"
'security/ir.model.access.csv',
],
"active": False,
"installable": True
}

8
base_address_category/base_address.py

@ -23,7 +23,8 @@
##############################################################################
from openerp.osv import osv, fields, orm
from openerp.osv import fields, orm
class ResPartnerAdressCategory(orm.Model):
def name_get(self, cr, uid, ids, context=None):
@ -54,10 +55,8 @@ class ResPartnerAdressCategory(orm.Model):
level -= 1
return True
_description='Partner address Categories'
_name = 'res.partner.address.category'
_description = 'Partner address Categories'
_columns = {
'name': fields.char('Category Name', required=True, size=64),
'parent_id': fields.many2one('res.partner.address.category',
@ -92,4 +91,3 @@ class ResPartnerAddress(orm.Model):
'category_id',
'Address categories'),
}

4
base_continent/__openerp__.py

@ -36,7 +36,7 @@ adds continent field on partner form
'data': [
'base_continent_view.xml',
'base_continent_data.xml',
'security/ir.model.access.csv'],
'active': False,
'security/ir.model.access.csv',
],
'installable': True,
}

29
base_partner_merge/base_partner_merge.py

@ -1,4 +1,5 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from email.utils import parseaddr
import functools
@ -14,7 +15,7 @@ from openerp.tools import mute_logger
from .validate_email import validate_email
import openerp
from openerp.osv import osv, orm
from openerp.osv import orm
from openerp.osv import fields
from openerp.osv.orm import browse_record
from openerp.tools.translate import _
@ -55,7 +56,7 @@ def is_integer_list(ids):
return all(isinstance(i, (int, long)) for i in ids)
class ResPartner(osv.Model):
class ResPartner(orm.Model):
_inherit = 'res.partner'
_columns = {
@ -64,7 +65,7 @@ class ResPartner(osv.Model):
}
class MergePartnerLine(osv.TransientModel):
class MergePartnerLine(orm.TransientModel):
_name = 'base.partner.merge.line'
_columns = {
@ -77,7 +78,7 @@ class MergePartnerLine(osv.TransientModel):
_order = 'min_id asc'
class MergePartnerAutomatic(osv.TransientModel):
class MergePartnerAutomatic(orm.TransientModel):
"""
The idea behind this wizard is to create a list of potential partners to
merge. We use two objects, the first one is the wizard for the end-user.
@ -326,7 +327,7 @@ class MergePartnerAutomatic(osv.TransientModel):
if parent_id and parent_id != dst_partner.id:
try:
dst_partner.write({'parent_id': parent_id})
except (osv.except_osv, orm.except_orm):
except (orm.except_orm, orm.except_orm):
_logger.info('Skip recursive partner hierarchies for '
'parent_id %s of partner: %s',
parent_id, dst_partner.id)
@ -341,7 +342,7 @@ class MergePartnerAutomatic(osv.TransientModel):
return
if len(partner_ids) > 3:
raise osv.except_osv(
raise orm.except_orm(
_('Error'),
_("For safety reasons, you cannot merge more than 3 contacts "
"together. You can re-open the wizard several times if "
@ -351,7 +352,7 @@ class MergePartnerAutomatic(osv.TransientModel):
and len(set(partner.email for partner
in proxy.browse(cr, uid, partner_ids,
context=context))) > 1):
raise osv.except_osv(
raise orm.except_orm(
_('Error'),
_("All contacts must have the same email. Only the "
"Administrator can merge contacts with different emails."))
@ -378,7 +379,7 @@ class MergePartnerAutomatic(osv.TransientModel):
[partner.id for partner
in src_partners])],
context=context)):
raise osv.except_osv(
raise orm.except_orm(
_('Error'),
_("Only the destination contact may be linked to existing "
"Journal Items. Please ask the Administrator if you need to"
@ -399,8 +400,12 @@ class MergePartnerAutomatic(osv.TransientModel):
dst_partner.message_post(
body='%s %s' % (
_("Merged with the following partners:"),
", ".join('%s<%s>(ID %s)' % (p.name, p.email or 'n/a', p.id)
for p in src_partners)))
", ".join(
'%s<%s>(ID %s)' % (p.name, p.email or 'n/a', p.id)
for p in src_partners
)
)
)
for partner in src_partners:
partner.unlink()
@ -513,7 +518,7 @@ class MergePartnerAutomatic(osv.TransientModel):
]
if not groups:
raise osv.except_osv(_('Error'),
raise orm.except_orm(_('Error'),
_("You have to specify a filter for your "
"selection"))

71
base_partner_merge/validate_email.py

@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
# RFC 2822 - style email validation for Python
# (c) 2012 Syrus Akbary <me@syrusakbary.com>
# Extended from (c) 2011 Noel Bush <noel@aitools.org>
@ -19,14 +20,15 @@
import re
import smtplib
import socket
try:
import DNS
ServerError = DNS.ServerError
except:
DNS = None
class ServerError(Exception): pass
class ServerError(Exception):
pass
# All we are really doing is comparing the input string to one
# gigantic regular expression. But building that regexp, and
# ensuring its correctness, is made much easier by assembling it
@ -44,43 +46,30 @@ WSP = r'[ \t]' # see 2.2.2. Structured Hea
CRLF = r'(?:\r\n)' # see 2.2.3. Long Header Fields
NO_WS_CTL = r'\x01-\x08\x0b\x0c\x0f-\x1f\x7f' # see 3.2.1. Primitive Tokens
QUOTED_PAIR = r'(?:\\.)' # see 3.2.2. Quoted characters
FWS = r'(?:(?:' + WSP + r'*' + CRLF + r')?' + \
WSP + r'+)' # see 3.2.3. Folding white space and comments
CTEXT = r'[' + NO_WS_CTL + \
r'\x21-\x27\x2a-\x5b\x5d-\x7e]' # see 3.2.3
CCONTENT = r'(?:' + CTEXT + r'|' + \
QUOTED_PAIR + r')' # see 3.2.3 (NB: The RFC includes COMMENT here
# as well, but that would be circular.)
COMMENT = r'\((?:' + FWS + r'?' + CCONTENT + \
r')*' + FWS + r'?\)' # see 3.2.3
CFWS = r'(?:' + FWS + r'?' + COMMENT + ')*(?:' + \
FWS + '?' + COMMENT + '|' + FWS + ')' # see 3.2.3
FWS = r'(?:(?:{0}*{1})?{0}+)'.format(WSP, CRLF) # see 3.2.3. Folding white space and comments
CTEXT = r'[{0}\x21-\x27\x2a-\x5b\x5d-\x7e]'.format(NO_WS_CTL) # see 3.2.3
# see 3.2.3 (NB: The RFC includes COMMENT here as well, but that would be circular.)
CCONTENT = r'(?:{0}|{1})'.format(CTEXT, QUOTED_PAIR)
COMMENT = r'\((?:{0}?{1})*{0}?\)'.format(FWS, CCONTENT) # see 3.2.3
CFWS = r'(?:{0}?{1})*(?:{0}?{1}|{0})'.format(FWS, COMMENT) # see 3.2.3
ATEXT = r'[\w!#$%&\'\*\+\-/=\?\^`\{\|\}~]' # see 3.2.4. Atom
ATOM = CFWS + r'?' + ATEXT + r'+' + CFWS + r'?' # see 3.2.4
DOT_ATOM_TEXT = ATEXT + r'+(?:\.' + ATEXT + r'+)*' # see 3.2.4
DOT_ATOM = CFWS + r'?' + DOT_ATOM_TEXT + CFWS + r'?' # see 3.2.4
QTEXT = r'[' + NO_WS_CTL + \
r'\x21\x23-\x5b\x5d-\x7e]' # see 3.2.5. Quoted strings
QCONTENT = r'(?:' + QTEXT + r'|' + \
QUOTED_PAIR + r')' # see 3.2.5
QUOTED_STRING = CFWS + r'?' + r'"(?:' + FWS + \
r'?' + QCONTENT + r')*' + FWS + \
r'?' + r'"' + CFWS + r'?'
LOCAL_PART = r'(?:' + DOT_ATOM + r'|' + \
QUOTED_STRING + r')' # see 3.4.1. Addr-spec specification
DTEXT = r'[' + NO_WS_CTL + r'\x21-\x5a\x5e-\x7e]' # see 3.4.1
DCONTENT = r'(?:' + DTEXT + r'|' + \
QUOTED_PAIR + r')' # see 3.4.1
DOMAIN_LITERAL = CFWS + r'?' + r'\[' + \
r'(?:' + FWS + r'?' + DCONTENT + \
r')*' + FWS + r'?\]' + CFWS + r'?' # see 3.4.1
DOMAIN = r'(?:' + DOT_ATOM + r'|' + \
DOMAIN_LITERAL + r')' # see 3.4.1
ADDR_SPEC = LOCAL_PART + r'@' + DOMAIN # see 3.4.1
ATOM = r'{0}?{1}+{0}?'.format(CFWS, ATEXT) # see 3.2.4
DOT_ATOM_TEXT = r'{0}+(?:\.{0}+)*'.format(ATEXT) # see 3.2.4
DOT_ATOM = r'{0}?{1}{0}?'.format(CFWS, DOT_ATOM_TEXT) # see 3.2.4
QTEXT = r'[{0}\x21\x23-\x5b\x5d-\x7e]'.format(NO_WS_CTL) # see 3.2.5. Quoted strings
QCONTENT = r'(?:{0}|{1})'.format(QTEXT, QUOTED_PAIR) # see 3.2.5
QUOTED_STRING = r'{0}?"(?:{1}?{2})*{1}?"{0}?'.format(CFWS, FWS, QCONTENT)
LOCAL_PART = r'(?:{0}|{1})'.format(DOT_ATOM, QUOTED_STRING) # see 3.4.1. Addr-spec specification
DTEXT = r'[{0}\x21-\x5a\x5e-\x7e]'.format(NO_WS_CTL) # see 3.4.1
DCONTENT = r'(?:{0}|{1})'.format(DTEXT, QUOTED_PAIR) # see 3.4.1
DOMAIN_LITERAL = r'{0}?\[(?:{1}?{2})*{1}?\]{0}?'.format(CFWS, FWS, DCONTENT) # see 3.4.1
DOMAIN = r'(?:{0}|{1})'.format(DOT_ATOM, DOMAIN_LITERAL) # see 3.4.1
ADDR_SPEC = r'{0}@{1}'.format(LOCAL_PART, DOMAIN) # see 3.4.1
# A valid address will match exactly the 3.4.1 addr-spec.
VALID_ADDRESS_REGEXP = '^' + ADDR_SPEC + '$'
def validate_email(email, check_mx=False, verify=False):
"""Indicate whether the given string is a valid email address
@ -94,7 +83,10 @@ def validate_email(email, check_mx=False,verify=False):
assert re.match(VALID_ADDRESS_REGEXP, email) is not None
check_mx |= verify
if check_mx:
if not DNS: raise Exception('For check the mx records or check if the email exists you must have installed pyDNS python package')
if not DNS:
raise Exception('For check the mx records or check if the '
'email exists you must have installed pyDNS '
'python package')
DNS.DiscoverNameServers()
hostname = email[email.find('@') + 1:]
mx_hosts = DNS.mxlookup(hostname)
@ -102,12 +94,15 @@ def validate_email(email, check_mx=False,verify=False):
try:
smtp = smtplib.SMTP()
smtp.connect(mx[1])
if not verify: return True
if not verify:
return True
status, _ = smtp.helo()
if status != 250: continue
if status != 250:
continue
smtp.mail('')
status, _ = smtp.rcpt(email)
if status != 250: return False
if status != 250:
return False
break
except smtplib.SMTPServerDisconnected: # Server not permits verify user
break

12
firstname_display_name_trigger/__openerp__.py

@ -18,12 +18,14 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
{'name': 'Link module if partner_lastname and account_report_company are installed',
{
'name': 'Link module if partner_lastname and account_report_company are installed',
'version': '1.0',
'author': 'Camptocamp',
'maintainer': 'Camptocamp',
'category': 'Hidden',
'complexity': 'normal', # easy, normal, expert
'license': 'AGPL-3',
'depends': [
'account_report_company',
'partner_firstname',
@ -34,8 +36,6 @@ Adapt the computation of display name so that it gets visible in tree and kanban
'website': 'http://www.camptocamp.com',
'data': [],
'installable': True,
'images': [],
'auto_install': True,
'license': 'AGPL-3',
'application': False}
'application': False,
}

1
firstname_display_name_trigger/res_partner.py

@ -50,7 +50,6 @@ class ResPartner(orm.Model):
res.append((record.id, name))
return res
_display_name_store_triggers = {
'res.partner': (lambda self, cr, uid, ids, context=None: self.search(cr, uid, [('id', 'child_of', ids)]),
['parent_id', 'is_company', 'name', 'firstname', 'lastname'], 10)

2
firstname_display_name_trigger/tests/__init__.py

@ -1,3 +1,5 @@
# -*- coding: utf-8 -*-
import test_display_name
checks = [

20
firstname_display_name_trigger/tests/test_display_name.py

@ -1,31 +1,39 @@
# -*- coding: utf-8 -*-
import unittest2
import openerp.tests.common as common
class test_display_name(common.TransactionCase):
def setUp(self):
super(test_display_name, self).setUp()
cr, uid = self.cr, self.uid
self.res_partner = self.registry('res.partner')
def test_00_create_res_partner(self):
""" Test if the display name has been correctly set """
cr, uid = self.cr, self.uid
partner_id = self.res_partner.create(cr, uid, {'lastname': 'Lastname', 'firstname': 'Firstname', 'is_company': True})
partner_id = self.res_partner.create(cr, uid, {
'lastname': 'Lastname',
'firstname': 'Firstname',
'is_company': True,
})
partner_records = self.res_partner.browse(cr, uid, [partner_id])
p1 = partner_records[0]
self.assertEqual(p1.display_name, 'Lastname Firstname', 'Partner display_name incorect')
self.assertEqual(p1.display_name, 'Lastname Firstname', 'Partner display_name incorrect')
def test_01_res_partner_write_lastname(self):
""" Test if the display name has been correctly set """
cr, uid = self.cr, self.uid
partner_id = self.res_partner.create(cr, uid, {'lastname': 'Lastname', 'firstname': 'Firstname', 'is_company': True})
partner_id = self.res_partner.create(cr, uid, {
'lastname': 'Lastname',
'firstname': 'Firstname',
'is_company': True
})
partner_records = self.res_partner.browse(cr, uid, [partner_id])
p1 = partner_records[0]
self.res_partner.write(cr, uid, partner_id, {'lastname': 'Last'})
self.assertEqual(p1.display_name, 'Last Firstname', 'Partner display_name incorect')
self.assertEqual(p1.display_name, 'Last Firstname', 'Partner display_name incorrect')
if __name__ == '__main__':
unittest2.main()

26
partner_address_ldap/__openerp__.py

@ -41,28 +41,32 @@
"description": """
Live partner address synchronization through a LDAP module (inetOrgPerson).
OpenERP becomes the master of the LDAP. Each time an address is deleted, created or updated the same is done in the ldap (a new record is pushed).
The LDAP configuration is done in the company view. There can be one different LDAP per company. Do not forget to activate
OpenERP becomes the master of the LDAP. Each time an address is deleted,
created or updated the same is done in the ldap (a new record is pushed).
The LDAP configuration is done in the company view. There can be one different
LDAP per company. Do not forget to activate
the LDAP link in the configuration.
The used LDAP depends on the current user company.
This module does not allows bulk batching synchronisation into the LDAP and is thus not suitable for an instant use with an existing LDAP.
In order to use it with an existing LDAP you have to alter the uid of contact in your LDAP. The uid should be terp_ plus the OpenERP
This module does not allows bulk batching synchronisation into the LDAP and is
thus not suitable for an instant use with an existing LDAP.
In order to use it with an existing LDAP you have to alter the uid of contact
in your LDAP. The uid should be terp_ plus the OpenERP
contact id (for example terp_10).
N.B:
The module requires the python-ldap library
Unicode support --> As python ldap does not support unicode we try to decode string if it fails we transliterate values.
Unicode support --> As python ldap does not support unicode we try to decode
string if it fails we transliterate values.
Active Directory Support for Windows server 2003, try 2008 at your own risk
(AD support not tested for Version 6 of OpenERP looking for active dir test infra)
""",
"init_xml" : ["security/security.xml"],
"update_xml":['company_view.xml',
"data": [
"security/security.xml"
'company_view.xml',
'address_view.xml',
"wizard.xml"],
"demo_xml" : [],
"active": False,
"wizard.xml",
],
"installable": False
}

72
partner_address_ldap/address.py

@ -9,10 +9,10 @@
# Contribution : 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
# programmers who take the whole responsibility 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
# guarantees and support are strongly advised to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
@ -30,22 +30,24 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
#TODO FInd why company parameter are cached
# TODO Find why company parameter are cached
import re
import unicodedata
import netsvc
from openerp import netsvc
try:
import ldap
import ldap.modlist
except:
print 'python ldap not installed please install it in order to use this module'
print('python ldap not installed please install it in order to use this module')
from osv import osv, fields
from tools.translate import _
from openerp.osv import orm, fields
from openerp.tools.translate import _
logger = netsvc.Logger()
class LdapConnMApper(object):
"""LdapConnMApper: push specific fields from the Terp Partner_contacts to the
LDAP schema inetOrgPerson. Ldap bind options are stored in company.r"""
@ -79,7 +81,7 @@ class LdapConnMApper(object):
if company.ldap_active:
for param in mand:
if not param:
raise osv.except_osv(_('Warning !'),
raise orm.except_orm(_('Warning !'),
_('An LDAP parameter is missing for company %s') % (company.name, ))
def get_connexion(self):
@ -94,7 +96,7 @@ class LdapConnMApper(object):
return self.connexion
class LDAPAddress(osv.osv):
class LDAPAddress(orm.Model):
"""Override the CRUD of the objet in order to dynamically bind to ldap"""
_inherit = 'res.partner.address'
ldapMapper = None
@ -108,7 +110,7 @@ class LDAPAddress(osv.osv):
'column name to lastname ;'))
cr.execute('ALTER TABLE res_partner_address RENAME column name to lastname ;')
except Exception, e:
except Exception:
cr.rollback()
logger.notifyChannel(_('LDAP address init'),
netsvc.LOG_INFO,
@ -129,7 +131,7 @@ class LDAPAddress(osv.osv):
reads = self.read(cursor, uid, ids, ['lastname', 'firstname'])
res = []
for record in reads:
## We want to have " firstname" or ""
# We want to have " firstname" or ""
name = self._compute_name(record['firstname'], record['lastname'])
res.append((record['id'], name))
return dict(res)
@ -160,7 +162,6 @@ class LDAPAddress(osv.osv):
# res.append(add.id)
# return self.name_get(cursor, user, res, context)
_columns = {
'firstname': fields.char('First name', size=256),
'lastname': fields.char('Last name', size=256),
@ -189,7 +190,7 @@ class LDAPAddress(osv.osv):
ids = [ids]
if ids:
self.validate_entries(vals, cursor, uid, ids)
if context.has_key('init_mode') and context['init_mode'] :
if context.get('init_mode'):
success = True
else:
success = super(LDAPAddress, self).write(cursor, uid, ids,
@ -200,7 +201,8 @@ class LDAPAddress(osv.osv):
return success
def unlink(self, cursor, uid, ids, context=None):
if not context: context = {}
if context is None:
context = {}
if ids:
self.getconn(cursor, uid, {})
if not isinstance(ids, list):
@ -230,12 +232,11 @@ class LDAPAddress(osv.osv):
phone = vals.get('phone', False)
fax = vals.get('fax', False)
mobile = vals.get('mobile', False)
lastname = vals.get('lastname', False)
private_phone = vals.get('private_phone', False)
if email:
if re.match("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$",
email) is None:
raise osv.except_osv(_('Warning !'),
raise orm.except_orm(_('Warning !'),
_('Please enter a valid e-mail'))
phones = (('phone', phone), ('fax', fax), ('mobile', mobile),
('private_phone', private_phone))
@ -243,15 +244,16 @@ class LDAPAddress(osv.osv):
phone_number = phone_tuple[1]
if phone_number:
if not phone_number.startswith('+'):
raise osv.except_osv(_('Warning !'),
raise orm.except_orm(_('Warning !'),
_('Please enter a valid phone number in %s'
' international format (i.e. leading +)') % phone_tuple[0])
def getVals(self, att_name, key, vals, dico, uid, ids, cursor, context=None):
"""map to values to dict"""
if not context: context = {}
## We explicitely test False value
if vals.get(key, False) != False:
if not context:
context = {}
# We explicitly test False value
if vals.get(key, False) is not False:
dico[att_name] = vals[key]
else:
if context.get('init_mode'):
@ -260,18 +262,18 @@ class LDAPAddress(osv.osv):
if tmp.get(key, False):
dico[att_name] = tmp[key]
def _un_unicodize_buf(self, in_buf):
if isinstance(in_buf, unicode):
try:
return in_buf.encode()
except Exception, e:
except Exception:
return unicodedata.normalize("NFKD", in_buf).encode('ascii', 'ignore')
return in_buf
def unUnicodize(self, indict):
"""remove unicode data of modlist as unicode is not supported
by python-ldap librairy till version 2.7"""
by python-ldap library till version 2.7
"""
for key in indict:
if not isinstance(indict[key], list):
indict[key] = self._un_unicodize_buf(indict[key])
@ -282,7 +284,6 @@ class LDAPAddress(osv.osv):
indict[key] = nonutfArray
def addNeededFields(self, id, vals, cursor, uid):
keys = vals.keys()
previousvalue = self.browse(cursor, uid, [id])[0]
if not vals.get('partner_id'):
vals['partner_id'] = previousvalue.partner_id.id
@ -296,7 +297,6 @@ class LDAPAddress(osv.osv):
"""Mapp ResPArtner adress to moddlist"""
self.addNeededFields(id, vals, cursor, uid)
conn = self.getconn(cursor, uid, {})
keys = vals.keys()
partner_obj = self.pool.get('res.partner')
part_name = partner_obj.browse(cursor, uid, vals['partner_id']).name
vals['partner'] = part_name
@ -326,7 +326,7 @@ class LDAPAddress(osv.osv):
contact_obj['objectclass'] = ['top', 'person', 'organizationalPerson', 'inetOrgPerson', 'user']
# we handle the country
if vals.get('country_id'):
country = self.browse(cursor, uid, id).country_id
country = self.browse(cursor, uid, id, context=context).country_id
if country:
vals['country_id'] = country.name
vals['c'] = country.code
@ -348,7 +348,7 @@ class LDAPAddress(osv.osv):
self.getVals('company', 'partner', vals, contact_obj, uid, id, cursor, context)
self.getVals('info', 'comment', vals, contact_obj, uid, id, cursor, context)
self.getVals('displayName', 'partner', vals, contact_obj, uid, id, cursor, context)
## Web site management
# Web site management
if self.browse(cursor, uid, id).partner_id.website:
vals['website'] = self.browse(cursor, uid, id).partner_id.website
self.getVals('wWWHomePage', 'website', vals, contact_obj, uid, id, cursor, context)
@ -381,8 +381,8 @@ class LDAPAddress(osv.osv):
else:
conn.connexion.add_s("uid=terp_%s,OU=%s,%s" % (str(id), conn.OU, conn.CONTACT_DN),
ldap.modlist.addModlist(contact_obj))
except Exception, e:
raise e
except Exception:
raise
conn.connexion.unbind_s()
def updateLdapContact(self, id, vals, cursor, uid, context):
@ -407,8 +407,8 @@ class LDAPAddress(osv.osv):
try:
conn.connexion.modify_s(old_contatc_obj[0], modlist)
conn.connexion.unbind_s()
except Exception, e:
raise e
except Exception:
raise
def removeLdapContact(self, id, cursor, uid):
"""Remove a contact from ldap"""
@ -419,14 +419,14 @@ class LDAPAddress(osv.osv):
except ldap.NO_SUCH_OBJECT:
logger.notifyChannel("Warning", netsvc.LOG_INFO,
_("'no object to delete in ldap' %s") % (id))
except Exception, e :
raise e
except Exception:
raise
try:
if to_delete:
conn.connexion.delete_s(to_delete[0])
conn.connexion.unbind_s()
except Exception, e:
raise e
except Exception:
raise
def getLdapContact(self, conn, id):
result = conn.connexion.search_ext_s("ou=%s, %s" % (conn.OU, conn.CONTACT_DN),
@ -455,5 +455,3 @@ class LDAPAddress(osv.osv):
self.getconn(cursor, uid, context)
self.ldapMapper.get_connexion()
return self.ldapMapper
LDAPAddress()

19
partner_address_ldap/company.py

@ -31,35 +31,36 @@
#
##############################################################################
from osv import osv, fields
from openerp.osv import orm, fields
class Res_company(osv.osv):
"""Defin ldap connexion parameters"""
class Res_company(orm.Model):
"""Define ldap connexion parameters"""
_inherit = 'res.company'
_columns = {
'base_dn': fields.char(
'User dn',
size=128,
help="Exemple: cn=contacts_admin,dc=ldap,dc=dcc2c"
help="Example: cn=contacts_admin,dc=ldap,dc=dcc2c"
),
'contact_dn': fields.char(
'Bind dn',
size=128,
help="Exemple: dc=ldap,dc=dcc2c -- watchout" +\
help="Example: dc=ldap,dc=dcc2c -- watch out "
"the OU will be automatically included inside"
),
'ounit': fields.char(
'Contact Organizational unit of the contacts',
size=128,
help="Exemple: Contacts"
help="Example: Contacts"
),
'ldap_server': fields.char(
'Server address',
size=128,
help="Exemple: ldap.camptocamp.com"
help="Example: ldap.camptocamp.com"
),
'passwd': fields.char('ldap password', size=128, help="Exemple: Mypassword1234"),
'passwd': fields.char('ldap password', size=128, help="Example: Mypassword1234"),
'ldap_active': fields.boolean(
'Activate ldap link for this company',
help='If not check nothing will be reported into the ldap'
@ -72,5 +73,3 @@ class Res_company(osv.osv):
help="If not specified, the default port"
"(389), will be used")
}
Res_company()

7
partner_address_ldap/partner.py

@ -31,9 +31,10 @@
#
##############################################################################
from osv import osv, fields
from openerp.osv import orm
class LdapPartner(osv.osv):
class LdapPartner(orm.Model):
"""Ensure that when deleting a partner unlink function is called on all
related addresses"""
_inherit = 'res.partner'
@ -46,5 +47,3 @@ class LdapPartner(osv.osv):
addr_ids = addr_obj.search(cursor, uid, [('partner_id', 'in', ids)])
addr_obj.unlink(cursor, uid, addr_ids, context=context)
return super(LdapPartner, self).unlink(cursor, uid, ids, context=context)
LdapPartner()

64
partner_address_ldap/wizard/wiz_import_adresses.py

@ -35,14 +35,15 @@
# Copyright (c) 2009 CamptoCamp. All rights reserved.
#
import wizard
import pooler
import base64
import unicodedata
import netsvc
import re
import wizard
from openerp import pooler
from openerp import netsvc
_FORM = '''<?xml version="1.0"?>
<form string="Export adresses to ldap">
<form string="Export addresses to ldap">
</form>'''
@ -61,12 +62,13 @@ _FIELDS = {
},
}
### As this is a bulck batch wizzard the performance process was not reallay taken in account ###
##The ideal way of doing would be to modify the connexion settings in order to have a connexion singelton
## in the file partner.py it will avoid connexion renegotiation for each partner.
def _action_import_adresses(self, cr, uid, data, context):
""" This function create or update each adresses present in the database.
It will also genreate an error report"""
# As this is a bulk batch wizard the performance process was not really taken in account ###
# The ideal way of doing would be to modify the connexion settings in order to have a connexion singleton
# in the file partner.py it will avoid connexion renegotiation for each partner.
def _action_import_addresses(self, cr, uid, data, context):
""" This function create or update each addresses present in the database.
It will also generate an error report"""
logger = netsvc.Logger()
error_report = [u'Error report']
add_obj = pooler.get_pool(cr.dbname).get('res.partner.address')
@ -74,24 +76,25 @@ def _action_import_adresses(self, cr, uid, data, context):
addresses = add_obj.browse(cr, uid, add_ids)
phone_fields = ['phone', 'fax', 'mobile', 'private_phone']
for add in addresses:
vals = {}
vals['partner_id'] = add.partner_id.id
vals['email'] = add.email
vals['phone'] = add.phone
vals['fax'] = add.fax
vals['mobile'] = add.mobile
vals['firstname'] = add.firstname
vals['lastname'] = add.lastname
vals['private_phone'] = add.private_phone
vals['street'] = add.street
vals['street2'] = add.street2
vals['city'] = add.city
vals = {
'partner_id': add.partner_id.id,
'email': add.email,
'phone': add.phone,
'fax': add.fax,
'mobile': add.mobile,
'firstname': add.firstname,
'lastname': add.lastname,
'private_phone': add.private_phone,
'street': add.street,
'street2': add.street2,
'city': add.city,
}
# Validating the mail
if add.email:
if re.match(
"^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$", add.email) is None or\
re.search(u"[éèàêöüäï&]", add.email) is not None:
msg=u'Addresse %s for partner %s has email that is invalid %s'%(
msg = u'Address %s for partner %s has email that is invalid %s' % (
unicode(vals['firstname']) + ' ' + unicode(vals['lastname']),
add.partner_id.name,
unicode(add.email)
@ -101,8 +104,8 @@ def _action_import_adresses(self, cr, uid, data, context):
vals['email'] = False
# Validating the Phone
for key in phone_fields:
if not unicode(vals[key]).startswith('+') or unicode(vals[key]).find("\n") != -1\
or re.search(u"[éèàêöüä#&]", unicode(vals[key])) is not None:
if (not unicode(vals[key]).startswith('+') or unicode(vals[key]).find("\n") != -1
or re.search(u"[éèàêöüä#&]", unicode(vals[key])) is not None):
vals[key] = False
msg = u'Addresse %s for partner %s has %s that is invalid ' % (
unicode(vals['firstname']) + ' ' + unicode(vals['lastname']),
@ -113,10 +116,8 @@ def _action_import_adresses(self, cr, uid, data, context):
error_report.append(msg)
# Validating the CN
if not add.lastname and add.firstname:
msg = u'!!! Addresse %s for partner %s has no last name and first name that is valid partner name was used'%(
unicode(add.id),
add.partner_id.name,
)
msg = (u'!!! Address %s for partner %s has no last name and first name that is valid partner name was used'
% (unicode(add.id), add.partner_id.name))
logger.notifyChannel('ldap export', netsvc.LOG_INFO, msg)
error_report.append(msg)
# We save to LDAP
@ -127,11 +128,12 @@ def _action_import_adresses(self, cr, uid, data, context):
logger.notifyChannel("MY TOPIC", netsvc.LOG_ERROR, error_report)
try:
data = base64.encodestring(error_report.encode())
except Exception, e:
except:
data = base64.encodestring("Could not generate report file. Please look in the log for details")
return {'errors': data}
class Wiz_import_addresses(wizard.interface):
states = {
'init': {
@ -147,7 +149,7 @@ class Wiz_import_addresses(wizard.interface):
}
},
'importadd': {
'actions': [_action_import_adresses],
'actions': [_action_import_addresses],
'result': {
'state': [('end', 'OK', 'gtk-ok', True)],
'arch': _FORM1,

1
partner_contact_address_detailed/__init__.py

@ -17,4 +17,3 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

5
partner_contact_address_detailed/__openerp__.py

@ -18,7 +18,8 @@
#
##############################################################################
{'name': 'All address data in summarized contact form',
{
'name': 'All address data in summarized contact form',
'description': """Show all informations of partner address
in summarized partner contact form when creating a new partner""",
'version': '1.0',
@ -31,5 +32,5 @@ in summarized partner contact form when creating a new partner""",
'test': [],
'auto_install': False,
'installable': True,
'images': []
'images': [],
}

3
partner_firstname/__openerp__.py

@ -18,7 +18,8 @@
#
##############################################################################
{'name': 'Partner first name, last name',
{
'name': 'Partner first name, last name',
'description': """
This module splits first name and last name for non company partners
====================================================================

4
partner_firstname/partner.py

@ -83,7 +83,9 @@ class ResPartner(Model):
default = default or {}
if not default.get('lastname'):
default = default.copy()
default['lastname'] = _('%s (copy)') % self.read(cr, uid, [_id], ['lastname'], context=context)[0]['lastname']
default['lastname'] = (
_('%s (copy)') % self.read(cr, uid, [_id], ['lastname'], context=context)[0]['lastname']
)
if default.get('name'):
del(default['name'])
return super(ResPartner, self).copy_data(cr, uid, _id, default, context=context)

4
partner_firstname/res_user.py

@ -32,7 +32,9 @@ class ResUsers(orm.Model):
default = default or {}
if not default.get('lastname'):
default = default.copy()
default['lastname'] = _('%s (copy)') % self.read(cr, uid, [_id], ['lastname'], context=context)[0]['lastname']
default['lastname'] = (
_('%s (copy)') % self.read(cr, uid, [_id], ['lastname'], context=context)[0]['lastname']
)
if default.get('name'):
del(default['name'])
return super(ResUsers, self).copy_data(cr, uid, _id, default, context=context)

2
partner_firstname/tests/__init__.py

@ -33,5 +33,3 @@ import test_partner_firstname
checks = [
test_partner_firstname
]
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

20
partner_firstname/tests/test_partner_firstname.py

@ -53,8 +53,16 @@ class test_partner_firstname(common.TransactionCase):
res_id = self.partner_model.copy(cr, uid, res_id, default={}, context=context)
vals = self.partner_model.read(cr, uid, [res_id], ['name', 'lastname', 'firstname'], context=context)[0]
self.assertEqual(vals['name'], _('%s (copy)') % 'lastname' + " firstname", 'Copy of the partner failed with wrong name')
self.assertEqual(vals['lastname'], _('%s (copy)') % 'lastname', 'Copy of the partner failed with wrong lastname')
self.assertEqual(
vals['name'],
_('%s (copy)') % 'lastname' + " firstname",
'Copy of the partner failed with wrong name'
)
self.assertEqual(
vals['lastname'],
_('%s (copy)') % 'lastname',
'Copy of the partner failed with wrong lastname'
)
self.assertEqual(vals['firstname'], 'firstname', 'Copy of the partner failed with wrong firstname')
def test_copy_user(self):
@ -68,7 +76,11 @@ class test_partner_firstname(common.TransactionCase):
res_id = self.user_model.copy(cr, uid, res_id, default={}, context=context)
vals = self.user_model.read(cr, uid, [res_id], ['name', 'lastname', 'firstname'], context=context)[0]
self.assertEqual(vals['name'], _('%s (copy)') % 'lastname' + ' firstname', 'Copy of the user failed with wrong name')
self.assertEqual(
vals['name'],
_('%s (copy)') % 'lastname' + ' firstname',
'Copy of the user failed with wrong name'
)
self.assertEqual(vals['lastname'], _('%s (copy)') % 'lastname', 'Copy of the user failed with wrong lastname')
self.assertEqual(vals['firstname'], 'firstname', 'Copy of the user failed with wrong firstname')
@ -99,5 +111,3 @@ class test_partner_firstname(common.TransactionCase):
self.assertEqual(vals['name'], 'lastname other', 'Update of the user firstname failed with wrong name')
self.assertEqual(vals['lastname'], 'lastname other', 'Update of the user firstname failed with wrong lastname')
self.assertFalse(vals['firstname'], 'Update of the user firstname failed with wrong firstname')
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

7
portal_partner_merge/wizard/portal_wizard.py

@ -19,10 +19,11 @@
#
##############################################################################
from openerp.osv import osv
from openerp.osv import orm
from openerp.tools.translate import _
class wizard_user(osv.TransientModel):
class wizard_user(orm.TransientModel):
_inherit = 'portal.wizard.user'
def get_error_messages(self, cr, uid, ids, context=None):
@ -35,5 +36,3 @@ class wizard_user(osv.TransientModel):
"Merge wizard, available in the More menu after selecting "
"several contacts in the Customers list"))
return error_msg
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

17
res_partner_affiliate/__openerp__.py

@ -18,25 +18,22 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
{'name': 'Partner Affilates',
{
'name': 'Partner Affiliates',
'version': '1.0',
'author': 'Camptocamp',
'maintainer': 'Camptocamp',
'category': 'CRM',
'complexity': 'normal', # easy, normal, expert
'license': 'AGPL-3',
'depends': ['base'],
'description': """Allows to use parent_id in company partner to refer to a parent company
Plus will show a tab in parent company of affiliated companies""",
'website': 'http://www.camptocamp.com',
'init_xml': [],
'update_xml': [
'data': [
'res_partner_view.xml',
],
'demo_xml': [],
'tests': [],
'demo': [],
'installable': True,
'images': [],
'auto_install': False,
'license': 'AGPL-3',
'application': True}
'application': True
}

2
res_partner_affiliate/res_partner.py

@ -18,8 +18,10 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp.osv import orm, fields
class ResPartner(orm.Model):
"""
Add relation affiliate_ids

Loading…
Cancel
Save