eiru_pos.py 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. # -*- coding: utf-8 -*-
  2. import logging
  3. from openerp import api, fields, models
  4. _logger = logging.getLogger(__name__)
  5. class EiruPOS(models.Model):
  6. _name = 'eiru.pos'
  7. # Get company
  8. @api.model
  9. def get_company(self):
  10. user = self.env.user
  11. return {
  12. 'id': user.company_id.id,
  13. 'name': user.company_id.name,
  14. 'currency': {
  15. 'id': user.company_id.currency_id.id,
  16. 'name': user.company_id.currency_id.name,
  17. 'display_name': user.company_id.currency_id.display_name,
  18. 'symbol': user.company_id.currency_id.symbol
  19. }
  20. # 'store': {
  21. # 'id': user.company_id.store_id.id,
  22. # 'name': user.company_id.store_id.name
  23. # }
  24. }
  25. # Get all products
  26. @api.model
  27. def get_products(self):
  28. domain = [('sale_ok', '=', True), ('active', '=', True)]
  29. products = []
  30. # map products
  31. for product in self.env['product.template'].search(domain):
  32. variants = []
  33. # map variants
  34. for variant in product.product_variant_ids:
  35. if not variant.active:
  36. continue
  37. attributes = []
  38. # map product attributes
  39. # for attribute_line in variant.attribute_line_ids:
  40. # values = []
  41. # # map product attributes values
  42. # for value in attribute_line.value_ids:
  43. # values.append({
  44. # 'id': value.id,
  45. # 'display_name': value.display_name,
  46. # 'name': value.name,
  47. # 'price_extra': value.price_extra
  48. # })
  49. # attributes.append({
  50. # 'id': attribute_line.id,
  51. # 'attribute': {
  52. # 'id': attribute_line.attribute_id.id,
  53. # 'name': attribute_line.attribute_id.name
  54. # },
  55. # 'values': values
  56. # })
  57. for attribute_value in variant.attribute_value_ids:
  58. attributes.append({
  59. 'id': attribute_value.id,
  60. 'name': attribute_value.name,
  61. 'display_name': attribute_value.display_name
  62. })
  63. variants.append({
  64. 'id': variant.id,
  65. 'display_name': variant.display_name,
  66. 'ean13': variant.ean13,
  67. 'image_medium': variant.image_medium,
  68. 'list_price': variant.list_price,
  69. 'name': variant.name,
  70. 'qty_available': variant.qty_available,
  71. 'attributes': attributes
  72. })
  73. products.append({
  74. 'id': product.id,
  75. 'display_name': product.display_name,
  76. 'ean13': product.ean13,
  77. 'image_medium': product.image_medium,
  78. 'list_price': product.list_price,
  79. 'name': product.name,
  80. 'qty_available': product.qty_available,
  81. 'category': {
  82. 'id': product.categ_id.id,
  83. 'display_name': product.categ_id.display_name,
  84. 'name': product.categ_id.name,
  85. 'account_journal': {
  86. 'id': product.categ_id.property_stock_journal.id,
  87. 'code': product.categ_id.property_stock_journal.code,
  88. 'company': {
  89. 'id': product.categ_id.property_stock_journal.company_id.id,
  90. 'name': product.categ_id.property_stock_journal.company_id.name,
  91. 'currency': {
  92. 'id': product.categ_id.property_stock_journal.company_id.currency_id.id,
  93. 'name': product.categ_id.property_stock_journal.company_id.currency_id.name
  94. }
  95. },
  96. 'currency': {
  97. 'id': product.categ_id.property_stock_journal.currency.id,
  98. 'name': product.categ_id.property_stock_journal.currency.name
  99. },
  100. 'display_name': product.categ_id.property_stock_journal.display_name,
  101. 'name': product.categ_id.property_stock_journal.name,
  102. }
  103. },
  104. 'uom': {
  105. 'id': product.uom_id.id,
  106. 'name': product.uom_id.name
  107. },
  108. 'uos': {
  109. 'id': product.uos_id.id,
  110. 'name': product.uos_id.name
  111. },
  112. 'variant_count': product.product_variant_count,
  113. 'variants': variants
  114. })
  115. return products
  116. # Get all currencies
  117. @api.model
  118. def get_currencies(self):
  119. domain = [('active', '=', True)]
  120. currencies = []
  121. # if self.env.user.store_id:
  122. # domain.append(('company_id', '=', self.env.user.store_id.company_id.id))
  123. # else:
  124. # domain.append(('company_id', '=', self.env.user.company_id.id))
  125. # print domain
  126. for currency in self.env['res.currency'].search(domain):
  127. currencies.append({
  128. 'id': currency.id,
  129. 'name': currency.name,
  130. 'display_name': currency.display_name,
  131. 'accuracy': currency.accuracy,
  132. 'base': currency.base,
  133. 'position': currency.position,
  134. 'rate': currency.rate,
  135. 'rounding': currency.rounding,
  136. 'symbol': currency.symbol,
  137. 'company': {
  138. 'id': currency.company_id.id,
  139. 'name': currency.company_id.name
  140. }
  141. })
  142. return currencies
  143. @api.model
  144. def get_customers(self):
  145. domain = [('customer', '=', True), ('is_company', '=', False), ('active', '=', True)]
  146. customers = []
  147. for customer in self.env['res.partner'].search(domain):
  148. categories = []
  149. for category in customer.category_id:
  150. categories.append({
  151. 'id': category.id,
  152. 'name': category.name,
  153. 'display_name': category.display_name
  154. })
  155. customers.append({
  156. 'id': customer.id,
  157. 'name': customer.name,
  158. 'display_name': customer.display_name,
  159. 'image_medium': customer.image_medium,
  160. 'phone': customer.phone,
  161. 'mobile': customer.mobile,
  162. 'email': customer.email,
  163. 'categories': categories
  164. })
  165. return customers
  166. class eiru_pos_session(models.Model):
  167. _name = 'eiru.pos.session'
  168. # Get all sessions
  169. def get_sessions(self):
  170. pass