fix: Remove Pick List Reference Item use Item locations table instead

This commit is contained in:
Suraj Shetty 2019-08-28 17:44:22 +05:30
parent 1cf7270049
commit f455c92d02
11 changed files with 49 additions and 228 deletions

View File

@ -735,33 +735,22 @@ def create_pick_list(source_name, target_doc=None, for_qty=None):
else:
target.delete()
doc = get_mapped_doc("Work Order", source_name, {
"Work Order": {
"doctype": "Pick List",
"validation": {
"docstatus": ["=", 1]
doc = get_mapped_doc('Work Order', source_name, {
'Work Order': {
'doctype': 'Pick List',
'validation': {
'docstatus': ['=', 1]
}
},
"Work Order Item": {
"doctype": "Pick List Reference Item",
"postprocess": update_item_quantity,
"condition": lambda doc: abs(doc.transferred_qty) < abs(doc.required_qty)
'Work Order Item': {
'doctype': 'Pick List Item',
'postprocess': update_item_quantity,
'condition': lambda doc: abs(doc.transferred_qty) < abs(doc.required_qty)
},
}, target_doc)
# # aggregate qty for same item
# item_map = frappe._dict()
# for item in doc.items:
# item.idx = None
# if not item_map.get(item.item_code):
# item_map[item.item_code] = item
# else:
# item_map[item.item_code].qty += item.qty
# item_map[item.item_code].stock_qty += item.stock_qty
# doc.delete_key('items')
# doc.set('items', item_map.values())
doc.for_qty = for_qty
doc.set_item_locations()
return doc

View File

@ -998,24 +998,26 @@ def create_pick_list(source_name, target_doc=None):
target.qty = flt(source.qty) - flt(source.delivered_qty)
target.stock_qty = (flt(source.qty) - flt(source.delivered_qty)) * flt(source.conversion_factor)
doc = get_mapped_doc("Sales Order", source_name, {
"Sales Order": {
"doctype": "Pick List",
"validation": {
"docstatus": ["=", 1]
doc = get_mapped_doc('Sales Order', source_name, {
'Sales Order': {
'doctype': 'Pick List',
'validation': {
'docstatus': ['=', 1]
}
},
"Sales Order Item": {
"doctype": "Pick List Reference Item",
"field_map": {
"parent": "sales_order",
"name": "sales_order_item"
'Sales Order Item': {
'doctype': 'Pick List Item',
'field_map': {
'parent': 'sales_order',
'name': 'sales_order_item'
},
"postprocess": update_item_quantity,
"condition": lambda doc: abs(doc.delivered_qty) < abs(doc.qty) and doc.delivered_by_supplier!=1
'postprocess': update_item_quantity,
'condition': lambda doc: abs(doc.delivered_qty) < abs(doc.qty) and doc.delivered_by_supplier!=1
},
}, target_doc)
doc.purpose = 'Delivery against Sales Order'
doc.set_item_locations()
return doc

View File

@ -516,7 +516,7 @@ def create_pick_list(source_name, target_doc=None):
}
},
'Material Request Item': {
'doctype': 'Pick List Reference Item',
'doctype': 'Pick List Item',
'field_map': {
'name': 'material_request_item',
'qty': 'stock_qty'
@ -524,4 +524,6 @@ def create_pick_list(source_name, target_doc=None):
},
}, target_doc)
doc.set_item_locations()
return doc

View File

@ -30,6 +30,7 @@ frappe.ui.form.on('Pick List', {
}
};
});
// frm.set_df_property('get_item_locations', 'hidden', frm.is_dirty());
},
get_item_locations: (frm) => {
frm.call('set_item_locations');
@ -69,7 +70,6 @@ frappe.ui.form.on('Pick List', {
frappe.msgprint(__('Quantity must not be more than {0}', [max]));
return;
}
frm.clear_table('items');
frm.clear_table('locations');
erpnext.utils.map_current_doc({
method: 'erpnext.manufacturing.doctype.work_order.work_order.create_pick_list',
@ -80,20 +80,13 @@ frappe.ui.form.on('Pick List', {
});
},
material_request: (frm) => {
frm.clear_table('items');
frm.clear_table('locations');
erpnext.utils.map_current_doc({
method: 'erpnext.stock.doctype.material_request.material_request.create_pick_list',
target: frm,
source_name: frm.doc.material_request
});
},
parent_warehouse: (frm) => {
frm.clear_table('locations');
frm.refresh_field('locations');
},
purpose: (frm) => {
frm.clear_table('items');
frm.clear_table('locations');
frm.trigger('add_get_items_button');
},
@ -140,7 +133,7 @@ frappe.ui.form.on('Pick List', {
}
});
frappe.ui.form.on('Pick List Reference Item', {
frappe.ui.form.on('Pick List Item', {
item_code: (frm, cdt, cdn) => {
let row = frappe.get_doc(cdt, cdn);
if (row.item_code) {

View File

@ -14,8 +14,6 @@
"for_qty",
"column_break_4",
"parent_warehouse",
"section_break_4",
"items",
"get_item_locations",
"section_break_6",
"locations",
@ -38,10 +36,6 @@
"fieldname": "section_break_6",
"fieldtype": "Section Break"
},
{
"fieldname": "section_break_4",
"fieldtype": "Section Break"
},
{
"description": "Items under this warehouse will be suggested",
"fieldname": "parent_warehouse",
@ -64,13 +58,6 @@
"label": "Work Order",
"options": "Work Order"
},
{
"fieldname": "items",
"fieldtype": "Table",
"label": "Items To Be Picked",
"options": "Pick List Reference Item",
"reqd": 1
},
{
"fieldname": "locations",
"fieldtype": "Table",
@ -109,7 +96,6 @@
"options": "Material Request"
},
{
"depends_on": "eval: doc.items.length && (doc.items.length > 1 || doc.items[0].item_code) && doc.docstatus === 0",
"fieldname": "get_item_locations",
"fieldtype": "Button",
"label": "Get Item Locations"
@ -124,7 +110,7 @@
}
],
"is_submittable": 1,
"modified": "2019-08-28 12:27:22.743705",
"modified": "2019-08-28 12:49:59.800807",
"modified_by": "Administrator",
"module": "Stock",
"name": "Pick List",
@ -191,7 +177,6 @@
"write": 1
}
],
"quick_entry": 1,
"sort_field": "modified",
"sort_order": "DESC",
"track_changes": 1

View File

@ -17,7 +17,7 @@ from erpnext.selling.doctype.sales_order.sales_order import make_delivery_note a
class PickList(Document):
def set_item_locations(self):
items = self.items
item_locations = self.locations
self.item_location_map = frappe._dict()
from_warehouses = None
@ -26,7 +26,7 @@ class PickList(Document):
# Reset
self.delete_key('locations')
for item_doc in items:
for item_doc in item_locations:
item_code = item_doc.item_code
if frappe.get_cached_value('Item', item_code, 'has_serial_no'):
locations = get_item_locations_based_on_serial_nos(item_doc)
@ -37,20 +37,21 @@ class PickList(Document):
self.item_location_map[item_code] = get_available_items(item_code, from_warehouses)
locations = get_items_with_warehouse_and_quantity(item_doc, from_warehouses, self.item_location_map)
# hack
del item_doc.idx
if len(locations) > 1:
del item_doc.name
for row in locations:
stock_qty = row.get('qty', 0) * item_doc.conversion_factor
row.update({
'item_code': item_code,
'sales_order': item_doc.sales_order,
'sales_order_item': item_doc.sales_order_item,
'material_request': item_doc.material_request,
'material_request_item': item_doc.material_request_item,
'uom': item_doc.uom,
'stock_uom': item_doc.stock_uom,
'conversion_factor': item_doc.conversion_factor,
'stock_qty': row.get("qty", 0) * item_doc.conversion_factor,
'picked_qty': row.get("qty", 0) * item_doc.conversion_factor
'stock_qty': stock_qty,
'picked_qty': stock_qty
})
self.append('locations', row)
location = item_doc
location.update(row)
self.append('locations', location)
def get_items_with_warehouse_and_quantity(item_doc, from_warehouses, item_location_map):
available_locations = item_location_map.get(item_doc.item_code)
@ -242,27 +243,6 @@ def create_stock_entry(pick_list):
return stock_entry.as_dict()
@frappe.whitelist()
def create_stock_entry_with_material_request_items(pick_list):
stock_entry = frappe.new_doc('Stock Entry')
stock_entry.pick_list = pick_list.get('name')
stock_entry.purpose = pick_list.get('purpose')
stock_entry.set_stock_entry_type()
doc = get_mapped_doc("Work Order", source_name, {
"Work Order": {
"doctype": "Pick List",
"validation": {
"docstatus": ["=", 1]
}
},
"Work Order Item": {
"doctype": "Pick List Reference Item",
"postprocess": update_item_quantity,
"condition": lambda doc: abs(doc.transferred_qty) < abs(doc.required_qty)
},
}, target_doc)
@frappe.whitelist()
def get_pending_work_orders(doctype, txt, searchfield, start, page_length, filters, as_dict):
return frappe.db.sql("""

View File

@ -33,8 +33,7 @@
"fieldname": "qty",
"fieldtype": "Float",
"in_list_view": 1,
"label": "Qty",
"read_only": 1
"label": "Qty"
},
{
"fieldname": "picked_qty",
@ -100,8 +99,7 @@
"fieldname": "uom",
"fieldtype": "Link",
"label": "UOM",
"options": "UOM",
"read_only": 1
"options": "UOM"
},
{
"fieldname": "conversion_factor",
@ -121,8 +119,7 @@
"fieldtype": "Link",
"in_list_view": 1,
"label": "Item",
"options": "Item",
"read_only": 1
"options": "Item"
},
{
"fieldname": "quantity_section",
@ -171,7 +168,7 @@
}
],
"istable": 1,
"modified": "2019-08-28 12:34:06.224534",
"modified": "2019-08-28 15:56:14.507776",
"modified_by": "Administrator",
"module": "Stock",
"name": "Pick List Item",

View File

@ -1,8 +0,0 @@
// Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and contributors
// For license information, please see license.txt
frappe.ui.form.on('Pick List Reference Item', {
// refresh: function(frm) {
// }
});

View File

@ -1,109 +0,0 @@
{
"creation": "2019-07-24 16:11:07.415562",
"doctype": "DocType",
"editable_grid": 1,
"engine": "InnoDB",
"field_order": [
"item_code",
"quantity_section",
"qty",
"stock_qty",
"column_break_5",
"uom",
"conversion_factor",
"stock_uom",
"reference_section",
"sales_order",
"sales_order_item",
"material_request",
"material_request_item"
],
"fields": [
{
"fieldname": "qty",
"fieldtype": "Float",
"in_list_view": 1,
"label": "Qty"
},
{
"fieldname": "quantity_section",
"fieldtype": "Section Break",
"label": "Quantity"
},
{
"fieldname": "stock_qty",
"fieldtype": "Float",
"label": "Stock Qty",
"read_only": 1
},
{
"fieldname": "uom",
"fieldtype": "Link",
"label": "UOM",
"options": "UOM"
},
{
"fieldname": "stock_uom",
"fieldtype": "Link",
"label": "Stock UOM",
"options": "UOM",
"read_only": 1
},
{
"fieldname": "item_code",
"fieldtype": "Link",
"in_list_view": 1,
"label": "Item",
"options": "Item"
},
{
"fieldname": "column_break_5",
"fieldtype": "Column Break"
},
{
"fieldname": "reference_section",
"fieldtype": "Section Break",
"label": "Reference"
},
{
"fieldname": "sales_order",
"fieldtype": "Link",
"label": "Sales Order",
"options": "Sales Order",
"read_only": 1
},
{
"fieldname": "sales_order_item",
"fieldtype": "Data",
"label": "Sales Order Item",
"read_only": 1
},
{
"fieldname": "conversion_factor",
"fieldtype": "Float",
"label": "UOM Conversion Factor"
},
{
"fieldname": "material_request",
"fieldtype": "Link",
"label": "Material Request",
"options": "Material Request",
"read_only": 1
},
{
"fieldname": "material_request_item",
"fieldtype": "Data",
"label": "Material Request Item",
"read_only": 1
}
],
"istable": 1,
"modified": "2019-08-27 08:40:21.870638",
"modified_by": "Administrator",
"module": "Stock",
"name": "Pick List Reference Item",
"owner": "Administrator",
"permissions": [],
"sort_field": "modified",
"sort_order": "DESC"
}

View File

@ -1,10 +0,0 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt
from __future__ import unicode_literals
# import frappe
from frappe.model.document import Document
class PickListReferenceItem(Document):
pass