-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3a4d4ad
commit abbafca
Showing
2 changed files
with
180 additions
and
0 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
asset/asset/customizations/material_request/material_request.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import json | ||
|
||
import frappe | ||
from frappe import _ | ||
from frappe.model.mapper import get_mapped_doc | ||
|
||
from erpnext.stock.doctype.item.item import get_item_defaults | ||
from erpnext.stock.doctype.material_request.material_request import set_missing_values, update_item | ||
|
||
|
||
@frappe.whitelist() | ||
def make_purchase_order(source_name, target_doc=None, args=None): | ||
if args is None: | ||
args = {} | ||
if isinstance(args, str): | ||
args = json.loads(args) | ||
|
||
def postprocess(source, target_doc): | ||
if frappe.flags.args and frappe.flags.args.default_supplier: | ||
# items only for given default supplier | ||
supplier_items = [] | ||
for d in target_doc.items: | ||
default_supplier = get_item_defaults(d.item_code, target_doc.company).get("default_supplier") | ||
if frappe.flags.args.default_supplier == default_supplier: | ||
supplier_items.append(d) | ||
target_doc.items = supplier_items | ||
|
||
set_missing_values(source, target_doc) | ||
|
||
def select_item(d): | ||
filtered_items = args.get("filtered_children", []) | ||
child_filter = d.name in filtered_items if filtered_items else True | ||
|
||
return d.ordered_qty < d.stock_qty and child_filter | ||
|
||
doclist = get_mapped_doc( | ||
"Material Request", | ||
source_name, | ||
{ | ||
"Material Request": { | ||
"doctype": "Purchase Order", | ||
"validation": {"docstatus": ["=", 1], "material_request_type": ["=", "Purchase"]}, | ||
}, | ||
"Material Request Item": { | ||
"doctype": "Purchase Order Item", | ||
"field_map": [ | ||
["name", "material_request_item"], | ||
["parent", "material_request"], | ||
["uom", "stock_uom"], | ||
["uom", "uom"], | ||
["sales_order", "sales_order"], | ||
["sales_order_item", "sales_order_item"], | ||
["wip_composite_asset", "wip_composite_asset"], | ||
], | ||
"postprocess": update_item, | ||
"condition": select_item, | ||
}, | ||
}, | ||
target_doc, | ||
postprocess, | ||
) | ||
|
||
doclist.set_onload("load_after_mapping", False) | ||
return doclist |
116 changes: 116 additions & 0 deletions
116
asset/asset/customizations/point_of_sale/point_of_sale.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import json | ||
|
||
import frappe | ||
from frappe.utils import cint | ||
from frappe.utils.nestedset import get_root_of | ||
|
||
from erpnext.accounts.doctype.pos_invoice.pos_invoice import get_stock_availability | ||
from erpnext.selling.page.point_of_sale.point_of_sale import ( | ||
search_by_term, | ||
get_conditions, | ||
get_item_group_condition | ||
) | ||
|
||
|
||
@frappe.whitelist() | ||
def get_items(start, page_length, price_list, item_group, pos_profile, search_term=""): | ||
warehouse, hide_unavailable_items = frappe.db.get_value( | ||
"POS Profile", pos_profile, ["warehouse", "hide_unavailable_items"] | ||
) | ||
|
||
result = [] | ||
|
||
if search_term: | ||
result = search_by_term(search_term, warehouse, price_list) or [] | ||
if result: | ||
return result | ||
|
||
if not frappe.db.exists("Item Group", item_group): | ||
item_group = get_root_of("Item Group") | ||
|
||
condition = get_conditions(search_term) | ||
condition += get_item_group_condition(pos_profile) | ||
|
||
lft, rgt = frappe.db.get_value("Item Group", item_group, ["lft", "rgt"]) | ||
|
||
bin_join_selection, bin_join_condition = "", "" | ||
if hide_unavailable_items: | ||
bin_join_selection = ", `tabBin` bin" | ||
bin_join_condition = ( | ||
"AND bin.warehouse = %(warehouse)s AND bin.item_code = item.name AND bin.actual_qty > 0" | ||
) | ||
|
||
items_data = frappe.db.sql( | ||
""" | ||
SELECT | ||
item.name AS item_code, | ||
item.item_name, | ||
item.description, | ||
item.stock_uom, | ||
item.image AS item_image, | ||
item.is_stock_item | ||
FROM | ||
`tabItem` item {bin_join_selection} | ||
WHERE | ||
item.disabled = 0 | ||
AND item.has_variants = 0 | ||
AND item.is_sales_item = 1 | ||
AND item.is_fixed_asset = 0 | ||
AND item.item_group in (SELECT name FROM `tabItem Group` WHERE lft >= {lft} AND rgt <= {rgt}) | ||
AND {condition} | ||
{bin_join_condition} | ||
ORDER BY | ||
item.name asc | ||
LIMIT | ||
{page_length} offset {start}""".format( | ||
start=cint(start), | ||
page_length=cint(page_length), | ||
lft=cint(lft), | ||
rgt=cint(rgt), | ||
condition=condition, | ||
bin_join_selection=bin_join_selection, | ||
bin_join_condition=bin_join_condition, | ||
), | ||
{"warehouse": warehouse}, | ||
as_dict=1, | ||
) | ||
|
||
# return (empty) list if there are no results | ||
if not items_data: | ||
return result | ||
|
||
for item in items_data: | ||
uoms = frappe.get_doc("Item", item.item_code).get("uoms", []) | ||
|
||
item.actual_qty, _ = get_stock_availability(item.item_code, warehouse) | ||
item.uom = item.stock_uom | ||
|
||
item_price = frappe.get_all( | ||
"Item Price", | ||
fields=["price_list_rate", "currency", "uom", "batch_no"], | ||
filters={ | ||
"price_list": price_list, | ||
"item_code": item.item_code, | ||
"selling": True, | ||
}, | ||
) | ||
|
||
if not item_price: | ||
result.append(item) | ||
|
||
for price in item_price: | ||
uom = next(filter(lambda x: x.uom == price.uom, uoms), {}) | ||
|
||
if price.uom != item.stock_uom and uom and uom.conversion_factor: | ||
item.actual_qty = item.actual_qty // uom.conversion_factor | ||
|
||
result.append( | ||
{ | ||
**item, | ||
"price_list_rate": price.get("price_list_rate"), | ||
"currency": price.get("currency"), | ||
"uom": price.uom or item.uom, | ||
"batch_no": price.batch_no, | ||
} | ||
) | ||
return {"items": result} |