openerp-connector-community team mailing list archive
-
openerp-connector-community team
-
Mailing list archive
-
Message #00171
Re: Indirect Mapping fields
On 01/28/2014 09:37 AM, jan-philipp.fischer@xxxxxxxxxxxxxx wrote:
Hi Guys,
hope you all are doing good.
Can someone help me out with indirect mapping?
All in all it works great and without problems. It's so easy to use.
Thank you!
But in Magento you can give multiply values to an attribute. For example
Product 1 is colored red/blue.
So to import that to OpenERP you have to map these values (Codes to
text) eg. 101 = red / 102 = blue.
That works fine if one value in magento is selected. Two doesn't work.
Magento gives an API String like "101,102" for "red,blue".
Can someone give me a tip how I can handle that in the mapping class?
Would be very thankful!
At the moment it is:
@mapping
def Farbe(self, record):
Farbe_Magento = MAGENTO_COLOR.get(record.get('filter_color'))
return {'Farbe': Farbe_Magento}
but I think I have to check for a "," and split it then in two parts.
But don't know how to arrange that...
Regards
Jan
Hi,
you can convert the ids to a list of integers:
magento_ids = record.get('filter_color') or ''
magento_ids = [int(n) for n in magento_ids.split(',') if n]
Then get the mapping:
openerp_ids = [MAGENTO_COLOR.get(mag_id) for mag_id in magento_ids]
And return it with the many2many syntax:
return {'farbe': [(6, 0, openerp_ids)]}
- Guewen
References