Skip to content

Commit

Permalink
fix: changes as per comment
Browse files Browse the repository at this point in the history
  • Loading branch information
Sanket322 committed May 23, 2024
1 parent 12e2681 commit c2b3347
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,8 @@ def get_fields(self, additional_fields=None, table=None):
"company_gstin",
"is_reverse_charge",
"place_of_supply",
"action",
"link_name",
]

if additional_fields:
Expand Down Expand Up @@ -810,6 +812,7 @@ def reconcile_for_rule(self, purchases, inward_supplies, match_status, rules):
- Where a match is found, update Inward Supply and Purchase Invoice.
"""

match_found = []
for supplier_gstin in purchases:
if not inward_supplies.get(supplier_gstin):
continue
Expand All @@ -820,6 +823,14 @@ def reconcile_for_rule(self, purchases, inward_supplies, match_status, rules):
for inward_supply_name, inward_supply in (
inward_supplies[supplier_gstin].copy().items()
):
doc_name = inward_supply.get("link_name")
if (
inward_supply.get("action") == "No Action"
and doc_name != ""
and doc_name not in match_found
):
match_found.append(doc_name)

if match_status == "Residual Match":
if (
abs((purchase.bill_date - inward_supply.bill_date).days)
Expand All @@ -842,6 +853,14 @@ def reconcile_for_rule(self, purchases, inward_supplies, match_status, rules):
inward_supplies[supplier_gstin].pop(inward_supply_name)
break

for doc in ("Purchase Invoice", "Bill of Entry"):
frappe.db.set_value(
doc,
{"name": ("in", match_found)},
"reconciliation_status",
"Match Found",
)

def is_doc_matching(self, purchase, inward_supply, rules):
"""
Returns true if all fields match from purchase and inward supply as per rules.
Expand Down Expand Up @@ -1137,37 +1156,20 @@ def process_data(self, reconciliation_data: list, retain_doc: bool = False):
"classification": "",
}

match_found = []

for data in reconciliation_data:
data.update(default_dict)
method = data.get if retain_doc else data.pop

purchase = method("_purchase_invoice", frappe._dict())
inward_supply = method("_inward_supply", frappe._dict())

if (
inward_supply
and inward_supply.get("action") == "No Action"
and inward_supply.get("link_name") != ""
):
match_found.append(inward_supply.get("link_name"))

self.update_fields(data, purchase, inward_supply)
self.update_amount_difference(data, purchase, inward_supply)
self.update_differences(data, purchase, inward_supply)

if retain_doc and purchase:
BaseUtil.update_cess_amount(purchase)

for doc in ("Purchase Invoice", "Bill of Entry"):
frappe.db.set_value(
doc,
{"name": ("in", match_found)},
"reconciliation_status",
"Match Found",
)

def update_fields(self, data, purchase, inward_supply):
for field in ("supplier_name", "supplier_gstin", "bill_no", "bill_date"):
data[field] = purchase.get(field) or inward_supply.get(field)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
import frappe

DOCTYPES = ("Purchase Invoice", "Bill of Entry")

def execute():
pi_and_boe_list = frappe.get_all(
"GST Inward Supply",
filters={"action": "No Action", "link_name": ("!=", "")},
pluck="link_name",
)
if not pi_and_boe_list:
return

for doc in ("Purchase Invoice", "Bill of Entry"):
def execute():
for doctype in DOCTYPES:
docs = get_inward_supply(doctype)
if not docs:
continue
frappe.db.set_value(
doc,
{"name": ("in", pi_and_boe_list)},
doctype,
{"name": ("in", docs)},
"reconciliation_status",
"Match Found",
)


def get_inward_supply(doctype):
return frappe.get_all(
"GST Inward Supply",
filters={
"action": "No Action",
"link_name": ("!=", ""),
"link_doctype": doctype,
},
pluck="link_name",
)

0 comments on commit c2b3347

Please sign in to comment.