Don't set batch nos automatically on saving, if already set and validate qty with batch (#8887)
This commit is contained in:
parent
52e1ba7714
commit
8fac2ad183
@ -17,6 +17,7 @@ from erpnext.stock.doctype.delivery_note.delivery_note import update_billed_amou
|
|||||||
from erpnext.projects.doctype.timesheet.timesheet import get_projectwise_timesheet_data
|
from erpnext.projects.doctype.timesheet.timesheet import get_projectwise_timesheet_data
|
||||||
from erpnext.accounts.doctype.asset.depreciation \
|
from erpnext.accounts.doctype.asset.depreciation \
|
||||||
import get_disposal_account_and_cost_center, get_gl_entries_on_asset_disposal
|
import get_disposal_account_and_cost_center, get_gl_entries_on_asset_disposal
|
||||||
|
from erpnext.stock.doctype.batch.batch import set_batch_nos
|
||||||
|
|
||||||
form_grid_templates = {
|
form_grid_templates = {
|
||||||
"items": "templates/form_grid/item_grid.html"
|
"items": "templates/form_grid/item_grid.html"
|
||||||
@ -79,6 +80,10 @@ class SalesInvoice(SellingController):
|
|||||||
if not self.is_opening:
|
if not self.is_opening:
|
||||||
self.is_opening = 'No'
|
self.is_opening = 'No'
|
||||||
|
|
||||||
|
if self._action != 'submit' and self.update_stock and not self.is_return:
|
||||||
|
set_batch_nos(self, 'warehouse', True)
|
||||||
|
|
||||||
|
|
||||||
self.set_against_income_account()
|
self.set_against_income_account()
|
||||||
self.validate_c_form()
|
self.validate_c_form()
|
||||||
self.validate_time_sheets_are_submitted()
|
self.validate_time_sheets_are_submitted()
|
||||||
|
@ -5,6 +5,7 @@ from __future__ import unicode_literals
|
|||||||
import frappe
|
import frappe
|
||||||
from frappe import _
|
from frappe import _
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
|
from frappe.utils import flt
|
||||||
|
|
||||||
class UnableToSelectBatchError(frappe.ValidationError): pass
|
class UnableToSelectBatchError(frappe.ValidationError): pass
|
||||||
|
|
||||||
@ -96,18 +97,21 @@ def set_batch_nos(doc, warehouse_field, throw = False):
|
|||||||
for d in doc.items:
|
for d in doc.items:
|
||||||
has_batch_no = frappe.db.get_value('Item', d.item_code, 'has_batch_no')
|
has_batch_no = frappe.db.get_value('Item', d.item_code, 'has_batch_no')
|
||||||
warehouse = d.get(warehouse_field, None)
|
warehouse = d.get(warehouse_field, None)
|
||||||
if has_batch_no and not d.batch_no and warehouse:
|
if has_batch_no and warehouse and d.qty > 0:
|
||||||
|
if not d.batch_no:
|
||||||
d.batch_no = get_batch_no(d.item_code, warehouse, d.qty, throw)
|
d.batch_no = get_batch_no(d.item_code, warehouse, d.qty, throw)
|
||||||
|
else:
|
||||||
|
batch_qty = get_batch_qty(batch_no=d.batch_no, warehouse=warehouse)
|
||||||
|
if flt(batch_qty) < flt(d.qty):
|
||||||
|
frappe.throw(_("Row #{0}: The batch {1} has only {2} qty. Please select another batch which has {3} qty available or split the row into multiple rows, to deliver/issue from multiple batches").format(d.idx, d.batch_no, batch_qty, d.qty))
|
||||||
|
|
||||||
def get_batch_no(item_code, warehouse, qty, throw=False):
|
def get_batch_no(item_code, warehouse, qty, throw=False):
|
||||||
'''get the smallest batch with for the given item_code, warehouse and qty'''
|
'''get the smallest batch with for the given item_code, warehouse and qty'''
|
||||||
|
|
||||||
batch_no = None
|
batch_no = None
|
||||||
|
|
||||||
batches = get_batch_qty(item_code = item_code, warehouse = warehouse)
|
batches = get_batch_qty(item_code = item_code, warehouse = warehouse)
|
||||||
if batches:
|
if batches:
|
||||||
batches = sorted(batches, lambda a, b: 1 if a.qty > b.qty else -1)
|
batches = sorted(batches, lambda a, b: 1 if a.qty > b.qty else -1)
|
||||||
|
|
||||||
for b in batches:
|
for b in batches:
|
||||||
if b.qty >= qty:
|
if b.qty >= qty:
|
||||||
batch_no = b.batch_no
|
batch_no = b.batch_no
|
||||||
|
@ -106,7 +106,7 @@ class DeliveryNote(SellingController):
|
|||||||
self.validate_uom_is_integer("uom", "qty")
|
self.validate_uom_is_integer("uom", "qty")
|
||||||
self.validate_with_previous_doc()
|
self.validate_with_previous_doc()
|
||||||
|
|
||||||
if self._action != 'submit':
|
if self._action != 'submit' and not self.is_return:
|
||||||
set_batch_nos(self, 'warehouse', True)
|
set_batch_nos(self, 'warehouse', True)
|
||||||
|
|
||||||
from erpnext.stock.doctype.packed_item.packed_item import make_packing_list
|
from erpnext.stock.doctype.packed_item.packed_item import make_packing_list
|
||||||
|
@ -81,7 +81,7 @@ def get_item_details(args):
|
|||||||
if out.has_serial_no:
|
if out.has_serial_no:
|
||||||
out.serial_no = get_serial_no(out)
|
out.serial_no = get_serial_no(out)
|
||||||
|
|
||||||
if out.has_batch_no:
|
if out.has_batch_no and not args.get("batch_no"):
|
||||||
out.batch_no = get_batch_no(out.item_code, out.warehouse, out.qty)
|
out.batch_no = get_batch_no(out.item_code, out.warehouse, out.qty)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user