[FIX] crm: simplify + fix multiple programming errors in partner merge wizard
bzr revid: odo@openerp.com-20130508162742-qxdrjg93r6md1tw5
This commit is contained in:
parent
cffffc9cd6
commit
4229cff81c
|
@ -108,16 +108,20 @@ class MergePartnerAutomatic(osv.TransientModel):
|
|||
'maximum_group': fields.integer("Maximum of Group of Contacts"),
|
||||
}
|
||||
|
||||
_defaults = {
|
||||
'state': 'option',
|
||||
}
|
||||
def default_get(self, cr, uid, fields, context=None):
|
||||
if context is None:
|
||||
context = {}
|
||||
res = super(MergePartnerAutomatic, self).default_get(cr, uid, fields, context)
|
||||
if context.get('active_model') == 'res.partner' and context.get('active_ids'):
|
||||
partner_ids = context['active_ids']
|
||||
res['state'] = 'selection'
|
||||
res['partner_ids'] = partner_ids
|
||||
res['dst_partner_id'] = self._get_ordered_partner(cr, uid, partner_ids, context=context)[-1].id
|
||||
return res
|
||||
|
||||
def onchange_partner_ids(self, cr, uid, ids, partner_ids=[], context=None):
|
||||
if partner_ids and isinstance(partner_ids[0], (list, tuple)):
|
||||
partner_ids = partner_ids[0][2]
|
||||
else:
|
||||
partner_ids = []
|
||||
return {'domain': {'dst_partner_id': [('id', 'in', partner_ids)]}}
|
||||
_defaults = {
|
||||
'state': 'option'
|
||||
}
|
||||
|
||||
def get_fk_on(self, cr, table):
|
||||
q = """ SELECT cl1.relname as table,
|
||||
|
@ -262,7 +266,6 @@ class MergePartnerAutomatic(osv.TransientModel):
|
|||
if field._type not in ('many2many', 'one2many', 'function'):
|
||||
for item in itertools.chain(src_partners, [dst_partner]):
|
||||
if item[column]:
|
||||
print column, item[column]
|
||||
values[column] = write_serializer(column, item[column])
|
||||
|
||||
values.pop('id', None)
|
||||
|
@ -275,19 +278,15 @@ class MergePartnerAutomatic(osv.TransientModel):
|
|||
_logger.info('Skip recursive partner hierarchies for parent_id %s of partner: %s', parent_id, dst_partner.id)
|
||||
|
||||
@mute_logger('openerp.osv.expression', 'openerp.osv.orm')
|
||||
def _merge(self, cr, uid, partner_ids, dst_partner_id=None, context=None):
|
||||
def _merge(self, cr, uid, partner_ids, dst_partner=None, context=None):
|
||||
proxy = self.pool.get('res.partner')
|
||||
|
||||
partner_ids = proxy.exists(cr, uid, list(partner_ids), context=context)
|
||||
if len(partner_ids) < 2:
|
||||
return
|
||||
|
||||
if dst_partner_id and dst_partner_id in partner_ids:
|
||||
partner_obj = self.pool.get('res.partner')
|
||||
def f(x):
|
||||
return x != dst_partner_id
|
||||
src_partners = partner_obj.browse(cr, uid, list(filter(f, partner_ids)), context=context)
|
||||
dst_partner = partner_obj.browse(cr, uid, list(partner_ids), context=context)
|
||||
if dst_partner and dst_partner.id in partner_ids:
|
||||
src_partners = proxy.browse(cr, uid, [id for id in partner_ids if id != dst_partner.id], context=context)
|
||||
else:
|
||||
ordered_partners = self._get_ordered_partner(cr, uid, partner_ids, context)
|
||||
dst_partner = ordered_partners[-1]
|
||||
|
@ -707,52 +706,11 @@ class MergePartnerAutomatic(osv.TransientModel):
|
|||
|
||||
self._merge(cr, uid, partner_ids, this.dst_partner_id, context=context)
|
||||
|
||||
this.current_line_id.unlink()
|
||||
if this.current_line_id:
|
||||
this.current_line_id.unlink()
|
||||
|
||||
return self._next_screen(cr, uid, this, context)
|
||||
|
||||
def merge_multi(self, cr, uid, ids, context=None):
|
||||
|
||||
active_model = context.get('active_model')
|
||||
if active_model != 'res.partner':
|
||||
raise osv.except_osv(
|
||||
_('Error'),
|
||||
_('This wizard can only used with the Partners')
|
||||
)
|
||||
|
||||
partner_ids = context.get('active_ids', [])
|
||||
|
||||
MINIMAL_NUMBER = 2
|
||||
if len(partner_ids) < MINIMAL_NUMBER:
|
||||
raise osv.except_osv(
|
||||
_('Error'),
|
||||
_("You can't use this wizard with only one Partner")
|
||||
)
|
||||
|
||||
ordered_partner = self._get_ordered_partner(cr, uid, partner_ids, context)
|
||||
def f(x): return x.id
|
||||
|
||||
current_line_id = self.pool.get('base.partner.merge.line').create(cr, uid, {'min_id': ordered_partner[-1].id, 'aggr_ids': map(f, ordered_partner)})
|
||||
context.update({
|
||||
'default_state': 'selection',
|
||||
'default_partner_ids': [(6, 0, partner_ids)],
|
||||
'default_dst_partner_id': ordered_partner[-1].id,
|
||||
'default_current_line_id': current_line_id,
|
||||
'default_number_group': 1,
|
||||
'default_maximum_group': 1,
|
||||
})
|
||||
|
||||
action = {
|
||||
'view_type': 'form',
|
||||
'view_mode': 'form',
|
||||
'res_model': self._name,
|
||||
'res_id': False,
|
||||
'type': 'ir.actions.act_window',
|
||||
'target': 'new',
|
||||
'context': context
|
||||
}
|
||||
return action
|
||||
|
||||
def auto_set_parent_id(self, cr, uid, ids, context=None):
|
||||
assert is_integer_list(ids)
|
||||
|
||||
|
|
|
@ -68,9 +68,9 @@
|
|||
OpenERP will propose you to merge only those having
|
||||
all these fields in common. (not one of the fields).
|
||||
</p>
|
||||
<group attrs="{'invisible': [('state', 'not in', ('selection', 'finished'))]}">
|
||||
<group attrs="{'invisible': ['|', ('state', 'not in', ('selection', 'finished')), ('number_group', '=', 0)]}">
|
||||
<field name="state" invisible="1" />
|
||||
<field name="number_group" invisible="0" />
|
||||
<field name="number_group"/>
|
||||
</group>
|
||||
<group string="Search duplicates based on duplicated data in"
|
||||
attrs="{'invisible': [('state', 'not in', ('option',))]}">
|
||||
|
@ -98,16 +98,15 @@
|
|||
redirected to the aggregated contact. You can remove
|
||||
contacts from this list to avoid merging them.
|
||||
</p>
|
||||
<field name="dst_partner_id" attrs="{'required': [('state', '=', 'selection')]}"/>
|
||||
<field name="partner_ids" nolabel="1" on_change="onchange_partner_ids(partner_ids)">
|
||||
<field name="dst_partner_id" domain="[('id', 'in', partner_ids and partner_ids[0] and partner_ids[0][2] or False)]" attrs="{'required': [('state', '=', 'selection')]}"/>
|
||||
<field name="partner_ids" nolabel="1">
|
||||
<tree string="Partners">
|
||||
<field name="id" />
|
||||
<field name="name" />
|
||||
<field name="display_name" />
|
||||
<field name="email" />
|
||||
<field name="is_company" />
|
||||
<field name="vat" />
|
||||
<field name="country_id" />
|
||||
<field name="parent_id" />
|
||||
</tree>
|
||||
</field>
|
||||
</group>
|
||||
|
@ -115,24 +114,9 @@
|
|||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.actions.server"
|
||||
id="ir_actions_server_merge_automatic">
|
||||
<field name="code">action = pool.get('base.partner.merge.automatic.wizard').merge_multi(cr, uid, None, context)</field>
|
||||
<field name="condition">True</field>
|
||||
<field name="model_id" ref="base.model_res_partner" />
|
||||
<field name="name">Automatic Merge</field>
|
||||
<field name="sequence" eval="5" />
|
||||
<field name="state">code</field>
|
||||
<field name="type">ir.actions.server</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.values" id="ir_open_merge_automatic">
|
||||
<field name="key2" eval="'client_action_multi'" />
|
||||
<field name="model">res.partner</field>
|
||||
<field name="name">Automatic Merge</field>
|
||||
<field name="value" eval="'ir.actions.server,%d' % ir_actions_server_merge_automatic" />
|
||||
</record>
|
||||
|
||||
<act_window id="action_partner_merge" res_model="base.partner.merge.automatic.wizard" src_model="res.partner"
|
||||
target="new" multi="True" key2="client_action_multi" view_mode="form" name="Automatic Merge"/>
|
||||
|
||||
</data>
|
||||
|
||||
|
|
Loading…
Reference in New Issue