# Party duplication

**URL:** https://discuss.tryton.org/t/party-duplication/168
**Category:** Feature
**Created:** [July 22, 2016, 8:03am UTC](https://discuss.tryton.org/t/party-duplication/168 "2016-07-22T08:03:30Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)
#### Post date: [July 22, 2016, 8:03am UTC](https://discuss.tryton.org/t/party-duplication/168/1 "2016-07-22T08:03:31Z")

</div>

## Rational

It is quite common to have duplicated parties. Even if there are custom checks that tries to avoid such cases, there is no solution that guarantee at 100% that no duplicates will ever exist.  
So it is needed to have a way to manage such duplication.

## Proposal

A wizard is used to replace all references (`Many2One` and `Reference` fields) to one party by another one. The replacement must be done at SQL level to avoid to trigger any validation or work-flow but the an history record must be created for historized model.  
The wizard should also re-link the addresses and contact mechanism to the new party and mark them inactive.  
For other fields like categories, it should create new entries for the missing values.  
The replaced party will be marked as inactive to avoid new usage.  
The wizard could have some comparison checks that will trigger a warning if both party fields does not match. This will avoid mistakes.  
The replacement could be stored in a model to let the party administrator to follow the history.  
The reference fields should be explicitly defined, here is a partial list:

- Account Move Line: party
- Invoice: party
- Account Payment: party
- Account Statement: party
- Carrier: party
- Company: party
- Employee: party
- Product Supplier: party
- Project work: party
- Purchase: party
- Sale: party
- Sale Opportunity: party
- Drop Shipment: party
- Shipments: party

## Implementation

> **[Add Replace Wizard (#5820) · Issues · Tryton / Tryton · GitLab](https://foss.heptapod.net/tryton/tryton/-/issues/5820)**
>
> Following the discussion: https://discuss.tryton.org/t/party-duplication/168 I started to implement a "Replace Party" wizard.

---

<div class="post-metadata">

### Author: ![pokoli](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/pokoli/32/22_2.png) [@pokoli](https://discuss.tryton.org/u/pokoli)
#### Post date: [July 22, 2016, 8:29am UTC](https://discuss.tryton.org/t/party-duplication/168/2 "2016-07-22T08:29:57Z")

</div>

> [@ced](#):
>
> The reference fields should be explicitly defined, here is a partial list:

So IIUC this list should be extendable by other modules, so each module adding a party field must be responsible of adding it into the deduplication, list if needed.

---

<div class="post-metadata">

### Author: ![SISalp](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/sisalp/32/200_2.png) [@SISalp](https://discuss.tryton.org/u/SISalp)
#### Post date: [July 22, 2016, 8:30am UTC](https://discuss.tryton.org/t/party-duplication/168/3 "2016-07-22T08:30:37Z")

</div>

Would a “is an alias of” relation between two parties do the the trick too ?

---

<div class="post-metadata">

### Author: ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)
#### Post date: [July 22, 2016, 9:13am UTC](https://discuss.tryton.org/t/party-duplication/168/4 "2016-07-22T09:13:37Z")

</div>

> [@SISalp](#):
>
> Would a “is an alias of” relation between two parties do the the trick too ?

No because the receivable, payable amount should be correctly computed and also one could expect that the relates will work correctly.

---

<div class="post-metadata">

### Author: ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)
#### Post date: [August 22, 2016, 2:54pm UTC](https://discuss.tryton.org/t/party-duplication/168/5 "2016-08-22T14:54:40Z")

</div>

> [@ced](#):
>
> The wizard should also ask for the replacement correspondence of each addresses, the possibilities could be to replace one address by another one or to create a new one.

Indeed I think it is simpler to just update the address to be linked to the new party and mark it as inactive.

---

<div class="post-metadata">

### Author: ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)
#### Post date: [August 23, 2016, 9:58am UTC](https://discuss.tryton.org/t/party-duplication/168/6 "2016-08-23T09:58:32Z")

</div>

> [@ced](#):
>
> Indeed I think it is simpler to just update the address to be linked to the new party and mark it as inactive.

With this design, it is no more needed to update address fields.

---

<div class="post-metadata">

### Author: ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)
#### Post date: [October 19, 2017, 9:53am UTC](https://discuss.tryton.org/t/party-duplication/168/7 "2017-10-19T09:53:46Z")

</div>


