Skip to content

Commit

Permalink
Merge pull request #2011 from resilient-tech/version-14-hotfix
Browse files Browse the repository at this point in the history
chore: release v14
  • Loading branch information
vorasmit authored Apr 10, 2024
2 parents 4ed6036 + bc52e21 commit 30b5f95
Show file tree
Hide file tree
Showing 17 changed files with 367 additions and 108 deletions.
29 changes: 18 additions & 11 deletions india_compliance/gst_india/api_classes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,9 @@ def _make_request(
raise e

finally:
log.output = response_json.copy()
if response_json:
log.output = response_json.copy()

self.mask_sensitive_info(log)

enqueue_integration_request(**log)
Expand Down Expand Up @@ -252,21 +254,26 @@ def generate_request_id(self, length=12):
return frappe.generate_hash(length=length)

def mask_sensitive_info(self, log):
request_headers = log.request_headers
output = log.output
data = log.data
request_body = data and data.get("body")

for key in self.SENSITIVE_INFO:
if key in log.request_headers:
log.request_headers[key] = "*****"
if key in request_headers:
request_headers[key] = "*****"

if key in log.output:
log.output[key] = "*****"
if output and key in output:
output[key] = "*****"

if not log.data:
return
if not data:
continue

if key in log.get("data", {}):
log.data[key] = "*****"
if key in data:
data[key] = "*****"

if key in log.get("data", {}).get("body", {}):
log.data["body"][key] = "*****"
if request_body and key in request_body:
request_body[key] = "*****"


def get_public_ip():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ function is_e_invoice_applicable(frm, show_message = false) {
) {
is_einv_applicable = false;
message_list.push(
"At least one item must be taxable or transaction is categorized as export."
"All items are either Nil-Rated/Exempted/Non-GST. At least one item must be taxable or the transaction should be categorised as export."
);
}

Expand Down
2 changes: 1 addition & 1 deletion india_compliance/gst_india/client_scripts/expense_claim.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ frappe.ui.form.on("Expense Taxes and Charges", {
});

function toggle_gstin_for_expense_claim(frm) {
toggle_company_gstin(frm, taxes_table="taxes", account_field="account_head");
toggle_company_gstin(frm, "taxes", "account_head");
}
2 changes: 1 addition & 1 deletion india_compliance/gst_india/client_scripts/journal_entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ frappe.ui.form.on("Journal Entry Account", {
});

function toggle_gstin_for_journal_entry(frm) {
toggle_company_gstin(frm, taxes_table="accounts", account_head="account");
toggle_company_gstin(frm, "accounts", "account");
}

async function toggle_company_gstin(frm, taxes_table, account_head) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ class TestPurchaseReconciliationTool(FrappeTestCase):
def setUpClass(cls):
super().setUpClass()

# create 2023-2024 fiscal year
fiscal_year = frappe.new_doc("Fiscal Year")
fiscal_year.update(
{
"year_start_date": "2023-04-01",
"year_end_date": "2024-03-31",
"year": "2023-2024",
}
).insert(ignore_if_duplicate=True)

cls.test_data = frappe.get_file_json(
frappe.get_app_path(
"india_compliance",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"aggregate_function_based_on": "",
"color": "#EC864B",
"creation": "2023-07-25 18:33:55.452360",
"docstatus": 0,
"doctype": "Number Card",
Expand All @@ -12,7 +13,7 @@
"is_standard": 1,
"label": "Active e-Invoice, Cancelled Invoice",
"method": "",
"modified": "2024-02-23 11:37:11.634469",
"modified": "2024-04-09 11:46:37.126752",
"modified_by": "Administrator",
"module": "GST India",
"name": "Invoice Cancelled But Not e-Invoice",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"aggregate_function_based_on": "",
"color": "#ECAD4B",
"color": "#EC864B",
"creation": "2023-07-25 15:10:39.976867",
"docstatus": 0,
"doctype": "Number Card",
Expand All @@ -14,7 +14,7 @@
"is_standard": 1,
"label": "Pending e-Invoices",
"method": "",
"modified": "2024-02-23 11:37:43.073988",
"modified": "2024-04-09 11:45:32.550901",
"modified_by": "Administrator",
"module": "GST India",
"name": "Pending e-Invoices",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"aggregate_function_based_on": "",
"color": "#e02f2f",
"color": "#EC864B",
"creation": "2023-08-04 11:30:55.485885",
"docstatus": 0,
"doctype": "Number Card",
Expand All @@ -12,7 +12,7 @@
"is_public": 1,
"is_standard": 1,
"label": "Pending e-Waybills",
"modified": "2023-10-12 17:16:39.286029",
"modified": "2024-04-09 11:46:27.074636",
"modified_by": "Administrator",
"module": "GST India",
"name": "Pending e-Waybill",
Expand Down
75 changes: 75 additions & 0 deletions india_compliance/gst_india/overrides/test_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from frappe.utils import today
from erpnext.accounts.doctype.sales_invoice.sales_invoice import make_sales_return
from erpnext.accounts.party import _get_party_details
from erpnext.controllers.accounts_controller import update_child_qty_rate
from erpnext.stock.doctype.delivery_note.delivery_note import make_sales_invoice

from india_compliance.gst_india.constants import SALES_DOCTYPES
Expand Down Expand Up @@ -905,3 +906,77 @@ def create_tax_accounts(account_name):
**defaults,
}
).insert(ignore_if_duplicate=True)


class TestItemUpdate(FrappeTestCase):
DATA = {
"customer": "_Test Unregistered Customer",
"item_code": "_Test Trading Goods 1",
"qty": 1,
"rate": 100,
"is_in_state": 1,
}

@classmethod
def setUpClass(cls):
super().setUpClass()

def create_order(self, doctype):
self.DATA["doctype"] = doctype
doc = create_transaction(**self.DATA)
return doc

def test_so_and_po_after_item_update(self):
for doctype in ["Sales Order", "Purchase Order"]:
doc = self.create_order(doctype)

self.assertDocumentEqual(
{
"taxable_value": 100,
"cgst_amount": 9,
"sgst_amount": 9,
},
doc.items[0],
)

# Update Item Rate
item = doc.items[0]
item_to_update = [
{
"item_code": item.item_code,
"qty": item.qty,
"rate": 200,
"docname": item.name,
"name": item.name,
"idx": item.idx,
}
]

update_child_qty_rate(doctype, json.dumps(item_to_update), doc.name)
doc = frappe.get_doc(doctype, doc.name)

self.assertDocumentEqual(
{
"taxable_value": 200,
"cgst_amount": 18,
"sgst_amount": 18,
},
doc.items[0],
)

# Insert New Item
item_to_update.append(
{"item_code": "_Test Trading Goods 1", "qty": 1, "rate": 50, "idx": 2}
)

update_child_qty_rate(doctype, json.dumps(item_to_update), doc.name)
doc = frappe.get_doc(doctype, doc.name)

self.assertDocumentEqual(
{
"taxable_value": 50,
"cgst_amount": 4.5,
"sgst_amount": 4.5,
},
doc.items[1],
)
21 changes: 16 additions & 5 deletions india_compliance/gst_india/overrides/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -1433,9 +1433,6 @@ def before_print(doc, method=None, print_settings=None):
):
return

if doc.get("group_same_items"):
ItemGSTDetails().update(doc)

set_gst_breakup(doc)


Expand Down Expand Up @@ -1490,8 +1487,22 @@ def ignore_gst_validations(doc, throw=True):
return True


def before_update_after_submit_item(doc, method=None):
frappe.flags.through_update_item = True
def on_change_item(doc, method=None):
"""
Objective:
Child item is saved before trying to update parent doc.
Hence we can't verify has_value_changed for items in the parent doc.
Solution:
- Set a flag in on_change of item
- Runs for both insert and save (update after submit)
- Set flag only if `ignore_validate_update_after_submit` is set
Reference:
erpnext.controllers.accounts_controller.update_child_qty_rate
"""
if doc.flags.ignore_validate_update_after_submit:
frappe.flags.through_update_item = True


def before_update_after_submit(doc, method=None):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
// Copyright (c) 2024, Resilient Tech and contributors
// For license information, please see license.txt
const INVOICE_TYPE = {
"B2B,SEZ,DE": ["B2B Regular", "B2B Reverse Charge", "SEZWP", "SEZWOP", "Deemed Exports"],
"B2B, SEZ, DE": [
"B2B Regular",
"B2B Reverse Charge",
"SEZWP",
"SEZWOP",
"Deemed Exports",
],
"B2C (Large)": ["B2C (Large)"],
"Exports": ["EXPWP", "EXPWOP"],
Exports: ["EXPWP", "EXPWOP"],
"B2C (Others)": ["B2C (Others)"],
"Nil-Rated,Exempted,Non-GST": ["Nil-Rated", "Exempted", "Non-GST"],
"Nil-Rated, Exempted, Non-GST": ["Nil-Rated", "Exempted", "Non-GST"],
"Credit/Debit Notes (Registered)": ["CDNR"],
"Credit/Debit Notes (Unregistered)": ["CDNUR"],
}
};

frappe.query_reports["GST Sales Register Beta"] = {
onload: set_sub_category_options,

filters: [
{
fieldname: "company",
Expand Down Expand Up @@ -46,42 +53,80 @@ frappe.query_reports["GST Sales Register Beta"] = {
fieldname: "date_range",
label: __("Date Range"),
fieldtype: "DateRange",
default: [india_compliance.last_month_start(), india_compliance.last_month_end()],
width: "80"
default: [
india_compliance.last_month_start(),
india_compliance.last_month_end(),
],
width: "80",
},
{
fieldtype: "Select",
fieldname: "summary_by",
label: __("Summary By"),
options: "Overview\nSummary by HSN\nSummary by Item",
default: "Summary by Item"
default: "Summary by Item",
},
{
fieldtype: "Autocomplete",
fieldname: "invoice_category",
label: __("Invoice Category"),
options: "B2B,SEZ,DE\nB2C (Large)\nExports\nB2C (Others)\nNil-Rated,Exempted,Non-GST\nCredit/Debit Notes (Registered)\nCredit/Debit Notes (Unregistered)",
options:
"B2B, SEZ, DE\nB2C (Large)\nExports\nB2C (Others)\nNil-Rated, Exempted, Non-GST\nCredit/Debit Notes (Registered)\nCredit/Debit Notes (Unregistered)",
on_change(report) {
report.set_filter_value('invoice_sub_category', "");
report.set_filter_value("invoice_sub_category", "");
set_sub_category_options(report);
},
depends_on: 'eval:doc.summary_by=="Summary by HSN" || doc.summary_by=="Summary by Item"'
depends_on:
'eval:doc.summary_by=="Summary by HSN" || doc.summary_by=="Summary by Item"',
},
{
fieldtype: "Autocomplete",
fieldname: "invoice_sub_category",
label: __("Invoice Sub Category"),
depends_on: 'eval:doc.summary_by=="Summary by HSN" || doc.summary_by=="Summary by Item"'
depends_on:
'eval:doc.summary_by=="Summary by HSN" || doc.summary_by=="Summary by Item"',
},
],

formatter: (value, row, column, data, default_formatter) => {
value = default_formatter(value, row, column, data);
if (data && data.indent === 0) {
let $value = $(`<span>${value}</span>`).css("font-weight", "bold");
value = $value.wrap("<p></p>").parent().html();
}
]

return value;
},
};

function set_sub_category_options(report) {
const invoice_category = frappe.query_report.get_filter_value("invoice_category");
report.get_filter('invoice_sub_category').set_data(INVOICE_TYPE[invoice_category] || []);
report
.get_filter("invoice_sub_category")
.set_data(INVOICE_TYPE[invoice_category] || []);

if (invoice_category && INVOICE_TYPE[invoice_category].length === 1) {
report.set_filter_value("invoice_sub_category", INVOICE_TYPE[invoice_category][0])
report.set_filter_value(
"invoice_sub_category",
INVOICE_TYPE[invoice_category][0]
);
}
}

frappe_report_column_total = frappe.utils.report_column_total;

// Override datatable hook for column total calculation
frappe.utils.report_column_total = function (...args) {
const summary_by = frappe.query_report.get_filter_value("summary_by");
if (summary_by !== "Overview") return frappe_report_column_total.apply(this, args);

const column_field = args[1].column.fieldname;
if (column_field === "description") return;

const total = this.datamanager.data.reduce((acc, row) => {
if (row.indent !== 1) acc += row[column_field] || 0;
return acc;
}, 0);

return total;
};
Loading

0 comments on commit 30b5f95

Please sign in to comment.