Skip to content

Commit

Permalink
fix: Extended E-Way Bill Support for Stock Entry (resilient-tech#2594)
Browse files Browse the repository at this point in the history
Co-authored-by: Smit Vora <[email protected]>
  • Loading branch information
Ninad1306 and vorasmit authored Nov 13, 2024
1 parent 18a5651 commit 13be533
Show file tree
Hide file tree
Showing 13 changed files with 382 additions and 74 deletions.
53 changes: 39 additions & 14 deletions india_compliance/gst_india/client_scripts/e_waybill_actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,9 @@ function show_generate_e_waybill_dialog(frm) {
api_enabled && frm.doc.doctype ? __("Download JSON") : null,
secondary_action: api_enabled
? () => {
d.hide();
json_action(d.get_values());
}
d.hide();
json_action(d.get_values());
}
: null,
},
frm
Expand Down Expand Up @@ -535,6 +535,29 @@ function get_sub_suppy_type_options(frm) {
sub_supply_type = ["Job Work", "SKD/CKD", "Others"];
}
}
} else if (frm.doctype === "Stock Entry") {
document_type = "Delivery Challan";

if (frm.doc.purpose === "Send to Subcontractor") {
supply_type = "Outward";
sub_supply_type = ["Job Work"];
} else if (["Material Transfer", "Material Issue"].includes(frm.doc.purpose)) {
const same_gstin = frm.doc.bill_from_gstin === frm.doc.bill_to_gstin;

if (frm.doc.is_return) {
supply_type = "Inward";
sub_supply_type = ["Job Work Returns"];
} else if (same_gstin) {
supply_type = "Outward";
sub_supply_type = [
"For Own Use",
"Exhibition or Fairs",
"Line Sales",
"Recipient Not Known",
"Others",
];
}
}
} else {
const key = `${frm.doctype}_${frm.doc.is_return || 0}`;
const default_supply_types = {
Expand Down Expand Up @@ -570,11 +593,6 @@ function get_sub_suppy_type_options(frm) {
sub_supply_desc: "Purchase Return",
document_type: "Delivery Challan",
},
"Stock Entry_0": {
supply_type: "Outward",
sub_supply_type: ["Job Work"],
document_type: "Delivery Challan",
},
"Subcontracting Receipt_0": {
supply_type: "Inward",
sub_supply_type: ["Job Work Returns"],
Expand All @@ -587,7 +605,7 @@ function get_sub_suppy_type_options(frm) {
},
};

return default_supply_types[key]
return default_supply_types[key];
}

return { supply_type, sub_supply_type, sub_supply_desc, document_type };
Expand Down Expand Up @@ -906,7 +924,7 @@ function show_update_transporter_dialog(frm) {
reqd: 1,
default:
frm.doc.gst_transporter_id &&
frm.doc.gst_transporter_id.length === 15
frm.doc.gst_transporter_id.length === 15
? frm.doc.gst_transporter_id
: "",
onchange: () => validate_gst_transporter_id(d),
Expand Down Expand Up @@ -1187,6 +1205,10 @@ function has_e_waybill_threshold_met(frm) {
return true;
}
function is_e_waybill_applicable(frm, show_message) {
/**
* Defines supported conditions where e-Waybill is applicable
* and it's generation is supported.
*/
return new E_WAYBILL_CLASS[frm.doctype](frm).is_e_waybill_applicable(show_message);
}

Expand All @@ -1195,6 +1217,9 @@ function is_e_waybill_api_enabled(frm) {
}

function is_e_waybill_generatable(frm, show_message) {
/**
* Checks if all information required to generate e-Waybill is available.
*/
return new E_WAYBILL_CLASS[frm.doctype](frm).is_e_waybill_generatable(show_message);
}

Expand Down Expand Up @@ -1383,11 +1408,11 @@ function show_sandbox_mode_indicator() {
`
<div class="sidebar-menu ic-sandbox-mode">
<p><label class="indicator-pill no-indicator-dot yellow" title="${__(
"Your site has enabled Sandbox Mode in GST Settings."
)}">${__("Sandbox Mode")}</label></p>
"Your site has enabled Sandbox Mode in GST Settings."
)}">${__("Sandbox Mode")}</label></p>
<p><a class="small text-muted" href="/app/gst-settings" target="_blank">${__(
"Sandbox Mode is enabled for GST APIs."
)}</a></p>
"Sandbox Mode is enabled for GST APIs."
)}</a></p>
</div>
`
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,20 +243,45 @@ class StockEntryEwaybill extends EwaybillApplicability {
if (
!gst_settings.enable_e_waybill ||
!gst_settings.enable_e_waybill_for_sc ||
this.frm.doc.purpose !== "Send to Subcontractor"
!["Material Transfer", "Material Issue", "Send to Subcontractor"].includes(
this.frm.doc.purpose
)
)
return false;

let is_ewb_applicable = true;
let message_list = [];
const is_return = this.frm.doc.is_return;

if (!this.frm.doc.bill_from_gstin) {
if (is_return && !this.frm.doc.bill_from_gstin) {
is_ewb_applicable = false;
message_list.push(
"Bill From GSTIN is not set. Ensure its set in Bill From Address."
);
}

if (!is_return && !this.frm.doc.bill_to_gstin) {
is_ewb_applicable = false;
message_list.push(
"Bill To GSTIN is not set. Ensure its set in Bill To Address."
);
}

const same_gstin = this.frm.doc.bill_from_gstin === this.frm.doc.bill_to_gstin;
const applicable_for_same_gstin = !(
is_return || this.frm.doc.purpose === "Send to Subcontractor"
);

if (same_gstin && !applicable_for_same_gstin) {
is_ewb_applicable = false;
message_list.push("Bill From GSTIN and Bill To GSTIN are same.");
}

if (!same_gstin && applicable_for_same_gstin) {
is_ewb_applicable = false;
message_list.push("Bill From GSTIN and Bill To GSTIN are different.");
}

if (this.frm.doc.is_opening === "Yes") {
is_ewb_applicable = false;
message_list.push(
Expand Down Expand Up @@ -288,11 +313,6 @@ class StockEntryEwaybill extends EwaybillApplicability {
message_list.push("Bill To address is mandatory to generate e-Waybill.");
}

if (this.frm.doc.bill_from_gstin === this.frm.doc.bill_to_gstin) {
is_ewb_generatable = false;
message_list.push("Bill From GSTIN and Bill To GSTIN are same.");
}

if (show_message) {
this.frm._ewb_message += message_list
.map(message => `<li>${message}</li>`)
Expand All @@ -304,7 +324,9 @@ class StockEntryEwaybill extends EwaybillApplicability {

is_e_waybill_api_enabled() {
return (
this.frm.doc.purpose == "Send to Subcontractor" &&
["Material Transfer", "Material Issue", "Send to Subcontractor"].includes(
this.frm.doc.purpose
) &&
super.is_e_waybill_api_enabled() &&
gst_settings.enable_e_waybill_for_sc
);
Expand Down
37 changes: 32 additions & 5 deletions india_compliance/gst_india/client_scripts/stock_entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ frappe.ui.form.on(DOCTYPE, {
},
};
});

// No event trigger are called when form is new
if (frm.is_new()) {
frm.trigger("bill_to_address");
}
},

onload(frm) {
Expand All @@ -49,8 +54,7 @@ frappe.ui.form.on(DOCTYPE, {
on_change_set_address(
frm,
"supplier_address",
"bill_to_address",
__("Bill To (same as Supplier Address)"),
...get_field_and_label(frm, "party_field"),
__("Bill To")
);

Expand Down Expand Up @@ -89,8 +93,7 @@ frappe.ui.form.on(DOCTYPE, {
on_change_set_address(
frm,
"supplier_address",
"bill_to_address",
__("Bill To (same as Supplier Address)"),
...get_field_and_label(frm, "party_field"),
__("Bill To")
);
},
Expand Down Expand Up @@ -124,7 +127,10 @@ frappe.ui.form.on(DOCTYPE, {
name: frm.doc.company,
},
callback(r) {
frm.set_value("bill_from_address", r.message);
frm.set_value(
get_field_and_label(frm, "company_field")[0],
r.message
);
},
});
}
Expand Down Expand Up @@ -207,3 +213,24 @@ function get_filters_for_relevant_stock_entries(doc) {
function get_items(doc) {
return Array.from(new Set(doc.items.map(row => row.item_code)));
}

function get_field_and_label(frm, field) {
let field_label_dict = {};

if (frm.doc.purpose === "Material Transfer" && frm.doc.is_return) {
field_label_dict = {
party_field: [
"bill_from_address",
__("Bill From (same as Supplier Address)"),
],
company_field: ["bill_to_address", __("Bill To")],
};
} else {
field_label_dict = {
party_field: ["bill_to_address", __("Bill To (same as Supplier Address)")],
company_field: ["bill_from_address", __("Bill From")],
};
}

return field_label_dict[field];
}
9 changes: 5 additions & 4 deletions india_compliance/gst_india/constants/custom_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@
"label": "Taxes",
"fieldtype": "Section Break",
"insert_after": "total",
"depends_on": "purchase_order",
"hide_border": 1,
"depends_on": "eval: doc.purchase_order && india_compliance.is_e_waybill_generatable_for_subcontracting(doc)",
},
],
"Subcontracting Receipt": [
Expand All @@ -66,6 +66,7 @@
"fieldtype": "Section Break",
"insert_after": "total",
"hide_border": 1,
"depends_on": "eval: india_compliance.is_e_waybill_generatable_for_subcontracting(doc)",
},
{
"fieldname": "section_break_ref_doc",
Expand Down Expand Up @@ -181,14 +182,14 @@
"label": "Taxes",
"fieldtype": "Section Break",
"insert_after": "get_stock_and_rate",
"depends_on": "eval:doc.subcontracting_order",
"depends_on": "eval: india_compliance.is_e_waybill_generatable_for_subcontracting(doc)",
},
{
"label": "E-Waybill Info",
"fieldname": "tab_break_ewaybill",
"fieldtype": "Tab Break",
"insert_after": "address_display",
"depends_on": "eval:doc.purpose === 'Send to Subcontractor'",
"depends_on": "eval: india_compliance.is_e_waybill_generatable_for_subcontracting(doc)",
},
{
"label": "e-Waybill Address",
Expand Down Expand Up @@ -341,7 +342,7 @@
"label": "References",
"fieldtype": "Section Break",
"insert_after": "value_difference",
"depends_on": "eval:doc.purpose === 'Material Transfer' && doc.subcontracting_order",
"depends_on": "eval:doc.purpose === 'Material Transfer' && doc.is_return",
},
{
"fieldname": "fetch_original_doc_ref",
Expand Down
88 changes: 88 additions & 0 deletions india_compliance/gst_india/data/test_e_waybill.json
Original file line number Diff line number Diff line change
Expand Up @@ -1164,5 +1164,93 @@
},
"success": true
}
},
"stock_entry_with_same_gstin": {
"kwargs": {
"stock_entry_type": "Material Transfer",
"purpose": "Material Transfer",
"bill_from_address": "_Test Indian Registered Company-Billing",
"bill_to_address": "_Test Indian Registered Company-Billing",
"items":
[{
"item_code": "_Test Trading Goods 1",
"qty": 1,
"gst_hsn_code": "61149090",
"s_warehouse": "Finished Goods - _TIRC",
"t_warehouse": "Goods In Transit - _TIRC",
"amount": 100,
"taxable_value": 100
}],
"company": "_Test Indian Registered Company",
"base_grand_total": 100
},
"values": {
"distance": 0.0,
"mode_of_transport": "Road",
"vehicle_no": "GJ07DL9009",
"sub_supply_type": "Job Work"
},
"request_data": {
"userGstin": "05AAACG2115R1ZN",
"supplyType": "O",
"subSupplyType": 4,
"docType": "CHL",
"docNo": "test_invoice_no",
"docDate": "19/07/2024",
"transactionType": 1,
"fromTrdName": "_Test Indian Registered Company",
"fromGstin": "05AAACG2115R1ZN",
"fromAddr1": "Test Address - 1",
"fromPlace": "Test City",
"fromPincode": 380015,
"fromStateCode": 24,
"actFromStateCode": 24,
"itemList": [
{
"itemNo": 1,
"productDesc": "Test Trading Goods 1",
"hsnCode": "61149090",
"qtyUnit": "NOS",
"quantity": 1.0,
"taxableAmount": 100.0,
"sgstRate": 0.0,
"cgstRate": 0.0,
"igstRate": 0.0,
"cessRate": 0.0,
"cessNonAdvol": 0.0
}
],
"totalValue": 100.0,
"cgstValue": 0,
"sgstValue": 0,
"igstValue": 0,
"cessValue": 0,
"cessNonAdvolValue": 0,
"otherValue": 0.0,
"totInvValue": 100.0,
"toTrdName": "Test Indian Registered Company",
"toGstin": "05AAACG2115R1ZN",
"toAddr1": "Test Address - 1",
"toPlace": "Test City",
"toPincode": 380015,
"toStateCode": 24,
"actToStateCode": 24,
"transMode": 1,
"transDistance": 1,
"vehicleNo": "GJ07DL9009",
"mainHsnCode": "61149090",
"vehicleType": "R"
},
"params": "action=GENEWAYBILL",
"response_data": {
"message": "E-Way Bill is generated successfully",
"result": {
"alert": "",
"ewayBillDate": "08/08/2023 03:30:00 PM",
"ewayBillNo": 341003383265,
"validUpto": "09/08/2023 11:59:00 PM"
},
"success": true
}
}
}
Loading

0 comments on commit 13be533

Please sign in to comment.