diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2023-06-02 14:16:33 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2023-06-02 14:16:33 +0700 |
| commit | aff9fdd49543648bfed395fff0c86af5b0269686 (patch) | |
| tree | 490a493d51660d9a7cf91ece5de0055cbce2a715 | |
| parent | 673e5500269f96492a447eb7ea38ed16b1827468 (diff) | |
add feature generate payment link midtrans
| -rwxr-xr-x | indoteknik_custom/models/sale_order.py | 33 | ||||
| -rw-r--r-- | indoteknik_custom/models/stock_picking.py | 5 | ||||
| -rwxr-xr-x | indoteknik_custom/views/sale_order.xml | 5 |
3 files changed, 43 insertions, 0 deletions
diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index d7b4331a..d021934f 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -5,6 +5,9 @@ import logging import warnings import random import string +import requests +import math +import json _logger = logging.getLogger(__name__) @@ -74,6 +77,36 @@ class SaleOrder(models.Model): notification = fields.Char(string='Notification', help='Dapat membantu error dari approval') delivery_service_type = fields.Char(string='Delivery Service Type', help='data dari rajaongkir') grand_total = fields.Monetary(string='Grand Total', help='Amount total + amount delivery', compute='_compute_grand_total') + payment_link_midtrans = fields.Char(string='Payment Link', help='Url payment yg digenerate oleh midtrans, harap diserahkan ke customer agar dapat dilakukan pembayaran secara mandiri') + + def generate_payment_link_midtrans_sales_order(self): + # midtrans_url = 'https://app.sandbox.midtrans.com/snap/v1/transactions' # dev - sandbox + # midtrans_auth = 'Basic U0ItTWlkLXNlcnZlci1uLVY3ZDJjMlpCMFNWRUQyOU95Q1dWWXA6' # dev - sandbox + midtrans_url = 'https://app.midtrans.com/snap/v1/transactions' # production + midtrans_auth = 'Basic TWlkLXNlcnZlci1SbGMxZ2gzWGpSVW5scl9JblZzTV9OTnU6' # production + so_number = self.name + so_number = so_number.replace('/', '-') + so_grandtotal = math.floor(self.grand_total) + headers = { + 'Accept': 'application/json', + 'Content-Type': 'application/json', + 'Authorization': midtrans_auth, + } + + json_data = { + 'transaction_details': { + 'order_id': so_number, + 'gross_amount': so_grandtotal, + }, + 'credit_card': { + 'secure': True, + }, + } + + response = requests.post(midtrans_url, headers=headers, json=json_data).json() + lookup_json = json.dumps(response, indent=4, sort_keys=True) + redirect_url = json.loads(lookup_json)['redirect_url'] + self.payment_link_midtrans = str(redirect_url) @api.model def _generate_so_access_token(self, limit=50): diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py index e63370f5..8c366082 100644 --- a/indoteknik_custom/models/stock_picking.py +++ b/indoteknik_custom/models/stock_picking.py @@ -256,6 +256,11 @@ class StockPicking(models.Model): if self.is_internal_use and not self.env.user.is_accounting: raise UserError("Harus di Approve oleh Accounting") + + if self.group_id.sale_id: + if self.group_id.sale_id.payment_link_midtrans: + if self.group_id.sale_id.payment_status != 'settlement': + raise UserError('Uang belum masuk (settlement), mohon konfirmasi ke sales atau finance') if self.is_internal_use: stock_move_lines = self.env['stock.move.line'].search([ diff --git a/indoteknik_custom/views/sale_order.xml b/indoteknik_custom/views/sale_order.xml index c66201a9..2fcef922 100755 --- a/indoteknik_custom/views/sale_order.xml +++ b/indoteknik_custom/views/sale_order.xml @@ -82,6 +82,11 @@ <field name="partner_purchase_order_file" readonly="True"/> </group> <group> + <button name="generate_payment_link_midtrans_sales_order" + string="Create Payment Link" + type="object" + /> + <field name="payment_link_midtrans" readonly="True" widget="url"/> <field name="gross_amount" readonly="True"/> <field name="payment_type" readonly="True"/> <field name="payment_status" readonly="True"/> |
