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.

34 lines
1.3 KiB

5 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
  8. class Main(http.Controller):
  9. @http.route("/transactions", auth='none', type='http',method=['GET'])
  10. def check_method_get(self,**post):
  11. headers = {'Content-Type': 'application/json'}
  12. pos_sessions = request.env['pos.session'].sudo().search([
  13. ('state', '=', 'opened'),
  14. ('rescue', '=', False)], limit=1)
  15. if post.get('datetime', ''):
  16. date_get = post.get('datetime', '')
  17. transaction_ids = request.env[
  18. 'pos.transaction'].sudo().search([('create_date', '>=', date_get)])
  19. else:
  20. transaction_ids = request.env[
  21. 'pos.transaction'].sudo().search([])
  22. balance_id = pos_sessions.config_id.balance_id
  23. if hasattr(datetime.today(), 'isoformat'):
  24. date = datetime.today().isoformat()
  25. data = {
  26. 'balance_id': balance_id,
  27. 'date': date,
  28. 'transactions': transaction_ids.read(
  29. ['qrcode', 'balance_id', 'ean13', 'ean13_verif'])
  30. }
  31. return Response(json.dumps(data), headers=headers)