fix: ignore scrap items while distribute additional cost

This commit is contained in:
s-aga-r 2023-08-25 20:18:30 +05:30
parent 879d31a588
commit 1504ff8b6c
4 changed files with 26 additions and 15 deletions

View File

@ -895,18 +895,23 @@ class SubcontractingController(StockController):
if self.total_additional_costs: if self.total_additional_costs:
if self.distribute_additional_costs_based_on == "Amount": if self.distribute_additional_costs_based_on == "Amount":
total_amt = sum(flt(item.amount) for item in self.get("items")) total_amt = sum(
flt(item.amount) for item in self.get("items") if not item.get("is_scrap_item")
)
for item in self.items: for item in self.items:
if not item.get("is_scrap_item"):
item.additional_cost_per_qty = ( item.additional_cost_per_qty = (
(item.amount * self.total_additional_costs) / total_amt (item.amount * self.total_additional_costs) / total_amt
) / item.qty ) / item.qty
else: else:
total_qty = sum(flt(item.qty) for item in self.get("items")) total_qty = sum(flt(item.qty) for item in self.get("items") if not item.get("is_scrap_item"))
additional_cost_per_qty = self.total_additional_costs / total_qty additional_cost_per_qty = self.total_additional_costs / total_qty
for item in self.items: for item in self.items:
if not item.get("is_scrap_item"):
item.additional_cost_per_qty = additional_cost_per_qty item.additional_cost_per_qty = additional_cost_per_qty
else: else:
for item in self.items: for item in self.items:
if not item.get("is_scrap_item"):
item.additional_cost_per_qty = 0 item.additional_cost_per_qty = 0
@frappe.whitelist() @frappe.whitelist()

View File

@ -201,11 +201,16 @@ frappe.ui.form.on('Subcontracting Receipt', {
frappe.ui.form.on('Landed Cost Taxes and Charges', { frappe.ui.form.on('Landed Cost Taxes and Charges', {
amount: function (frm, cdt, cdn) { amount: function (frm, cdt, cdn) {
set_missing_values(frm);
frm.events.set_base_amount(frm, cdt, cdn); frm.events.set_base_amount(frm, cdt, cdn);
}, },
expense_account: function (frm, cdt, cdn) { expense_account: function (frm, cdt, cdn) {
frm.events.set_account_currency(frm, cdt, cdn); frm.events.set_account_currency(frm, cdt, cdn);
},
additional_costs_remove: function(frm) {
set_missing_values(frm);
} }
}); });

View File

@ -169,12 +169,12 @@ class SubcontractingReceipt(SubcontractingController):
"item_name": scrap_item.item_name, "item_name": scrap_item.item_name,
"qty": qty, "qty": qty,
"stock_uom": scrap_item.stock_uom, "stock_uom": scrap_item.stock_uom,
"recalculate_rate": 1, "recalculate_rate": 0,
"rate": scrap_item.rate, "rate": scrap_item.rate,
"rm_cost_per_qty": 0, "rm_cost_per_qty": 0,
"service_cost_per_qty": 0, "service_cost_per_qty": 0,
"additional_cost_per_qty": 0, "additional_cost_per_qty": 0,
"scrap_cost_per_qty": scrap_item.rate, "scrap_cost_per_qty": 0,
"amount": qty * scrap_item.rate, "amount": qty * scrap_item.rate,
"warehouse": self.set_warehouse, "warehouse": self.set_warehouse,
"rejected_warehouse": self.rejected_warehouse, "rejected_warehouse": self.rejected_warehouse,
@ -244,9 +244,6 @@ class SubcontractingReceipt(SubcontractingController):
scrap_cost_map = {} scrap_cost_map = {}
for item in self.get("items") or []: for item in self.get("items") or []:
if item.is_scrap_item: if item.is_scrap_item:
if item.recalculate_rate:
item.rate = flt(item.scrap_cost_per_qty) + flt(item.additional_cost_per_qty)
item.amount = flt(item.qty) * flt(item.rate) item.amount = flt(item.qty) * flt(item.rate)
if item.reference_name in scrap_cost_map: if item.reference_name in scrap_cost_map:

View File

@ -237,6 +237,7 @@
}, },
{ {
"default": "0", "default": "0",
"depends_on": "eval: !doc.is_scrap_item",
"fieldname": "additional_cost_per_qty", "fieldname": "additional_cost_per_qty",
"fieldtype": "Currency", "fieldtype": "Currency",
"label": "Additional Cost Per Qty", "label": "Additional Cost Per Qty",
@ -476,9 +477,11 @@
}, },
{ {
"default": "1", "default": "1",
"depends_on": "eval: !doc.is_scrap_item",
"fieldname": "recalculate_rate", "fieldname": "recalculate_rate",
"fieldtype": "Check", "fieldtype": "Check",
"label": "Recalculate Rate" "label": "Recalculate Rate",
"read_only_depends_on": "eval: doc.is_scrap_item"
}, },
{ {
"fieldname": "serial_and_batch_bundle", "fieldname": "serial_and_batch_bundle",
@ -508,6 +511,7 @@
}, },
{ {
"default": "0", "default": "0",
"depends_on": "eval: !doc.is_scrap_item",
"fieldname": "scrap_cost_per_qty", "fieldname": "scrap_cost_per_qty",
"fieldtype": "Float", "fieldtype": "Float",
"label": "Scrap Cost Per Qty", "label": "Scrap Cost Per Qty",
@ -527,7 +531,7 @@
"idx": 1, "idx": 1,
"istable": 1, "istable": 1,
"links": [], "links": [],
"modified": "2023-08-25 15:42:36.923833", "modified": "2023-08-25 20:09:03.069417",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Subcontracting", "module": "Subcontracting",
"name": "Subcontracting Receipt Item", "name": "Subcontracting Receipt Item",