Skip to content

Commit

Permalink
fix: check items and taxes before inserting
Browse files Browse the repository at this point in the history
  • Loading branch information
Sanket322 committed Jan 10, 2025
1 parent 5b947ee commit 73578c7
Showing 1 changed file with 29 additions and 22 deletions.
51 changes: 29 additions & 22 deletions india_compliance/gst_india/doctype/bill_of_entry/bill_of_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,15 +382,15 @@ def get_items_from_purchase_invoice(self):
frappe.has_permission("Bill Of Entry", "write")
frappe.has_permission("Purchase Invoice", "read")

self.set("items", [])
self.set("taxes", [])
existing_items = [item.pi_detail for item in self.get("items")]

for pi in self.get("purchase_invoices"):
if not pi.purchase_invoice:
continue

for item in get_pi_items(pi.purchase_invoice):
self.append("items", {**item})
if item.pi_detail not in existing_items:
self.append("items", {**item})

set_missing_values(self)

Expand All @@ -403,30 +403,37 @@ def set_missing_values(source, target=None):

# Add default tax
input_igst_account = get_gst_accounts_by_type(source.company, "Input").igst_account

if not input_igst_account:
return

rate, description = frappe.db.get_value(
"Purchase Taxes and Charges",
{
"parenttype": "Purchase Taxes and Charges Template",
"account_head": input_igst_account,
},
("rate", "description"),
) or (0, input_igst_account)

target.append(
"taxes",
{
"charge_type": "On Net Total",
"account_head": input_igst_account,
"rate": rate,
"gst_tax_type": "igst",
"description": description,
},
rate = (
frappe.db.get_value(
"Purchase Taxes and Charges",
{
"parenttype": "Purchase Taxes and Charges Template",
"account_head": input_igst_account,
},
"rate",
)
or 0
)

taxes = target.get("taxes")
if not taxes or (
taxes[0].charge_type != "On Net Total"
or taxes[0].account_head != input_igst_account
or taxes[0].rate != rate
):
target.append(
"taxes",
{
"charge_type": "On Net Total",
"account_head": input_igst_account,
"rate": rate,
"gst_tax_type": "igst",
},
)

target.set_taxes_and_totals()


Expand Down

0 comments on commit 73578c7

Please sign in to comment.