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.

224 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. table_domain = {
  23. 'res.partner' : [('supplier', '=', True), '|', ('active', '=', True), ('active', '=', False)],
  24. 'product.template' : ['|', ('active', '=', True), ('active', '=', False)]
  25. }
  26. def initialize(self):
  27. self.connection = self.obj.env['import.odoo.connection'].search([], limit=1)
  28. self.set_table_list(self.tables)
  29. print self.connection.name
  30. def _get_field(self, model):
  31. fields_info = model.fields_get()
  32. fields = ['id']
  33. for f_name, f_info in fields_info.items():
  34. if f_info['type'] in ('many2one', 'many2many'):
  35. fields.append(f_name + '/id')
  36. elif f_info['type'] != 'one2many':
  37. fields.append(f_name)
  38. #if not 'function' in f_info.keys():
  39. # elif f_info['type'] in ('float', 'integer', 'char', 'text', 'date', 'datetime', 'boolean', 'selection'):
  40. # fields.append(f_name)
  41. #if f_name in self.black_list_field.get(model.model_name, []):
  42. # print f_info
  43. return fields
  44. def res_to_dict(self, fields, datas):
  45. datas = datas['datas']
  46. res = []
  47. for data in datas:
  48. data_dict = {}
  49. for i, field in enumerate(fields):
  50. data_dict[field] = data[i]
  51. res.append(data_dict)
  52. return res
  53. def get_data(self, table):
  54. con = self.connection._get_connection()
  55. obj = con.get_model(table)
  56. fields = self._get_field(obj)
  57. ids = obj.search(self.table_domain.get(table, []))
  58. datas = obj.export_data(ids, fields, context={'lang' : 'fr_BE'})
  59. return self.res_to_dict(fields, datas)
  60. def _generate_xml_id(self, name, table):
  61. """
  62. @param name: name of the object, has to be unique in for a given table
  63. @param table : table where the record we want generate come from
  64. @return: a unique xml id for record, the xml_id will be the same given the same table and same name
  65. To be used to avoid duplication of data that don't have ids
  66. """
  67. return name
  68. def get_mapping(self):
  69. return {
  70. 'product.category': {
  71. 'model' : 'product.category',
  72. 'dependencies' : [],
  73. 'map' : {
  74. 'name' : 'name',
  75. 'parent_id/id_parent' : 'parent_id/id',
  76. 'type' : 'type',
  77. }
  78. },
  79. 'product.uom.categ' : {
  80. 'model' : 'product.uom.categ',
  81. 'dependencies' : [],
  82. 'map' : {
  83. 'name' : 'name',
  84. }
  85. },
  86. 'product.uom': {
  87. 'model' : 'product.uom',
  88. 'dependencies' : ['product.uom.categ'],
  89. 'map' : {
  90. 'name' : 'name',
  91. 'category_id/id' : 'category_id/id',
  92. 'rounding' : 'rounding',
  93. 'uom_type' : 'uom_type',
  94. 'factor' : 'factor',
  95. 'factor_inv' : 'factor_inv',
  96. }
  97. },
  98. 'pos.category': {
  99. 'model' : 'pos.category',
  100. 'dependencies' : [],
  101. 'map' : {
  102. 'id' : 'id',
  103. 'name' : 'name',
  104. 'parent_id/id_parent' : 'parent_id/id',
  105. }
  106. },
  107. 'res.partner': {
  108. 'model' : 'res.partner',
  109. 'dependencies' : [],
  110. 'map' : {
  111. 'active' : 'active',
  112. 'barcode' : 'barcode',
  113. 'birthdate' : 'birthdate',
  114. 'city' : 'city',
  115. 'comment' : 'comment',
  116. 'company_type' : 'company_type',
  117. 'contact_address' : 'contact_address',
  118. 'country_id/id' : 'country_id/id',
  119. 'email' : 'email',
  120. 'employee' : 'employee',
  121. 'fax' : 'fax',
  122. 'first_name' : 'first_name',
  123. 'function' : 'function',
  124. 'is_company' : 'is_company',
  125. 'lang' : 'lang',
  126. 'last_name' : 'last_name',
  127. 'mobile' : 'mobile',
  128. 'name' : 'name',
  129. 'parent_id/id_parent' : 'parent_id/id',
  130. 'phone' : 'phone',
  131. 'ref' : 'ref',
  132. 'street' : 'street',
  133. 'street2' : 'street2',
  134. 'supplier' : 'supplier',
  135. 'vat' : 'website',
  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' : 'descritpion_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' : 'supplier_taxes_id', #Taxes problème
  177. 'taxes_id' : 'taxes_id',
  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. }
  184. },
  185. 'product.supplierinfo': {
  186. 'model' : 'product.supplierinfo',
  187. 'dependencies' : ['product.template'],
  188. 'map' : {
  189. 'delay' : 'delay',
  190. 'min_qty' : 'min_qty',
  191. 'name/id' : 'name/id',
  192. 'price' : 'price',
  193. 'product_code' : 'product_code',
  194. 'product_name' : 'product_name',
  195. 'product_uom/id' : 'product_uom/id',
  196. 'date_start' : 'date_start',
  197. 'date_end' : 'date_end',
  198. 'product_tmpl_id/id': 'product_tmpl_id/id',
  199. }
  200. },
  201. }