Skip to content

Commit

Permalink
[REV]
Browse files Browse the repository at this point in the history
  • Loading branch information
mikevhe18 committed Dec 18, 2024
1 parent 44a1296 commit 784d732
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 30 deletions.
5 changes: 4 additions & 1 deletion bssb_core_banking_asset/models/cb_asset_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,12 @@ def _default_company_id(self):
string="Password",
required=True,
)
token = fields.Char(
token = fields.Text(
string="Token",
)
app_id = fields.Char(
string="App ID",
)

@api.multi
def name_get(self):
Expand Down
78 changes: 50 additions & 28 deletions bssb_core_banking_asset/models/cb_asset_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,16 +272,18 @@ def action_done(self):

@api.multi
def _prepare_data_core_banking(self):
company = self.env.user.company_id
backend = company.cb_asset_backend_id
data = {
"APP_ID": "ATI-UMUM",
"APP_ID": backend.app_id,
"NO_TRANS": self.name,
"REK_DEBET": self.warehouse_id.code + self.depreciation_expense_account_id.code,
"NOMINAL_DEBET": self.final_depreciation_amount,
"KET_DEBET": self.description,
"NOTLP_DEBET": "",
"JENIS_TRANS": ""
"JENIS_TRANS": "0200",
}

# Range nanti diganti sama line_ids
for i in range(1,4):
rek_kredit = "REK_KREDIT" + str(i)
nominal_kredit = "NOMINAL_KREDIT" + str(i)
Expand All @@ -308,8 +310,8 @@ def _get_token(self):
url = backend.base_url + backend.api_token

payload = json.dumps({
"user": "ati-umum",
"password": "ati-umum"
"user": backend.username,
"password": backend.password,
})
headers = {
"Content-Type": "application/json",
Expand All @@ -323,16 +325,27 @@ def _get_token(self):
code = result["code"]
if code == "00":
backend.token = result["message"]
msg_err = _(
msg_err = _(
"""
Status: Success
API: %s
Payload: %s
Response: %s
"""
Status: Success
API: %s
Payload: %s
Response: %s
"""
% (url, payload, response.text)
)
return self._set_response("success", msg_err)
% (url, payload, response.text)
)
return self._set_response("success", msg_err)
else:
msg_err = _(
"""
Status: Error
API: %s
Payload: %s
Response: %s
"""
% (url, payload, response.text)
)
return self._set_response("failed", msg_err)
except requests.exceptions.Timeout as e:
msg_err = _(
"""
Expand Down Expand Up @@ -385,24 +398,33 @@ def _send_2_core_banking(self, data):
headers = {
"Authorization": "Bearer " + backend.token,
}

payload = json.dumps(data)

try:
response = requests.request(
"POST", url, headers=headers, data=payload
"POST", url, headers=headers, json=data
)
self.action_done()
msg_err = _(
if response.status_code == 200:
self.action_done()
msg_err = _(
"""
Status: Success
API: %s
Payload: %s
Response: %s
"""
Status: Success
API: %s
Payload: %s
Response: %s
"""
% (url, payload, response.text)
)
return self._set_response("success", msg_err)
% (url, payload, response.text)
)
return self._set_response("success", msg_err)
else:
msg_err = _(
"""
Status: Error
API: %s
Payload: %s
Response: %s
"""
% (url, payload, response.text)
)
return self._set_response("success", msg_err)
except requests.exceptions.Timeout as e:
msg_err = _(
"""
Expand Down
6 changes: 5 additions & 1 deletion bssb_core_banking_asset/views/cb_asset_backend_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,14 @@
<field name="api_token" />
<field name="username" />
<field name="password" password="True"/>
<field name="token"/>
<field name="app_id"/>

</group>
</group>
<notebook>
<page name="token" string="Token">
<field name="token"/>
</page>
<page name="note" string="Note">
<field name="note" colspan="4" nolabel="1" />
</page>
Expand Down

0 comments on commit 784d732

Please sign in to comment.