Skip to content

Commit

Permalink
feat: E-WayBill for Subcontracting (#2210)
Browse files Browse the repository at this point in the history
* fix: options for child_doctype not ending with Item

* fix: custom fields and overrides for tax related fields in stock entry

* fix: custom fields and overrides for tax related fields in subcontracting receipt

* fix: custom fields and overrides for tax related fields in subcontracting order

* fix: doctypes to be treated as sales_doctype

* fix: redundant functionality

* feat: e-waybill setup in stock entry

* feat: e-waybill setup in subcontracting receipt

* feat: e-waybill setup in subcontracting order

* fix: required changes for e-waybill setup

* fix: minor fix

* test: test case to validate e-waybill generation in stock entry

* fix: updated doctypes for e-waybill generation

* fix: field renaming

* fix: e-waybill functionality not required in subcontracting order

* fix: constant for subcontracting doctypes

* fix: different function for subcontracting doctypes

* fix: minor fix

* fix: custom field refactor

* fix: use stock_entry_purpose

* fix: invalid hooks

* fix: consistent with items table

* fix: company gstin fetched from company

* fix: change in transporter fields

* fix: common class for tax calculation

* fix: new class for taxes controller

* fix: common functions for doctype events

* fix: taxes in subcontracting receipt dosen't depend on purchase_order

* fix: module for backend validations

* fix: changes related to e-waybill

* fix: minor fixes

* fix: grand total field added and client-side events

* refactor: improved readability

* fix: validate same gstin

* fix: change in fieldname

* fix: changes related to address for e-waybill

* fix: query for taxes and charges

* fix: changes as per review

* fix: update patch for custom field creation

* fix: linters

* fix: Merge branch 'develop' of github.com:resilient-tech/india-compliance into e-way_bill_for_subcontracting

* fix: set item wise tax rates

* refactor: remove code duplicacy

* fix: fields not at item level in some doctypes

* fix: updated test records

* fix: skip validation for subcontracting doctypes

* fix: rename taxes table

* fix: changes to support gst tax type

* refactor: modular implementation

* fix: fields reordering

* fix: modular implementation for consistency with BOE

* fix: taxes not calculated properly

* fix: field_map should be instance variable and update tax_amount properly

* fix: override doctype class not to be used

* fix: commonify subcontracting overrides

* refactor: taxes controller, similar for frontend and backend

* chore: move item events in respective client script files

* fix: gst_tax_type not set in taxes table

* fix: use grand total field as rounding not done

* fix: redundant field

* fix: e_waybill fields for subcontracting order not required

* fix: update doc from server_side

* fix: changes to taxes controller as per review

* fix: error message, formatting, correct query for subcontracting e-Waybill

* fix: extensible address fields for stock entry and related changes

* fix: minor fix

* fix: set bill_from_address value when company changes

* fix: address displays should be virtual field

* fix: review and make fixes for property setters and fields

* fix: changes as per review

* fix: changes as per reivew in JS

* fix: changes to transaction validation as per review

* fix: style for text_editor

* fix: update all address fields

* fix: fields mapping for modular implementation

* fix: update gst details on change of supplier

* fix: minor fixes for e-waybill generation

* fix: fetch party details on change of supplier

* fix: load tax details correctly in subcontracting transactions

* fix: changes to validate subcontracting transaction

* fix: use correct gst category for stock entry

* fix: changes as per review with testing

* test: fix failing test cases

* fix: dashboard links related to e-Waybill

* fix: updated test records of e-Waybill for stock entry

* test: better error messages and ensure test cases pass

---------

Co-authored-by: ljain112 <ljain112@gmail.com>
Co-authored-by: Smit Vora <smitvora203@gmail.com>
(cherry picked from commit 48ca23d)

# Conflicts:
#	india_compliance/gst_india/doctype/e_waybill_log/e_waybill_log.json
#	india_compliance/gst_india/utils/e_waybill.py
  • Loading branch information
Ninad1306 authored and mergify[bot] committed Jul 18, 2024
1 parent c7a7753 commit 57a0474
Show file tree
Hide file tree
Showing 29 changed files with 2,274 additions and 177 deletions.
79 changes: 50 additions & 29 deletions india_compliance/gst_india/client_scripts/e_waybill_actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ const E_WAYBILL_CLASS = {
"Purchase Invoice": PurchaseInvoiceEwaybill,
"Delivery Note": DeliveryNoteEwaybill,
"Purchase Receipt": PurchaseReceiptEwaybill,
"Stock Entry": StockEntryEwaybill,
"Subcontracting Receipt": SubcontractingReceiptEwaybill,
};

function setup_e_waybill_actions(doctype) {
Expand Down Expand Up @@ -286,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 @@ -375,7 +377,6 @@ function get_generate_e_waybill_dialog(opts, frm) {
? frm.doc.gst_transporter_id
: "",
onchange: () => validate_gst_transporter_id(d),

},
// Sub Supply Type will be visible here for Delivery Note
{
Expand Down Expand Up @@ -431,36 +432,17 @@ function get_generate_e_waybill_dialog(opts, frm) {
},
];

if (frm.doctype === "Delivery Note") {
const same_gstin = frm.doc.billing_address_gstin == frm.doc.company_gstin;
let options;

if (frm.doc.is_return) {
if (same_gstin) {
options = ["For Own Use", "Exhibition or Fairs"];
} else {
options = ["Job Work Returns", "SKD/CKD"];
}
} else {
if (same_gstin) {
options = [
"For Own Use",
"Exhibition or Fairs",
"Line Sales",
"Recipient Not Known",
];
} else {
options = ["Job Work", "SKD/CKD"];
}
}
options = get_sub_suppy_type_options(frm);

if (options) {
// Inserted at the end of Part A section
fields.splice(5, 0, {
label: "Sub Supply Type",
fieldname: "sub_supply_type",
fieldtype: "Select",
options: options.join("\n"),
default: options[0],
read_only: options.length === 1,
reqd: 1,
});
}
Expand Down Expand Up @@ -498,6 +480,43 @@ function get_generate_e_waybill_dialog(opts, frm) {
return d;
}

function get_sub_suppy_type_options(frm) {
let options;

if (frm.doctype === "Delivery Note") {
const same_gstin = frm.doc.billing_address_gstin == frm.doc.company_gstin;

if (frm.doc.is_return) {
if (same_gstin) {
options = ["For Own Use", "Exhibition or Fairs"];
} else {
options = ["Job Work Returns", "SKD/CKD"];
}
} else {
if (same_gstin) {
options = [
"For Own Use",
"Exhibition or Fairs",
"Line Sales",
"Recipient Not Known",
];
} else {
options = ["Job Work", "SKD/CKD"];
}
}
} else if (frm.doctype === "Stock Entry") {
options = ["Job Work"];
} else if (frm.doctype === "Subcontracting Receipt") {
if (frm.doc.is_return) {
options = ["Job Work"];
} else {
options = ["Job Work Returns"];
}
}

return options;
}

function show_fetch_if_generated_dialog(frm) {
const d = new frappe.ui.Dialog({
title: __("Fetch e-Waybill"),
Expand Down Expand Up @@ -811,7 +830,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 @@ -1022,7 +1041,7 @@ async function show_extend_validity_dialog(frm) {
},
callback: () => frm.refresh(),
});
d.hide();
if (can_extend_now) d.hide();
},
});
if (!can_extend_now) {
Expand Down Expand Up @@ -1162,7 +1181,9 @@ async function update_gst_tranporter_id(dialog) {
}

function validate_gst_transporter_id(dialog) {
india_compliance.validate_gst_transporter_id(dialog.get_value("gst_transporter_id"));
india_compliance.validate_gst_transporter_id(
dialog.get_value("gst_transporter_id")
);
}

function update_generation_dialog(dialog, doc) {
Expand Down
127 changes: 120 additions & 7 deletions india_compliance/gst_india/client_scripts/e_waybill_applicability.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@ class EwaybillApplicability {
}

// at least one item is not a service
is_ewb_applicable = this.has_goods_item(is_ewb_applicable, message_list);

this.frm._ewb_message = "";
if (show_message) {
this.frm._ewb_message = message_list
.map(message => `<li>${message}</li>`)
.join("");
}

return is_ewb_applicable;
}

has_goods_item(is_ewb_applicable, message_list) {
let has_goods_item = false;
for (const item of this.frm.doc.items) {
if (
Expand All @@ -41,13 +54,6 @@ class EwaybillApplicability {
message_list.push("All items are service items (HSN code starts with 99).");
}

this.frm._ewb_message = "";
if (show_message) {
this.frm._ewb_message = message_list
.map(message => `<li>${message}</li>`)
.join("");
}

return is_ewb_applicable;
}

Expand Down Expand Up @@ -232,3 +238,110 @@ class DeliveryNoteEwaybill extends EwaybillApplicability {
);
}
}

class StockEntryEwaybill extends EwaybillApplicability {
is_e_waybill_applicable(show_message = false) {
if (
!gst_settings.enable_e_waybill ||
!gst_settings.enable_e_waybill_for_sc ||
this.frm.doc.purpose !== "Send to Subcontractor"
)
return false;

let is_ewb_applicable = true;
let message_list = [];

if (!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 (this.frm.doc.is_opening === "Yes") {
is_ewb_applicable = false;
message_list.push(
"e-Waybill cannot be generated for transaction with 'Is Opening Entry' set to Yes."
);
}

// at least one item is not a service
is_ewb_applicable = this.has_goods_item(is_ewb_applicable, message_list);

this.frm._ewb_message = "";

if (show_message) {
this.frm._ewb_message = message_list
.map(message => `<li>${message}</li>`)
.join("");
}

return is_ewb_applicable;
}

is_e_waybill_generatable(show_message = false) {
let is_ewb_generatable = this.is_e_waybill_applicable(show_message);

let message_list = [];

if (!this.frm.doc.bill_to_address) {
is_ewb_generatable = false;
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>`)
.join("");
}

return is_ewb_generatable;
}

is_e_waybill_api_enabled() {
return (
this.frm.doc.purpose == "Send to Subcontractor" &&
super.is_e_waybill_api_enabled() &&
gst_settings.enable_e_waybill_for_sc
);
}
}

class SubcontractingReceiptEwaybill extends EwaybillApplicability {
is_e_waybill_applicable(show_message = false) {
return (
super.is_e_waybill_applicable(show_message) &&
gst_settings.enable_e_waybill_for_sc
);
}

is_e_waybill_generatable(show_message = false) {
let is_ewb_generatable = this.is_e_waybill_applicable(show_message);

let message_list = [];

if (!this.frm.doc.supplier_address) {
is_ewb_generatable = false;
message_list.push(
"Supplier addresss is mandatory for e-waybill generation."
);
}

if (show_message) {
this.frm._ewb_message += message_list
.map(message => `<li>${message}</li>`)
.join("");
}

return is_ewb_generatable;
}

is_e_waybill_api_enabled() {
return super.is_e_waybill_api_enabled() && gst_settings.enable_e_waybill_for_sc;
}
}
Loading

0 comments on commit 57a0474

Please sign in to comment.