Skip to content

Commit

Permalink
chore: Removed hard-coded value used to fetch tax information from tax
Browse files Browse the repository at this point in the history
breakdown table to a value fetched according to tax description present
in taxes and charges table. Disabled installation scripts in favour of
using doc. naming settings to set the invoice series numbers.
  • Loading branch information
GichanaMayaka committed Oct 7, 2024
1 parent c9265bc commit 06c57e3
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 22 deletions.
8 changes: 4 additions & 4 deletions kenya_compliance/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,15 @@
# ------------

# before_install = "kenya_compliance.install.before_install"
after_install = "kenya_compliance.kenya_compliance.setup.after_install.after_install"
# after_install = "kenya_compliance.kenya_compliance.setup.after_install.after_install"

# Uninstallation
# ------------

# before_uninstall = "kenya_compliance.uninstall.before_uninstall"
after_uninstall = (
"kenya_compliance.kenya_compliance.setup.after_uninstall.after_uninstall"
)
# after_uninstall = (
# "kenya_compliance.kenya_compliance.setup.after_uninstall.after_uninstall"
# )

# Integration Setup
# ------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ def validate(doc: Document, method: str) -> None:
)

else:
tax_head = doc.taxes[0].description
for index, item in enumerate(doc.items):
taxes_breakdown[item.custom_taxation_type].append(
item_taxes[index]["VAT"]["tax_amount"]
item_taxes[index][tax_head]["tax_amount"]
)
taxable_breakdown[item.custom_taxation_type].append(
item_taxes[index]["taxable_amount"]
Expand Down Expand Up @@ -158,11 +159,9 @@ def get_items_details(doc: Document) -> list:
)

actual_tax_amount = 0
tax_head = doc.taxes[0].description # Fetch tax head from taxes table

try:
actual_tax_amount = item_taxes[index]["VAT"]["tax_amount"]
except KeyError:
actual_tax_amount = item_taxes[index]["VAT @ 16.0"]["tax_amount"]
actual_tax_amount = item_taxes[index][tax_head]["tax_amount"]

tax_amount = actual_tax_amount

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,11 @@ def validate(doc: Document, method: str) -> None:

taxes_breakdown = defaultdict(list)
taxable_breakdown = defaultdict(list)
tax_head = doc.taxes[0].description

for index, item in enumerate(doc.items):
taxes_breakdown[item.custom_taxation_type_code].append(
item_taxes[index]["VAT"]["tax_amount"]
item_taxes[index][tax_head]["tax_amount"]
)
taxable_breakdown[item.custom_taxation_type_code].append(
item_taxes[index]["taxable_amount"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,9 @@ def on_update(doc: Document, method: str | None = None) -> None:
)

actual_tax_amount = 0
tax_head = doc.taxes[0].description

try:
actual_tax_amount = tax_details["VAT"]["tax_amount"]
except KeyError:
actual_tax_amount = tax_details["VAT @ 16.0"]["tax_amount"]
actual_tax_amount = tax_details[tax_head]["tax_amount"]

current_item[0]["taxAmt"] = round(actual_tax_amount / current_item[0]["qty"], 2)

Expand Down Expand Up @@ -196,11 +194,9 @@ def on_update(doc: Document, method: str | None = None) -> None:
) # calculate total amt

actual_tax_amount = 0
tax_head = doc.taxes[0].description

try:
actual_tax_amount = tax_details["VAT"]["tax_amount"]
except KeyError:
actual_tax_amount = tax_details["VAT @ 16.0"]["tax_amount"]
actual_tax_amount = tax_details[tax_head]["tax_amount"]

current_item[0]["taxAmt"] = round(
actual_tax_amount / current_item[0]["qty"], 2
Expand Down
6 changes: 2 additions & 4 deletions kenya_compliance/kenya_compliance/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,11 +347,9 @@ def get_invoice_items_list(invoice: Document) -> list[dict[str, str | int | None
for index, item in enumerate(invoice.items):
taxable_amount = round(int(item_taxes[index]["taxable_amount"]), 2)
actual_tax_amount = 0
tax_head = invoice.taxes[0].description # Fetch tax head from taxes table

try:
actual_tax_amount = item_taxes[index]["VAT"]["tax_amount"]
except KeyError:
actual_tax_amount = item_taxes[index]["VAT @ 16.0"]["tax_amount"]
actual_tax_amount = item_taxes[index][tax_head]["tax_amount"]

tax_amount = round(actual_tax_amount, 2)

Expand Down

0 comments on commit 06c57e3

Please sign in to comment.