-
Notifications
You must be signed in to change notification settings - Fork 230
feat: e-waybill support for Subcontracting Inward #3822
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from 6 commits
c5d3338
0db2e3e
6d6ba6d
555f9c3
faef75f
0fc335b
cb44e52
67f2f81
f3f4ed1
2bf9563
35e801b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,4 +1,5 @@ | ||||||||||||||||||||||||||||||||
| import json | ||||||||||||||||||||||||||||||||
| from collections import defaultdict | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| import frappe | ||||||||||||||||||||||||||||||||
| from frappe import _ | ||||||||||||||||||||||||||||||||
|
|
@@ -112,6 +113,7 @@ def __init__(self, doc, field_map=None): | |||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| def set_taxes_and_totals(self): | ||||||||||||||||||||||||||||||||
| self.set_item_wise_tax_rates() | ||||||||||||||||||||||||||||||||
| self.set_additional_taxable_value() | ||||||||||||||||||||||||||||||||
| self.update_item_taxable_value() | ||||||||||||||||||||||||||||||||
| self.update_tax_amount() | ||||||||||||||||||||||||||||||||
| self.update_base_grand_total() | ||||||||||||||||||||||||||||||||
|
|
@@ -149,7 +151,24 @@ def set_item_wise_tax_rates(self, item_name=None, tax_name=None): | |||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| def update_item_taxable_value(self): | ||||||||||||||||||||||||||||||||
| for item in self.doc.get("items"): | ||||||||||||||||||||||||||||||||
| item.taxable_value = self.get_value("amount", item) | ||||||||||||||||||||||||||||||||
| taxable_value = self.get_value("amount", item) | ||||||||||||||||||||||||||||||||
| taxable_value += flt( | ||||||||||||||||||||||||||||||||
| item.get("additional_taxable_value", 0), item.precision("taxable_value") | ||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| item.taxable_value = taxable_value | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| def set_additional_taxable_value(self): | ||||||||||||||||||||||||||||||||
| if self.doc.doctype != "Stock Entry" or not self.doc.items: | ||||||||||||||||||||||||||||||||
| return | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| for item in self.doc.items: | ||||||||||||||||||||||||||||||||
| item.additional_taxable_value = 0 | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| if self.doc.purpose == "Subcontracting Delivery": | ||||||||||||||||||||||||||||||||
| _set_subcontracting_delivery_additional_value(self.doc) | ||||||||||||||||||||||||||||||||
| elif self.doc.purpose == "Return Raw Material to Customer": | ||||||||||||||||||||||||||||||||
| _set_return_raw_material_additional_value(self.doc) | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| def update_tax_amount(self): | ||||||||||||||||||||||||||||||||
| total_taxes = 0 | ||||||||||||||||||||||||||||||||
|
|
@@ -267,3 +286,80 @@ def validate_taxes(doc): | |||||||||||||||||||||||||||||||
| tax.idx, doc.doctype | ||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| def _set_subcontracting_delivery_additional_value(doc): | ||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||
| additional_taxable_value = SUM(received_items.rate * received_items.consumed_qty) | ||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||
| scio_details = [item.scio_detail for item in doc.items if item.get("scio_detail")] | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| if not scio_details: | ||||||||||||||||||||||||||||||||
| return | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| received_items = frappe.get_all( | ||||||||||||||||||||||||||||||||
| "Subcontracting Inward Order Received Item", | ||||||||||||||||||||||||||||||||
| filters={ | ||||||||||||||||||||||||||||||||
| "scio_item_detail": ["in", scio_details], | ||||||||||||||||||||||||||||||||
| "is_customer_provided_item": 1, | ||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||
| fields=["scio_item_detail", "rate", "consumed_qty"], | ||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| if not received_items: | ||||||||||||||||||||||||||||||||
| return | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| # Calculate total material cost per FG item | ||||||||||||||||||||||||||||||||
| fg_material_cost = defaultdict(float) | ||||||||||||||||||||||||||||||||
| for received_item in received_items: | ||||||||||||||||||||||||||||||||
| key = received_item.scio_item_detail | ||||||||||||||||||||||||||||||||
| cost = flt(received_item.rate) * flt(received_item.consumed_qty) | ||||||||||||||||||||||||||||||||
| fg_material_cost[key] += cost | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| precision = doc.precision("additional_taxable_value", "taxes") | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| # Set additional_taxable_value for each item | ||||||||||||||||||||||||||||||||
| for item in doc.items: | ||||||||||||||||||||||||||||||||
| if not item.get("scio_detail"): | ||||||||||||||||||||||||||||||||
| continue | ||||||||||||||||||||||||||||||||
| item.additional_taxable_value = flt( | ||||||||||||||||||||||||||||||||
| fg_material_cost.get(item.scio_detail), precision | ||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||
|
Comment on lines
+339
to
+344
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The early-return guard at line 323 ( Fix: use
Suggested change
Comment on lines
+339
to
+344
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Guard against division by zero when If While 🛡️ Proposed fix to guard against zero division # Set additional_taxable_value for each item
for item in doc.items:
if not item.get("scio_detail"):
continue
+ produced_qty = quantity_processed.get(item.scio_detail) or 1
item.additional_taxable_value = flt(
fg_material_cost.get(item.scio_detail)
- / quantity_processed.get(item.scio_detail, 1)
+ / produced_qty
* item.qty,
precision,
) |
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| def _set_return_raw_material_additional_value(doc): | ||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||
| - additional_taxable_value = (SCIO Received Item rate * qty) - Stock Entry amount | ||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||
| scio_details = [item.scio_detail for item in doc.items if item.get("scio_detail")] | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| if not scio_details: | ||||||||||||||||||||||||||||||||
| return | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| received_items = frappe._dict( | ||||||||||||||||||||||||||||||||
| frappe.get_all( | ||||||||||||||||||||||||||||||||
| "Subcontracting Inward Order Received Item", | ||||||||||||||||||||||||||||||||
| filters={ | ||||||||||||||||||||||||||||||||
| "name": ["in", scio_details], | ||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||
| fields=["name", "rate"], | ||||||||||||||||||||||||||||||||
| as_list=True, | ||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| if not received_items: | ||||||||||||||||||||||||||||||||
| return | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| precision = doc.precision("additional_taxable_value", "taxes") | ||||||||||||||||||||||||||||||||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| for item in doc.items: | ||||||||||||||||||||||||||||||||
| scio_detail = item.get("scio_detail") | ||||||||||||||||||||||||||||||||
| if not scio_detail: | ||||||||||||||||||||||||||||||||
| continue | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| scio_rate = received_items.get(scio_detail) | ||||||||||||||||||||||||||||||||
| if not scio_rate: | ||||||||||||||||||||||||||||||||
| continue | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| scio_value = flt(scio_rate) * flt(item.qty) | ||||||||||||||||||||||||||||||||
| item.additional_taxable_value = flt(scio_value - flt(item.amount), precision) | ||||||||||||||||||||||||||||||||
|
Comment on lines
+381
to
+382
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Negative If the Stock Entry Consider clamping the result to zero so that the addition in
Suggested change
|
||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -4,7 +4,7 @@ india_compliance.patches.v15.remove_duplicate_web_template | |||||
|
|
||||||
| [post_model_sync] | ||||||
| india_compliance.patches.v14.set_default_for_overridden_accounts_setting | ||||||
| execute:from india_compliance.gst_india.setup import create_custom_fields; create_custom_fields() #66 | ||||||
| execute:from india_compliance.gst_india.setup import create_custom_fields; create_custom_fields() #67 | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Patch counter decremented — new custom field may not be created on existing deployments The counter was changed from The standard practice is to increment the counter (e.g., to
Suggested change
|
||||||
| execute:from india_compliance.gst_india.setup import create_property_setters; create_property_setters() #11 | ||||||
| execute:from india_compliance.income_tax_india.setup import create_custom_fields; create_custom_fields() #4 | ||||||
| india_compliance.patches.post_install.remove_old_fields #2 | ||||||
|
|
||||||
Uh oh!
There was an error while loading. Please reload this page.