Skip to content

Commit

Permalink
Merge pull request #2551 from resilient-tech/version-15-hotfix
Browse files Browse the repository at this point in the history
chore: release v15
  • Loading branch information
vorasmit authored Aug 22, 2024
2 parents 7e1ed2d + f91fc8b commit 1a5661a
Show file tree
Hide file tree
Showing 40 changed files with 1,500 additions and 178 deletions.
16 changes: 16 additions & 0 deletions india_compliance/gst_india/api_classes/taxpayer_returns.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import frappe
from frappe import _

from india_compliance.gst_india.api_classes.taxpayer_base import TaxpayerBaseAPI


Expand Down Expand Up @@ -58,6 +61,19 @@ def get_data(self, action, return_period, otp=None):
class GSTR1API(ReturnsAPI):
API_NAME = "GSTR-1"

def setup(self, doc=None, *, company_gstin=None):
if doc:
company_gstin = doc.gstin
self.default_log_values.update(
reference_doctype=doc.doctype,
reference_name=doc.name,
)

if not company_gstin:
frappe.throw(_("Company GSTIN is required to use the GSTR-1 API"))

super().setup(company_gstin=company_gstin)

def get_gstr_1_data(self, action, return_period, otp=None):
return self.get(
action=action,
Expand Down
1 change: 1 addition & 0 deletions india_compliance/gst_india/client_scripts/company.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ validate_gstin(DOCTYPE);
update_gstin_in_other_documents(DOCTYPE);
show_overseas_disabled_warning(DOCTYPE);
set_gstin_options_and_status(DOCTYPE);
set_pan_status(DOCTYPE)

frappe.ui.form.off(DOCTYPE, "make_default_tax_template");
frappe.ui.form.on(DOCTYPE, {
Expand Down
1 change: 1 addition & 0 deletions india_compliance/gst_india/client_scripts/customer.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ update_gstin_in_other_documents(DOCTYPE);
show_overseas_disabled_warning(DOCTYPE);
set_gstin_options_and_status(DOCTYPE);
set_gst_category(DOCTYPE);
set_pan_status(DOCTYPE)
14 changes: 14 additions & 0 deletions india_compliance/gst_india/client_scripts/party.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ function validate_gstin(doctype) {
frm.doc.pan = pan;
frm.refresh_field("pan");
set_party_type(frm);
if(doctype != "Address"){
india_compliance.set_pan_status(frm.get_field("pan"));
}
}
},
});
Expand Down Expand Up @@ -130,6 +133,17 @@ function set_gstin_options_and_status(doctype) {
});
}

function set_pan_status(doctype) {
frappe.ui.form.on(doctype, {
refresh(frm) {
india_compliance.set_pan_status(frm.get_field("pan"));
},
pan(frm) {
india_compliance.set_pan_status(frm.get_field("pan"));
},
});
}

async function set_gstin_options(frm) {
if (frm.is_new() || frm._gstin_options_set_for === frm.doc.name) return;

Expand Down
71 changes: 53 additions & 18 deletions india_compliance/gst_india/client_scripts/stock_entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,35 @@ setup_e_waybill_actions(DOCTYPE);

frappe.ui.form.on(DOCTYPE, {
setup(frm) {
frm.set_query("taxes_and_charges", function () {
return {
filters: [
["disabled", "=", 0],
["company", "=", frm.doc.company],
],
};
frm.set_query("taxes_and_charges", {
filters: [
["disabled", "=", 0],
["company", "=", frm.doc.company],
],
});

frm.set_query("transporter", function () {
return {
filters: [
["disabled", "=", 0],
["is_transporter", "=", 1],
],
};
frm.set_query("transporter", {
filters: [
["disabled", "=", 0],
["is_transporter", "=", 1],
],
});

["ship_from_address", "ship_to_address"].forEach(field => {
frm.set_query(field, function () {
return { filters: { country: "India", disabled: 0 } };
});
frm.set_query(field, { filters: { country: "India", disabled: 0 } });
});

set_address_display_events();

frm.set_query("link_doctype", "doc_references", {
name: ["=", "Stock Entry"],
});

frm.set_query("link_name", "doc_references", function (doc) {
return {
filters: get_filters_for_relevant_stock_entries(doc),
};
});
},

onload(frm) {
Expand All @@ -46,7 +50,7 @@ frappe.ui.form.on(DOCTYPE, {
);
},

refresh(frm) {
refresh() {
if (!gst_settings.enable_e_waybill || !gst_settings.enable_e_waybill_for_sc)
return;

Expand Down Expand Up @@ -112,6 +116,24 @@ frappe.ui.form.on(DOCTYPE, {
taxes_and_charges(frm) {
frm.taxes_controller.update_taxes(frm);
},

async fetch_original_doc_ref(frm) {
let existing_references = frm.doc.doc_references.map(row => row.link_name);

data = await frappe.db.get_list(DOCTYPE, {
filters: get_filters_for_relevant_stock_entries(frm.doc),
group_by: "name",
});

data.forEach(doc => {
if (existing_references.includes(doc.name)) return;
var row = frm.add_child("doc_references");
row.link_doctype = DOCTYPE;
row.link_name = doc.name;
});

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

function set_address_display_events() {
Expand Down Expand Up @@ -155,3 +177,16 @@ function on_change_set_address(frm, source_field, target_field, label1, label2)
}

frappe.ui.form.on("Stock Entry Detail", india_compliance.taxes_controller_events);

function get_filters_for_relevant_stock_entries(doc) {
return [
["docstatus", "=", 1],
["purpose", "=", "Send to Subcontractor"],
["subcontracting_order", "=", doc.subcontracting_order],
["Stock Entry Detail", "item_code", "in", get_items(doc)],
];
}

function get_items(doc) {
return Array.from(new Set(doc.items.map(row => row.item_code)));
}
135 changes: 115 additions & 20 deletions india_compliance/gst_india/client_scripts/subcontracting_receipt.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,70 @@
setup_e_waybill_actions("Subcontracting Receipt");
DOCTYPE = "Subcontracting Receipt";
setup_e_waybill_actions(DOCTYPE);

frappe.ui.form.on("Subcontracting Receipt", {
frappe.ui.form.on(DOCTYPE, {
setup(frm) {
frm.set_query("taxes_and_charges", function () {
return {
filters: [
["disabled", "=", 0],
["company", "=", frm.doc.company],
],
};
frm.set_query("taxes_and_charges", {
filters: [
["disabled", "=", 0],
["company", "=", frm.doc.company],
],
});

frm.set_query("transporter", function () {
return {
filters: [
["disabled", "=", 0],
["is_transporter", "=", 1],
],
};
frm.set_query("transporter", {
filters: [
["disabled", "=", 0],
["is_transporter", "=", 1],
],
});

["supplier_address", "shipping_address"].forEach(field => {
frm.set_query(field, function () {
return { filters: { country: "India", disabled: 0 } };
});
frm.set_query(field, { filters: { country: "India", disabled: 0 } });
});

frm.set_query("link_doctype", "doc_references", {
filters: {
name: ["in", ["Subcontracting Receipt", "Stock Entry"]],
},
});

frm.set_query("link_name", "doc_references", function (doc, cdt, cdn) {
const row = locals[cdt][cdn];
const subcontracting_orders = get_subcontracting_orders(doc);

// same as backend query in get_relevant_references
if (row.link_doctype == "Stock Entry") {
const supplied_items = get_supplied_items(doc);
return {
filters: [
["docstatus", "=", 1],
["purpose", "=", "Send to Subcontractor"],
["subcontracting_order", "in", subcontracting_orders],
["supplier", "=", doc.supplier],
["Stock Entry Detail", "item_code", "in", supplied_items],
],
};
} else if (row.link_doctype == "Subcontracting Receipt") {
const received_items = get_received_items(doc);
return {
filters: [
["docstatus", "=", 1],
["is_return", "=", 1],
["supplier", "=", doc.supplier],
[
"Subcontracting Receipt Item",
"item_code",
"in",
received_items,
],
[
"Subcontracting Receipt Item",
"subcontracting_order",
"in",
subcontracting_orders,
],
],
};
}
});
},
onload(frm) {
Expand All @@ -32,9 +73,10 @@ frappe.ui.form.on("Subcontracting Receipt", {
});
},

refresh(frm) {
refresh() {
if (!gst_settings.enable_e_waybill || !gst_settings.enable_e_waybill_for_sc)
return;

show_sandbox_mode_indicator();
},

Expand All @@ -49,6 +91,35 @@ frappe.ui.form.on("Subcontracting Receipt", {
);
},

fetch_original_doc_ref(frm) {
let existing_references = get_existing_references(frm);

frappe.call({
method: "india_compliance.gst_india.overrides.subcontracting_transaction.get_relevant_references",
args: {
supplier: frm.doc.supplier,
supplied_items: get_supplied_items(frm.doc),
received_items: get_received_items(frm.doc),
subcontracting_orders: get_subcontracting_orders(frm.doc),
},
callback: function (r) {
if (!r.message) return;

Object.entries(r.message).forEach(([doctype, docnames]) => {
docnames.forEach(docname => {
if (existing_references[doctype]?.includes(docname)) return;

let row = frm.add_child("doc_references");
row.link_doctype = doctype;
row.link_name = docname;
});
});

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

taxes_and_charges(frm) {
frm.taxes_controller.update_taxes(frm);
},
Expand All @@ -58,3 +129,27 @@ frappe.ui.form.on(
"Subcontracting Receipt Item",
india_compliance.taxes_controller_events
);

function get_existing_references(frm) {
let existing_references = {};

frm.doc.doc_references.forEach(row => {
if (!existing_references[row.link_doctype])
existing_references[row.link_doctype] = [];
existing_references[row.link_doctype].push(row.link_name);
});

return existing_references;
}

function get_supplied_items(doc) {
return Array.from(new Set(doc.supplied_items.map(row => row.rm_item_code)));
}

function get_received_items(doc) {
return Array.from(new Set(doc.items.map(row => row.item_code)));
}

function get_subcontracting_orders(doc) {
return Array.from(new Set(doc.items.map(row => row.subcontracting_order)));
}
1 change: 1 addition & 0 deletions india_compliance/gst_india/client_scripts/supplier.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ update_gstin_in_other_documents(DOCTYPE);
show_overseas_disabled_warning(DOCTYPE);
set_gstin_options_and_status(DOCTYPE);
set_gst_category(DOCTYPE);
set_pan_status(DOCTYPE)

frappe.ui.form.on(DOCTYPE, {
gstin(frm) {
Expand Down
Loading

0 comments on commit 1a5661a

Please sign in to comment.