mirror of
https://github.com/frappe/erpnext.git
synced 2026-09-20 03:47:11 +00:00
refactor(treewide): formatting and ruff fixes, + manually enabled F401
Signed-off-by: Akhil Narang <me@akhilnarang.dev>
This commit is contained in:
@@ -45,9 +45,7 @@ class SubcontractingBOM(Document):
|
||||
if disabled:
|
||||
frappe.throw(_("Finished Good {0} is disabled.").format(frappe.bold(self.finished_good)))
|
||||
if not is_stock_item:
|
||||
frappe.throw(
|
||||
_("Finished Good {0} must be a stock item.").format(frappe.bold(self.finished_good))
|
||||
)
|
||||
frappe.throw(_("Finished Good {0} must be a stock item.").format(frappe.bold(self.finished_good)))
|
||||
if not default_bom:
|
||||
frappe.throw(
|
||||
_("Finished Good {0} does not have a default BOM.").format(frappe.bold(self.finished_good))
|
||||
|
||||
@@ -83,7 +83,7 @@ class SubcontractingOrder(SubcontractingController):
|
||||
# end: auto-generated types
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(SubcontractingOrder, self).__init__(*args, **kwargs)
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
self.status_updater = [
|
||||
{
|
||||
@@ -100,10 +100,10 @@ class SubcontractingOrder(SubcontractingController):
|
||||
]
|
||||
|
||||
def before_validate(self):
|
||||
super(SubcontractingOrder, self).before_validate()
|
||||
super().before_validate()
|
||||
|
||||
def validate(self):
|
||||
super(SubcontractingOrder, self).validate()
|
||||
super().validate()
|
||||
self.validate_purchase_order_for_subcontracting()
|
||||
self.validate_items()
|
||||
self.validate_service_items()
|
||||
@@ -198,9 +198,7 @@ class SubcontractingOrder(SubcontractingController):
|
||||
):
|
||||
item_wh_list.append([item.item_code, item.warehouse])
|
||||
for item_code, warehouse in item_wh_list:
|
||||
update_bin_qty(
|
||||
item_code, warehouse, {"ordered_qty": self.get_ordered_qty(item_code, warehouse)}
|
||||
)
|
||||
update_bin_qty(item_code, warehouse, {"ordered_qty": self.get_ordered_qty(item_code, warehouse)})
|
||||
|
||||
@staticmethod
|
||||
def get_ordered_qty(item_code, warehouse):
|
||||
@@ -239,7 +237,9 @@ class SubcontractingOrder(SubcontractingController):
|
||||
item = frappe.get_doc("Item", si.fg_item)
|
||||
bom = (
|
||||
frappe.db.get_value(
|
||||
"Subcontracting BOM", {"finished_good": item.item_code, "is_active": 1}, "finished_good_bom"
|
||||
"Subcontracting BOM",
|
||||
{"finished_good": item.item_code, "is_active": 1},
|
||||
"finished_good_bom",
|
||||
)
|
||||
or item.default_bom
|
||||
)
|
||||
|
||||
@@ -211,7 +211,7 @@ class TestSubcontractingOrder(FrappeTestCase):
|
||||
item["qty"] -= 1
|
||||
itemwise_transfer_qty[item["item_code"]] += item["qty"]
|
||||
|
||||
ste = make_stock_transfer_entry(
|
||||
make_stock_transfer_entry(
|
||||
sco_no=sco.name,
|
||||
rm_items=rm_items,
|
||||
itemwise_details=copy.deepcopy(itemwise_details),
|
||||
@@ -713,7 +713,7 @@ def create_subcontracting_order(**args):
|
||||
warehouses.add(item.warehouse)
|
||||
|
||||
if len(warehouses) == 1:
|
||||
sco.set_warehouse = list(warehouses)[0]
|
||||
sco.set_warehouse = next(iter(warehouses))
|
||||
|
||||
if not args.do_not_save:
|
||||
sco.insert()
|
||||
|
||||
@@ -85,7 +85,7 @@ class SubcontractingReceipt(SubcontractingController):
|
||||
# end: auto-generated types
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(SubcontractingReceipt, self).__init__(*args, **kwargs)
|
||||
super().__init__(*args, **kwargs)
|
||||
self.status_updater = [
|
||||
{
|
||||
"target_dt": "Subcontracting Order Item",
|
||||
@@ -104,13 +104,11 @@ class SubcontractingReceipt(SubcontractingController):
|
||||
def onload(self):
|
||||
self.set_onload(
|
||||
"backflush_based_on",
|
||||
frappe.db.get_single_value(
|
||||
"Buying Settings", "backflush_raw_materials_of_subcontract_based_on"
|
||||
),
|
||||
frappe.db.get_single_value("Buying Settings", "backflush_raw_materials_of_subcontract_based_on"),
|
||||
)
|
||||
|
||||
def before_validate(self):
|
||||
super(SubcontractingReceipt, self).before_validate()
|
||||
super().before_validate()
|
||||
self.validate_items_qty()
|
||||
self.set_items_bom()
|
||||
self.set_items_cost_center()
|
||||
@@ -126,7 +124,7 @@ class SubcontractingReceipt(SubcontractingController):
|
||||
if getdate(self.posting_date) > getdate(nowdate()):
|
||||
frappe.throw(_("Posting Date cannot be future date"))
|
||||
|
||||
super(SubcontractingReceipt, self).validate()
|
||||
super().validate()
|
||||
|
||||
if self.is_new() and self.get("_action") == "save" and not frappe.flags.in_test:
|
||||
self.get_scrap_items()
|
||||
@@ -190,7 +188,9 @@ class SubcontractingReceipt(SubcontractingController):
|
||||
for item in self.items:
|
||||
if not (item.qty or item.rejected_qty):
|
||||
frappe.throw(
|
||||
_("Row {0}: Accepted Qty and Rejected Qty can't be zero at the same time.").format(item.idx)
|
||||
_("Row {0}: Accepted Qty and Rejected Qty can't be zero at the same time.").format(
|
||||
item.idx
|
||||
)
|
||||
)
|
||||
|
||||
def set_items_bom(self):
|
||||
@@ -306,7 +306,9 @@ class SubcontractingReceipt(SubcontractingController):
|
||||
.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"),
|
||||
(sco_supplied_item.total_supplied_qty - sco_supplied_item.consumed_qty).as_(
|
||||
"available_qty"
|
||||
),
|
||||
)
|
||||
.where(
|
||||
(sco_supplied_item.parent == item.subcontracting_order)
|
||||
@@ -319,7 +321,9 @@ class SubcontractingReceipt(SubcontractingController):
|
||||
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
|
||||
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(
|
||||
@@ -515,10 +519,12 @@ class SubcontractingReceipt(SubcontractingController):
|
||||
|
||||
warehouse_account_name = warehouse_account[item.warehouse]["account"]
|
||||
warehouse_account_currency = warehouse_account[item.warehouse]["account_currency"]
|
||||
supplier_warehouse_account = warehouse_account.get(self.supplier_warehouse, {}).get("account")
|
||||
supplier_warehouse_account_currency = warehouse_account.get(self.supplier_warehouse, {}).get(
|
||||
"account_currency"
|
||||
supplier_warehouse_account = warehouse_account.get(self.supplier_warehouse, {}).get(
|
||||
"account"
|
||||
)
|
||||
supplier_warehouse_account_currency = warehouse_account.get(
|
||||
self.supplier_warehouse, {}
|
||||
).get("account_currency")
|
||||
remarks = self.get("remarks") or _("Accounting Entry for Stock")
|
||||
|
||||
# FG Warehouse Account (Debit)
|
||||
@@ -662,7 +668,9 @@ def make_purchase_receipt(source_name, target_doc=None, save=False, submit=False
|
||||
if item.purchase_order and item.purchase_order_item:
|
||||
if item.purchase_order not in po_items_details:
|
||||
po_doc = frappe.get_doc("Purchase Order", item.purchase_order)
|
||||
po_items_details[item.purchase_order] = {po_item.name: po_item for po_item in po_doc.items}
|
||||
po_items_details[item.purchase_order] = {
|
||||
po_item.name: po_item for po_item in po_doc.items
|
||||
}
|
||||
|
||||
if po_item := po_items_details[item.purchase_order].get(item.purchase_order_item):
|
||||
conversion_factor = flt(po_item.qty) / flt(po_item.fg_item_qty)
|
||||
|
||||
@@ -6,7 +6,7 @@ import copy
|
||||
|
||||
import frappe
|
||||
from frappe.tests.utils import FrappeTestCase, change_settings
|
||||
from frappe.utils import add_days, cint, cstr, flt, nowtime, today
|
||||
from frappe.utils import add_days, cint, flt, nowtime, today
|
||||
|
||||
import erpnext
|
||||
from erpnext.accounts.doctype.account.test_account import get_inventory_account
|
||||
@@ -48,9 +48,7 @@ class TestSubcontractingReceipt(FrappeTestCase):
|
||||
|
||||
def test_subcontracting(self):
|
||||
set_backflush_based_on("BOM")
|
||||
make_stock_entry(
|
||||
item_code="_Test Item", qty=100, target="_Test Warehouse 1 - _TC", basic_rate=100
|
||||
)
|
||||
make_stock_entry(item_code="_Test Item", qty=100, target="_Test Warehouse 1 - _TC", basic_rate=100)
|
||||
make_stock_entry(
|
||||
item_code="_Test Item Home Desktop 100",
|
||||
qty=100,
|
||||
@@ -82,9 +80,7 @@ class TestSubcontractingReceipt(FrappeTestCase):
|
||||
self.assertEqual(scr.get("items")[0].rm_supp_cost, flt(rm_supp_cost))
|
||||
|
||||
def test_available_qty_for_consumption(self):
|
||||
make_stock_entry(
|
||||
item_code="_Test Item", qty=100, target="_Test Warehouse 1 - _TC", basic_rate=100
|
||||
)
|
||||
make_stock_entry(item_code="_Test Item", qty=100, target="_Test Warehouse 1 - _TC", basic_rate=100)
|
||||
make_stock_entry(
|
||||
item_code="_Test Item Home Desktop 100",
|
||||
qty=100,
|
||||
@@ -185,9 +181,6 @@ class TestSubcontractingReceipt(FrappeTestCase):
|
||||
from erpnext.subcontracting.doctype.subcontracting_order.subcontracting_order import (
|
||||
make_subcontracting_receipt,
|
||||
)
|
||||
from erpnext.subcontracting.doctype.subcontracting_order.test_subcontracting_order import (
|
||||
make_subcontracted_item,
|
||||
)
|
||||
|
||||
set_backflush_based_on("Material Transferred for Subcontract")
|
||||
item_code = "_Test Subcontracted FG Item 1"
|
||||
@@ -211,12 +204,8 @@ class TestSubcontractingReceipt(FrappeTestCase):
|
||||
make_stock_entry(
|
||||
target="_Test Warehouse - _TC", item_code="Test Extra Item 1", qty=10, basic_rate=100
|
||||
)
|
||||
make_stock_entry(
|
||||
target="_Test Warehouse - _TC", item_code="_Test FG Item", qty=1, basic_rate=100
|
||||
)
|
||||
make_stock_entry(
|
||||
target="_Test Warehouse - _TC", item_code="Test Extra Item 2", qty=1, basic_rate=100
|
||||
)
|
||||
make_stock_entry(target="_Test Warehouse - _TC", item_code="_Test FG Item", qty=1, basic_rate=100)
|
||||
make_stock_entry(target="_Test Warehouse - _TC", item_code="Test Extra Item 2", qty=1, basic_rate=100)
|
||||
|
||||
rm_items = [
|
||||
{
|
||||
@@ -397,9 +386,7 @@ class TestSubcontractingReceipt(FrappeTestCase):
|
||||
set_backflush_based_on("Material Transferred for Subcontract")
|
||||
|
||||
# Create Material Receipt for RM's
|
||||
make_stock_entry(
|
||||
item_code="_Test Item", qty=100, target="_Test Warehouse 1 - _TC", basic_rate=100
|
||||
)
|
||||
make_stock_entry(item_code="_Test Item", qty=100, target="_Test Warehouse 1 - _TC", basic_rate=100)
|
||||
make_stock_entry(
|
||||
item_code="_Test Item Home Desktop 100",
|
||||
qty=100,
|
||||
@@ -614,7 +601,6 @@ class TestSubcontractingReceipt(FrappeTestCase):
|
||||
|
||||
bom = make_bom(item=fg_item, raw_materials=[rm_item1, rm_item2, rm_item3])
|
||||
|
||||
rm_batch_no = None
|
||||
for row in bom.items:
|
||||
make_stock_entry(
|
||||
item_code=row.item_code,
|
||||
@@ -642,9 +628,7 @@ class TestSubcontractingReceipt(FrappeTestCase):
|
||||
]
|
||||
sco = get_subcontracting_order(service_items=service_items)
|
||||
|
||||
frappe.db.set_single_value(
|
||||
"Stock Settings", "auto_create_serial_and_batch_bundle_for_outward", 1
|
||||
)
|
||||
frappe.db.set_single_value("Stock Settings", "auto_create_serial_and_batch_bundle_for_outward", 1)
|
||||
scr = make_subcontracting_receipt(sco.name)
|
||||
scr.save()
|
||||
scr.submit()
|
||||
@@ -663,9 +647,7 @@ class TestSubcontractingReceipt(FrappeTestCase):
|
||||
|
||||
self.assertEqual(scr.items[0].rm_cost_per_qty, 900)
|
||||
self.assertEqual(scr.items[0].service_cost_per_qty, 100)
|
||||
frappe.db.set_single_value(
|
||||
"Stock Settings", "auto_create_serial_and_batch_bundle_for_outward", 0
|
||||
)
|
||||
frappe.db.set_single_value("Stock Settings", "auto_create_serial_and_batch_bundle_for_outward", 0)
|
||||
|
||||
def test_subcontracting_receipt_valuation_for_fg_with_auto_created_serial_batch_bundle(self):
|
||||
frappe.db.set_single_value("Stock Settings", "use_serial_batch_fields", 0)
|
||||
@@ -711,7 +693,6 @@ class TestSubcontractingReceipt(FrappeTestCase):
|
||||
|
||||
bom = make_bom(item=fg_item, raw_materials=[rm_item1, rm_item2, rm_item3])
|
||||
|
||||
rm_batch_no = None
|
||||
for row in bom.items:
|
||||
make_stock_entry(
|
||||
item_code=row.item_code,
|
||||
@@ -732,9 +713,7 @@ class TestSubcontractingReceipt(FrappeTestCase):
|
||||
]
|
||||
sco = get_subcontracting_order(service_items=service_items)
|
||||
|
||||
frappe.db.set_single_value(
|
||||
"Stock Settings", "auto_create_serial_and_batch_bundle_for_outward", 1
|
||||
)
|
||||
frappe.db.set_single_value("Stock Settings", "auto_create_serial_and_batch_bundle_for_outward", 1)
|
||||
scr = make_subcontracting_receipt(sco.name)
|
||||
scr.save()
|
||||
scr.submit()
|
||||
@@ -762,9 +741,7 @@ class TestSubcontractingReceipt(FrappeTestCase):
|
||||
|
||||
self.assertEqual(flt(valuation_rate), flt(1000))
|
||||
|
||||
frappe.db.set_single_value(
|
||||
"Stock Settings", "auto_create_serial_and_batch_bundle_for_outward", 0
|
||||
)
|
||||
frappe.db.set_single_value("Stock Settings", "auto_create_serial_and_batch_bundle_for_outward", 0)
|
||||
frappe.db.set_single_value("Stock Settings", "use_serial_batch_fields", 1)
|
||||
|
||||
def test_subcontracting_receipt_raw_material_rate(self):
|
||||
@@ -1225,9 +1202,7 @@ class TestSubcontractingReceipt(FrappeTestCase):
|
||||
def make_return_subcontracting_receipt(**args):
|
||||
args = frappe._dict(args)
|
||||
return_doc = make_return_doc("Subcontracting Receipt", args.scr_name)
|
||||
return_doc.supplier_warehouse = (
|
||||
args.supplier_warehouse or args.warehouse or "_Test Warehouse 1 - _TC"
|
||||
)
|
||||
return_doc.supplier_warehouse = args.supplier_warehouse or args.warehouse or "_Test Warehouse 1 - _TC"
|
||||
|
||||
if args.qty:
|
||||
for item in return_doc.items:
|
||||
|
||||
Reference in New Issue
Block a user