Browse Source

[FIX] taxes import issue

pull/7/head
Thibault Francois 9 years ago
parent
commit
6bb1d34a0a
  1. 40
      beesdoo_migration_asbl_to_coop/migration.py
  2. 44
      import_base/mapper.py

40
beesdoo_migration_asbl_to_coop/migration.py

@ -22,13 +22,14 @@ class migration_framework(import_framework):
}
tables = ['product.category',
'product.uom',
'product.uom.categ',
tables = ['product.category',
'product.uom',
'product.uom.categ',
'pos.category',
'res.partner',
'product.template',
'product.supplierinfo']
'product.supplierinfo',
]
table_domain = {
'res.partner' : [('supplier', '=', True), '|', ('active', '=', True), ('active', '=', False)],
@ -42,18 +43,14 @@ class migration_framework(import_framework):
print self.connection.name
def _get_field(self, model):
fields_info = model.fields_get()
fields = ['id']
for f_name, f_info in fields_info.items():
if f_info['type'] in ('many2one', 'many2many'):
fields.append(f_name + '/id')
elif f_info['type'] != 'one2many':
fields.append(f_name)
#if not 'function' in f_info.keys():
# elif f_info['type'] in ('float', 'integer', 'char', 'text', 'date', 'datetime', 'boolean', 'selection'):
# fields.append(f_name)
#if f_name in self.black_list_field.get(model.model_name, []):
# print f_info
for mapper_object in self.get_mapping()[model.model_name]['map'].values():
if isinstance(mapper_object, basestring):
fields.append(mapper_object)
else:
fields.extend(mapper_object.get_fields())
print "read field", fields
return fields
def res_to_dict(self, fields, datas):
@ -82,6 +79,12 @@ class migration_framework(import_framework):
To be used to avoid duplication of data that don't have ids
"""
return name
taxes_mapping = {
'5.5% Marchandise' : '6% Marchandises',
'6% Marchandise' : '6% Marchandises',
'21% Services incluse' : '21% Services',
}
def get_mapping(self):
@ -152,7 +155,6 @@ class migration_framework(import_framework):
'street' : 'street',
'street2' : 'street2',
'supplier' : 'supplier',
'vat' : 'website',
'website' : 'website',
'zip' : 'zip',
'supplier' : 'supplier',
@ -181,7 +183,7 @@ class migration_framework(import_framework):
'description' : 'description',
'description_picking' : 'description_picking',
'description_purchase' : 'description_purchase',
'description_sale' : 'descritpion_sale',
'description_sale' : 'description_sale',
'eco_label/id' : 'eco_label/id',
'fair_label/id' : 'fair_label/id',
'invoice_policy' : 'invoice_policy',
@ -193,8 +195,8 @@ class migration_framework(import_framework):
'sale_delay' : 'sale_delay',
'sale_ok' : 'sale_ok',
'standard_price' : 'standard_price',
'supplier_taxes_id' : 'supplier_taxes_id', #Taxes problème
'taxes_id' : 'taxes_id',
'supplier_taxes_id' : map_val_default('supplier_taxes_id', self.taxes_mapping), #Taxes problème
'taxes_id' : map_val_default('taxes_id', self.taxes_mapping),
'to_weight' : 'to_weight',
'type' : 'type',
'uom_id/id' : 'uom_id/id',

44
import_base/mapper.py

@ -32,6 +32,9 @@ class mapper(object):
"""
def __call__(self, external_values):
raise NotImplementedError()
def get_fields(self):
return []
class dbmapper(mapper):
"""
@ -58,7 +61,10 @@ class concat(mapper):
def __call__(self, external_values):
return self.delimiter.join(map(lambda x : tools.ustr(external_values.get(x,'')), self.arg))
class ppconcat(mapper):
def get_fields(self):
return self.arg
class ppconcat(concat):
"""
Use : contact('field_name1', 'field_name2', delimiter='_')
concat external field name and value of fields using the delimiter,
@ -104,6 +110,9 @@ class value(mapper):
val = external_values.get(self.fallback, self.default)
return val
def get_fields(self):
return [self.val]
class map_val(mapper):
"""
@ -122,6 +131,31 @@ class map_val(mapper):
def __call__(self, external_values):
return self.map.get(self.val(external_values), self.default)
def get_fields(self):
return self.val.get_fields()
class map_val_default(mapper):
"""
Use : map_val(external_field, val_mapping)
where val_mapping is a dictionary
with external_val : openerp_val
usefull for selection field like state
to map value
"""
def __init__(self, val, map):
self.val = value(val)
self.map = map
def __call__(self, external_values):
print self.val(external_values)
value = self.map.get(self.val(external_values), self.val(external_values))
print value
return value
def get_fields(self):
return self.val.get_fields()
class ref(dbmapper):
"""
Use : ref(table_name, external_id)
@ -135,6 +169,9 @@ class ref(dbmapper):
def __call__(self, external_values):
return self.parent.xml_id_exist(self.table, external_values.get(self.field_name))
def get_fields(self):
return self.field_name
class refbyname(dbmapper):
"""
@ -149,7 +186,10 @@ class refbyname(dbmapper):
def __call__(self, external_values):
v = external_values.get(self.field_name, '')
return self.parent.name_exist(self.table, v , self.model)
def get_fields(self):
return self.field_name
class call(mapper):
"""
Use : call(function, arg1, arg2)

Loading…
Cancel
Save