fix: Select location based on group warehouse

This commit is contained in:
Suraj Shetty 2019-07-30 11:47:21 +05:30
parent 341f7733d1
commit 14fb1600ec
2 changed files with 39 additions and 18 deletions

View File

@ -2,6 +2,16 @@
// For license information, please see license.txt
frappe.ui.form.on('Pick Ticket', {
setup: (frm) => {
frm.set_query('group_warehouse', () => {
return {
filters: {
'is_group': 1,
'company': frm.doc.company
}
};
});
},
refresh: (frm) => {
this.frm.add_custom_button(__('Sales Order'), function() {
erpnext.utils.map_current_doc({

View File

@ -9,10 +9,15 @@ from frappe.model.document import Document
class PickTicket(Document):
def set_item_locations(self):
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')
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:
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'):
set_batch_no(item_doc, self)
def get_available_items(item):
# 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):
def get_items_with_warehouse_and_quantity(item_doc, from_warehouses):
items = []
item_locations = get_available_items(item_doc.item)
item_locations = get_available_items(item_doc.item, from_warehouses)
remaining_qty = item_doc.qty
while remaining_qty > 0 and item_locations:
item_location = item_locations.pop(0)
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
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
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):
serial_nos = frappe.get_all('Serial No', {
'item_code': item_doc.item,
@ -91,7 +102,7 @@ def set_batch_no(item_doc, parent_doc):
batch = batches.pop()
batch_expiry = frappe.get_value('Batch', batch.batch_no, 'expiry_date')
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
item_doc.batch_no = batch.batch_no
if batch.qty >= item_doc.qty:
@ -112,5 +123,5 @@ def set_batch_no(item_doc, parent_doc):
'reference_name': item_doc.reference_name
})
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)