mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-03 12:19:12 +00:00
fix: Select location based on group warehouse
This commit is contained in:
@@ -2,6 +2,16 @@
|
|||||||
// For license information, please see license.txt
|
// For license information, please see license.txt
|
||||||
|
|
||||||
frappe.ui.form.on('Pick Ticket', {
|
frappe.ui.form.on('Pick Ticket', {
|
||||||
|
setup: (frm) => {
|
||||||
|
frm.set_query('group_warehouse', () => {
|
||||||
|
return {
|
||||||
|
filters: {
|
||||||
|
'is_group': 1,
|
||||||
|
'company': frm.doc.company
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
},
|
||||||
refresh: (frm) => {
|
refresh: (frm) => {
|
||||||
this.frm.add_custom_button(__('Sales Order'), function() {
|
this.frm.add_custom_button(__('Sales Order'), function() {
|
||||||
erpnext.utils.map_current_doc({
|
erpnext.utils.map_current_doc({
|
||||||
|
|||||||
@@ -9,10 +9,15 @@ from frappe.model.document import Document
|
|||||||
class PickTicket(Document):
|
class PickTicket(Document):
|
||||||
def set_item_locations(self):
|
def set_item_locations(self):
|
||||||
reference_items = self.reference_document_items
|
reference_items = self.reference_document_items
|
||||||
|
|
||||||
|
from_warehouses = None
|
||||||
|
if self.group_warehouse:
|
||||||
|
from_warehouses = frappe.db.get_descendants('Warehouse', self.group_warehouse)
|
||||||
|
|
||||||
|
# Reset
|
||||||
self.delete_key('items')
|
self.delete_key('items')
|
||||||
for item in reference_items:
|
for item in reference_items:
|
||||||
data = get_items_with_warehouse_and_quantity(item)
|
data = get_items_with_warehouse_and_quantity(item, from_warehouses)
|
||||||
|
|
||||||
for item_info in data:
|
for item_info in data:
|
||||||
print(self.append('items', item_info))
|
print(self.append('items', item_info))
|
||||||
|
|
||||||
@@ -22,22 +27,11 @@ class PickTicket(Document):
|
|||||||
elif frappe.get_cached_value('Item', item_doc.item, 'has_batch_no'):
|
elif frappe.get_cached_value('Item', item_doc.item, 'has_batch_no'):
|
||||||
set_batch_no(item_doc, self)
|
set_batch_no(item_doc, self)
|
||||||
|
|
||||||
def get_available_items(item):
|
def get_items_with_warehouse_and_quantity(item_doc, from_warehouses):
|
||||||
# gets all items available in different warehouses
|
|
||||||
# FIFO
|
|
||||||
available_items = frappe.get_all('Bin', filters={
|
|
||||||
'item_code': item,
|
|
||||||
'actual_qty': ['>', 0]
|
|
||||||
}, fields=['warehouse', 'actual_qty as qty'], order_by='creation')
|
|
||||||
|
|
||||||
return available_items
|
|
||||||
|
|
||||||
def get_items_with_warehouse_and_quantity(item_doc):
|
|
||||||
items = []
|
items = []
|
||||||
item_locations = get_available_items(item_doc.item)
|
item_locations = get_available_items(item_doc.item, from_warehouses)
|
||||||
remaining_qty = item_doc.qty
|
remaining_qty = item_doc.qty
|
||||||
|
|
||||||
|
|
||||||
while remaining_qty > 0 and item_locations:
|
while remaining_qty > 0 and item_locations:
|
||||||
item_location = item_locations.pop(0)
|
item_location = item_locations.pop(0)
|
||||||
qty = remaining_qty if item_location.qty >= remaining_qty else item_location.qty
|
qty = remaining_qty if item_location.qty >= remaining_qty else item_location.qty
|
||||||
@@ -51,11 +45,28 @@ def get_items_with_warehouse_and_quantity(item_doc):
|
|||||||
remaining_qty -= qty
|
remaining_qty -= qty
|
||||||
|
|
||||||
if remaining_qty:
|
if remaining_qty:
|
||||||
print('---------- {} qty of {} is out of stock. Skipping... -------------'.format(remaining_qty, item_doc.item))
|
frappe.msgprint('{} qty of {} is out of stock. Skipping...'.format(remaining_qty, item_doc.item))
|
||||||
return items
|
return items
|
||||||
|
|
||||||
return items
|
return items
|
||||||
|
|
||||||
|
def get_available_items(item, from_warehouses):
|
||||||
|
# gets all items available in different warehouses
|
||||||
|
# FIFO
|
||||||
|
filters = frappe._dict({
|
||||||
|
'item_code': item,
|
||||||
|
'actual_qty': ['>', 0]
|
||||||
|
})
|
||||||
|
if from_warehouses:
|
||||||
|
filters.warehouse = ['in', from_warehouses]
|
||||||
|
|
||||||
|
available_items = frappe.get_all('Bin',
|
||||||
|
fields=['warehouse', 'actual_qty as qty'],
|
||||||
|
filters=filters,
|
||||||
|
order_by='creation')
|
||||||
|
|
||||||
|
return available_items
|
||||||
|
|
||||||
def set_serial_nos(item_doc):
|
def set_serial_nos(item_doc):
|
||||||
serial_nos = frappe.get_all('Serial No', {
|
serial_nos = frappe.get_all('Serial No', {
|
||||||
'item_code': item_doc.item,
|
'item_code': item_doc.item,
|
||||||
@@ -91,7 +102,7 @@ def set_batch_no(item_doc, parent_doc):
|
|||||||
batch = batches.pop()
|
batch = batches.pop()
|
||||||
batch_expiry = frappe.get_value('Batch', batch.batch_no, 'expiry_date')
|
batch_expiry = frappe.get_value('Batch', batch.batch_no, 'expiry_date')
|
||||||
if batch_expiry and batch_expiry <= frappe.utils.getdate():
|
if batch_expiry and batch_expiry <= frappe.utils.getdate():
|
||||||
print('---------- Batch {} is expired. Skipping... -------------'.format(batch.batch_no))
|
frappe.msgprint('Skipping expired Batch {}'.format(batch.batch_no))
|
||||||
continue
|
continue
|
||||||
item_doc.batch_no = batch.batch_no
|
item_doc.batch_no = batch.batch_no
|
||||||
if batch.qty >= item_doc.qty:
|
if batch.qty >= item_doc.qty:
|
||||||
@@ -112,5 +123,5 @@ def set_batch_no(item_doc, parent_doc):
|
|||||||
'reference_name': item_doc.reference_name
|
'reference_name': item_doc.reference_name
|
||||||
})
|
})
|
||||||
if required_qty:
|
if required_qty:
|
||||||
print('---------- No batches found for {} qty of {}. Skipping... -------------'.format(required_qty, item_doc.item))
|
frappe.msgprint('No batches found for {} qty of {}. Skipping...'.format(required_qty, item_doc.item))
|
||||||
parent_doc.remove(item_doc)
|
parent_doc.remove(item_doc)
|
||||||
|
|||||||
Reference in New Issue
Block a user