From 5999ade43a1ba75d88906e936220547dd4181569 Mon Sep 17 00:00:00 2001 From: rohitwaghchaure Date: Wed, 9 Aug 2017 17:24:13 +0530 Subject: [PATCH] [Fix] Auto batch creation not working for purchase invoice is update stock is enabled (#10348) --- .../purchase_invoice/purchase_invoice.py | 3 +++ .../purchase_invoice/test_purchase_invoice.py | 21 +++++++++++++++++++ erpnext/public/js/controllers/transaction.js | 2 +- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py index 589bc40cd5..7ab790118a 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -53,6 +53,9 @@ class PurchaseInvoice(BuyingController): if (self.is_paid == 1): self.validate_cash() + if self._action=="submit" and self.update_stock: + self.make_batches('warehouse') + self.check_conversion_rate() self.validate_credit_to_acc() self.clear_unallocated_advances("Purchase Invoice Advance", "advances") diff --git a/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py index 8bbd6c5f05..3454a2e9b4 100644 --- a/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py @@ -403,6 +403,27 @@ class TestPurchaseInvoice(unittest.TestCase): self.assertEquals(expected_gl_entries[gle.account][1], gle.debit) self.assertEquals(expected_gl_entries[gle.account][2], gle.credit) + def test_auto_batch(self): + item_code = frappe.db.get_value('Item', + {'has_batch_no': 1, 'create_new_batch':1}, 'name') + + if not item_code: + doc = frappe.get_doc({ + 'doctype': 'Item', + 'is_stock_item': 1, + 'item_code': 'test batch item', + 'item_group': 'Products', + 'has_batch_no': 1, + 'create_new_batch': 1 + }).insert(ignore_permissions=True) + item_code = doc.name + + pi = make_purchase_invoice(update_stock=1, posting_date=frappe.utils.nowdate(), + posting_time=frappe.utils.nowtime(), item_code=item_code) + + self.assertTrue(frappe.db.get_value('Batch', + {'item': item_code, 'reference_name': pi.name})) + def test_update_stock_and_purchase_return(self): actual_qty_0 = get_qty_after_transaction() diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index c798ade137..3a8ddb5927 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -261,7 +261,7 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ var item = frappe.get_doc(cdt, cdn); var update_stock = 0, show_batch_dialog = 0; - if(['Sales Invoice', 'Purchase Invoice'].includes(this.frm.doc.doctype)) { + if(['Sales Invoice'].includes(this.frm.doc.doctype)) { update_stock = cint(me.frm.doc.update_stock); show_batch_dialog = update_stock;