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.

220 lines
8.4 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. def get_mapping(self):
  65. return {
  66. 'product.category': {
  67. 'model' : 'product.category',
  68. 'dependencies' : [],
  69. 'map' : {
  70. 'name' : 'name',
  71. 'parent_id/id_parent' : 'parent_id/id',
  72. 'type' : 'type',
  73. }
  74. },
  75. 'product.uom.categ' : {
  76. 'model' : 'product.uom.categ',
  77. 'dependencies' : [],
  78. 'map' : {
  79. 'name' : 'name',
  80. }
  81. },
  82. 'product.uom': {
  83. 'model' : 'product.uom',
  84. 'dependencies' : ['product.uom.categ'],
  85. 'map' : {
  86. 'name' : 'name',
  87. 'category_id/id' : 'category_id/id',
  88. 'rounding' : 'rounding',
  89. 'uom_type' : 'uom_type',
  90. 'factor' : 'factor',
  91. 'factor_inv' : 'factor_inv',
  92. }
  93. },
  94. 'pos.category': {
  95. 'model' : 'pos.category',
  96. 'dependencies' : [],
  97. 'map' : {
  98. 'id' : 'id',
  99. 'name' : 'name',
  100. 'parent_id/id_parent' : 'parent_id/id',
  101. }
  102. },
  103. 'res.partner': {
  104. 'model' : 'res.partner',
  105. 'dependencies' : [],
  106. 'map' : {
  107. 'active' : 'active',
  108. 'barcode' : 'barcode',
  109. 'birthdate' : 'birthdate',
  110. 'city' : 'city',
  111. 'comment' : 'comment',
  112. 'company_type' : 'company_type',
  113. 'contact_address' : 'contact_address',
  114. 'country_id/id' : 'country_id/id',
  115. 'email' : 'email',
  116. 'employee' : 'employee',
  117. 'fax' : 'fax',
  118. 'first_name' : 'first_name',
  119. 'function' : 'function',
  120. 'is_company' : 'is_company',
  121. 'lang' : 'lang',
  122. 'last_name' : 'last_name',
  123. 'mobile' : 'mobile',
  124. 'name' : 'name',
  125. 'parent_id/id_parent' : 'parent_id/id',
  126. 'phone' : 'phone',
  127. 'ref' : 'ref',
  128. 'street' : 'street',
  129. 'street2' : 'street2',
  130. 'supplier' : 'supplier',
  131. 'website' : 'website',
  132. 'zip' : 'zip',
  133. 'supplier' : 'supplier',
  134. 'customer' : 'customer',
  135. 'vat' : 'vat',
  136. }
  137. },
  138. 'beesdoo.product.label' : {
  139. 'model' : 'beesdoo.product.label',
  140. 'dependencies' : [],
  141. 'map' : {
  142. 'color_code' : 'color_code',
  143. 'name' : 'name',
  144. 'type' : 'type',
  145. }
  146. },
  147. 'product.template': {
  148. 'model' : 'product.template',
  149. 'dependencies' : ['pos.category', 'product.category', 'beesdoo.product.label'],
  150. 'map' : {
  151. 'active' : 'active',
  152. 'available_in_pos' : 'available_in_pos',
  153. 'barcode' : 'barcode',
  154. 'categ_id/id' : 'categ_id/id',
  155. 'default_code' : 'default_code',
  156. 'description' : 'description',
  157. 'description_picking' : 'description_picking',
  158. 'description_purchase' : 'description_purchase',
  159. 'description_sale' : 'description_sale',
  160. 'eco_label/id' : 'eco_label/id',
  161. 'fair_label/id' : 'fair_label/id',
  162. 'invoice_policy' : 'invoice_policy',
  163. 'local_label/id' : 'local_label/id',
  164. 'name' : 'name',
  165. 'origin_label/id' : 'origin_label/id',
  166. 'pos_categ_id/id' : 'pos_categ_id/id',
  167. 'purchase_ok' : 'purchase_ok',
  168. 'sale_delay' : 'sale_delay',
  169. 'sale_ok' : 'sale_ok',
  170. 'standard_price' : 'standard_price',
  171. 'supplier_taxes_id/id' : 'supplier_taxes_id/id', #Taxes problème
  172. 'taxes_id/id' : 'taxes_id/id',
  173. 'to_weight' : 'to_weight',
  174. 'type' : 'type',
  175. 'uom_id/id' : 'uom_id/id',
  176. 'uom_po_id/id' : 'uom_po_id/id',
  177. 'weight' : 'weight',
  178. 'list_price' : 'list_price',
  179. }
  180. },
  181. 'product.supplierinfo': {
  182. 'model' : 'product.supplierinfo',
  183. 'dependencies' : ['product.template'],
  184. 'map' : {
  185. 'delay' : 'delay',
  186. 'min_qty' : 'min_qty',
  187. 'name/id' : 'name/id',
  188. 'price' : 'price',
  189. 'product_code' : 'product_code',
  190. 'product_name' : 'product_name',
  191. 'product_uom/id' : 'product_uom/id',
  192. 'date_start' : 'date_start',
  193. 'date_end' : 'date_end',
  194. 'product_tmpl_id/id': 'product_tmpl_id/id',
  195. }
  196. },
  197. }