fix: update received qty in PO from PR

This commit is contained in:
Nabin Hait 2019-05-21 18:30:15 +05:30
parent 7327f8a901
commit d752051b8d
4 changed files with 3082 additions and 3067 deletions

View File

@ -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)
@ -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

View File

@ -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):

View File

@ -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):