diff options
| author | Rafi Zadanly <zadanlyr@gmail.com> | 2023-02-02 17:12:04 +0700 |
|---|---|---|
| committer | Rafi Zadanly <zadanlyr@gmail.com> | 2023-02-02 17:12:04 +0700 |
| commit | 3d402f5a12d50d2264dde918d4b893b9c8943389 (patch) | |
| tree | 617bb24a36a096f5b315d0e49f38218b37802ec5 | |
| parent | 6b97d72c91f9a36462d08027660dddab945db01c (diff) | |
download tax invoice
| -rw-r--r-- | indoteknik_api/controllers/api_v1/__init__.py | 1 | ||||
| -rw-r--r-- | indoteknik_api/controllers/api_v1/download.py | 25 | ||||
| -rw-r--r-- | indoteknik_api/controllers/api_v1/sale_order.py | 5 | ||||
| -rw-r--r-- | indoteknik_api/models/account_move.py | 5 | ||||
| -rw-r--r-- | indoteknik_api/models/rest_api.py | 6 |
5 files changed, 38 insertions, 4 deletions
diff --git a/indoteknik_api/controllers/api_v1/__init__.py b/indoteknik_api/controllers/api_v1/__init__.py index ab499443..63540928 100644 --- a/indoteknik_api/controllers/api_v1/__init__.py +++ b/indoteknik_api/controllers/api_v1/__init__.py @@ -4,6 +4,7 @@ from . import cart from . import category from . import city from . import district +from . import download from . import flash_sale from . import invoice from . import manufacture diff --git a/indoteknik_api/controllers/api_v1/download.py b/indoteknik_api/controllers/api_v1/download.py new file mode 100644 index 00000000..b215a4cd --- /dev/null +++ b/indoteknik_api/controllers/api_v1/download.py @@ -0,0 +1,25 @@ +from .. import controller +from odoo import http +from odoo.http import request +import base64 + + +class Download(controller.Controller): + PREFIX = '/api/v1/' + + @http.route(PREFIX + 'download/tax-invoice/<id>/<token>', auth='none', method=['GET']) + def download_tax_invoice(self, **kw): + id = int(kw.get('id', 0)) + token = kw.get('token', '') + + md5_by_id = request.env['rest.api'].md5_salt(id, 'account.move$') + if md5_by_id == token: + attachment = request.env['ir.attachment'].sudo().search_read([ + ('res_model', '=', 'account.move'), + ('res_field', '=', 'efaktur_document'), + ('res_id', '=', id), + ], ['datas', 'mimetype']) + attachment = attachment[0] + return request.make_response(base64.b64decode(attachment['datas']), [('Content-Type', attachment['mimetype'])]) + + return self.response('Tidak diizinkan') diff --git a/indoteknik_api/controllers/api_v1/sale_order.py b/indoteknik_api/controllers/api_v1/sale_order.py index 11186605..52ccf9fa 100644 --- a/indoteknik_api/controllers/api_v1/sale_order.py +++ b/indoteknik_api/controllers/api_v1/sale_order.py @@ -121,6 +121,7 @@ class SaleOrder(controller.Controller): 'order_line': ['required', 'default:[]'], 'po_number': [], 'po_file': [], + 'type': [], }) if not user_token['partner_id'] == params['value']['partner_id']: @@ -145,8 +146,10 @@ class SaleOrder(controller.Controller): 'real_shipping_id': params['value']['partner_shipping_id'], 'partner_invoice_id': params['value']['partner_invoice_id'], 'partner_purchase_order_name': params['value']['po_number'], - 'partner_purchase_order_file': params['value']['po_file'] + 'partner_purchase_order_file': params['value']['po_file'], } + if params['value']['type'] == 'sale_order': + parameters['approval_status'] = 'pengajuan1' sale_order = request.env['sale.order'].create([[parameters]]) order_line = json.loads(params['value']['order_line']) parameters = [] diff --git a/indoteknik_api/models/account_move.py b/indoteknik_api/models/account_move.py index c70c21a5..5589b5fc 100644 --- a/indoteknik_api/models/account_move.py +++ b/indoteknik_api/models/account_move.py @@ -1,6 +1,6 @@ import datetime from odoo import models -from pytz import timezone +import hashlib class AccountMove(models.Model): @@ -15,7 +15,8 @@ class AccountMove(models.Model): 'sales': account_move.invoice_user_id.name, 'amount_total': account_move.amount_total, 'amount_residual': account_move.amount_residual, - 'invoice_date': '' + 'invoice_date': '', + 'efaktur_token': self.env['rest.api'].md5_salt(account_move.id, 'account.move$') if account_move.efaktur_document else '', } if isinstance(object, datetime.date): data['invoice_date'] = account_move.invoice_date.strftime('%d/%m/%Y') diff --git a/indoteknik_api/models/rest_api.py b/indoteknik_api/models/rest_api.py index 35cce201..2c54769e 100644 --- a/indoteknik_api/models/rest_api.py +++ b/indoteknik_api/models/rest_api.py @@ -1,6 +1,7 @@ from odoo import models import datetime from pytz import timezone +import hashlib class RestApi(models.TransientModel): @@ -10,4 +11,7 @@ class RestApi(models.TransientModel): time = '' if isinstance(object, datetime.datetime): time = object.astimezone(timezone('Asia/Jakarta')).strftime(format) - return time
\ No newline at end of file + return time + + def md5_salt(self, value, salt): + return hashlib.md5((salt + str(value)).encode()).hexdigest()
\ No newline at end of file |
