mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-25 16:04:46 +00:00
fix: Test case and refactored some code
This commit is contained in:
@@ -540,6 +540,7 @@ class TestProductionPlan(IntegrationTestCase):
|
|||||||
po_doc.submit()
|
po_doc.submit()
|
||||||
make_purchase_receipt_from_po(po_doc)
|
make_purchase_receipt_from_po(po_doc)
|
||||||
|
|
||||||
|
plan.reload()
|
||||||
plan.make_work_order()
|
plan.make_work_order()
|
||||||
po = frappe.db.get_value("Purchase Order Item", {"production_plan": plan.name}, "parent")
|
po = frappe.db.get_value("Purchase Order Item", {"production_plan": plan.name}, "parent")
|
||||||
po_doc = frappe.get_doc("Purchase Order", po)
|
po_doc = frappe.get_doc("Purchase Order", po)
|
||||||
|
|||||||
@@ -210,7 +210,7 @@
|
|||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
"istable": 1,
|
"istable": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2025-01-01 14:27:52.956484",
|
"modified": "2025-01-01 17:50:32.273610",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Manufacturing",
|
"module": "Manufacturing",
|
||||||
"name": "Production Plan Sub Assembly Item",
|
"name": "Production Plan Sub Assembly Item",
|
||||||
|
|||||||
@@ -385,39 +385,36 @@ class PurchaseReceipt(BuyingController):
|
|||||||
self.reserve_stock_for_sales_order()
|
self.reserve_stock_for_sales_order()
|
||||||
self.update_received_qty_if_from_pp()
|
self.update_received_qty_if_from_pp()
|
||||||
|
|
||||||
def update_received_qty_if_from_pp(self, cancel=False):
|
def update_received_qty_if_from_pp(self):
|
||||||
from frappe.query_builder.functions import Sum
|
from frappe.query_builder.functions import Sum
|
||||||
|
|
||||||
items_with_po_item = [item for item in self.items if item.purchase_order_item]
|
items_from_po = [item.purchase_order_item for item in self.items if item.purchase_order_item]
|
||||||
if items_with_po_item:
|
if items_from_po:
|
||||||
po_items = [item.purchase_order_item for item in items_with_po_item]
|
|
||||||
table = frappe.qb.DocType("Purchase Order Item")
|
table = frappe.qb.DocType("Purchase Order Item")
|
||||||
query = (
|
subquery = (
|
||||||
frappe.qb.from_(table)
|
frappe.qb.from_(table)
|
||||||
.select(
|
.select(table.production_plan_sub_assembly_item)
|
||||||
table.name,
|
.distinct()
|
||||||
(table.qty / table.fg_item_qty).as_("sc_conversion_factor"),
|
.where(table.name.isin(items_from_po) & table.production_plan_sub_assembly_item.isnotnull())
|
||||||
table.production_plan_sub_assembly_item,
|
|
||||||
Sum(table.received_qty).as_("received_qty"),
|
|
||||||
)
|
|
||||||
.where(table.name.isin(po_items))
|
|
||||||
.groupby(table.name)
|
|
||||||
)
|
)
|
||||||
result = query.run(as_dict=True)
|
result = subquery.run(as_dict=True)
|
||||||
|
if result:
|
||||||
for item in items_with_po_item:
|
result = [item.production_plan_sub_assembly_item for item in result]
|
||||||
row = next(d for d in result if d.name == item.purchase_order_item)
|
query = (
|
||||||
if row.production_plan_sub_assembly_item:
|
frappe.qb.from_(table)
|
||||||
received_qty = (
|
.select(
|
||||||
(row.received_qty + (item.qty / row.sc_conversion_factor))
|
table.production_plan_sub_assembly_item,
|
||||||
if not cancel
|
Sum(table.received_qty / (table.qty / table.fg_item_qty)).as_("received_qty"),
|
||||||
else (row.received_qty - (item.qty / row.sc_conversion_factor))
|
|
||||||
)
|
)
|
||||||
|
.where(table.production_plan_sub_assembly_item.isin(result))
|
||||||
|
.groupby(table.production_plan_sub_assembly_item)
|
||||||
|
)
|
||||||
|
for row in query.run(as_dict=True):
|
||||||
frappe.set_value(
|
frappe.set_value(
|
||||||
"Production Plan Sub Assembly Item",
|
"Production Plan Sub Assembly Item",
|
||||||
row.production_plan_sub_assembly_item,
|
row.production_plan_sub_assembly_item,
|
||||||
"received_qty",
|
"received_qty",
|
||||||
received_qty,
|
row.received_qty,
|
||||||
)
|
)
|
||||||
|
|
||||||
def check_next_docstatus(self):
|
def check_next_docstatus(self):
|
||||||
@@ -460,7 +457,7 @@ class PurchaseReceipt(BuyingController):
|
|||||||
)
|
)
|
||||||
self.delete_auto_created_batches()
|
self.delete_auto_created_batches()
|
||||||
self.set_consumed_qty_in_subcontract_order()
|
self.set_consumed_qty_in_subcontract_order()
|
||||||
self.update_received_qty_if_from_pp(cancel=True)
|
self.update_received_qty_if_from_pp()
|
||||||
|
|
||||||
def get_gl_entries(self, warehouse_account=None, via_landed_cost_voucher=False):
|
def get_gl_entries(self, warehouse_account=None, via_landed_cost_voucher=False):
|
||||||
from erpnext.accounts.general_ledger import process_gl_map
|
from erpnext.accounts.general_ledger import process_gl_map
|
||||||
|
|||||||
Reference in New Issue
Block a user