Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADD] Pezesha Changes POSAWesome #465

Open
wants to merge 33 commits into
base: version-14
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
a016493
[ADD] Pezesha Changes POSAWesome
erpbox-sols Apr 11, 2024
c1f37b5
Merge branch 'yrestom:version-14' into version-14
erpbox-sols Apr 12, 2024
b7564f5
Update pezesha_settings.py
erpbox-sols Apr 17, 2024
c6dfa86
Update pezesha_settings.py
erpbox-sols Apr 17, 2024
04d4837
Update pezesha_settings.py
erpbox-sols Apr 29, 2024
8886db2
Revert "Update pezesha_settings.py"
erpbox-sols Apr 29, 2024
f7867c4
Update pezesha_settings.py
erpbox-sols Apr 29, 2024
dbbea47
[ADD] Changes
erpbox-sols Apr 29, 2024
c2a0782
Update pezesha_settings.py
erpbox-sols Apr 29, 2024
8e4d3e8
Update pezesha_settings.py
erpbox-sols Apr 30, 2024
74640bb
Update pezesha_settings.py
erpbox-sols Apr 30, 2024
9202f38
Update pezesha_settings.py
erpbox-sols Apr 30, 2024
9df0089
Update pezesha_settings.py
erpbox-sols Apr 30, 2024
cd9c46e
[UPDATE] code
erpbox-sols Apr 30, 2024
ab3977e
Update pezesha_settings.py
erpbox-sols Apr 30, 2024
8f9dfe3
Update pezesha_settings.py
erpbox-sols Apr 30, 2024
6a8bd8b
Update pezesha_settings.py
erpbox-sols Apr 30, 2024
413a555
Update pezesha_settings.py
erpbox-sols Apr 30, 2024
a43d775
[UPDATE] consoole code
erpbox-sols Apr 30, 2024
8537ade
Added files 2-5-24
ketanserpentcs May 2, 2024
2ca7472
Update pezesha_settings.py
erpbox-sols May 2, 2024
58d19c5
Update pezesha_settings.py
erpbox-sols May 2, 2024
1ceb408
Added files 14-5-24
ketanserpentcs May 14, 2024
e2b617e
Update Hooks.py and Pezesha settings file
erpbox-sols May 29, 2024
db11a1a
fix: Pezesha API URL and headers changes
sahil170401 Jul 29, 2024
b5ce674
fix: Error message added for Loan Not Approved
sahil170401 Aug 3, 2024
5477c26
fix: error msg update in Pezesha
sahil170401 Aug 7, 2024
f8d8a01
fix: error fix in vue
sahil170401 Aug 7, 2024
edc48fc
fix: Pezesha Error bug fixes
sahil170401 Aug 8, 2024
292fa68
fix: typo corrected for status issue
sahil170401 Aug 12, 2024
5ff9cc5
fix: Pezesha Error msg updated
sahil170401 Aug 12, 2024
a1b37b6
Update Payments.vue
erpbox-sols Aug 26, 2024
4ea2d15
Update pezesha_settings.py
erpbox-sols Oct 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
885 changes: 470 additions & 415 deletions posawesome/fixtures/custom_field.json

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions posawesome/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@
"POS Profile-posa_allow_reconcile_payments",
"POS Profile-column_break_uolvm",
"POS Profile-posa_allow_mpesa_reconcile_payments",
"POS Profile-custom_pezesha_channel_id",
),
]
],
Expand All @@ -265,4 +266,10 @@
"doctype": "Property Setter",
"filters": [["name", "in", ("Sales Invoice-posa_pos_opening_shift-no_copy")]],
},

]
scheduler_events = {
"daily": [
"posawesome.posawesome.doctype.pezesha_settings.pezesha_settings.corn"
]
}
70 changes: 70 additions & 0 deletions posawesome/posawesome/custom/pos_settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"custom_fields": [
{
"_assign": null,
"_comments": null,
"_liked_by": null,
"_user_tags": null,
"allow_in_quick_entry": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"collapsible_depends_on": null,
"columns": 0,
"creation": "2023-10-16 15:52:07.916335",
"default": null,
"depends_on": null,
"description": null,
"docstatus": 0,
"dt": "POS Settings",
"fetch_from": null,
"fetch_if_empty": 0,
"fieldname": "custom_auto_close_shift",
"fieldtype": "Datetime",
"hidden": 0,
"hide_border": 0,
"hide_days": 0,
"hide_seconds": 0,
"idx": 3,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_preview": 0,
"in_standard_filter": 0,
"insert_after": "auto_close_shift",
"is_system_generated": 0,
"is_virtual": 0,
"label": "Auto Close Shift",
"length": 0,
"mandatory_depends_on": null,
"modified": "2023-10-16 15:52:07.916335",
"modified_by": "Administrator",
"module": "POSAwesome",
"name": "POS Settings-custom_auto_close_shift",
"no_copy": 0,
"non_negative": 0,
"options": null,
"owner": "Administrator",
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"print_width": null,
"read_only": 0,
"read_only_depends_on": null,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"sort_options": 0,
"translatable": 0,
"unique": 0,
"width": null
}
],
"custom_perms": [],
"doctype": "POS Settings",
"links": [],
"property_setters": [],
"sync_on_migrate": 1
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright (c) 2024, Youssef Restom and contributors
// For license information, please see license.txt

frappe.ui.form.on('Pezesha Settings', {
// refresh: function(frm) {

// }
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"actions": [],
"allow_rename": 1,
"creation": "2024-03-28 12:08:55.556406",
"default_view": "List",
"doctype": "DocType",
"editable_grid": 1,
"engine": "InnoDB",
"field_order": [
"enable",
"client_id",
"client_secret_id",
"authorization"
],
"fields": [
{
"fieldname": "client_id",
"fieldtype": "Data",
"label": "Client ID",
"mandatory_depends_on": "eval:doc.enable == 1;"
},
{
"fieldname": "client_secret_id",
"fieldtype": "Data",
"label": "Client Secret ID",
"mandatory_depends_on": "eval:doc.enable == 1;"
},
{
"fieldname": "authorization",
"fieldtype": "Small Text",
"label": "Authorization",
"read_only": 1
},
{
"default": "0",
"fieldname": "enable",
"fieldtype": "Check",
"label": "Enable"
}
],
"index_web_pages_for_search": 1,
"issingle": 1,
"links": [],
"modified": "2024-03-28 14:27:25.725083",
"modified_by": "Administrator",
"module": "POSAwesome",
"name": "Pezesha Settings",
"owner": "Administrator",
"permissions": [
{
"create": 1,
"delete": 1,
"email": 1,
"print": 1,
"read": 1,
"role": "System Manager",
"share": 1,
"write": 1
}
],
"sort_field": "modified",
"sort_order": "DESC",
"states": []
}
141 changes: 141 additions & 0 deletions posawesome/posawesome/doctype/pezesha_settings/pezesha_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
# Copyright (c) 2024, Youssef Restom and contributors
# For license information, please see license.txt

import frappe
import requests
import json
from frappe.model.document import Document
from frappe import _
from frappe.integrations.utils import (make_get_request, make_post_request, create_request_log)

class PezeshaSettings(Document):
def before_validate(self):
if self.enable:
try:
response = make_post_request(
# url = 'https://gateway.pezesha.com',
url="https://gateway.pezesha.com/oauth/token",
headers = {
'pezesha-apikey': '9ea7l6xraTJjDAXU6KYogxcArmlDGE1u',
'Accept-Encoding': 'gzip, deflate'
},
data={
"grant_type": "client_credentials",
"client_id": self.client_id,
"client_secret": self.client_secret_id,
"provider": "users"
},
auth=(
self.client_id,
self.get_password(fieldname="client_secret_id", raise_exception=False),
),
)
self.authorization = response['access_token']
except Exception as e:
frappe.throw(_("Seems API Key or API Secret is wrong !!!"))



@frappe.whitelist()
def pezesha_loan_offer(customer, pos_profile):
pos = frappe.get_doc("POS Profile", pos_profile)
pz_st = frappe.db.get_single_value('Pezesha Settings', 'authorization')
url = 'https://gateway.pezesha.com/mfi/v1/borrowers/options'
headers = {
'Authorization': f'Bearer {pz_st}',
'pezesha-apikey': '9ea7l6xraTJjDAXU6KYogxcArmlDGE1u',
'Accept-Encoding': 'gzip, deflate'
}
data = {
'channel': pos.custom_pezesha_channel_id,
'identifier': customer
}
response = requests.post(url, headers=headers, data=data)
if response.status_code == 200:
try:
dt = response.json()
ddt = dt['data']
return dt
except KeyError:
frappe.msgprint("You already have a pending loan. Cannot apply for new loan until current one is cleared")
return "You already have a pending loan. Cannot apply for new loan until current one is cleared"
else:
frappe.msgprint(f"Unable To Find Borrower <b>{customer}</b>")
return response.status_code

@frappe.whitelist()
def pezesha_loan_application(data, pos_profile):
res = json.loads(data)
pos = frappe.get_doc("POS Profile", pos_profile)
pz_st = frappe.db.get_single_value('Pezesha Settings', 'authorization')
url = 'https://gateway.pezesha.com/mfi/v1/borrowers/loans'
headers = {
'Authorization': f'Bearer {pz_st}',
'pezesha-apikey': '9ea7l6xraTJjDAXU6KYogxcArmlDGE1u',
'Accept-Encoding': 'gzip, deflate'
}
data = {
'channel': pos.custom_pezesha_channel_id,
'pezesha_id': res.get('pezesha_customer_id'),
'amount': res.get('amount'),
'duration': res.get('duration'),
'interest': res.get('interest'),
'rate': res.get('rate'),
'fee': res.get('fee')
}

response = requests.post(url, headers=headers, data=data)
return response.json()

@frappe.whitelist()
def pezesha_loan_status(customer, pos_profile):
pos = frappe.get_doc("POS Profile", pos_profile)
pz_st = frappe.db.get_single_value('Pezesha Settings', 'authorization')
url = 'https://gateway.pezesha.com/mfi/v1/borrowers/latest'
headers = {
'Authorization': f'Bearer {pz_st}',
'pezesha-apikey': '9ea7l6xraTJjDAXU6KYogxcArmlDGE1u',
'Accept-Encoding': 'gzip, deflate'
}
data = {
'channel': pos.custom_pezesha_channel_id,
'identifier': customer
}
response = requests.post(url, headers=headers, data=data)
if response.status_code == 200:
try:
dt = response.json()
ddt = dt['data']
amt = ddt['loan_amount']
return ddt
except KeyError:
frappe.msgprint("Please Apply Loan Application")
return "Please Apply Loan Application"
else:
frappe.msgprint("Please Apply Loan Application")
return response.status_code

def corn():
doc = frappe.get_doc('Pezesha Settings')
if doc.enable:
try:
response = make_post_request(
url="https://gateway.pezesha.com/oauth/token",
headers = {
'pezesha-apikey': '9ea7l6xraTJjDAXU6KYogxcArmlDGE1u',
'Accept-Encoding': 'gzip, deflate'
},
data={
"grant_type": "client_credentials",
"client_id": doc.client_id,
"client_secret": doc.client_secret_id,
"provider": "users"
},
auth=(
doc.client_id,
doc.get_password(fieldname="client_secret_id", raise_exception=False),
),
)
doc.db_set('authorization', response['access_token'])
except Exception as e:
frappe.throw(_("Seems API Key or API Secret is wrong !!!"))
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright (c) 2024, Youssef Restom and Contributors
# See license.txt

# import frappe
from frappe.tests.utils import FrappeTestCase


class TestPezeshaSettings(FrappeTestCase):
pass
9 changes: 6 additions & 3 deletions posawesome/public/js/posapp/components/pos/Invoice.vue
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@
</td>
</template>
</v-data-table>
</template>
</template>
</div>
</v-card>
<v-card class="cards mb-0 mt-3 py-0 grey lighten-5">
Expand Down Expand Up @@ -742,7 +742,7 @@
</v-row>
</v-col>
<v-col cols="5">
<v-row no-gutters class="pa-1 pt-2 pl-0">
<v-row no-gutters class="pa-1 pt-2 pl-0">
<v-col cols="6" class="pa-1">
<v-btn
block
Expand Down Expand Up @@ -889,6 +889,10 @@ export default {
},

computed: {
pezesha_amount(){
let sum = 0;
return flt(sum)
},
total_qty() {
this.close_payments();
let qty = 0;
Expand Down Expand Up @@ -1450,7 +1454,6 @@ export default {
return this.update_invoice_from_order(doc);
}
},

async show_payment() {
if (!this.customer) {
evntBus.$emit("show_mesage", {
Expand Down
Loading