Skip to content

Commit

Permalink
chore: conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
s-aga-r committed Sep 3, 2023
1 parent a003945 commit 9a45c58
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 297 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,6 @@ frappe.ui.form.on('Subcontracting Receipt Item', {
rate(frm) {
set_missing_values(frm);
},
<<<<<<< HEAD
=======

items_remove: (frm) => {
set_missing_values(frm);
},
>>>>>>> cd8ddae7c5 (refactor: remove `Recalculate Rate` from SCR Item (#36929))
});

frappe.ui.form.on('Subcontracting Receipt Supplied Item', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,9 @@ def calculate_items_qty_and_amount(self):
item.rm_cost_per_qty = item.rm_supp_cost / item.qty
rm_supp_cost.pop(item.name)

if item.recalculate_rate:
item.rate = (
flt(item.rm_cost_per_qty) + flt(item.service_cost_per_qty) + flt(item.additional_cost_per_qty)
)
item.rate = (
flt(item.rm_cost_per_qty) + flt(item.service_cost_per_qty) + flt(item.additional_cost_per_qty)
)

item.received_qty = item.qty + flt(item.rejected_qty)
item.amount = item.qty * item.rate
Expand Down Expand Up @@ -262,237 +261,6 @@ def set_items_expense_account(self):
if not item.expense_account:
item.expense_account = expense_account

<<<<<<< HEAD
=======
def reset_supplied_items(self):
if (
frappe.db.get_single_value("Buying Settings", "backflush_raw_materials_of_subcontract_based_on")
== "BOM"
):
self.supplied_items = []

@frappe.whitelist()
def get_scrap_items(self, recalculate_rate=False):
self.remove_scrap_items()

for item in list(self.items):
if item.bom:
bom = frappe.get_doc("BOM", item.bom)
for scrap_item in bom.scrap_items:
qty = flt(item.qty) * (flt(scrap_item.stock_qty) / flt(bom.quantity))
rate = (
get_valuation_rate(
scrap_item.item_code,
self.set_warehouse,
self.doctype,
self.name,
currency=erpnext.get_company_currency(self.company),
company=self.company,
)
or scrap_item.rate
)
self.append(
"items",
{
"is_scrap_item": 1,
"reference_name": item.name,
"item_code": scrap_item.item_code,
"item_name": scrap_item.item_name,
"qty": qty,
"stock_uom": scrap_item.stock_uom,
"rate": rate,
"rm_cost_per_qty": 0,
"service_cost_per_qty": 0,
"additional_cost_per_qty": 0,
"scrap_cost_per_qty": 0,
"amount": qty * rate,
"warehouse": self.set_warehouse,
"rejected_warehouse": self.rejected_warehouse,
},
)

if recalculate_rate:
self.calculate_additional_costs()
self.calculate_items_qty_and_amount()

def remove_scrap_items(self, recalculate_rate=False):
for item in list(self.items):
if item.is_scrap_item:
self.remove(item)
else:
item.scrap_cost_per_qty = 0

if recalculate_rate:
self.calculate_items_qty_and_amount()

@frappe.whitelist()
def set_missing_values(self):
self.set_available_qty_for_consumption()
self.calculate_additional_costs()
self.calculate_items_qty_and_amount()

def set_available_qty_for_consumption(self):
supplied_items_details = {}

sco_supplied_item = frappe.qb.DocType("Subcontracting Order Supplied Item")
for item in self.get("items"):
supplied_items = (
frappe.qb.from_(sco_supplied_item)
.select(
sco_supplied_item.rm_item_code,
sco_supplied_item.reference_name,
(sco_supplied_item.total_supplied_qty - sco_supplied_item.consumed_qty).as_("available_qty"),
)
.where(
(sco_supplied_item.parent == item.subcontracting_order)
& (sco_supplied_item.main_item_code == item.item_code)
& (sco_supplied_item.reference_name == item.subcontracting_order_item)
)
).run(as_dict=True)

if supplied_items:
supplied_items_details[item.name] = {}

for supplied_item in supplied_items:
supplied_items_details[item.name][supplied_item.rm_item_code] = supplied_item.available_qty
else:
for item in self.get("supplied_items"):
item.available_qty_for_consumption = supplied_items_details.get(item.reference_name, {}).get(
item.rm_item_code, 0
)

def calculate_items_qty_and_amount(self):
rm_cost_map = {}
for item in self.get("supplied_items") or []:
item.amount = flt(item.consumed_qty) * flt(item.rate)

if item.reference_name in rm_cost_map:
rm_cost_map[item.reference_name] += item.amount
else:
rm_cost_map[item.reference_name] = item.amount

scrap_cost_map = {}
for item in self.get("items") or []:
if item.is_scrap_item:
item.amount = flt(item.qty) * flt(item.rate)

if item.reference_name in scrap_cost_map:
scrap_cost_map[item.reference_name] += item.amount
else:
scrap_cost_map[item.reference_name] = item.amount

total_qty = total_amount = 0
for item in self.get("items") or []:
if not item.is_scrap_item:
if item.qty:
if item.name in rm_cost_map:
item.rm_supp_cost = rm_cost_map[item.name]
item.rm_cost_per_qty = item.rm_supp_cost / item.qty
rm_cost_map.pop(item.name)

if item.name in scrap_cost_map:
item.scrap_cost_per_qty = scrap_cost_map[item.name] / item.qty
scrap_cost_map.pop(item.name)
else:
item.scrap_cost_per_qty = 0

item.rate = (
flt(item.rm_cost_per_qty)
+ flt(item.service_cost_per_qty)
+ flt(item.additional_cost_per_qty)
- flt(item.scrap_cost_per_qty)
)

item.received_qty = flt(item.qty) + flt(item.rejected_qty)
item.amount = flt(item.qty) * flt(item.rate)

total_qty += flt(item.qty)
total_amount += item.amount
else:
self.total_qty = total_qty
self.total = total_amount

def validate_scrap_items(self):
for item in self.items:
if item.is_scrap_item:
if not item.qty:
frappe.throw(
_("Row #{0}: Scrap Item Qty cannot be zero").format(item.idx),
)

if item.rejected_qty:
frappe.throw(
_("Row #{0}: Rejected Qty cannot be set for Scrap Item {1}.").format(
item.idx, frappe.bold(item.item_code)
),
)

if not item.reference_name:
frappe.throw(
_("Row #{0}: Finished Good reference is mandatory for Scrap Item {1}.").format(
item.idx, frappe.bold(item.item_code)
),
)

def validate_accepted_warehouse(self):
for item in self.get("items"):
if flt(item.qty) and not item.warehouse:
if self.set_warehouse:
item.warehouse = self.set_warehouse
else:
frappe.throw(
_("Row #{0}: Accepted Warehouse is mandatory for the accepted Item {1}").format(
item.idx, item.item_code
)
)

if item.get("warehouse") and (item.get("warehouse") == item.get("rejected_warehouse")):
frappe.throw(
_("Row #{0}: Accepted Warehouse and Rejected Warehouse cannot be same").format(item.idx)
)

def validate_available_qty_for_consumption(self):
for item in self.get("supplied_items"):
precision = item.precision("consumed_qty")
if (
item.available_qty_for_consumption
and flt(item.available_qty_for_consumption, precision) - flt(item.consumed_qty, precision) < 0
):
msg = f"""Row {item.idx}: Consumed Qty {flt(item.consumed_qty, precision)}
must be less than or equal to Available Qty For Consumption
{flt(item.available_qty_for_consumption, precision)}
in Consumed Items Table."""

frappe.throw(_(msg))

def update_status_updater_args(self):
if cint(self.is_return):
self.status_updater.extend(
[
{
"source_dt": "Subcontracting Receipt Item",
"target_dt": "Subcontracting Order Item",
"join_field": "subcontracting_order_item",
"target_field": "returned_qty",
"source_field": "-1 * qty",
"extra_cond": """ and exists (select name from `tabSubcontracting Receipt`
where name=`tabSubcontracting Receipt Item`.parent and is_return=1)""",
},
{
"source_dt": "Subcontracting Receipt Item",
"target_dt": "Subcontracting Receipt Item",
"join_field": "subcontracting_receipt_item",
"target_field": "returned_qty",
"target_parent_dt": "Subcontracting Receipt",
"target_parent_field": "per_returned",
"target_ref_field": "received_qty",
"source_field": "-1 * received_qty",
"percent_join_field_parent": "return_against",
},
]
)

>>>>>>> cd8ddae7c5 (refactor: remove `Recalculate Rate` from SCR Item (#36929))
def update_status(self, status=None, update_modified=False):
if not status:
if self.docstatus == 0:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -464,67 +464,12 @@
"fieldname": "accounting_details_section",
"fieldtype": "Section Break",
"label": "Accounting Details"
},
{
<<<<<<< HEAD
"default": "1",
"fieldname": "recalculate_rate",
"fieldtype": "Check",
"label": "Recalculate Rate"
=======
"fieldname": "serial_and_batch_bundle",
"fieldtype": "Link",
"label": "Serial and Batch Bundle",
"no_copy": 1,
"options": "Serial and Batch Bundle",
"print_hide": 1
},
{
"fieldname": "rejected_serial_and_batch_bundle",
"fieldtype": "Link",
"label": "Rejected Serial and Batch Bundle",
"no_copy": 1,
"options": "Serial and Batch Bundle",
"print_hide": 1
},
{
"default": "0",
"depends_on": "eval: !doc.bom",
"fieldname": "is_scrap_item",
"fieldtype": "Check",
"label": "Is Scrap Item",
"no_copy": 1,
"print_hide": 1,
"read_only_depends_on": "eval: doc.bom"
},
{
"default": "0",
"depends_on": "eval: !doc.is_scrap_item",
"fieldname": "scrap_cost_per_qty",
"fieldtype": "Float",
"label": "Scrap Cost Per Qty",
"no_copy": 1,
"non_negative": 1,
"read_only": 1
},
{
"fieldname": "reference_name",
"fieldtype": "Data",
"hidden": 1,
"label": "Reference Name",
"no_copy": 1,
"read_only": 1
>>>>>>> cd8ddae7c5 (refactor: remove `Recalculate Rate` from SCR Item (#36929))
}
],
"idx": 1,
"istable": 1,
"links": [],
<<<<<<< HEAD
"modified": "2023-07-06 18:44:45.599761",
=======
"modified": "2023-09-03 17:04:21.214316",
>>>>>>> cd8ddae7c5 (refactor: remove `Recalculate Rate` from SCR Item (#36929))
"modified_by": "Administrator",
"module": "Subcontracting",
"name": "Subcontracting Receipt Item",
Expand Down

0 comments on commit 9a45c58

Please sign in to comment.