[6.1-oldstable] IntegrityError when a customer changes his email address and create a new account with the first email
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Magento OpenERP Connector |
Fix Released
|
High
|
Yannick Vaucher @ Camptocamp |
Bug Description
revision-id: <email address hidden>
It happens when:
1. Customer A creates an account on Magento. It uses the e-mail "<email address hidden>"
2. Customer A is imported in OpenERP with the email "<email address hidden>"
3. Customer A changes his email on Magento to "<email address hidden>"
* OpenERP still knows the email "<email address hidden>" for customer A
4. Customer A forget his password and creates a new account on Magento
with the email "<email address hidden>"
5. Customer A orders some stuff on Magento with his new account
* OpenERP import the sale order.
It doesn't know the customer, but in such case, it tries to find
an existing record with the same email.
It finds the first account of customer A and rebind it with the new Magento account
(instead of creating a new partner).
A duplicate key error is thrown because only 1 Magento customer is allowed
for 1 OpenERP partner.
Traceback with some slight changes on the path to shorten it.
2012-11-26 14:00:19,759 4344 ERROR ? openerp.
Traceback (most recent call last):
File "/srv/openerp/
context=
File "/srv/openerp/
self.
File "/srv/openerp/
return self.pool.
File "/srv/openerp/
cr.
File "/srv/openerp/
return f(self, *args, **kwargs)
File "/srv/openerp/
res = self._obj.
IntegrityError: duplicate key value violates unique constraint "ir_model_
DETAIL: Key (model, res_id, external_
To solve this issue, we have to never bind new Magento accounts to already bound partners.
We should bind a new Magento account only if a partner with the same email is found,
but is not already bound to a Magento customer.
(By bound, I means linked with Magento customer)
It should be as simple as:
=== modified file 'magentoerpconn
--- magentoerpconne
+++ magentoerpconne
@@ -312,7 +312,7 @@
cr,cr uid,
- is_bound=None,
+ is_bound=False,
return False, partner_id
BUT, we'll have issues with the following unique constraint, because we'll have 2 accounts with the same email and website...
_sql_
The last and the better option would be to allows to have 1 partner
for multiple customers on Magento, but so far I do not measure the consequences.
And as the ir_model_data table is shared for all the external ids, we can't actually
remove the ir_model_
Related branches
- Guewen Baconnier @ Camptocamp: Approve
-
Diff: 365 lines (+259/-55)3 files modifiedmagentoerpconnect/magerp_data.xml (+54/-40)
magentoerpconnect/partner.py (+65/-0)
magentoerpconnect/sale.py (+140/-15)
Changed in magentoerpconnect: | |
assignee: | nobody → Yannick Vaucher @ Camptocamp (yvaucher-c2c) |
Changed in magentoerpconnect: | |
status: | Confirmed → Fix Released |
Another solution could be to add a new cron job which updates regularly the customers, but it would not really solve the issue, just reduce the chances to issue it.