eiru_pos.py 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. # -*- coding: utf-8 -*-
  2. import logging
  3. from openerp import api, fields, models
  4. _logger = logging.getLogger(__name__)
  5. class eiru_pos(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. 'format': user.company_id.currency_id.format
  20. }
  21. # 'store': {
  22. # 'id': user.company_id.store_id.id,
  23. # 'name': user.company_id.store_id.name
  24. # }
  25. }
  26. # Get all products
  27. @api.model
  28. def get_products(self):
  29. domain = [('sale_ok', '=', True), ('active', '=', True)]
  30. products = []
  31. for product in self.env['product.template'].search(domain):
  32. variants = []
  33. for variant in product.product_variant_ids:
  34. if not variant.active:
  35. continue
  36. attributes = []
  37. for attribute_line in variant.attribute_line_ids:
  38. values = []
  39. for value in attribute_line.value_ids:
  40. values.append({
  41. 'id': value.id,
  42. 'display_name': value.display_name,
  43. 'name': value.name,
  44. 'price_extra': value.price_extra
  45. })
  46. attributes.append({
  47. 'id': attribute_line.id,
  48. 'attribute': {
  49. 'id': attribute_line.attribute_id.id,
  50. 'name': attribute_line.attribute_id.name
  51. },
  52. 'values': values
  53. })
  54. variants.append({
  55. 'id': variant.id,
  56. 'display_name': variant.display_name,
  57. 'ean13': variant.ean13,
  58. 'image_medium': variant.image_medium,
  59. 'list_price': variant.list_price,
  60. 'name': variant.name,
  61. 'qty_available': variant.qty_available,
  62. 'attributes': attributes
  63. })
  64. products.append({
  65. 'id': product.id,
  66. 'display_name': product.display_name,
  67. 'ean13': product.ean13,
  68. 'image_medium': product.image_medium,
  69. 'list_price': product.list_price,
  70. 'name': product.name,
  71. 'qty_available': product.qty_available,
  72. 'category': {
  73. 'id': product.categ_id.id,
  74. 'display_name': product.categ_id.display_name,
  75. 'name': product.categ_id.name,
  76. 'account_journal': {
  77. 'id': product.categ_id.property_stock_journal.id,
  78. 'code': product.categ_id.property_stock_journal.code,
  79. 'company': {
  80. 'id': product.categ_id.property_stock_journal.company_id.id,
  81. 'name': product.categ_id.property_stock_journal.company_id.name,
  82. 'currency': {
  83. 'id': product.categ_id.property_stock_journal.company_id.currency_id.id,
  84. 'name': product.categ_id.property_stock_journal.company_id.currency_id.name
  85. }
  86. },
  87. 'currency': {
  88. 'id': product.categ_id.property_stock_journal.currency.id,
  89. 'name': product.categ_id.property_stock_journal.currency.name
  90. },
  91. 'display_name': product.categ_id.property_stock_journal.display_name,
  92. 'name': product.categ_id.property_stock_journal.name,
  93. }
  94. },
  95. 'uom': {
  96. 'id': product.uom_id.id,
  97. 'name': product.uom_id.name
  98. },
  99. 'uos': {
  100. 'id': product.uos_id.id,
  101. 'name': product.uos_id.name
  102. },
  103. 'variant_count': product.product_variant_count,
  104. 'variants': variants
  105. })
  106. return products
  107. # Get all currencies
  108. @api.model
  109. def get_currencies(self):
  110. domain = [('active', '=', True)]
  111. currencies = []
  112. # if self.env.user.store_id:
  113. # domain.append(('company_id', '=', self.env.user.store_id.company_id.id))
  114. # else:
  115. # domain.append(('company_id', '=', self.env.user.company_id.id))
  116. # print domain
  117. for currency in self.env['res.currency'].search(domain):
  118. currencies.append({
  119. 'id': currency.id,
  120. 'name': currency.name,
  121. 'display_name': currency.display_name,
  122. 'accuracy': currency.accuracy,
  123. 'base': currency.base,
  124. 'position': currency.position,
  125. 'rate': currency.rate,
  126. 'rounding': currency.rounding,
  127. 'symbol': currency.symbol,
  128. 'format': currency.format,
  129. 'company': {
  130. 'id': currency.company_id.id,
  131. 'name': currency.company_id.name
  132. }
  133. })
  134. return currencies
  135. class eiru_pos_session(models.Model):
  136. _name = 'eiru.pos.session'
  137. # Get all sessions
  138. def get_sessions(self):
  139. pass