pos_report_parser.py 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # Cybrosys Technologies Pvt. Ltd.
  5. # Copyright (C) 2015-TODAY Cybrosys Technologies(<http://www.cybrosys.com>).
  6. # Author: Sreejith P(<http://www.cybrosys.com>)
  7. # you can modify it under the terms of the GNU LESSER
  8. # GENERAL PUBLIC LICENSE (LGPL v3), Version 3.
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details.
  13. #
  14. # You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE
  15. # GENERAL PUBLIC LICENSE (LGPL v3) along with this program.
  16. # If not, see <http://www.gnu.org/licenses/>.
  17. #
  18. ##############################################################################
  19. from openerp.report import report_sxw
  20. from openerp.osv import osv
  21. from dateutil import parser
  22. import datetime
  23. import pytz
  24. from datetime import datetime
  25. from pytz import timezone
  26. from openerp import SUPERUSER_ID
  27. fmt1 = "%Y-%m-%d"
  28. class POSReportParser(report_sxw.rml_parse):
  29. def __init__(self, cr, uid, name, context=None):
  30. super(POSReportParser, self).__init__(cr, uid, name, context=context)
  31. self.localcontext.update({
  32. 'get_sale_details': self.get_sale_details,
  33. 'get_date': self.get_date,
  34. 'get_change_date': self.get_change_date,
  35. })
  36. self.context = context
  37. def get_date(self):
  38. now_utc = datetime.now(timezone('UTC'))
  39. user_list = self.pool.get('res.users').search(self.cr, self.uid,
  40. [('id', '=', SUPERUSER_ID)])
  41. obj1 = self.pool.get('res.users').browse(self.cr, self.uid, user_list, context=None)
  42. tz = pytz.timezone(obj1.partner_id.tz)
  43. now_pacific = now_utc.astimezone(timezone(str(tz)))
  44. current_date = now_pacific.strftime(fmt1)
  45. return current_date
  46. def get_change_date(self, data):
  47. my_date = parser.parse(data['form']['date'])
  48. proper_date_string = my_date.strftime('%d-%m-%Y')
  49. return proper_date_string
  50. def get_sale_details(self, data):
  51. lines = []
  52. if data['form']['sales_person'] and data['form']['point_of_sale']:
  53. pos_orders = self.pool.get('pos.order').search(self.cr, self.uid,
  54. [('date_order', '>=', data['form']['date']),
  55. ('date_order', '<=', data['form']['date_to']),
  56. ('user_id', '=', data['form']['sales_person'][0]),
  57. ('session_id.config_id', '=', data['form']['point_of_sale'][0])])
  58. elif data['form']['point_of_sale']:
  59. pos_orders = self.pool.get('pos.order').search(self.cr, self.uid,
  60. [('date_order', '>=', data['form']['date']),
  61. ('date_order', '<=', data['form']['date_to']),
  62. ('session_id.config_id', '=', data['form']['point_of_sale'][0])])
  63. elif data['form']['sales_person']:
  64. pos_orders = self.pool.get('pos.order').search(self.cr, self.uid,
  65. [('date_order', '>=', data['form']['date']),
  66. ('date_order', '<=', data['form']['date_to']),
  67. ('user_id', '=', data['form']['sales_person'][0])])
  68. else:
  69. pos_orders = self.pool.get('pos.order').search(self.cr, self.uid,
  70. [('date_order', '>=', data['form']['date']),
  71. ('date_order', '<=', data['form']['date_to'])])
  72. for order in pos_orders:
  73. obj1 = self.pool.get('pos.order').browse(self.cr, self.uid, order, context=None)
  74. if data['form']['select_company'][0] == 1:
  75. order = obj1.name
  76. if obj1.partner_id.name:
  77. partner = obj1.partner_id.name
  78. else:
  79. partner = ""
  80. price = obj1.amount_total
  81. bank_amount = 0
  82. cash_amount = 0
  83. for statements in obj1.statement_ids:
  84. if statements.journal_id.name == "Debt":
  85. debit = debit + statements.amount
  86. continue
  87. if statements.journal_id.type == "bank":
  88. if statements.amount > price:
  89. bank_amount += price
  90. elif statements.amount > 0:
  91. bank_amount += statements.amount
  92. else:
  93. pass
  94. if statements.journal_id.type == "cash":
  95. if statements.amount > price:
  96. cash_amount += price
  97. elif statements.amount > 0:
  98. cash_amount += statements.amount
  99. else:
  100. pass
  101. vals = {
  102. 'order': order,
  103. 'partner': partner,
  104. 'price': price,
  105. 'cash': cash_amount,
  106. 'bank': bank_amount,
  107. }
  108. lines.append(vals)
  109. elif obj1.company_id.id == data['form']['select_company'][0]:
  110. order = obj1.name
  111. if obj1.partner_id.name:
  112. partner = obj1.partner_id.name
  113. else:
  114. partner = ""
  115. price = obj1.amount_total
  116. bank_amount = 0
  117. cash_amount = 0
  118. for statements in obj1.statement_ids:
  119. if statements.journal_id.type == "bank":
  120. if statements.amount > price:
  121. bank_amount += price
  122. elif statements.amount > 0:
  123. bank_amount += statements.amount
  124. else:
  125. pass
  126. if statements.journal_id.type == "cash":
  127. if statements.amount > price:
  128. cash_amount += price
  129. elif statements.amount > 0:
  130. cash_amount += statements.amount
  131. else:
  132. pass
  133. vals = {
  134. 'order': order,
  135. 'partner': partner,
  136. 'price': price,
  137. 'cash': cash_amount,
  138. 'bank': bank_amount,
  139. }
  140. lines.append(vals)
  141. return lines
  142. class PrintReport(osv.AbstractModel):
  143. _name = 'report.pos_sale_reports.report_daily_pos_sales'
  144. _inherit = 'report.abstract_report'
  145. _template = 'pos_sale_reports.report_daily_pos_sales'
  146. _wrapped_report_class = POSReportParser