OCA / connector-magento

Connect Odoo with Magento
http://odoo-magento-connector.com/
GNU Affero General Public License v3.0
105 stars 206 forks source link

partner merging and duplicate key violation #137

Open ulbiopro opened 9 years ago

ulbiopro commented 9 years ago

Hello, we use the Odoo-Magento-Connector and are pretty happy about it's functionality so far.

The only big issue we found is the import of customers after changing the default billing or shipping address on magento.

The error from odoo-log is following:

 File "/usr/lib/python2.7/dist-packages/openerp/sql_db.py", line 234, in execute
    res = self._obj.execute(query, params)
IntegrityError: duplicate key value violates unique constraint "magento_address_openerp_uniq"
DETAIL:  Key (backend_id, openerp_id)=(1, 7) already exists.

This error is due to constraint in magentoerpconnector/partner.py Class MagentoAddress:

_sql_constraints = [
        ('openerp_uniq', 'unique(backend_id, openerp_id)',
         'A partner address can only have one binding by backend.'),
    ]

This duplicate key violation error is caused when an address is merged with a root address.

The Steps to reproduce:

Create a customer Place an order with the created customer Import that order into Odoo. 
(everything is fine until here) Add a second customer address in Magento and set it as default billing address Place a new order and import it (or just import partners) into Odoo Exception (already mentioned above)

What seems to happen is the following: Odoo imports a new partner contact/address which is now the default billing address. In that case it tries to create a new binding in the magento_address table. Because the associated openerp_id already exists it isn’t possible to create a new entry with the same openerp_id.

We are using: Magento V1.9.2.1 and Odoo V8.0-20150831

A possible workaround is to disable merging in the class PartnerAddressBook / method _get_address_infos:

[…]
                else:
                    # for B2C individual customers, merge with the main
                    # partner
                    merge = False
                    # in the case if the billing address no longer
                    # has a company, reset the flag
                    partner_binding.write({'consider_as_company': False})
[…]

Another thing we couldn’t figure out: if we’re working with a „Job-Worker“ the job is set to failed after the duplicate key violation error appears. But: If we’re working with a „Job-Runner“ the job is stuck in status „started“ and not set to „failed“.

regards Ulli

dhecar commented 8 years ago

Same problem.

Openerp V7 with magento 1.9.0.1

HOw can I solve this¿?

kayaj commented 7 years ago

Hi Ulli

Did you have any success fixing this issue? We're facing the exactly same one with Odoo V8 + Magento 1.9.2.2.

Would be awesome if we could get some more insights on the issue.

Best

JuanjoA commented 7 years ago

Hi, same issue here. Odoov8 <-> Magento 1.9