Skip to content

Commit

Permalink
chore: updated values sent in splyAmnt. Ensured no sending sales and
Browse files Browse the repository at this point in the history
purchase info if no stock is updated.
  • Loading branch information
GichanaMayaka committed Aug 30, 2024
1 parent c11a826 commit 0954a2e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,35 +58,36 @@ def validate(doc: Document, method: str) -> None:


def on_submit(doc: Document, method: str) -> None:
# TODO: Handle cases when item tax templates have not been picked
company_name = doc.company

headers = build_headers(company_name, doc.branch)
server_url = get_server_url(company_name, doc.branch)
route_path, last_request_date = get_route_path("TrnsPurchaseSaveReq")

if headers and server_url and route_path:
url = f"{server_url}{route_path}"
payload = build_purchase_invoice_payload(doc)

endpoints_builder.url = url
endpoints_builder.headers = headers
endpoints_builder.payload = payload
endpoints_builder.success_callback = partial(
purchase_invoice_submission_on_success, document_name=doc.name
)
if doc.is_return == 0 and doc.update_stock == 1:
# TODO: Handle cases when item tax templates have not been picked
company_name = doc.company

headers = build_headers(company_name, doc.branch)
server_url = get_server_url(company_name, doc.branch)
route_path, last_request_date = get_route_path("TrnsPurchaseSaveReq")

if headers and server_url and route_path:
url = f"{server_url}{route_path}"
payload = build_purchase_invoice_payload(doc)

endpoints_builder.url = url
endpoints_builder.headers = headers
endpoints_builder.payload = payload
endpoints_builder.success_callback = partial(
purchase_invoice_submission_on_success, document_name=doc.name
)

endpoints_builder.error_callback = on_error
endpoints_builder.error_callback = on_error

frappe.enqueue(
endpoints_builder.make_remote_call,
is_async=True,
queue="default",
timeout=300,
job_name=f"{doc.name}_send_purchase_information",
doctype="Purchase Invoice",
document_name=doc.name,
)
frappe.enqueue(
endpoints_builder.make_remote_call,
is_async=True,
queue="default",
timeout=300,
job_name=f"{doc.name}_send_purchase_information",
doctype="Purchase Invoice",
document_name=doc.name,
)


def build_purchase_invoice_payload(doc: Document) -> dict:
Expand Down Expand Up @@ -179,7 +180,7 @@ def get_items_details(doc: Document) -> list:
"qtyUnitCd": item.custom_unit_of_quantity_code,
"qty": abs(item.qty),
"prc": item.base_rate,
"splyAmt": item.base_rate,
"splyAmt": item.base_amount,
"dcRt": quantize_number(item.discount_percentage) or 0,
"dcAmt": quantize_number(item.discount_amount) or 0,
"taxblAmt": quantize_number(taxable_amount),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,9 @@
def on_submit(doc: Document, method: str) -> None:
"""Intercepts submit event for document"""

if not doc.is_consolidated and not doc.custom_successfully_submitted:
if (
not doc.is_consolidated
and not doc.custom_successfully_submitted
and doc.update_stock == 1
):
generic_invoices_on_submit_override(doc, "Sales Invoice")
2 changes: 1 addition & 1 deletion kenya_compliance/kenya_compliance/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ def get_invoice_items_list(invoice: Document) -> list[dict[str, str | int | None
"qtyUnitCd": item.custom_unit_of_quantity_code,
"qty": abs(item.qty),
"prc": round(item.base_rate, 2),
"splyAmt": round(item.base_rate, 2),
"splyAmt": round(item.base_amount, 2),
"dcRt": round(item.discount_percentage, 2) or 0,
"dcAmt": round(item.discount_amount, 2) or 0,
"isrccCd": None,
Expand Down

0 comments on commit 0954a2e

Please sign in to comment.