refactor!: Subcontracted Item To Be Received
This commit is contained in:
parent
8486bbf31a
commit
3be663b121
@ -19,10 +19,10 @@ def execute(filters=None):
|
||||
def get_columns():
|
||||
return [
|
||||
{
|
||||
"label": _("Purchase Order"),
|
||||
"label": _("Subcontracting Order"),
|
||||
"fieldtype": "Link",
|
||||
"fieldname": "purchase_order",
|
||||
"options": "Purchase Order",
|
||||
"fieldname": "subcontracting_order",
|
||||
"options": "Subcontracting Order",
|
||||
"width": 150,
|
||||
},
|
||||
{"label": _("Date"), "fieldtype": "Date", "fieldname": "date", "hidden": 1, "width": 150},
|
||||
@ -57,14 +57,14 @@ def get_columns():
|
||||
|
||||
|
||||
def get_data(data, filters):
|
||||
po = get_po(filters)
|
||||
po_name = [v.name for v in po]
|
||||
sub_items = get_purchase_order_item_supplied(po_name)
|
||||
sco = get_sco(filters)
|
||||
sco_name = [v.name for v in sco]
|
||||
sub_items = get_subcontracting_order_item_supplied(sco_name)
|
||||
for item in sub_items:
|
||||
for order in po:
|
||||
for order in sco:
|
||||
if order.name == item.parent and item.received_qty < item.qty:
|
||||
row = {
|
||||
"purchase_order": item.parent,
|
||||
"subcontracting_order": item.parent,
|
||||
"date": order.transaction_date,
|
||||
"supplier": order.supplier,
|
||||
"fg_item_code": item.item_code,
|
||||
@ -76,22 +76,21 @@ def get_data(data, filters):
|
||||
data.append(row)
|
||||
|
||||
|
||||
def get_po(filters):
|
||||
def get_sco(filters):
|
||||
record_filters = [
|
||||
["is_subcontracted", "=", 1],
|
||||
["supplier", "=", filters.supplier],
|
||||
["transaction_date", "<=", filters.to_date],
|
||||
["transaction_date", ">=", filters.from_date],
|
||||
["docstatus", "=", 1],
|
||||
]
|
||||
return frappe.get_all(
|
||||
"Purchase Order", filters=record_filters, fields=["name", "transaction_date", "supplier"]
|
||||
"Subcontracting Order", filters=record_filters, fields=["name", "transaction_date", "supplier"]
|
||||
)
|
||||
|
||||
|
||||
def get_purchase_order_item_supplied(po):
|
||||
def get_subcontracting_order_item_supplied(sco):
|
||||
return frappe.get_all(
|
||||
"Purchase Order Item",
|
||||
filters=[("parent", "IN", po)],
|
||||
"Subcontracting Order Item",
|
||||
filters=[("parent", "IN", sco)],
|
||||
fields=["parent", "item_code", "item_name", "qty", "received_qty"],
|
||||
)
|
||||
|
@ -7,18 +7,35 @@
|
||||
import frappe
|
||||
from frappe.tests.utils import FrappeTestCase
|
||||
|
||||
from erpnext.buying.doctype.purchase_order.purchase_order import make_purchase_receipt
|
||||
from erpnext.buying.doctype.purchase_order.test_purchase_order import create_purchase_order
|
||||
from erpnext.buying.report.subcontracted_item_to_be_received.subcontracted_item_to_be_received import (
|
||||
execute,
|
||||
)
|
||||
from erpnext.controllers.tests.test_subcontracting_controller import (
|
||||
get_subcontracting_order,
|
||||
make_service_item,
|
||||
)
|
||||
from erpnext.stock.doctype.stock_entry.test_stock_entry import make_stock_entry
|
||||
from erpnext.subcontracting.doctype.subcontracting_order.subcontracting_order import (
|
||||
make_subcontracting_receipt,
|
||||
)
|
||||
|
||||
|
||||
class TestSubcontractedItemToBeReceived(FrappeTestCase):
|
||||
def test_pending_and_received_qty(self):
|
||||
po = create_purchase_order(item_code="_Test FG Item", is_subcontracted=1)
|
||||
transfer_param = []
|
||||
make_service_item("Subcontracted Service Item 1")
|
||||
service_items = [
|
||||
{
|
||||
"warehouse": "_Test Warehouse - _TC",
|
||||
"item_code": "Subcontracted Service Item 1",
|
||||
"qty": 10,
|
||||
"rate": 500,
|
||||
"fg_item": "_Test FG Item",
|
||||
"fg_item_qty": 10,
|
||||
},
|
||||
]
|
||||
sco = get_subcontracting_order(
|
||||
service_items=service_items, supplier_warehouse="_Test Warehouse 1 - _TC"
|
||||
)
|
||||
make_stock_entry(
|
||||
item_code="_Test Item", target="_Test Warehouse 1 - _TC", qty=100, basic_rate=100
|
||||
)
|
||||
@ -28,28 +45,27 @@ class TestSubcontractedItemToBeReceived(FrappeTestCase):
|
||||
qty=100,
|
||||
basic_rate=100,
|
||||
)
|
||||
make_purchase_receipt_against_po(po.name)
|
||||
po.reload()
|
||||
make_subcontracting_receipt_against_sco(sco.name)
|
||||
sco.reload()
|
||||
col, data = execute(
|
||||
filters=frappe._dict(
|
||||
{
|
||||
"supplier": po.supplier,
|
||||
"supplier": sco.supplier,
|
||||
"from_date": frappe.utils.get_datetime(
|
||||
frappe.utils.add_to_date(po.transaction_date, days=-10)
|
||||
frappe.utils.add_to_date(sco.transaction_date, days=-10)
|
||||
),
|
||||
"to_date": frappe.utils.get_datetime(frappe.utils.add_to_date(po.transaction_date, days=10)),
|
||||
"to_date": frappe.utils.get_datetime(frappe.utils.add_to_date(sco.transaction_date, days=10)),
|
||||
}
|
||||
)
|
||||
)
|
||||
self.assertEqual(data[0]["pending_qty"], 5)
|
||||
self.assertEqual(data[0]["received_qty"], 5)
|
||||
self.assertEqual(data[0]["purchase_order"], po.name)
|
||||
self.assertEqual(data[0]["supplier"], po.supplier)
|
||||
self.assertEqual(data[0]["subcontracting_order"], sco.name)
|
||||
self.assertEqual(data[0]["supplier"], sco.supplier)
|
||||
|
||||
|
||||
def make_purchase_receipt_against_po(po, quantity=5):
|
||||
pr = make_purchase_receipt(po)
|
||||
pr.items[0].qty = quantity
|
||||
pr.supplier_warehouse = "_Test Warehouse 1 - _TC"
|
||||
pr.insert()
|
||||
pr.submit()
|
||||
def make_subcontracting_receipt_against_sco(sco, quantity=5):
|
||||
scr = make_subcontracting_receipt(sco)
|
||||
scr.items[0].qty = quantity
|
||||
scr.insert()
|
||||
scr.submit()
|
||||
|
Loading…
Reference in New Issue
Block a user