Merge pull request #17697 from nabinhait/po-status-updater-dev-1
fix: update received qty in PO from PR and PI
This commit is contained in:
commit
e662be7508
@ -8,7 +8,9 @@ import frappe.defaults
|
||||
from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry
|
||||
from frappe.utils import flt, add_days, nowdate, getdate
|
||||
from erpnext.stock.doctype.item.test_item import make_item
|
||||
from erpnext.buying.doctype.purchase_order.purchase_order import (make_purchase_receipt, make_purchase_invoice, make_rm_stock_entry as make_subcontract_transfer_entry)
|
||||
from erpnext.buying.doctype.purchase_order.purchase_order \
|
||||
import (make_purchase_receipt, make_purchase_invoice as make_pi_from_po, make_rm_stock_entry as make_subcontract_transfer_entry)
|
||||
from erpnext.stock.doctype.purchase_receipt.purchase_receipt import make_purchase_invoice as make_pi_from_pr
|
||||
from erpnext.stock.doctype.material_request.test_material_request import make_material_request
|
||||
from erpnext.stock.doctype.material_request.material_request import make_purchase_order
|
||||
from erpnext.stock.doctype.stock_entry.test_stock_entry import make_stock_entry
|
||||
@ -62,7 +64,7 @@ class TestPurchaseOrder(unittest.TestCase):
|
||||
|
||||
frappe.db.set_value('Item', '_Test Item', 'tolerance', 50)
|
||||
|
||||
pi = make_purchase_invoice(po.name)
|
||||
pi = make_pi_from_po(po.name)
|
||||
pi.update_stock = 1
|
||||
pi.items[0].qty = 12
|
||||
pi.insert()
|
||||
@ -89,7 +91,7 @@ class TestPurchaseOrder(unittest.TestCase):
|
||||
|
||||
create_pr_against_po(po.name)
|
||||
|
||||
make_purchase_invoice(po.name)
|
||||
make_pi_from_po(po.name)
|
||||
|
||||
existing_ordered_qty = get_ordered_qty()
|
||||
existing_requested_qty = get_requested_qty()
|
||||
@ -111,29 +113,37 @@ class TestPurchaseOrder(unittest.TestCase):
|
||||
def test_update_qty(self):
|
||||
po = create_purchase_order()
|
||||
|
||||
make_pr_against_po(po.name, 6)
|
||||
pr = make_pr_against_po(po.name, 2)
|
||||
|
||||
po.load_from_db()
|
||||
self.assertEqual(po.get("items")[0].received_qty, 6)
|
||||
self.assertEqual(po.get("items")[0].received_qty, 2)
|
||||
|
||||
# Check received_qty after make_purchase_invoice without update_stock checked
|
||||
pi1 = make_purchase_invoice(po.name)
|
||||
pi1.get("items")[0].qty = 6
|
||||
# Check received_qty after making PI from PR without update_stock checked
|
||||
pi1 = make_pi_from_pr(pr.name)
|
||||
pi1.get("items")[0].qty = 2
|
||||
pi1.insert()
|
||||
pi1.submit()
|
||||
|
||||
po.load_from_db()
|
||||
self.assertEqual(po.get("items")[0].received_qty, 6)
|
||||
self.assertEqual(po.get("items")[0].received_qty, 2)
|
||||
|
||||
# Check received_qty after make_purchase_invoice with update_stock checked
|
||||
pi2 = make_purchase_invoice(po.name)
|
||||
# Check received_qty after making PI from PO with update_stock checked
|
||||
pi2 = make_pi_from_po(po.name)
|
||||
pi2.set("update_stock", 1)
|
||||
pi2.get("items")[0].qty = 3
|
||||
pi2.insert()
|
||||
pi2.submit()
|
||||
|
||||
po.load_from_db()
|
||||
self.assertEqual(po.get("items")[0].received_qty, 9)
|
||||
self.assertEqual(po.get("items")[0].received_qty, 5)
|
||||
|
||||
# Check received_qty after making PR from PO
|
||||
pr = make_pr_against_po(po.name, 1)
|
||||
|
||||
po.load_from_db()
|
||||
self.assertEqual(po.get("items")[0].received_qty, 6)
|
||||
|
||||
|
||||
|
||||
def test_return_against_purchase_order(self):
|
||||
po = create_purchase_order()
|
||||
@ -143,7 +153,7 @@ class TestPurchaseOrder(unittest.TestCase):
|
||||
po.load_from_db()
|
||||
self.assertEqual(po.get("items")[0].received_qty, 6)
|
||||
|
||||
pi2 = make_purchase_invoice(po.name)
|
||||
pi2 = make_pi_from_po(po.name)
|
||||
pi2.set("update_stock", 1)
|
||||
pi2.get("items")[0].qty = 3
|
||||
pi2.insert()
|
||||
@ -175,10 +185,10 @@ class TestPurchaseOrder(unittest.TestCase):
|
||||
def test_make_purchase_invoice(self):
|
||||
po = create_purchase_order(do_not_submit=True)
|
||||
|
||||
self.assertRaises(frappe.ValidationError, make_purchase_invoice, po.name)
|
||||
self.assertRaises(frappe.ValidationError, make_pi_from_po, po.name)
|
||||
|
||||
po.submit()
|
||||
pi = make_purchase_invoice(po.name)
|
||||
pi = make_pi_from_po(po.name)
|
||||
|
||||
self.assertEqual(pi.doctype, "Purchase Invoice")
|
||||
self.assertEqual(len(pi.get("items", [])), 1)
|
||||
@ -186,7 +196,7 @@ class TestPurchaseOrder(unittest.TestCase):
|
||||
def test_purchase_order_on_hold(self):
|
||||
po = create_purchase_order(item_code="_Test Product Bundle Item")
|
||||
po.db_set('Status', "On Hold")
|
||||
pi = make_purchase_invoice(po.name)
|
||||
pi = make_pi_from_po(po.name)
|
||||
pr = make_purchase_receipt(po.name)
|
||||
self.assertRaises(frappe.ValidationError, pr.submit)
|
||||
self.assertRaises(frappe.ValidationError, pi.submit)
|
||||
@ -195,7 +205,7 @@ class TestPurchaseOrder(unittest.TestCase):
|
||||
def test_make_purchase_invoice_with_terms(self):
|
||||
po = create_purchase_order(do_not_save=True)
|
||||
|
||||
self.assertRaises(frappe.ValidationError, make_purchase_invoice, po.name)
|
||||
self.assertRaises(frappe.ValidationError, make_pi_from_po, po.name)
|
||||
|
||||
po.update(
|
||||
{"payment_terms_template": "_Test Payment Term Template"}
|
||||
@ -208,7 +218,7 @@ class TestPurchaseOrder(unittest.TestCase):
|
||||
self.assertEqual(getdate(po.payment_schedule[0].due_date), getdate(po.transaction_date))
|
||||
self.assertEqual(po.payment_schedule[1].payment_amount, 2500.0)
|
||||
self.assertEqual(getdate(po.payment_schedule[1].due_date), add_days(getdate(po.transaction_date), 30))
|
||||
pi = make_purchase_invoice(po.name)
|
||||
pi = make_pi_from_po(po.name)
|
||||
pi.save()
|
||||
|
||||
self.assertEqual(pi.doctype, "Purchase Invoice")
|
||||
@ -346,7 +356,7 @@ class TestPurchaseOrder(unittest.TestCase):
|
||||
|
||||
self.assertTrue(po.get('payment_schedule'))
|
||||
|
||||
pi = make_purchase_invoice(po.name)
|
||||
pi = make_pi_from_po(po.name)
|
||||
|
||||
self.assertFalse(pi.get('payment_schedule'))
|
||||
|
||||
@ -357,7 +367,7 @@ class TestPurchaseOrder(unittest.TestCase):
|
||||
po.submit()
|
||||
self.assertTrue(po.get('payment_schedule'))
|
||||
|
||||
pi = make_purchase_invoice(po.name)
|
||||
pi = make_pi_from_po(po.name)
|
||||
pi.insert()
|
||||
self.assertTrue(pi.get('payment_schedule'))
|
||||
|
||||
@ -442,7 +452,7 @@ class TestPurchaseOrder(unittest.TestCase):
|
||||
self.assertEquals(bin7.reserved_qty_for_sub_contract, bin2.reserved_qty_for_sub_contract - 6)
|
||||
|
||||
# Make Purchase Invoice
|
||||
pi = make_purchase_invoice(po.name)
|
||||
pi = make_pi_from_po(po.name)
|
||||
pi.update_stock = 1
|
||||
pi.supplier_warehouse = "_Test Warehouse 1 - _TC"
|
||||
pi.insert()
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -64,7 +64,10 @@ class DeliveryNote(SellingController):
|
||||
'second_source_dt': 'Sales Invoice Item',
|
||||
'second_source_field': '-1 * qty',
|
||||
'second_join_field': 'so_detail',
|
||||
'extra_cond': """ and exists (select name from `tabDelivery Note` where name=`tabDelivery Note Item`.parent and is_return=1)"""
|
||||
'extra_cond': """ and exists (select name from `tabDelivery Note`
|
||||
where name=`tabDelivery Note Item`.parent and is_return=1)""",
|
||||
'second_source_extra_cond': """ and exists (select name from `tabSales Invoice`
|
||||
where name=`tabSales Invoice Item`.parent and is_return=1 and update_stock=1)"""
|
||||
})
|
||||
|
||||
def before_print(self):
|
||||
|
@ -233,6 +233,8 @@ def update_completed_and_requested_qty(stock_entry, method):
|
||||
mr_obj.update_requested_qty(mr_item_rows)
|
||||
|
||||
def set_missing_values(source, target_doc):
|
||||
if target_doc.doctype == "Purchase Order" and getdate(target_doc.schedule_date) < getdate(nowdate()):
|
||||
target_doc.schedule_date = None
|
||||
target_doc.run_method("set_missing_values")
|
||||
target_doc.run_method("calculate_taxes_and_totals")
|
||||
|
||||
@ -240,6 +242,8 @@ def update_item(obj, target, source_parent):
|
||||
target.conversion_factor = obj.conversion_factor
|
||||
target.qty = flt(flt(obj.stock_qty) - flt(obj.ordered_qty))/ target.conversion_factor
|
||||
target.stock_qty = (target.qty * target.conversion_factor)
|
||||
if getdate(target.schedule_date) < getdate(nowdate()):
|
||||
target.schedule_date = None
|
||||
|
||||
def get_list_context(context=None):
|
||||
from erpnext.controllers.website_list_for_contact import get_list_context
|
||||
@ -336,7 +340,8 @@ def make_purchase_order_based_on_supplier(source_name, target_doc=None):
|
||||
|
||||
def postprocess(source, target_doc):
|
||||
target_doc.supplier = source_name
|
||||
target_doc.schedule_date = add_days(nowdate(), 1)
|
||||
if getdate(target_doc.schedule_date) < getdate(nowdate()):
|
||||
target_doc.schedule_date = None
|
||||
target_doc.set("items", [d for d in target_doc.get("items")
|
||||
if d.get("item_code") in supplier_items and d.get("qty") > 0])
|
||||
|
||||
|
@ -36,7 +36,9 @@ class PurchaseReceipt(BuyingController):
|
||||
'second_source_field': 'received_qty',
|
||||
'second_join_field': 'po_detail',
|
||||
'percent_join_field': 'purchase_order',
|
||||
'overflow_type': 'receipt'
|
||||
'overflow_type': 'receipt',
|
||||
'second_source_extra_cond': """ and exists(select name from `tabPurchase Invoice`
|
||||
where name=`tabPurchase Invoice Item`.parent and update_stock = 1)"""
|
||||
},
|
||||
{
|
||||
'source_dt': 'Purchase Receipt Item',
|
||||
@ -55,10 +57,7 @@ class PurchaseReceipt(BuyingController):
|
||||
'join_field': 'purchase_order_item',
|
||||
'target_field': 'returned_qty',
|
||||
'target_parent_dt': 'Purchase Order',
|
||||
# 'target_parent_field': 'per_received',
|
||||
# 'target_ref_field': 'qty',
|
||||
'source_field': '-1 * qty',
|
||||
# 'overflow_type': 'receipt',
|
||||
'extra_cond': """ and exists (select name from `tabPurchase Receipt` where name=`tabPurchase Receipt Item`.parent and is_return=1)"""
|
||||
}]
|
||||
if cint(self.is_return):
|
||||
@ -71,7 +70,10 @@ class PurchaseReceipt(BuyingController):
|
||||
'second_source_dt': 'Purchase Invoice Item',
|
||||
'second_source_field': '-1 * qty',
|
||||
'second_join_field': 'po_detail',
|
||||
'extra_cond': """ and exists (select name from `tabPurchase Receipt` where name=`tabPurchase Receipt Item`.parent and is_return=1)"""
|
||||
'extra_cond': """ and exists (select name from `tabPurchase Receipt`
|
||||
where name=`tabPurchase Receipt Item`.parent and is_return=1)""",
|
||||
'second_source_extra_cond': """ and exists (select name from `tabPurchase Invoice`
|
||||
where name=`tabPurchase Invoice Item`.parent and is_return=1 and update_stock=1)"""
|
||||
})
|
||||
|
||||
def validate(self):
|
||||
|
Loading…
x
Reference in New Issue
Block a user