models.py 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. # -*- coding: utf-8 -*-
  2. from openerp import models, fields
  3. import inspect
  4. '''
  5. Users class with token field for manage authentication
  6. '''
  7. class res_users(models.Model):
  8. _inherit = 'res.users'
  9. jwt_token = fields.Char(string = 'JWT Authentication Token');
  10. def dump(self):
  11. return {
  12. 'id': self.id,
  13. 'name': self.name,
  14. 'login': self.login,
  15. 'email': self.email,
  16. 'image_small': self.image_small,
  17. 'image_medium': self.image_medium,
  18. 'jwt_token': self.jwt_token,
  19. 'company_id': self.company_id.id,
  20. 'partner_id': self.partner_id.id,
  21. }
  22. '''
  23. '''
  24. class res_partner(models.Model):
  25. _inherit = 'res.partner'
  26. def dump(self):
  27. return {
  28. 'id': self.id,
  29. 'name': self.name,
  30. 'display_name': self.display_name,
  31. 'phone': self.phone,
  32. 'mobile': self.mobile,
  33. 'email': self.email,
  34. 'birthdate': self.birthdate,
  35. 'city': self.city,
  36. 'street': self.street,
  37. 'partner_latitude': self.partner_latitude,
  38. 'partner_longitude': self.partner_longitude,
  39. 'image_medium': self.image_medium,
  40. 'image_small': self.image_small,
  41. 'comment': self.comment,
  42. 'phonecall_count': self.phonecall_count,
  43. 'opportunity_count': self.opportunity_count,
  44. 'meeting_count': self.meeting_count,
  45. 'journal_item_count': self.journal_item_count,
  46. 'sale_order_count': self.sale_order_count,
  47. 'contracts_count': self.contracts_count,
  48. 'company_id': self.company_id.id,
  49. 'country_id': self.country_id.id
  50. }
  51. '''
  52. '''
  53. class crm_lead(models.Model):
  54. _inherit = 'crm.lead'
  55. def dump(self):
  56. return {
  57. 'id': self.id,
  58. 'name': self.name,
  59. 'display_name': self.display_name,
  60. 'phone': self.phone,
  61. 'mobile': self.mobile,
  62. 'city': self.city,
  63. 'street': self.street,
  64. 'street2': self.street2,
  65. 'partner_name': self.partner_name,
  66. 'contact_name': self.contact_name,
  67. 'date_open': self.day_open,
  68. 'day_close': self.day_close,
  69. 'day_open': self.day_open,
  70. 'priority': self.priority,
  71. 'probability': self.probability,
  72. 'planned_cost': self.planned_cost,
  73. 'description': self.description,
  74. 'meeting_count': self.meeting_count,
  75. 'partner_id': self.partner_id.id,
  76. 'company_id': self.company_id.id,
  77. 'stage_id': self.stage_id.id,
  78. 'campaign_id': self.campaign_id.id,
  79. 'country_id': self.country_id.id
  80. }
  81. '''
  82. '''
  83. class product_template(models.Model):
  84. _inherit = 'product.template'
  85. def dump(self):
  86. return {
  87. 'active': self.active,
  88. 'alternative_product_ids': [alt.id for alt in self.alternative_product_ids] if self.alternative_product_ids else [],
  89. 'attribute_line_ids': [line.id for line in self.attribute_line_ids] if self.attribute_line_ids else [],
  90. 'color': self.color,
  91. 'company_id': self.company_id.id if self.company_id.id else None,
  92. 'categ_id': self.categ_id.id if self.categ_id.id else None,
  93. 'default_code': self.default_code if self.default_code else None,
  94. 'description': self.description if self.description else None,
  95. 'display_name': self.display_name,
  96. 'ean13': self.ean13 if self.ean13 else None,
  97. 'factory_barcode': self.factory_barcode if self.factory_reference else None,
  98. 'factory_reference': self.factory_reference if self.factory_reference else None,
  99. 'flip_image': self.flip_image if hasattr(self, 'flip_image') else None,
  100. 'image_medium': self.image_medium,
  101. 'image_small': self.image_small,
  102. 'is_flip_image': self.is_flip_image if hasattr(self, 'is_flip_image') else False,
  103. 'is_product_variant': self.is_product_variant,
  104. 'list_price': self.list_price,
  105. 'mes_type': self.mes_type,
  106. 'multiple_image': self.multiple_image if hasattr(self, 'multiple_image') else False,
  107. 'name': self.name,
  108. 'price': self.price,
  109. 'product_variant_count': self.product_variant_count,
  110. 'product_variant_ids': [variant.id for variant in self.product_variant_ids] if self.product_variant_ids else [],
  111. 'purchase_ok': self.purchase_ok if hasattr(self, 'purchase_ok') else False,
  112. 'qty_available': self.qty_available if hasattr(self, 'qty_available') else 0,
  113. 'rental': self.rental if hasattr(self, 'rental') else False,
  114. 'sale_ok': self.sale_ok if hasattr(self, 'sale_ok') else False,
  115. 'type': self.type if hasattr(self, 'type') else None,
  116. 'website_published': self.website_published if hasattr(self, 'website_published') else False
  117. }
  118. '''
  119. '''
  120. class product_attribute_line(models.Model):
  121. _inherit = 'product.attribute.line'
  122. def dump(self):
  123. return {
  124. 'attribute_id': self.attribute_id.id if self.attribute_id.id else None,
  125. 'create_date': self.create_date,
  126. 'display_name': self.display_name,
  127. 'id': self.id,
  128. 'product_tmpl_id': self.product_tmpl_id.id if self.product_tmpl_id.id else None,
  129. 'value_ids': [value.id for value in self.value_ids] if self.value_ids else []
  130. }
  131. '''
  132. '''
  133. class product_attribute(models.Model):
  134. _inherit = 'product.attribute'
  135. def dump(self):
  136. return {
  137. 'active': self.active,
  138. 'create_date': self.create_date,
  139. 'display_name': self.display_name,
  140. 'id': self.id,
  141. 'name': self.name,
  142. 'type': self.type,
  143. 'value_ids': [value.id for value in self.value_ids] if self.value_ids else []
  144. }
  145. '''
  146. '''
  147. class product_attribute_price(models.Model):
  148. _inherit = 'product.attribute.price'
  149. def dump(self):
  150. attributes = inspect(self, lambda a:not(isroutine(a)))
  151. print '----------------------------------------------------------------'
  152. print attributes
  153. print '----------------------------------------------------------------'
  154. return {
  155. 'response': 'ok'
  156. }
  157. '''
  158. '''
  159. class product_attribute_value(models.Model):
  160. _inherit = 'product.attribute.value'
  161. def dump(self):
  162. return {
  163. 'attribute_id': self.attribute_id.id if self.attribute_id.id else None,
  164. 'color': self.color if self.color else None,
  165. 'create_date': self.create_date,
  166. 'display_name': self.display_name,
  167. 'id': self.id,
  168. 'name': self.name,
  169. 'price_extra': self.price_extra,
  170. 'price_ids': [price.id for price in self.price_ids] if self.price_ids else [],
  171. 'product_ids': [product.id for product in self.product_ids] if self.product_ids else []
  172. }
  173. '''
  174. '''
  175. class product_product(models.Model):
  176. _inherit = 'product.product'
  177. def dump(self):
  178. return {
  179. 'active': self.active,
  180. 'alternative_product_ids': [alternative.id for alternative in self.alternative_product_ids] if self.alternative_product_ids else [],
  181. 'attribute_line_ids': [alt.id for alt in self.attribute_line_ids] if self.attribute_line_ids else [],
  182. 'attribute_value_ids': [value.id for value in self.attribute_value_ids] if self.attribute_value_ids else [],
  183. 'categ_id': self.categ_id.id if self.categ_id else None,
  184. 'code': self.code,
  185. 'company_id': self.company_id.id if self.company_id else None,
  186. 'create_date': self.create_date,
  187. 'default_code': self.default_code if self.default_code else None,
  188. 'description': self.description if self.description else None,
  189. 'display_name': self.display_name,
  190. 'ean13': self.ean13 if self.ean13 else None,
  191. 'factory_barcode': self.factory_barcode if self.factory_barcode else None,
  192. 'factory_reference': self.factory_reference if self.factory_reference else None,
  193. 'image_medium': self.image_medium,
  194. 'image_small': self.image_small,
  195. 'image_variant': self.image_variant,
  196. 'id': self.id,
  197. 'is_product_variant': self.is_product_variant,
  198. 'list_price': self.list_price,
  199. 'name': self.name,
  200. 'name_template': self.name_template,
  201. 'price': self.price,
  202. 'price_extra': self.price_extra,
  203. 'product_tmpl_id': self.product_tmpl_id.id if self.product_tmpl_id else None,
  204. 'product_variant_count': self.product_variant_count,
  205. 'product_variant_ids': [variant.id for variant in self.product_variant_ids] if self.product_variant_ids else []
  206. }