Skip to content

Commit

Permalink
Merge pull request #1449 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 Dec 22, 2023
2 parents c6da85d + a344e37 commit 772ef17
Show file tree
Hide file tree
Showing 41 changed files with 2,207 additions and 173 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand All @@ -56,4 +56,4 @@ jobs:
# queries: ./path/to/local/query, your-org/your-repo/queries@main

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
uses: github/codeql-action/analyze@v3
4 changes: 2 additions & 2 deletions .github/workflows/server-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ jobs:
run: cat ~/frappe-bench/bench_start.log || true

- name: Upload coverage data
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: coverage
path: /home/runner/frappe-bench/sites/coverage.xml
Expand All @@ -120,7 +120,7 @@ jobs:
uses: actions/checkout@v4

- name: Download artifacts
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4

- name: Upload coverage data
uses: codecov/codecov-action@v3
Expand Down
10 changes: 10 additions & 0 deletions india_compliance/boot.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def set_bootinfo(bootinfo):
bootinfo["ic_api_enabled_from_conf"] = bool(frappe.conf.ic_api_secret)

set_trigger_for_audit_trail_notification(bootinfo)
set_trigger_for_item_tax_template_notification(bootinfo)


def set_trigger_for_audit_trail_notification(bootinfo):
Expand All @@ -39,3 +40,12 @@ def set_trigger_for_audit_trail_notification(bootinfo):
return

bootinfo["needs_audit_trail_notification"] = True


def set_trigger_for_item_tax_template_notification(bootinfo):
if not bootinfo.sysdefaults or not cint(
bootinfo.sysdefaults.get("needs_item_tax_template_notification", 0)
):
return

bootinfo["needs_item_tax_template_notification"] = True
10 changes: 7 additions & 3 deletions india_compliance/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
class GatewayTimeoutError(Exception):
class GSPServerError(Exception):
def __init__(self, message="GSP/GST server is down", *args, **kwargs):
super().__init__(message, *args, **kwargs)


class GatewayTimeoutError(GSPServerError):
def __init__(self, message="The server took too long to respond", *args, **kwargs):
self.message = message
super().__init__(self.message, *args, **kwargs)
super().__init__(message, *args, **kwargs)
17 changes: 16 additions & 1 deletion india_compliance/gst_india/api_classes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from frappe import _
from frappe.utils import sbool

from india_compliance.exceptions import GatewayTimeoutError
from india_compliance.exceptions import GatewayTimeoutError, GSPServerError
from india_compliance.gst_india.utils import is_api_enabled
from india_compliance.gst_india.utils.api import enqueue_integration_request

Expand Down Expand Up @@ -187,6 +187,9 @@ def handle_error_response(self, response_json):
if isinstance(success_value, str):
success_value = sbool(success_value)

if not success_value:
self.handle_server_error(response_json)

if not success_value and not self.is_ignored_error(response_json):
frappe.throw(
response_json.get("message")
Expand All @@ -195,6 +198,18 @@ def handle_error_response(self, response_json):
title=_("API Request Failed"),
)

def handle_server_error(self, response_json):
error_message_list = [
"GSPGSTDOWN",
"GSPERR300",
"Connection reset",
"No route to host",
]

for error in error_message_list:
if error in response_json.get("message"):
raise GSPServerError

def is_ignored_error(self, response_json):
# Override in subclass, return truthy value to stop frappe.throw
pass
Expand Down
2 changes: 1 addition & 1 deletion india_compliance/gst_india/client_scripts/company.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ frappe.ui.form.on(DOCTYPE, {

frappe.call({
method: "india_compliance.gst_india.overrides.company.make_default_tax_templates",
args: { company: frm.doc.name },
args: { company: frm.doc.name, gst_rate: frm.doc.default_gst_rate},
callback: function () {
frappe.msgprint(__("Default Tax Templates created"));
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,9 @@ function is_e_invoice_applicable(frm) {
frm.doc.company_gstin != frm.doc.billing_address_gstin &&
(frm.doc.place_of_supply === "96-Other Countries" ||
frm.doc.billing_address_gstin) &&
!frm.doc.items[0].is_non_gst &&
frm.doc.items.some(item =>
["Taxable", "Zero-Rated"].includes(item.gst_treatment)
) &&
is_valid_e_invoice_applicability_date(frm)
);
}
Expand Down
95 changes: 95 additions & 0 deletions india_compliance/gst_india/client_scripts/item_tax_template.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
frappe.ui.form.on("Item Tax Template", {
refresh: show_missing_accounts_banner,
fetch_gst_accounts: fetch_and_update_missing_gst_accounts,
async gst_rate(frm) {
if (frm.doc.gst_rate === null) return;

await Promise.all(
frm.doc.taxes.map(async row => {
const tax_rate = await get_tax_rate_for_account(frm, row.tax_type);
if (tax_rate == null) return;

row.tax_rate = tax_rate;
})
);

frm.refresh_field("taxes");
},
});

async function show_missing_accounts_banner(frm) {
if (frm.doc.gst_treatment === "Non-GST" || frm.doc.__islocal) return;

const missing_accounts = await get_missing_gst_accounts(frm);
if (!missing_accounts) return;

// show banner
frm.dashboard.add_comment(
__(`<strong>Missing GST Accounts:</strong> {0}`, [missing_accounts.join(", ")]),
"orange",
true
);
}

async function fetch_and_update_missing_gst_accounts(frm) {
const missing_accounts = await get_missing_gst_accounts(frm);
if (!missing_accounts) return;

// cleanup existing empty rows
frm.doc.taxes = frm.doc.taxes.filter(row => row.tax_type);

// add missing rows
await Promise.all(
missing_accounts.map(async account => {
const tax_rate = await get_tax_rate_for_account(frm, account);
frm.add_child("taxes", { tax_type: account, tax_rate: tax_rate });
})
);

frm.refresh_field("taxes");
}

async function get_tax_rate_for_account(frm, account) {
const gst_rate = frm.doc.gst_rate;
if (!gst_rate) return 0;

const gst_accounts = await get_gst_accounts(frm);
if (!gst_accounts) return null;

const [_, intra_state_accounts, inter_state_accounts] = gst_accounts;

if (intra_state_accounts.includes(account)) return gst_rate / 2;
else if (inter_state_accounts.includes(account)) return gst_rate;
else return null;
}

async function get_missing_gst_accounts(frm) {
let gst_accounts = await get_gst_accounts(frm);
if (!gst_accounts) return;

const all_gst_accounts = gst_accounts[0];
const template_accounts = frm.doc.taxes.map(t => t.tax_type);
const missing_accounts = all_gst_accounts.filter(
a => a && !template_accounts.includes(a)
);

if (missing_accounts.length) return missing_accounts;
}

async function get_gst_accounts(frm) {
const company = frm.doc.company;

// cache company gst accounts
if (!frm._company_gst_accounts?.[company]) {
frm._company_gst_accounts = frm._company_gst_accounts || {};
const { message } = await frappe.call({
method: "india_compliance.gst_india.overrides.transaction.get_valid_gst_accounts",
args: { company: company },
});

frm._company_gst_accounts[company] = message;
}

if (!frm._company_gst_accounts[company]) return;
return frm._company_gst_accounts[company];
}
7 changes: 5 additions & 2 deletions india_compliance/gst_india/client_scripts/sales_invoice.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,11 @@ function is_gst_invoice(frm) {
frm.doc.is_opening != "Yes" &&
frm.doc.company_gstin &&
frm.doc.company_gstin != frm.doc.billing_address_gstin &&
!frm.doc.items.some(item => item.is_non_gst) &&
!frm.doc.items.every(item => item.is_nil_exempt);
!frm.doc.items.some(item => item.gst_treatment == "Non-GST") &&
!frm.doc.items.every(
item =>
item.gst_treatment == "Nil-Rated" || item.gst_treatment == "Exempted"
);

if (frm.doc.place_of_supply === "96-Other Countries") {
return gst_invoice_conditions && frm.doc.is_export_with_gst;
Expand Down
Loading

0 comments on commit 772ef17

Please sign in to comment.