Skip to content

Commit

Permalink
Merge pull request #350 from aakvatech/version-14
Browse files Browse the repository at this point in the history
v15.0.0
  • Loading branch information
aakvatech authored Jul 16, 2024
2 parents 84f4c90 + 7316fc0 commit 83b7e9d
Show file tree
Hide file tree
Showing 70 changed files with 2,562 additions and 383 deletions.
2 changes: 1 addition & 1 deletion csf_tz/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import frappe

__version__ = "14.3.1"
__version__ = "14.5.1"

patches_loaded = False
app_name = "csf_tz"
Expand Down
86 changes: 86 additions & 0 deletions csf_tz/api/selcom.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
from selcom_apigw_client import apigwClient
import json
import frappe
from frappe import _


def create_order_log(method, status, request_json, response, reference):
doc = frappe.new_doc("Selcom Order Log")
doc.date = frappe.utils.today()
doc.time = frappe.utils.nowtime()
doc.method = method
doc.status = status
doc.reference = reference
doc.request_data = json.dumps(request_json, indent=4)
doc.response_data = json.dumps(response, indent=4)
doc.insert(ignore_permissions=True)
frappe.db.commit()


@frappe.whitelist()
def create_order_minimal():
# Initialize API client
apiKey = ""
apiSecret = ""
baseUrl = "https://apigw.selcommobile.com/v1"

client = apigwClient.Client(baseUrl, apiKey, apiSecret)

# Order data
orderDict = {
"vendor": "TILL61056542",
"order_id": "1218d5Qb",
"buyer_email": "john@example.com",
"buyer_name": "John Joh",
"buyer_phone": "255789968024",
"amount": 8000,
"currency": "TZS",
"buyer_remarks": "None",
"merchant_remarks": "None",
"no_of_items": 1,
}

# API endpoint
orderPath = "/checkout/create-order-minimal"

# Send order request
try:
response = client.postFunc(orderPath, orderDict)
if response.get("resultcode") != "000":
frappe.log_error(
f"Error on Create Order {response.get('reference')} to Payment Gateway",
response,
)
create_order_log(
"Create Order Minimal",
"Failed",
orderDict,
response,
reference=response.get("reference"),
)
else:
frappe.msgprint(_("Order created successfully"), alert=True)
create_order_log(
"Create Order Minimal",
"Success",
orderDict,
response,
reference=response.get("reference"),
)
return response

except Exception as e:
frappe.log_error(
f"Error on Create Order {response.get('reference')} to Payment Gateway",
str(e),
)
create_order_log(
"Create Order Minimal",
"Failed",
orderDict,
str(e),
reference=response.get("reference"),
)
frappe.throw(
_("Failed to create order, please try again, or contact the administrator")
)
17 changes: 17 additions & 0 deletions csf_tz/csf_tz/company.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ frappe.ui.form.on("Company", {
frappe.call({
method: 'csf_tz.custom_api.linking_tax_template',
args: {
abbr: frm.doc.abbr,
doctype: 'Item',
default_tax_template: {
default_tax_template: values.default_tax_template
Expand All @@ -95,6 +96,10 @@ frappe.ui.form.on("Company", {
auto_create_account: function(frm) {
frappe.call({
method: 'csf_tz.custom_api.auto_create_account',
args:{
abbr: frm.doc.abbr

},
callback: function(response) {
if (response.message) {
frappe.msgprint(__('Accounts created successfully.'));
Expand All @@ -105,6 +110,10 @@ frappe.ui.form.on("Company", {
create_tax_template: function(frm) {
frappe.call({
method: 'csf_tz.custom_api.create_item_tax_template',
args:{
abbr: frm.doc.abbr

},
callback: function(response) {
if (response.message) {
frappe.msgprint(__('Item Tax Templates created successfully.'));
Expand All @@ -116,6 +125,10 @@ frappe.ui.form.on("Company", {
make_tax_category: function(frm) {
frappe.call({
method: 'csf_tz.custom_api.create_tax_category',
args:{
abbr: frm.doc.abbr

},
callback: function(response) {
if (response.message) {
frappe.msgprint(__('Tax Category created successfully.'));
Expand All @@ -126,6 +139,10 @@ frappe.ui.form.on("Company", {
make_salary_components_and_structure: function(frm) {
frappe.call({
method: 'csf_tz.custom_api.make_salary_components_and_structure',
args:{
abbr: frm.doc.abbr

},
callback: function(response) {
if (response.message) {
frappe.msgprint(__('Salary Components and Structure are created successfully.'));
Expand Down
80 changes: 80 additions & 0 deletions csf_tz/csf_tz/custom_field.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
frappe.listview_settings['Custom Field'] = {
onload: function (listview) {
listview.page.add_menu_item(__('Export Selected'), async function () {
const selected_docs = listview.get_checked_items();
if (selected_docs.length === 0) {
frappe.msgprint(__('Please select at least one document.'));
return;
}

const detailed_docs = await Promise.all(selected_docs.map(doc =>
fetch(`/api/resource/Custom Field/${doc.name}`)
.then(response => response.json())
.then(data => data.data)
));

const data_to_export = detailed_docs.map(doc => {
return {
name: doc.name,
owner: doc.owner,
creation: doc.creation,
modified: doc.modified,
modified_by: doc.modified_by,
docstatus: doc.docstatus,
idx: doc.idx,
is_system_generated: doc.is_system_generated,
dt: doc.dt,
label: doc.label,
fieldname: doc.fieldname,
insert_after: doc.insert_after,
length: doc.length,
fieldtype: doc.fieldtype,
precision: doc.precision,
hide_seconds: doc.hide_seconds,
hide_days: doc.hide_days,
options: doc.options,
sort_options: doc.sort_options,
fetch_if_empty: doc.fetch_if_empty,
fetch_from: doc.fetch_from,
collapsible: doc.collapsible,
non_negative: doc.non_negative,
reqd: doc.reqd,
unique: doc.unique,
is_virtual: doc.is_virtual,
read_only: doc.read_only,
ignore_user_permissions: doc.ignore_user_permissions,
hidden: doc.hidden,
print_hide: doc.print_hide,
print_hide_if_no_value: doc.print_hide_if_no_value,
no_copy: doc.no_copy,
allow_on_submit: doc.allow_on_submit,
in_list_view: doc.in_list_view,
in_standard_filter: doc.in_standard_filter,
in_global_search: doc.in_global_search,
in_preview: doc.in_preview,
bold: doc.bold,
report_hide: doc.report_hide,
search_index: doc.search_index,
allow_in_quick_entry: doc.allow_in_quick_entry,
ignore_xss_filter: doc.ignore_xss_filter,
translatable: doc.translatable,
hide_border: doc.hide_border,
show_dashboard: doc.show_dashboard,
permlevel: doc.permlevel,
columns: doc.columns,
doctype: doc.doctype,
__last_sync_on: doc.__last_sync_on
};
});

const jsonStr = JSON.stringify(data_to_export);
let blob = new Blob([jsonStr], { type: "application/json" });
let a = document.createElement("a");
a.href = URL.createObjectURL(blob);
a.download = "exported_custom_fields.json";
a.click();
URL.revokeObjectURL(a.href);
a.remove();
});
}
};
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright (c) 2024, Aakvatech and contributors
// For license information, please see license.txt

frappe.ui.form.on('CSF TZ Bank Charges', {
// refresh: function(frm) {

// }
});
144 changes: 144 additions & 0 deletions csf_tz/csf_tz/doctype/csf_tz_bank_charges/csf_tz_bank_charges.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
{
"actions": [],
"allow_rename": 1,
"autoname": "format:CTBC-{###}",
"creation": "2024-03-08 09:00:14.016189",
"default_view": "List",
"doctype": "DocType",
"editable_grid": 1,
"engine": "InnoDB",
"field_order": [
"posting_date",
"bank_account",
"currency",
"company",
"column_break_ttbjl",
"account",
"bank_supplier",
"exchange_rate",
"section_break_31h9g",
"csf_tz_bank_charges_detail",
"total_bank_charges",
"ref_pi",
"section_break_x1dgr",
"amended_from"
],
"fields": [
{
"fieldname": "bank_account",
"fieldtype": "Link",
"in_list_view": 1,
"label": "Bank Account",
"options": "Bank Account",
"reqd": 1
},
{
"fieldname": "currency",
"fieldtype": "Link",
"label": "Bank Account Currency",
"options": "Currency"
},
{
"fieldname": "column_break_ttbjl",
"fieldtype": "Column Break"
},
{
"fetch_from": "bank_account.custom_bank_supplier",
"fieldname": "bank_supplier",
"fieldtype": "Data",
"label": "Bank Supplier",
"read_only": 1
},
{
"default": "1",
"fieldname": "exchange_rate",
"fieldtype": "Currency",
"label": "Exchange Rate"
},
{
"fieldname": "section_break_31h9g",
"fieldtype": "Section Break",
"label": "CSF TZ Bank Charges Detail"
},
{
"allow_bulk_edit": 1,
"fieldname": "csf_tz_bank_charges_detail",
"fieldtype": "Table",
"options": "CSF TZ Bank Charges Detail"
},
{
"default": "0",
"fieldname": "total_bank_charges",
"fieldtype": "Currency",
"label": "Total Bank Charges",
"options": "currency",
"read_only": 1
},
{
"fieldname": "section_break_x1dgr",
"fieldtype": "Section Break"
},
{
"fetch_from": "bank_account.account",
"fieldname": "account",
"fieldtype": "Link",
"label": "Account",
"options": "Account"
},
{
"default": "Today",
"fieldname": "posting_date",
"fieldtype": "Date",
"label": "Posting Date"
},
{
"fieldname": "ref_pi",
"fieldtype": "Data",
"label": " Ref PI",
"read_only": 1
},
{
"fetch_from": "bank_account.company",
"fieldname": "company",
"fieldtype": "Link",
"label": "Company",
"options": "Company"
},
{
"fieldname": "amended_from",
"fieldtype": "Link",
"label": "Amended From",
"no_copy": 1,
"options": "CSF TZ Bank Charges",
"print_hide": 1,
"read_only": 1,
"search_index": 1
}
],
"index_web_pages_for_search": 1,
"is_submittable": 1,
"links": [],
"modified": "2024-05-03 18:07:21.621574",
"modified_by": "Administrator",
"module": "CSF TZ",
"name": "CSF TZ Bank Charges",
"naming_rule": "Expression",
"owner": "Administrator",
"permissions": [
{
"create": 1,
"delete": 1,
"email": 1,
"export": 1,
"print": 1,
"read": 1,
"report": 1,
"role": "System Manager",
"share": 1,
"write": 1
}
],
"sort_field": "modified",
"sort_order": "DESC",
"states": []
}
Loading

0 comments on commit 83b7e9d

Please sign in to comment.