Skip to content

Commit

Permalink
Refactored settings doctype as well as relevant utility function to r…
Browse files Browse the repository at this point in the history
…eflect new requirements in settings management. Exported fixtures with updated field definitions. Added implementation for pos invoice overrides for server and client.
  • Loading branch information
GichanaMayaka committed Mar 19, 2024
1 parent 54d69ca commit f101e3b
Show file tree
Hide file tree
Showing 15 changed files with 2,932 additions and 540 deletions.
1,766 changes: 1,527 additions & 239 deletions kenya_compliance/fixtures/custom_field.json

Large diffs are not rendered by default.

1,248 changes: 1,144 additions & 104 deletions kenya_compliance/fixtures/navari_etims_packaging_unit.json

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions kenya_compliance/fixtures/navari_kra_etims_payment_type.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
[
{
"code": "01",
"code_description": "CASH",
"code_name": "CASH",
"docstatus": 0,
"doctype": "Navari KRA eTims Payment Type",
"modified": "2024-03-11 14:43:28.889289",
"name": "CASH",
"sort_order": 1
},
{
"code": "03",
"code_description": "CASH/CREDIT",
Expand Down Expand Up @@ -59,6 +49,16 @@
"name": "CREDIT",
"sort_order": 2
},
{
"code": "01",
"code_description": "CASH",
"code_name": "CASH",
"docstatus": 0,
"doctype": "Navari KRA eTims Payment Type",
"modified": "2024-03-11 14:43:28.889289",
"name": "CASH",
"sort_order": 1
},
{
"code": "04",
"code_description": "BANK CHECK",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,6 @@
"name": "Transferred",
"sort_order": 6
},
{
"code": "02",
"code_description": "Approved",
"code_name": "Approved",
"docstatus": 0,
"doctype": "Navari KRA eTims Transaction Progress",
"modified": "2024-03-11 15:27:26.812218",
"name": "Approved",
"sort_order": 2
},
{
"code": "01",
"code_description": "Wait for Approval",
Expand All @@ -58,5 +48,15 @@
"modified": "2024-03-11 15:27:01.848076",
"name": "Wait for Approval",
"sort_order": 1
},
{
"code": "02",
"code_description": "Approved",
"code_name": "Approved",
"docstatus": 0,
"doctype": "Navari KRA eTims Transaction Progress",
"modified": "2024-03-11 15:27:26.812218",
"name": "Approved",
"sort_order": 2
}
]
47 changes: 29 additions & 18 deletions kenya_compliance/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
"Item",
"Sales Invoice",
"Sales Invoice Item",
"POS Invoice",
"POS Invoice Item",
"Customer",
),
]
Expand Down Expand Up @@ -98,6 +100,7 @@
# include js in doctype views
doctype_js = {
"Sales Invoice": "kenya_compliance/overrides/client/sales_invoice.js",
"POS Invoice": "kenya_compliance/overrides/client/pos_invoice.js",
"Customer": "kenya_compliance/overrides/client/customer.js",
}
# doctype_list_js = {"doctype" : "public/js/doctype_list.js"}
Expand Down Expand Up @@ -203,29 +206,37 @@
"on_submit": [
"kenya_compliance.kenya_compliance.overrides.server.sales_invoice.on_submit"
]
}
},
"POS Invoice": {
"on_submit": [
"kenya_compliance.kenya_compliance.overrides.server.pos_invoice.on_submit"
]
},
}

# Scheduled Tasks
# ---------------

# scheduler_events = {
# "all": [
# "kenya_compliance.tasks.all"
# ],
# "daily": [
# "kenya_compliance.tasks.daily"
# ],
# "hourly": [
# "kenya_compliance.tasks.hourly"
# ],
# "weekly": [
# "kenya_compliance.tasks.weekly"
# ],
# "monthly": [
# "kenya_compliance.tasks.monthly"
# ],
# }
scheduler_events = {
"cron": {
"*/5 * * * *": "kenya_compliance.kenya_compliance.background_tasks.update_code_lists.get_code_list"
}
# "all": [
# "kenya_compliance.tasks.all"
# ],
# "daily": [
# "kenya_compliance.tasks.daily"
# ],
# "hourly": [
# "kenya_compliance.tasks.hourly"
# ],
# "weekly": [
# "kenya_compliance.tasks.weekly"
# ],
# "monthly": [
# "kenya_compliance.tasks.monthly"
# ],
}

# Testing
# -------
Expand Down
4 changes: 2 additions & 2 deletions kenya_compliance/kenya_compliance/apis/apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ def perform_customer_search(request_data: str) -> dict | None:
dict | None: The server's response
"""
data = json.loads(request_data)
server_url = get_server_url(data["company_tax_id"])
server_url = get_server_url(data["company_name"])
route_path = get_route_path("CustSearchReq")

if server_url and route_path:
url = f"{server_url}{route_path}"

payload = {"custmTin": data["tax_id"]}
headers = build_headers(data["company_tax_id"])
headers = build_headers(data["company_name"])

# TODO: Enqueue in background jobs queue
response = asyncio.run(make_post_request(url, payload, headers))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"actions": [],
"autoname": "format:{tin}-{env}-{dvcsrlno}",
"allow_rename": 1,
"autoname": "hash",
"creation": "2024-02-19 01:07:18.311952",
"doctype": "DocType",
"engine": "InnoDB",
Expand Down Expand Up @@ -94,11 +95,11 @@
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2024-02-21 02:31:39.494562",
"modified": "2024-03-19 09:39:53.184195",
"modified_by": "Administrator",
"module": "Kenya Compliance",
"name": "Navari KRA eTims Settings",
"naming_rule": "Expression",
"naming_rule": "Random",
"owner": "Administrator",
"permissions": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,17 @@ def validate(self) -> None:
title="Validation Error",
)

if self.name:
# Check if user is attempting to modify pin, environment type, or serial number after setting record
# has been created.
pin, env, device_serial = self.name.split("-")

if pin != self.tin or env != self.env or device_serial != self.dvcsrlno:
self.error = "You are attempting to change key details of this integration settings. Please duplicate and save this record instead of modifying it."
etims_logger.error(self.error)

frappe.throw(
self.error,
frappe.ValidationError,
title="Validation Error",
)
# if self.name:
# # Check if user is attempting to modify pin, environment type, or serial number after setting record
# # has been created.
# pin, env, device_serial = self.name.split("-")

# if pin != self.tin or env != self.env or device_serial != self.dvcsrlno:
# self.error = "You are attempting to change key details of this integration settings. Please duplicate and save this record instead of modifying it."
# etims_logger.error(self.error)

# frappe.throw(
# self.error,
# frappe.ValidationError,
# title="Validation Error",
# )
12 changes: 1 addition & 11 deletions kenya_compliance/kenya_compliance/overrides/client/customer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,6 @@ frappe.ui.form.on(doctype, {
refresh: async function (frm) {
if (!frm.is_new() && frm.doc.tax_id) {
const companyName = frappe.boot.sysdefaults.company;
const companyTaxIdResponse = await frappe.db.get_value(
"Company",
{ name: frappe.boot.sysdefaults.company },
["tax_id"]
);
let companyTaxId = null;

if (companyTaxIdResponse) {
companyTaxId = companyTaxIdResponse.message?.tax_id;
}

frm.add_custom_button(
__("Perform Customer Search"),
Expand All @@ -26,7 +16,7 @@ frappe.ui.form.on(doctype, {
request_data: {
name: frm.doc.name,
tax_id: frm.doc.tax_id,
company_tax_id: companyTaxId,
company_name: companyName,
},
},
callback: (response) => {
Expand Down
42 changes: 42 additions & 0 deletions kenya_compliance/kenya_compliance/overrides/client/pos_invoice.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const doctypeName = "POS Invoice";
const childDoctypeName = `${doctypeName} Item`;

frappe.ui.form.on(childDoctype, {
custom_item_classification: async function (frm, cdt, cdn) {
const itemClassificationCode = locals[cdt][cdn].custom_item_classification;
},
custom_packaging_unit: async function (frm, cdt, cdn) {
const packagingUnit = locals[cdt][cdn].custom_packaging_unit;

if (packagingUnit) {
const response = await frappe.db.get_value(
packagingUnitDoctypeName,
{
name: packagingUnit,
},
["code"]
);

const code = response.message?.code;
locals[cdt][cdn].custom_packaging_unit_code = code;
frm.refresh_field("custom_packaging_unit_code");
}
},
custom_unit_of_quantity: async function (frm, cdt, cdn) {
const unitOfQuantity = locals[cdt][cdn].custom_unit_of_quantity;

if (unitOfQuantity) {
const response = await frappe.db.get_value(
unitOfQuantityDoctypeName,
{
name: unitOfQuantity,
},
["code"]
);

const code = response.message?.code;
locals[cdt][cdn].custom_unit_of_quantity_code = code;
frm.refresh_field("custom_unit_of_quantity_code");
}
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,28 @@ const childDoctype = `${parentDoctype} Item`;
const packagingUnitDoctypeName = "Navari eTims Packaging Unit";
const unitOfQuantityDoctypeName = "Navari eTims Unit of Quantity";

// frappe.ui.form.on(parentDoctype, {
// refresh: function (frm) {},
// });
frappe.ui.form.on(parentDoctype, {
refresh: function (frm) {
frm.set_value("custom_transaction_progres", "Wait for Approval");
frm.set_value("custom_payment_type", "BANK CHECK");
},
status: function (frm) {
const invoiceStatus = frm.doc.status;
if (invoiceStatus === "Credit Note Issued") {
frm.set_value("custom_transaction_progres", "Credit Note Generated");
} else if (invoiceStatus === "Submitted") {
frm.set_value("custom_transaction_progres", "Approved");
} else if (invoiceStatus === "Cancelled") {
frm.set_value("custom_transaction_progres", "Cancelled");
} else if (invoiceStatus === "Draft") {
frm.set_value("custom_transaction_progres", "Wait for Approval");
} else if (invoiceStatus === "Internal Transfer") {
frm.set_value("custom_transaction_progres", "Transferred");
} else {
frm.set_value("custom_transaction_progres", "Wait for Approval");
}
},
});

frappe.ui.form.on(childDoctype, {
custom_item_classification: async function (frm, cdt, cdn) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from frappe.model.document import Document

from .shared_overrides import generic_invoices_on_submit_override


def on_submit(doc: Document, method: str) -> None:
"""Intercepts POS invoice on submit event"""

generic_invoices_on_submit_override(doc, "POS Invoice")
Loading

0 comments on commit f101e3b

Please sign in to comment.