'website': mapper.val('id', postprocess=lambda x: "http://website-%s.com" % x), 'street': mapper.val('id', postprocess=lambda x: "Street %s" % x), 'city': mapper.val('id', postprocess=lambda x: "City %s" % x), 'zip': mapper.val('id', postprocess=lambda x: ("%s" % x).zfill(6)), 'country_id/id': mapper.const('base.be'), 'company_type': mapper.const('company'), 'customer': mapper.val('id', postprocess=lambda x: str(int(x) % 2)), 'supplier': mapper.val('id', postprocess=lambda x: str((int(x) + 1) % 2)), 'lang': mapper.const('English'), 'category_id/id': mapper.m2m(TAG_PREFIX, 'tags') } tag_mapping = { 'id': mapper.m2m_id_list(TAG_PREFIX, 'tags'), 'name': mapper.m2m_value_list('tags'), 'parent_id/id': mapper.const('base.res_partner_category_0'), } processor = transform.Processor(header=header, data=data) processor.process(tag_mapping, tag_output, { 'worker': 1, 'batch_size': 10, 'model': 'res.partner.category', }, m2m=True) processor.process(mapping, output, { 'worker': 4, 'batch_size': 100, 'model': 'res.partner',
#STEP 4: Attribute List attribute_list = ['Color', 'Gender', 'Size_H', 'Size_W'] processor.process_attribute_data(attribute_list, ATTRIBUTE_PREFIX, 'data%sproduct.attribute.csv' % os.sep, { 'worker': 4, 'batch_size': 10, 'context': context }) #STEP 5: Attribute Value attribue_value_mapping = { 'id': mapper.m2m_id_list( ATTRIBUTE_VALUE_PREFIX, *[mapper.concat_field_value_m2m('_', f) for f in attribute_list]), 'name': mapper.m2m_value_list(*attribute_list), 'attribute_id/id': mapper.m2m_id_list(ATTRIBUTE_PREFIX, *[mapper.field(f) for f in attribute_list]), } processor.process(attribue_value_mapping, 'data%sproduct.attribute.value.csv' % os.sep, { 'worker': 3, 'batch_size': 50, 'context': context, 'groupby': 'attribute_id/id' }, m2m=True) #STEP 6: Attribute Value Line line_mapping = {
'phone': mapper.val('id', postprocess=lambda x: "0032%s" % (int(x) * 11)), 'website': mapper.val('id', postprocess=lambda x: "http://website-%s.com" % x), 'street': mapper.val('id', postprocess=lambda x: "Street %s" % x), 'city': mapper.val('id', postprocess=lambda x: "City %s" % x), 'zip': mapper.val('id', postprocess=lambda x: ("%s" % x).zfill(6)), 'country_id/id': mapper.const('base.be'), 'company_type': mapper.const('company'), 'customer': mapper.val('id', postprocess=lambda x: str(int(x) % 2)), 'supplier': mapper.val('id', postprocess=lambda x: str((int(x) + 1) % 2)), 'lang': mapper.const('English'), 'category_id/id': mapper.m2m(TAG_PREFIX, 'tags') } tag_mapping = { 'id': mapper.m2m_id_list(TAG_PREFIX, 'tags'), 'name': mapper.m2m_value_list('tags'), 'parent_id/id': mapper.const('base.res_partner_category_0'), } processor = transform.Processor(header=header, data=data) processor.process(tag_mapping, tag_output, { 'worker': 1, 'batch_size': 10, 'model': 'res.partner.category', }, m2m=True) processor.process(mapping, output, { 'worker': 4, 'batch_size': 100, 'model': 'res.partner', }) processor.write_to_file(script, python_exe=EXEC, path='../')
mapper.map_val('Language', lang_map), 'image': mapper.binary("Image", "origin/img/"), 'create_uid': mapper.val('Create BY'), 'create_date': mapper.val('Create ON', postprocess=lambda x: datetime.strptime(x, "%d/%m/%y").strftime( "%Y-%m-%d 00:00:00")), 'category_id/id': mapper.m2m(PARTNER_CATEGORY_PREFIX, 'Tag', 'Fidelity Grade'), } tag_mapping = { 'id': mapper.m2m_id_list(PARTNER_CATEGORY_PREFIX, 'Tag'), 'name': mapper.m2m_value_list('Tag'), } grade_mapping = { 'id': mapper.m2m_id_list(PARTNER_CATEGORY_PREFIX, 'Fidelity Grade'), 'name': mapper.m2m_value_list('Fidelity Grade'), } #Step 4: Process data processor.process(tag_mapping, 'data%sres.partner.category.csv' % os.sep, {}, m2m=True) processor.process(grade_mapping, 'data%sres.partner.category.grade.csv' % os.sep, {'model': 'res.partner.category'}, m2m=True)
'lst_price': mapper.num('public_price'), 'default_code': mapper.val('ref'), 'name': mapper.val('name'), } processor.process(template_map, 'data%sproduct.template.csv' % os.sep, {'worker': 4, 'batch_size': 10, 'context': context}, 'set') # STEP 4: Attribute List attribute_list = ['Color', 'Gender', 'Size_H', 'Size_W'] processor.process_attribute_data(attribute_list, ATTRIBUTE_PREFIX, 'data%sproduct.attribute.csv' % os.sep, {'worker': 4, 'batch_size': 10, 'context': context}) # STEP 5: Attribute Value attribue_value_mapping = { 'id': mapper.m2m_id_list(ATTRIBUTE_VALUE_PREFIX, *[mapper.concat_field_value_m2m('_', f) for f in attribute_list]), 'name': mapper.m2m_value_list(*attribute_list), 'attribute_id/id': mapper.m2m_id_list(ATTRIBUTE_PREFIX, *[mapper.field(f) for f in attribute_list]), } processor.process(attribue_value_mapping, 'data%sproduct.attribute.value.csv' % os.sep, {'worker': 3, 'batch_size': 50, 'context': context, 'groupby': 'attribute_id/id'}, m2m=True) # STEP 6: Attribute Value Line line_mapping = { 'id': mapper.m2m_id_list(ATTRIBUTE_LINE_PREFIX, *[mapper.concat_mapper_all('_', mapper.field(f), mapper.val('ref')) for f in attribute_list]), 'product_tmpl_id/id': mapper.m2o(TEMPLATE_PREFIX, 'ref'), 'attribute_id/id': mapper.m2m_id_list(ATTRIBUTE_PREFIX, *[mapper.field(f) for f in attribute_list]), 'value_ids/id': mapper.m2m_id_list(ATTRIBUTE_VALUE_PREFIX,