Skip to content

Commit

Permalink
[IMP] add wrap management to to_backend method
Browse files Browse the repository at this point in the history
  • Loading branch information
bealdav committed Nov 12, 2013
1 parent ba212b3 commit a10c452
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions magentoerpconnect/unit/binder.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,31 @@ def to_openerp(self, external_id, unwrap=False):
else:
return binding_id

def to_backend(self, binding_id):
def to_backend(self, binding_id, wrap=False):
""" Give the external ID for an OpenERP ID
:param binding_id: OpenERP ID for which we want the external id
:param wrap: if True and OpenERP ID is the id of a normal model,
allow to get 'external id'
(e.g. with id of 'product.product' you get 'magento_id'
from 'magento.product.product')
if False, with OpenERP ID of magento.product.product
you get magento_id of the same model
:return: backend identifier of the record
"""
if wrap:
erp_id = self.session.search(self.model._name, [
['openerp_id', '=', binding_id],
['backend_id', '=', self.backend_record.id]
])
if erp_id:
erp_id = erp_id[0]
else:
return None
else:
erp_id = binding_id
magento_record = self.session.read(self.model._name,
binding_id,
erp_id,
['magento_id'])
assert magento_record
return magento_record['magento_id']
Expand Down

0 comments on commit a10c452

Please sign in to comment.