runbot/runbot_merge/tests/test_oddities.py
Xavier Morel 5f8ad6a626 [IMP] runbot_merge: support for merging partners w/ github_login
The logic of the partner merge wizard is to collect all relevant data
from source partners, write them to a destination partner, then remove
the sources.

This... doesn't work when the field in question has a UNIQUE
constraint (like github_login), because it's going to copy the value
from a source onto a dest which will blow the constraint, and so the
copy fails. In that case the user first has to *move over* the unique
field's value then they can use the wizard.

Just fix for the github login: take all sources, remove (and store)
their github logins, then write the login onto the dst.

An alternative would have been to *defer* the constraint, however:

* it only works on unique constraints, not unique indexes
* it requires the constraint to be declared DEFERRABLE

Closes #301
2020-03-16 15:03:11 +01:00

23 lines
694 B
Python

def test_partner_merge(env):
p_src = env['res.partner'].create({
'name': 'kfhsf',
'github_login': 'tyu'
}) | env['res.partner'].create({
'name': "xxx",
'github_login': 'xxx'
})
# proper login with useful info
p_dest = env['res.partner'].create({
'name': 'Partner P. Partnersson',
'github_login': ''
})
env['base.partner.merge.automatic.wizard'].create({
'state': 'selection',
'partner_ids': (p_src + p_dest).ids,
'dst_partner_id': p_dest.id,
})._call('action_merge')
assert not p_src.exists()
assert p_dest.name == 'Partner P. Partnersson'
assert p_dest.github_login == 'xxx'