Browse Source

Merge pull request #92 from savoirfairelinux/7.0-pep8

Fix added pep8 conventions
pull/102/head
Yannick Vaucher 10 years ago
parent
commit
ab258bdb07
  1. 31
      base_partner_merge/base_partner_merge.py
  2. 8
      firstname_display_name_trigger/res_partner.py
  3. 7
      partner_firstname/partner.py
  4. 23
      partner_relations/model/res_partner_relation.py

31
base_partner_merge/base_partner_merge.py

@ -123,8 +123,8 @@ class MergePartnerAutomatic(orm.TransientModel):
context = {} context = {}
res = super(MergePartnerAutomatic, self res = super(MergePartnerAutomatic, self
).default_get(cr, uid, fields, context) ).default_get(cr, uid, fields, context)
if (context.get('active_model') == 'res.partner'
and context.get('active_ids')):
if (context.get('active_model') == 'res.partner' and
context.get('active_ids')):
partner_ids = context['active_ids'] partner_ids = context['active_ids']
res['state'] = 'selection' res['state'] = 'selection'
res['partner_ids'] = partner_ids res['partner_ids'] = partner_ids
@ -212,8 +212,8 @@ class MergePartnerAutomatic(orm.TransientModel):
'%(column)s IN %%s') % query_dic '%(column)s IN %%s') % query_dic
cr.execute(query, (dst_partner.id, partner_ids,)) cr.execute(query, (dst_partner.id, partner_ids,))
if (column == proxy._parent_name
and table == 'res_partner'):
if (column == proxy._parent_name and
table == 'res_partner'):
query = """ query = """
WITH RECURSIVE cycle(id, parent_id) AS ( WITH RECURSIVE cycle(id, parent_id) AS (
SELECT id, parent_id FROM res_partner SELECT id, parent_id FROM res_partner
@ -316,8 +316,8 @@ class MergePartnerAutomatic(orm.TransientModel):
values = dict() values = dict()
for column, field in columns.iteritems(): for column, field in columns.iteritems():
if (field._type not in ('many2many', 'one2many')
and not isinstance(field, fields.function)):
if (field._type not in ('many2many', 'one2many') and
not isinstance(field, fields.function)):
for item in itertools.chain(src_partners, [dst_partner]): for item in itertools.chain(src_partners, [dst_partner]):
if item[column]: if item[column]:
values[column] = write_serializer(column, values[column] = write_serializer(column,
@ -381,12 +381,15 @@ class MergePartnerAutomatic(orm.TransientModel):
src_partners = ordered_partners[:-1] src_partners = ordered_partners[:-1]
_logger.info("dst_partner: %s", dst_partner.id) _logger.info("dst_partner: %s", dst_partner.id)
call_it = lambda function: function(cr, uid, src_partners,
dst_partner, context=context)
call_it(self._update_foreign_keys)
call_it(self._update_reference_fields)
call_it(self._update_values)
self._update_foreign_keys(
cr, uid, src_partners, dst_partner, context=context
)
self._update_reference_fields(
cr, uid, src_partners, dst_partner, context=context
)
self._update_values(
cr, uid, src_partners, dst_partner, context=context
)
_logger.info('(uid = %s) merged the partners %r with %s', _logger.info('(uid = %s) merged the partners %r with %s',
uid, uid,
@ -612,8 +615,8 @@ class MergePartnerAutomatic(orm.TransientModel):
models['res.users'] = 'partner_id' models['res.users'] = 'partner_id'
if (self._model_is_installed(cr, uid, 'account.move.line', if (self._model_is_installed(cr, uid, 'account.move.line',
context=context)
and this.exclude_journal_item):
context=context) and
this.exclude_journal_item):
models['account.move.line'] = 'partner_id' models['account.move.line'] = 'partner_id'
return models return models

8
firstname_display_name_trigger/res_partner.py

@ -62,14 +62,12 @@ class ResPartner(orm.Model):
) )
} }
# indirection to avoid passing a copy of the overridable method when
# declaring the function field
_display_name = lambda self, *a, **kw: self._display_name_compute(*a, **kw)
_columns = { _columns = {
# extra field to allow ORDER BY to match visible names # extra field to allow ORDER BY to match visible names
'display_name': fields.function( 'display_name': fields.function(
_display_name,
# indirection to avoid passing a copy of the overridable method
# when declaring the function field
lambda self, *a, **kw: self._display_name_compute(*a, **kw),
type='char', type='char',
string='Name', string='Name',
store=_display_name_store_triggers store=_display_name_store_triggers

7
partner_firstname/partner.py

@ -68,10 +68,9 @@ class ResPartner(orm.Model):
In addition an heuristic avoids to keep a firstname without a In addition an heuristic avoids to keep a firstname without a
non-blank lastname non-blank lastname
""" """
field_value = (field_value
and not field_value.isspace()
and field_value
or False)
field_value = (
field_value if field_value and not field_value.isspace() else False
)
vals = {'lastname': field_value, 'firstname': False} vals = {'lastname': field_value, 'firstname': False}
if field_value: if field_value:
flds = self.read( flds = self.read(

23
partner_relations/model/res_partner_relation.py

@ -44,8 +44,8 @@ class ResPartnerRelation(Model):
'''Determine wether functions are called in a situation where the '''Determine wether functions are called in a situation where the
active partner is the right partner. Default False! active partner is the right partner. Default False!
''' '''
if (context and 'active_ids' in context
and right_partner_id in context.get('active_ids', [])):
if (context and 'active_ids' in context and
right_partner_id in context.get('active_ids', [])):
return True return True
return False return False
@ -77,30 +77,31 @@ class ResPartnerRelation(Model):
self, cr, uid, ids, field_names, arg, context=None): self, cr, uid, ids, field_names, arg, context=None):
'''Return a dictionary of dictionaries, with for every partner for '''Return a dictionary of dictionaries, with for every partner for
ids, the computed values.''' ids, the computed values.'''
def get_values(this, dummy_field_names, dummy_arg, context=None):
def get_values(self, dummy_field_names, dummy_arg, context=None):
'''Get computed values for record''' '''Get computed values for record'''
values = {} values = {}
on_right_partner = self._on_right_partner( on_right_partner = self._on_right_partner(
cr, uid, this.right_partner_id.id, context=context)
cr, uid, self.right_partner_id.id, context=context)
# type_selection_id # type_selection_id
values['type_selection_id'] = ( values['type_selection_id'] = (
((this.type_id.id) * 10) + (on_right_partner and 1 or 0))
((self.type_id.id) * 10) + (on_right_partner and 1 or 0))
# partner_id_display # partner_id_display
values['partner_id_display'] = ( values['partner_id_display'] = (
on_right_partner and this.left_partner_id.id
or this.right_partner_id.id
self.left_partner_id.id
if on_right_partner
else self.right_partner_id.id
) )
# is_relation_expired # is_relation_expired
today = fields.date.context_today(self, cr, uid, context=context) today = fields.date.context_today(self, cr, uid, context=context)
values['is_relation_expired'] = ( values['is_relation_expired'] = (
this.date_end and (this.date_end < today))
self.date_end and (self.date_end < today))
# is_relation_future # is_relation_future
values['is_relation_future'] = this.date_start > today
values['is_relation_future'] = self.date_start > today
return values return values
return dict([ return dict([
(this.id, get_values(this, field_names, arg, context=context))
for this in self.browse(cr, uid, ids, context=context)
(i.id, get_values(i, field_names, arg, context=context))
for i in self.browse(cr, uid, ids, context=context)
]) ])
def write(self, cr, uid, ids, vals, context=None): def write(self, cr, uid, ids, vals, context=None):

Loading…
Cancel
Save