Skip to content

Commit

Permalink
Merge pull request #10 from navariltd/dev1
Browse files Browse the repository at this point in the history
Dev1
  • Loading branch information
maniamartial authored Jan 24, 2025
2 parents c909b16 + 1879fff commit 626e7ba
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,28 @@ frappe.ui.form.on("Sales Invoice", {
frappe.throw(`Please select the Customer ${customer}'s Tax Category`);
}
},
refresh: function (frm) {
if(frm.doc.docstatus === 1 && !frm.doc.custom_cu_invoice_number){
frm.add_custom_button(
__("Submit"),
function () {


frappe.call({
method: "tims_tevin_typec_integration.tims_tevic_type_c_integration.overrides.server.sales_invoice.single_invoice_submission",
args: {
doc: frm.doc,
},
callback: function (response) {
if (response.message) {
console.log()
}
},
});
},
__("eTims Actions")
);
}
},
});

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import qrcode
import requests

import json
import frappe
from frappe.integrations.utils import create_request_log
from frappe.model.document import Document
Expand All @@ -21,7 +21,6 @@ def on_submit(doc: Document, method: str | None = None) -> None:
"""Submit hook for Sales Invoice that submits tax information to TIMS device"""
company = frappe.defaults.get_user_default("Company")

# Fetch active setting tied to current company
# TODO: tie in additional filters to allow fine-grained searching of setting[s]
setting = frappe.db.get_value(
"TIMS Settings",
Expand Down Expand Up @@ -94,7 +93,7 @@ def on_submit(doc: Document, method: str | None = None) -> None:
for item in doc.items:
item_details.append(
{
"HSDesc": item.description,
"HSDesc": strip_html_tags(item.description),
"TaxRate": 0,
"ItemAmount": abs(item.net_amount),
"TaxAmount": 0,
Expand Down Expand Up @@ -197,6 +196,11 @@ def is_valid_kra_pin(pin: str) -> bool:
return bool(re.match(pattern, pin))


def strip_html_tags(text):
clean_text = re.sub(r'<[^>]*>', '', text)
return clean_text


def update_integration_request(
integration_request: str,
status: Literal["Completed", "Failed"],
Expand Down Expand Up @@ -363,3 +367,14 @@ def validate_relevant_invoice_number(relevant_invoice_number):
"The <b>Relevant Invoice Number</b> must be exactly 19 characters long and should be the CU number. Current length: {}.".format(len(relevant_invoice_number))
)

@frappe.whitelist()
def single_invoice_submission(doc):
doc_name = json.loads(doc).get("name")
doc = frappe.get_doc("Sales Invoice", doc_name)
on_submit(doc)
frappe.msgprint("TIMS submission successful")





0 comments on commit 626e7ba

Please sign in to comment.