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.

48 lines
1.8 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. # © 2019 Le Filament (<http://www.le-filament.com>)
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  3. import json
  4. from odoo import http
  5. from odoo.http import request
  6. from odoo.http import Response
  7. from datetime import datetime, date
  8. from pytz import timezone
  9. class Main(http.Controller):
  10. @http.route("/transactions", auth='none', type='http',method=['GET'])
  11. def check_method_get(self,**post):
  12. headers = {'Content-Type': 'application/json'}
  13. pos_sessions = request.env['pos.session'].sudo().search([
  14. ('state', '=', 'opened'),
  15. ('rescue', '=', False)], limit=1)
  16. if post.get('datetime', ''):
  17. date_get = post.get('datetime', '')
  18. transaction_ids = request.env[
  19. 'pos.transaction'].sudo().search([('create_date', '>=', date_get)])
  20. else:
  21. today_datetime_utc = datetime.now()
  22. today_datetime = datetime(
  23. today_datetime_utc.year,
  24. today_datetime_utc.month,
  25. today_datetime_utc.day,
  26. 00,
  27. 00,
  28. 00)
  29. transaction_ids = request.env[
  30. 'pos.transaction'].sudo().search([('create_date', '>=', today_datetime)])
  31. balance_id = pos_sessions.config_id.balance_id
  32. today_datetime_utc = datetime.now(timezone('UTC'))
  33. if hasattr(today_datetime_utc, 'isoformat'):
  34. date = today_datetime_utc.isoformat('T')[:19]
  35. data = {
  36. 'balance_id': balance_id,
  37. 'date': date,
  38. 'transactions': transaction_ids.read(
  39. ['qrcode', 'balance_id', 'ean13', 'ean13_verif', 'date_iso'])
  40. }
  41. return Response(json.dumps(data), headers=headers)