Skip to content

Commit

Permalink
fix(new_sc_flow): Changes requested by pre-commit and fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mihir-kandoi committed Dec 12, 2024
1 parent fc21c84 commit 518f7d2
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 20 deletions.
8 changes: 5 additions & 3 deletions erpnext/buying/doctype/purchase_order/test_purchase_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -1025,7 +1025,7 @@ def test_update_items_for_subcontracting_purchase_order(self):
)

def update_items(po, qty):
trans_items = [po.items[0].as_dict()]
trans_items = [po.items[0].as_dict().update({"docname": po.items[0].name})]
trans_items[0]["qty"] = qty
trans_items[0]["fg_item_qty"] = qty
trans_items = json.dumps(trans_items, default=str)
Expand Down Expand Up @@ -1112,7 +1112,7 @@ def test_new_sc_flow(self):
self.assertEqual(sco.service_items[1].qty, 12.5)

sco = make_subcontracting_order(po.name)

sco.items[0].qty = 6

# Test - 6: Saving document should not be allowed if Quantity exceeds available Subcontracting Quantity of any Purchase Order Item
Expand Down Expand Up @@ -1143,7 +1143,7 @@ def test_new_sc_flow(self):
sco = make_subcontracting_order(po.name)
sco.save()
sco.submit()

# Test - 8: Since this PO is now fully subcontracted, creating a new SCO from it should throw error
self.assertRaises(frappe.ValidationError, make_subcontracting_order, po.name)

Expand Down Expand Up @@ -1239,6 +1239,7 @@ def test_po_billed_amount_against_return_entry(self):
po.reload()
self.assertEqual(po.per_billed, 100)


def create_po_for_sc_testing():
from erpnext.controllers.tests.test_subcontracting_controller import (
make_bom_for_subcontracted_items,
Expand Down Expand Up @@ -1285,6 +1286,7 @@ def create_po_for_sc_testing():
supplier_warehouse="_Test Warehouse 1 - _TC",
)


def prepare_data_for_internal_transfer():
from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_internal_supplier
from erpnext.selling.doctype.customer.test_customer import create_internal_customer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,29 @@ erpnext.landed_cost_taxes_and_charges.setup_triggers("Subcontracting Order");
// this is just so that the user does not get potentially confused
frappe.ui.form.on("Subcontracting Order Item", {
qty(frm, cdt, cdn) {
let row = locals[cdt][cdn];
const row = locals[cdt][cdn];
frappe.model.set_value(cdt, cdn, "amount", row.qty * row.rate);
service_item = frm.doc.service_items[row.idx - 1];
frappe.model.set_value(service_item.doctype, service_item.name, "qty", row.qty * row.sc_conversion_factor);
const service_item = frm.doc.service_items[row.idx - 1];
frappe.model.set_value(
service_item.doctype,
service_item.name,
"qty",
row.qty * row.sc_conversion_factor
);
frappe.model.set_value(service_item.doctype, service_item.name, "fg_item_qty", row.qty);
frappe.model.set_value(service_item.doctype, service_item.name, "amount", (row.qty * row.sc_conversion_factor) * service_item.rate);
frappe.model.set_value(
service_item.doctype,
service_item.name,
"amount",
row.qty * row.sc_conversion_factor * service_item.rate
);
},
before_items_remove(frm, cdt, cdn) {
let row = locals[cdt][cdn];
const row = locals[cdt][cdn];
frm.toggle_enable(["service_items"], true);
frm.get_field("service_items").grid.grid_rows[row.idx - 1].remove();
frm.toggle_enable(["service_items"], false);
}
},
});

frappe.ui.form.on("Subcontracting Order", {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,15 @@ def validate_purchase_order_for_subcontracting(self):

def validate_service_items(self):
purchase_order_items = [item.purchase_order_item for item in self.items]
self.service_items = list(
filter(lambda item: item.purchase_order_item in purchase_order_items, self.service_items)
)
self.service_items = [
service_item
for service_item in self.service_items
if service_item.purchase_order_item in purchase_order_items
]

for service_item in self.service_items:
if frappe.get_value("Item", service_item.item_code, "is_stock_item"):
msg = f"Service Item {service_item.item_name} must be a non-stock item."
frappe.throw(_(msg))
frappe.throw(_(f"Service Item {service_item.item_name} must be a non-stock item."))

item = next(
item for item in self.items if item.purchase_order_item == service_item.purchase_order_item
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,6 @@ def setUp(self):
make_service_items()
make_bom_for_subcontracted_items()

def test_populate_items_table(self):
sco = get_subcontracting_order()
sco.items = None
sco.populate_items_table()
self.assertEqual(len(sco.service_items), len(sco.items))

def test_set_missing_values(self):
sco = get_subcontracting_order()
before = {sco.total_qty, sco.total, sco.total_additional_costs}
Expand Down

0 comments on commit 518f7d2

Please sign in to comment.