Skip to content

Commit

Permalink
Merge pull request #1283 from resilient-tech/version-14-hotfix
Browse files Browse the repository at this point in the history
  • Loading branch information
vorasmit authored Nov 19, 2023
2 parents 0f2f765 + c22998f commit 0731ee8
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 12 deletions.
10 changes: 10 additions & 0 deletions .mergify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,13 @@ pull_request_rules:
- version-14-hotfix
assignees:
- "{{ author }}"

- name: automatically merge backport if they pass tests
conditions:
- author=mergify[bot]
- base~=^version-
- head~=^mergify/bp/
- label!=conflicts
actions:
merge:
method: merge
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,9 @@ def fuzzy_match(self, purchase, inward_supply):
- First check for partial ratio, with 100% confidence
- Next check for approximate match, with 90% confidence
"""
if not purchase.bill_no or not inward_supply.bill_no:
return False

if abs((purchase.bill_date - inward_supply.bill_date).days) > 10:
return False

Expand Down
2 changes: 1 addition & 1 deletion india_compliance/gst_india/overrides/payment_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def get_gl_for_advance_gst_reversal(payment_entry, reference_row):
# Reduce receivables
gl_entry = payment_entry.get_gl_dict(
{
"account": reference_row.account,
"account": reference_row.get("account") or payment_entry.paid_from,
"credit": total_amount,
"credit_in_account_currency": total_amount,
"party_type": payment_entry.party_type,
Expand Down
109 changes: 109 additions & 0 deletions india_compliance/gst_india/overrides/test_advance_payment_entry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import json

import frappe
from frappe.tests.utils import FrappeTestCase

from india_compliance.gst_india.utils.tests import create_transaction


class TestAdvancePaymentEntry(FrappeTestCase):
EXPECTED_GL = [
{"account": "Cash - _TIRC", "debit": 11800.0, "credit": 0.0},
{"account": "Debtors - _TIRC", "debit": 0.0, "credit": 10000.0},
{"account": "Output Tax SGST - _TIRC", "debit": 0.0, "credit": 900.0},
{"account": "Output Tax CGST - _TIRC", "debit": 0.0, "credit": 900.0},
{"account": "Debtors - _TIRC", "debit": 0.0, "credit": 18.0},
{"account": "Output Tax SGST - _TIRC", "debit": 9.0, "credit": 0.0},
{"account": "Output Tax CGST - _TIRC", "debit": 9.0, "credit": 0.0},
]

def test_advance_payment_entry(self):
payment_doc = self._create_payment_entry()
self._create_sales_invoice(payment_doc)

# Assert GL Entries for Payment Entry
self.assertGLEntries(payment_doc, self.EXPECTED_GL)

def test_payment_entry_allocation(self):
payment_doc = self._create_payment_entry()
invoice_doc = self._create_sales_invoice()

pr = frappe.get_doc("Payment Reconciliation")
pr.company = "_Test Indian Registered Company"
pr.party_type = "Customer"
pr.party = invoice_doc.customer
pr.receivable_payable_account = invoice_doc.debit_to

pr.get_unreconciled_entries()

invoices = [
row.as_dict()
for row in pr.invoices
if row.invoice_number == invoice_doc.name
]
payments = [
row.as_dict()
for row in pr.payments
if row.reference_name == payment_doc.name
]

pr.allocate_entries(frappe._dict({"invoices": invoices, "payments": payments}))
pr.reconcile()

self.assertGLEntries(payment_doc, self.EXPECTED_GL)

def _create_sales_invoice(self, payment_doc=None):
invoice_doc = create_transaction(
doctype="Sales Invoice",
is_in_state=1,
do_not_submit=True,
)

if payment_doc:
invoice_doc.set_advances()
for row in invoice_doc.advances:
if row.reference_name == payment_doc.name:
# Allocate Net of taxes
row.allocated_amount = invoice_doc.net_total # 100
else:
row.allocated_amount = 0

invoice_doc.submit()

return invoice_doc

def _create_payment_entry(self):
payment_doc = create_transaction(
doctype="Payment Entry",
payment_type="Receive",
mode_of_payment="Cash",
company_address="_Test Indian Registered Company-Billing",
party_type="Customer",
party="_Test Registered Customer",
customer_address="_Test Registered Customer-Billing",
paid_to="Cash - _TIRC",
paid_amount=10000,
is_in_state=1,
do_not_save=True,
)

payment_doc.setup_party_account_field()
payment_doc.set_missing_values()
payment_doc.set_exchange_rate()
payment_doc.received_amount = (
payment_doc.paid_amount / payment_doc.target_exchange_rate
)
payment_doc.save()
payment_doc.submit()

return payment_doc

def assertGLEntries(self, payment_doc, expected_gl_entries):
gl_entries = frappe.get_all(
"GL Entry",
filters={"voucher_no": payment_doc.name},
fields=["account", "debit", "credit"],
)
out_str = json.dumps(sorted(gl_entries, key=json.dumps))
expected_out_str = json.dumps(sorted(expected_gl_entries, key=json.dumps))
self.assertEqual(out_str, expected_out_str)
11 changes: 4 additions & 7 deletions india_compliance/gst_india/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ def send_updated_doc(doc, set_docinfo=False):
def get_gstin_list(party, party_type="Company"):
"""
Returns a list the party's GSTINs.
This function doesn't check for permissions since GSTINs are publicly available.
"""

frappe.has_permission(party_type, doc=party, throw=True)
Expand Down Expand Up @@ -464,15 +463,13 @@ def get_gst_accounts_by_type(company, account_type, throw=True):

@frappe.whitelist()
def get_all_gst_accounts(company):
"""
Permission not checked here:
List of GST account names isn't considered sensitive data
"""
if not company:
frappe.throw(_("Please set Company first"))

if not (
frappe.has_permission("Account", "read")
or frappe.has_permission("Account", "select")
):
frappe.throw(_("Not Permitted to select/read Accounts"), frappe.PermissionError)

settings = frappe.get_cached_doc("GST Settings")

accounts_list = []
Expand Down
10 changes: 8 additions & 2 deletions india_compliance/gst_india/utils/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def create_transaction(**data):
if not transaction.get("customer") and transaction.doctype != "Quotation":
transaction.customer = "_Test Registered Customer"

else:
elif transaction.doctype not in ["Payment Entry", "Journal Entry"]:
if not transaction.supplier:
transaction.supplier = "_Test Registered Supplier"

Expand Down Expand Up @@ -90,6 +90,9 @@ def append_item(transaction, data=None, company_abbr="_TIRC"):
if not data:
data = frappe._dict()

if data.doctype in ["Payment Entry", "Journal Entry"]:
return

return transaction.append(
"items",
{
Expand Down Expand Up @@ -119,11 +122,14 @@ def _append_taxes(
if isinstance(accounts, str):
accounts = [accounts]

if transaction.doctype in SALES_DOCTYPES:
if transaction.doctype in SALES_DOCTYPES or transaction.doctype == "Payment Entry":
account_type = "Output Tax"
else:
account_type = "Input Tax"

if transaction.doctype == "Payment Entry" and charge_type == "On Net Total":
charge_type = "On Paid Amount"

for account in accounts:
tax = {
"charge_type": charge_type,
Expand Down
4 changes: 2 additions & 2 deletions india_compliance/patches/check_version_compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
{
"app_name": "Frappe",
"current_version": version.parse(frappe.__version__),
"required_versions": {"version-14": "14.54.0"},
"required_versions": {"version-14": "14.54.0", "version-15": "15.1.0"},
},
{
"app_name": "ERPNext",
"current_version": version.parse(erpnext.__version__),
"required_versions": {"version-14": "14.45.1"},
"required_versions": {"version-14": "14.45.1", "version-15": "15.2.0"},
},
]

Expand Down

0 comments on commit 0731ee8

Please sign in to comment.