You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

227 lines
8.6 KiB

  1. # -*- coding: utf-8 -*-
  2. from openerp import models, fields, api
  3. from openerp.exceptions import Warning
  4. from openerp.addons.import_base.import_framework import *
  5. from openerp.addons.import_base.mapper import *
  6. class odoo_connection_data(models.TransientModel):
  7. _name = 'beesdoo.import.asbl'
  8. @api.multi
  9. def migrate(self):
  10. imp = migration_framework(self, self.env.cr, self.env.uid, "Odoo", 'beesdoo.import.asbl', dict(self.env.context))
  11. imp.launch_import()
  12. class migration_framework(import_framework):
  13. black_list_field = {
  14. }
  15. tables = ['product.category',
  16. 'product.uom',
  17. 'product.uom.categ',
  18. 'pos.category',
  19. 'res.partner',
  20. 'product.template',
  21. 'product.supplierinfo',
  22. ]
  23. table_domain = {
  24. 'res.partner' : [('supplier', '=', True), '|', ('active', '=', True), ('active', '=', False)],
  25. 'product.template' : ['|', ('active', '=', True), ('active', '=', False)]
  26. }
  27. def initialize(self):
  28. self.connection = self.obj.env['import.odoo.connection'].search([], limit=1)
  29. self.set_table_list(self.tables)
  30. print self.connection.name
  31. def _get_field(self, model):
  32. fields = ['id']
  33. for mapper_object in self.get_mapping()[model.model_name]['map'].values():
  34. if isinstance(mapper_object, basestring):
  35. fields.append(mapper_object)
  36. else:
  37. fields.extend(mapper_object.get_fields())
  38. print "read field", fields
  39. return fields
  40. def res_to_dict(self, fields, datas):
  41. datas = datas['datas']
  42. res = []
  43. for data in datas:
  44. data_dict = {}
  45. for i, field in enumerate(fields):
  46. data_dict[field] = data[i]
  47. res.append(data_dict)
  48. return res
  49. def get_data(self, table):
  50. con = self.connection._get_connection()
  51. obj = con.get_model(table)
  52. fields = self._get_field(obj)
  53. ids = obj.search(self.table_domain.get(table, []))
  54. datas = obj.export_data(ids, fields, context={'lang' : 'fr_BE'})
  55. return self.res_to_dict(fields, datas)
  56. def _generate_xml_id(self, name, table):
  57. """
  58. @param name: name of the object, has to be unique in for a given table
  59. @param table : table where the record we want generate come from
  60. @return: a unique xml id for record, the xml_id will be the same given the same table and same name
  61. To be used to avoid duplication of data that don't have ids
  62. """
  63. return name
  64. taxes_mapping = {
  65. '5.5% Marchandise' : '6% Marchandises',
  66. '6% Marchandise' : '6% Marchandises',
  67. '21% Services incluse' : '21% Services',
  68. }
  69. def get_mapping(self):
  70. return {
  71. 'product.category': {
  72. 'model' : 'product.category',
  73. 'dependencies' : [],
  74. 'map' : {
  75. 'name' : 'name',
  76. 'parent_id/id_parent' : 'parent_id/id',
  77. 'type' : 'type',
  78. }
  79. },
  80. 'product.uom.categ' : {
  81. 'model' : 'product.uom.categ',
  82. 'dependencies' : [],
  83. 'map' : {
  84. 'name' : 'name',
  85. }
  86. },
  87. 'product.uom': {
  88. 'model' : 'product.uom',
  89. 'dependencies' : ['product.uom.categ'],
  90. 'map' : {
  91. 'name' : 'name',
  92. 'category_id/id' : 'category_id/id',
  93. 'rounding' : 'rounding',
  94. 'uom_type' : 'uom_type',
  95. 'factor' : 'factor',
  96. 'factor_inv' : 'factor_inv',
  97. }
  98. },
  99. 'pos.category': {
  100. 'model' : 'pos.category',
  101. 'dependencies' : [],
  102. 'map' : {
  103. 'id' : 'id',
  104. 'name' : 'name',
  105. 'parent_id/id_parent' : 'parent_id/id',
  106. }
  107. },
  108. 'res.partner': {
  109. 'model' : 'res.partner',
  110. 'dependencies' : [],
  111. 'map' : {
  112. 'active' : 'active',
  113. 'barcode' : 'barcode',
  114. 'birthdate' : 'birthdate',
  115. 'city' : 'city',
  116. 'comment' : 'comment',
  117. 'company_type' : 'company_type',
  118. 'contact_address' : 'contact_address',
  119. 'country_id/id' : 'country_id/id',
  120. 'email' : 'email',
  121. 'employee' : 'employee',
  122. 'fax' : 'fax',
  123. 'first_name' : 'first_name',
  124. 'function' : 'function',
  125. 'is_company' : 'is_company',
  126. 'lang' : 'lang',
  127. 'last_name' : 'last_name',
  128. 'mobile' : 'mobile',
  129. 'name' : 'name',
  130. 'parent_id/id_parent' : 'parent_id/id',
  131. 'phone' : 'phone',
  132. 'ref' : 'ref',
  133. 'street' : 'street',
  134. 'street2' : 'street2',
  135. 'supplier' : 'supplier',
  136. 'website' : 'website',
  137. 'zip' : 'zip',
  138. 'supplier' : 'supplier',
  139. 'customer' : 'customer',
  140. 'vat' : 'vat',
  141. }
  142. },
  143. 'beesdoo.product.label' : {
  144. 'model' : 'beesdoo.product.label',
  145. 'dependencies' : [],
  146. 'map' : {
  147. 'color_code' : 'color_code',
  148. 'name' : 'name',
  149. 'type' : 'type',
  150. }
  151. },
  152. 'product.template': {
  153. 'model' : 'product.template',
  154. 'dependencies' : ['pos.category', 'product.category', 'beesdoo.product.label'],
  155. 'map' : {
  156. 'active' : 'active',
  157. 'available_in_pos' : 'available_in_pos',
  158. 'barcode' : 'barcode',
  159. 'categ_id/id' : 'categ_id/id',
  160. 'default_code' : 'default_code',
  161. 'description' : 'description',
  162. 'description_picking' : 'description_picking',
  163. 'description_purchase' : 'description_purchase',
  164. 'description_sale' : 'description_sale',
  165. 'eco_label/id' : 'eco_label/id',
  166. 'fair_label/id' : 'fair_label/id',
  167. 'invoice_policy' : 'invoice_policy',
  168. 'local_label/id' : 'local_label/id',
  169. 'name' : 'name',
  170. 'origin_label/id' : 'origin_label/id',
  171. 'pos_categ_id/id' : 'pos_categ_id/id',
  172. 'purchase_ok' : 'purchase_ok',
  173. 'sale_delay' : 'sale_delay',
  174. 'sale_ok' : 'sale_ok',
  175. 'standard_price' : 'standard_price',
  176. 'supplier_taxes_id' : map_val_default('supplier_taxes_id', self.taxes_mapping), #Taxes problème
  177. 'taxes_id' : map_val_default('taxes_id', self.taxes_mapping),
  178. 'to_weight' : 'to_weight',
  179. 'type' : 'type',
  180. 'uom_id/id' : 'uom_id/id',
  181. 'uom_po_id/id' : 'uom_po_id/id',
  182. 'weight' : 'weight',
  183. 'list_price' : 'list_price',
  184. }
  185. },
  186. 'product.supplierinfo': {
  187. 'model' : 'product.supplierinfo',
  188. 'dependencies' : ['product.template'],
  189. 'map' : {
  190. 'delay' : 'delay',
  191. 'min_qty' : 'min_qty',
  192. 'name/id' : 'name/id',
  193. 'price' : 'price',
  194. 'product_code' : 'product_code',
  195. 'product_name' : 'product_name',
  196. 'product_uom/id' : 'product_uom/id',
  197. 'date_start' : 'date_start',
  198. 'date_end' : 'date_end',
  199. 'product_tmpl_id/id': 'product_tmpl_id/id',
  200. }
  201. },
  202. }