2015-03-03 09:25:30 +00:00
|
|
|
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
2014-02-10 09:17:54 +00:00
|
|
|
# License: GNU General Public License v3. See license.txt
|
|
|
|
|
|
|
|
from __future__ import unicode_literals
|
2014-02-14 10:17:51 +00:00
|
|
|
import frappe
|
|
|
|
from frappe import _, throw
|
2015-01-12 12:05:14 +00:00
|
|
|
from frappe.utils import flt, cint, add_days, cstr
|
2014-02-10 09:17:54 +00:00
|
|
|
import json
|
2016-01-19 10:15:49 +00:00
|
|
|
from erpnext.accounts.doctype.pricing_rule.pricing_rule import get_pricing_rule_for_item, set_transaction_type
|
2014-07-01 12:15:15 +00:00
|
|
|
from erpnext.setup.utils import get_exchange_rate
|
2014-09-29 06:47:03 +00:00
|
|
|
from frappe.model.meta import get_field_precision
|
2017-04-21 07:10:19 +00:00
|
|
|
from erpnext.stock.doctype.batch.batch import get_batch_no
|
2018-02-12 09:48:57 +00:00
|
|
|
from erpnext import get_company_currency
|
2014-05-05 13:11:41 +00:00
|
|
|
|
2017-11-23 07:35:15 +00:00
|
|
|
|
2014-02-14 10:17:51 +00:00
|
|
|
@frappe.whitelist()
|
2014-02-10 09:17:54 +00:00
|
|
|
def get_item_details(args):
|
|
|
|
"""
|
|
|
|
args = {
|
|
|
|
"item_code": "",
|
|
|
|
"warehouse": None,
|
|
|
|
"customer": "",
|
|
|
|
"conversion_rate": 1.0,
|
|
|
|
"selling_price_list": None,
|
|
|
|
"price_list_currency": None,
|
2014-02-25 13:31:20 +00:00
|
|
|
"plc_conversion_rate": 1.0,
|
2016-01-15 11:29:26 +00:00
|
|
|
"doctype": "",
|
|
|
|
"name": "",
|
2014-02-10 09:17:54 +00:00
|
|
|
"supplier": None,
|
|
|
|
"transaction_date": None,
|
|
|
|
"conversion_rate": 1.0,
|
|
|
|
"buying_price_list": None,
|
|
|
|
"is_subcontracted": "Yes" / "No",
|
2014-06-20 10:29:49 +00:00
|
|
|
"ignore_pricing_rule": 0/1
|
2016-03-09 11:32:59 +00:00
|
|
|
"project": ""
|
2014-02-10 09:17:54 +00:00
|
|
|
}
|
|
|
|
"""
|
2014-07-01 12:15:15 +00:00
|
|
|
args = process_args(args)
|
2014-04-03 09:00:42 +00:00
|
|
|
item_doc = frappe.get_doc("Item", args.item_code)
|
|
|
|
item = item_doc
|
2014-02-10 09:17:54 +00:00
|
|
|
|
|
|
|
validate_item_details(args, item)
|
2014-04-11 11:21:27 +00:00
|
|
|
|
2014-10-03 11:06:43 +00:00
|
|
|
out = get_basic_details(args, item)
|
2014-04-11 11:21:27 +00:00
|
|
|
|
2014-04-03 09:00:42 +00:00
|
|
|
get_party_item_code(args, item_doc, out)
|
2014-02-10 09:17:54 +00:00
|
|
|
|
2016-03-09 10:01:04 +00:00
|
|
|
if frappe.db.exists("Product Bundle", args.item_code):
|
2016-03-07 09:02:23 +00:00
|
|
|
valuation_rate = 0.0
|
2016-03-09 10:01:04 +00:00
|
|
|
bundled_items = frappe.get_doc("Product Bundle", args.item_code)
|
2016-04-22 11:52:22 +00:00
|
|
|
|
2016-03-09 10:01:04 +00:00
|
|
|
for bundle_item in bundled_items.items:
|
|
|
|
valuation_rate += \
|
|
|
|
flt(get_valuation_rate(bundle_item.item_code, out.get("warehouse")).get("valuation_rate") \
|
|
|
|
* bundle_item.qty)
|
2016-03-07 09:02:23 +00:00
|
|
|
|
|
|
|
out.update({
|
|
|
|
"valuation_rate": valuation_rate
|
|
|
|
})
|
2016-03-09 10:01:04 +00:00
|
|
|
|
2016-02-26 12:32:55 +00:00
|
|
|
else:
|
2016-03-09 10:01:04 +00:00
|
|
|
out.update(get_valuation_rate(args.item_code, out.get("warehouse")))
|
2014-04-11 11:21:27 +00:00
|
|
|
|
2014-04-03 09:00:42 +00:00
|
|
|
get_price_list_rate(args, item_doc, out)
|
2014-02-10 09:17:54 +00:00
|
|
|
|
2016-01-15 11:29:26 +00:00
|
|
|
if args.customer and cint(args.is_pos):
|
2015-08-18 09:59:42 +00:00
|
|
|
out.update(get_pos_profile_item_details(args.company, args))
|
2017-03-14 11:29:11 +00:00
|
|
|
|
2017-01-11 05:01:33 +00:00
|
|
|
if out.get("warehouse"):
|
|
|
|
out.update(get_bin_details(args.item_code, out.warehouse))
|
2014-04-11 11:21:27 +00:00
|
|
|
|
2014-05-28 07:19:20 +00:00
|
|
|
# update args with out, if key or value not exists
|
|
|
|
for key, value in out.iteritems():
|
|
|
|
if args.get(key) is None:
|
|
|
|
args[key] = value
|
|
|
|
|
2014-06-20 10:29:49 +00:00
|
|
|
out.update(get_pricing_rule_for_item(args))
|
2014-04-11 11:21:27 +00:00
|
|
|
|
2017-06-23 06:09:03 +00:00
|
|
|
if (args.get("doctype") == "Delivery Note" or
|
2017-05-03 12:52:24 +00:00
|
|
|
(args.get("doctype") == "Sales Invoice" and args.get('update_stock'))) \
|
|
|
|
and out.warehouse and out.stock_qty > 0:
|
2017-06-23 06:09:03 +00:00
|
|
|
|
2017-04-21 07:10:19 +00:00
|
|
|
if out.has_serial_no:
|
2017-08-28 11:49:28 +00:00
|
|
|
out.serial_no = get_serial_no(out, args.serial_no)
|
2017-04-21 07:10:19 +00:00
|
|
|
|
2017-05-18 06:24:24 +00:00
|
|
|
if out.has_batch_no and not args.get("batch_no"):
|
2017-04-21 07:10:19 +00:00
|
|
|
out.batch_no = get_batch_no(out.item_code, out.warehouse, out.qty)
|
2017-11-29 08:20:04 +00:00
|
|
|
actual_batch_qty = get_batch_qty(out.batch_no, out.warehouse, out.item_code)
|
|
|
|
if actual_batch_qty:
|
|
|
|
out.update(actual_batch_qty)
|
2017-04-21 07:10:19 +00:00
|
|
|
|
2014-02-12 09:23:18 +00:00
|
|
|
if args.transaction_date and item.lead_time_days:
|
|
|
|
out.schedule_date = out.lead_time_date = add_days(args.transaction_date,
|
|
|
|
item.lead_time_days)
|
2014-04-11 11:21:27 +00:00
|
|
|
|
2014-11-05 14:44:53 +00:00
|
|
|
if args.get("is_subcontracted") == "Yes":
|
2017-09-18 10:19:19 +00:00
|
|
|
out.bom = args.get('bom') or get_default_bom(args.item_code)
|
2016-04-22 11:52:22 +00:00
|
|
|
|
2016-02-26 05:39:20 +00:00
|
|
|
get_gross_profit(out)
|
2015-11-27 09:07:40 +00:00
|
|
|
|
2014-02-10 09:17:54 +00:00
|
|
|
return out
|
|
|
|
|
2014-07-01 12:15:15 +00:00
|
|
|
def process_args(args):
|
|
|
|
if isinstance(args, basestring):
|
|
|
|
args = json.loads(args)
|
|
|
|
|
|
|
|
args = frappe._dict(args)
|
|
|
|
|
|
|
|
if not args.get("price_list"):
|
|
|
|
args.price_list = args.get("selling_price_list") or args.get("buying_price_list")
|
|
|
|
|
|
|
|
if args.barcode:
|
|
|
|
args.item_code = get_item_code(barcode=args.barcode)
|
|
|
|
elif not args.item_code and args.serial_no:
|
|
|
|
args.item_code = get_item_code(serial_no=args.serial_no)
|
2016-04-22 11:52:22 +00:00
|
|
|
|
2016-01-21 10:40:22 +00:00
|
|
|
set_transaction_type(args)
|
2014-07-01 12:15:15 +00:00
|
|
|
return args
|
|
|
|
|
2017-11-23 07:35:15 +00:00
|
|
|
|
2015-02-25 12:04:27 +00:00
|
|
|
@frappe.whitelist()
|
2014-02-10 09:17:54 +00:00
|
|
|
def get_item_code(barcode=None, serial_no=None):
|
|
|
|
if barcode:
|
2014-02-26 07:05:33 +00:00
|
|
|
item_code = frappe.db.get_value("Item", {"barcode": barcode})
|
2014-04-16 11:51:25 +00:00
|
|
|
if not item_code:
|
|
|
|
frappe.throw(_("No Item with Barcode {0}").format(barcode))
|
2014-02-10 09:17:54 +00:00
|
|
|
elif serial_no:
|
2014-02-26 07:05:33 +00:00
|
|
|
item_code = frappe.db.get_value("Serial No", serial_no, "item_code")
|
2014-04-16 11:51:25 +00:00
|
|
|
if not item_code:
|
|
|
|
frappe.throw(_("No Item with Serial No {0}").format(serial_no))
|
2014-04-11 11:21:27 +00:00
|
|
|
|
2014-02-10 09:17:54 +00:00
|
|
|
return item_code
|
2014-04-11 11:21:27 +00:00
|
|
|
|
2017-11-23 07:35:15 +00:00
|
|
|
|
2014-02-10 09:17:54 +00:00
|
|
|
def validate_item_details(args, item):
|
|
|
|
if not args.company:
|
|
|
|
throw(_("Please specify Company"))
|
2014-04-11 11:21:27 +00:00
|
|
|
|
2014-02-10 09:17:54 +00:00
|
|
|
from erpnext.stock.doctype.item.item import validate_end_of_life
|
2015-10-29 06:51:41 +00:00
|
|
|
validate_end_of_life(item.name, item.end_of_life, item.disabled)
|
2014-04-11 11:21:27 +00:00
|
|
|
|
2017-11-23 07:35:15 +00:00
|
|
|
if args.transaction_type == "selling" and cint(item.has_variants):
|
2016-04-15 07:22:12 +00:00
|
|
|
throw(_("Item {0} is a template, please select one of its variants").format(item.name))
|
2016-04-22 11:52:22 +00:00
|
|
|
|
2017-11-23 07:35:15 +00:00
|
|
|
elif args.transaction_type == "buying" and args.doctype != "Material Request":
|
2015-07-24 09:46:25 +00:00
|
|
|
if args.get("is_subcontracted") == "Yes" and item.is_sub_contracted_item != 1:
|
2014-04-16 11:51:25 +00:00
|
|
|
throw(_("Item {0} must be a Sub-contracted Item").format(item.name))
|
2014-04-11 11:21:27 +00:00
|
|
|
|
2017-11-23 07:35:15 +00:00
|
|
|
|
2014-10-03 11:06:43 +00:00
|
|
|
def get_basic_details(args, item):
|
2017-11-23 07:35:15 +00:00
|
|
|
"""
|
|
|
|
:param args: {
|
|
|
|
"item_code": "",
|
|
|
|
"warehouse": None,
|
|
|
|
"customer": "",
|
|
|
|
"conversion_rate": 1.0,
|
|
|
|
"selling_price_list": None,
|
|
|
|
"price_list_currency": None,
|
2017-12-06 13:47:04 +00:00
|
|
|
"price_list_uom_dependant": None,
|
2017-11-23 07:35:15 +00:00
|
|
|
"plc_conversion_rate": 1.0,
|
|
|
|
"doctype": "",
|
|
|
|
"name": "",
|
|
|
|
"supplier": None,
|
|
|
|
"transaction_date": None,
|
|
|
|
"conversion_rate": 1.0,
|
|
|
|
"buying_price_list": None,
|
|
|
|
"is_subcontracted": "Yes" / "No",
|
|
|
|
"ignore_pricing_rule": 0/1
|
|
|
|
"project": "",
|
|
|
|
barcode: "",
|
|
|
|
serial_no: "",
|
|
|
|
warehouse: "",
|
|
|
|
currency: "",
|
|
|
|
update_stock: "",
|
|
|
|
price_list: "",
|
|
|
|
company: "",
|
|
|
|
order_type: "",
|
|
|
|
is_pos: "",
|
|
|
|
ignore_pricing_rule: "",
|
|
|
|
project: "",
|
|
|
|
qty: "",
|
|
|
|
stock_qty: "",
|
|
|
|
conversion_factor: ""
|
|
|
|
}
|
|
|
|
:param item: `item_code` of Item object
|
|
|
|
:return: frappe._dict
|
|
|
|
"""
|
|
|
|
|
2014-10-03 11:06:43 +00:00
|
|
|
if not item:
|
|
|
|
item = frappe.get_doc("Item", args.get("item_code"))
|
2014-04-11 11:21:27 +00:00
|
|
|
|
2014-10-07 09:59:58 +00:00
|
|
|
if item.variant_of:
|
|
|
|
item.update_template_tables()
|
|
|
|
|
2014-02-14 10:17:51 +00:00
|
|
|
from frappe.defaults import get_user_default_as_list
|
2015-12-23 11:07:00 +00:00
|
|
|
user_default_warehouse_list = get_user_default_as_list('Warehouse')
|
2014-02-10 09:17:54 +00:00
|
|
|
user_default_warehouse = user_default_warehouse_list[0] \
|
2017-11-23 07:35:15 +00:00
|
|
|
if len(user_default_warehouse_list) == 1 else ""
|
2016-04-22 11:52:22 +00:00
|
|
|
|
2017-01-06 09:09:40 +00:00
|
|
|
warehouse = user_default_warehouse or item.default_warehouse or args.warehouse
|
2014-02-12 13:39:28 +00:00
|
|
|
|
2017-11-21 10:47:22 +00:00
|
|
|
material_request_type = ''
|
|
|
|
if args.get('doctype') == "Material Request":
|
|
|
|
material_request_type = frappe.db.get_value('Material Request',
|
|
|
|
args.get('name'), 'material_request_type')
|
|
|
|
|
2017-09-29 12:44:10 +00:00
|
|
|
#Set the UOM to the Default Sales UOM or Default Purchase UOM if configured in the Item Master
|
|
|
|
if not args.uom:
|
|
|
|
if args.get('doctype') in ['Quotation', 'Sales Order', 'Delivery Note', 'Sales Invoice']:
|
|
|
|
args.uom = item.sales_uom if item.sales_uom else item.stock_uom
|
2017-11-21 10:47:22 +00:00
|
|
|
elif (args.get('doctype') in ['Purchase Order', 'Purchase Receipt', 'Purchase Invoice']) or \
|
|
|
|
(args.get('doctype') == 'Material Request' and material_request_type == 'Purchase'):
|
2017-09-29 12:44:10 +00:00
|
|
|
args.uom = item.purchase_uom if item.purchase_uom else item.stock_uom
|
|
|
|
else:
|
|
|
|
args.uom = item.stock_uom
|
|
|
|
|
2014-02-14 10:17:51 +00:00
|
|
|
out = frappe._dict({
|
2014-02-12 09:23:18 +00:00
|
|
|
"item_code": item.name,
|
|
|
|
"item_name": item.item_name,
|
2015-02-10 11:19:16 +00:00
|
|
|
"description": cstr(item.description).strip(),
|
|
|
|
"image": cstr(item.image).strip(),
|
2016-02-25 13:29:20 +00:00
|
|
|
"warehouse": warehouse,
|
2014-10-03 11:06:43 +00:00
|
|
|
"income_account": get_default_income_account(args, item),
|
|
|
|
"expense_account": get_default_expense_account(args, item),
|
|
|
|
"cost_center": get_default_cost_center(args, item),
|
2017-04-21 07:10:19 +00:00
|
|
|
'has_serial_no': item.has_serial_no,
|
|
|
|
'has_batch_no': item.has_batch_no,
|
2014-02-12 09:23:18 +00:00
|
|
|
"batch_no": None,
|
2014-04-11 11:21:27 +00:00
|
|
|
"item_tax_rate": json.dumps(dict(([d.tax_type, d.tax_rate] for d in
|
2014-12-25 10:31:55 +00:00
|
|
|
item.get("taxes")))),
|
2017-09-29 12:44:10 +00:00
|
|
|
"uom": args.uom,
|
2016-01-15 11:29:26 +00:00
|
|
|
"min_order_qty": flt(item.min_order_qty) if args.doctype == "Material Request" else "",
|
2015-05-29 12:01:31 +00:00
|
|
|
"qty": args.qty or 1.0,
|
2017-04-03 08:47:08 +00:00
|
|
|
"stock_qty": args.qty or 1.0,
|
2014-02-12 09:23:18 +00:00
|
|
|
"price_list_rate": 0.0,
|
|
|
|
"base_price_list_rate": 0.0,
|
|
|
|
"rate": 0.0,
|
|
|
|
"base_rate": 0.0,
|
|
|
|
"amount": 0.0,
|
|
|
|
"base_amount": 0.0,
|
2015-02-23 11:28:30 +00:00
|
|
|
"net_rate": 0.0,
|
|
|
|
"net_amount": 0.0,
|
2015-10-19 08:47:52 +00:00
|
|
|
"discount_percentage": 0.0,
|
|
|
|
"supplier": item.default_supplier,
|
2017-04-03 08:47:08 +00:00
|
|
|
"update_stock": args.get("update_stock") if args.get('doctype') in ['Sales Invoice', 'Purchase Invoice'] else 0,
|
2016-12-12 07:31:43 +00:00
|
|
|
"delivered_by_supplier": item.delivered_by_supplier if args.get("doctype") in ["Sales Order", "Sales Invoice"] else 0,
|
2017-11-29 10:39:59 +00:00
|
|
|
"is_fixed_asset": item.is_fixed_asset,
|
|
|
|
"weight_per_unit":item.weight_per_unit,
|
|
|
|
"weight_uom":item.weight_uom,
|
2018-01-08 09:28:20 +00:00
|
|
|
"last_purchase_rate": item.last_purchase_rate if args.get("doctype") in ["Purchase Order"] else 0
|
2014-02-12 09:23:18 +00:00
|
|
|
})
|
2014-04-11 11:21:27 +00:00
|
|
|
|
2017-04-03 08:47:08 +00:00
|
|
|
# calculate conversion factor
|
2017-04-10 13:45:57 +00:00
|
|
|
if item.stock_uom == args.uom:
|
|
|
|
out.conversion_factor = 1.0
|
|
|
|
else:
|
|
|
|
out.conversion_factor = args.conversion_factor or \
|
2017-11-23 07:35:15 +00:00
|
|
|
get_conversion_factor(item.item_code, args.uom).get("conversion_factor") or 1.0
|
2017-04-10 13:45:57 +00:00
|
|
|
|
|
|
|
args.conversion_factor = out.conversion_factor
|
|
|
|
out.stock_qty = out.qty * out.conversion_factor
|
2017-04-03 08:47:08 +00:00
|
|
|
|
2018-01-08 09:28:20 +00:00
|
|
|
# calculate last purchase rate
|
|
|
|
from erpnext.buying.doctype.purchase_order.purchase_order import item_last_purchase_rate
|
|
|
|
out.last_purchase_rate = item_last_purchase_rate(args.name, args.conversion_rate, item.item_code, out.conversion_factor)
|
|
|
|
|
2015-02-17 05:03:58 +00:00
|
|
|
# if default specified in item is for another company, fetch from company
|
2017-04-20 09:51:01 +00:00
|
|
|
for d in [
|
|
|
|
["Account", "income_account", "default_income_account"],
|
2016-04-22 11:52:22 +00:00
|
|
|
["Account", "expense_account", "default_expense_account"],
|
2017-04-20 09:51:01 +00:00
|
|
|
["Cost Center", "cost_center", "cost_center"],
|
|
|
|
["Warehouse", "warehouse", ""]]:
|
2015-02-26 06:07:07 +00:00
|
|
|
company = frappe.db.get_value(d[0], out.get(d[1]), "company")
|
|
|
|
if not out[d[1]] or (company and args.company != company):
|
2015-02-17 05:03:58 +00:00
|
|
|
out[d[1]] = frappe.db.get_value("Company", args.company, d[2]) if d[2] else None
|
|
|
|
|
2014-02-10 09:17:54 +00:00
|
|
|
for fieldname in ("item_name", "item_group", "barcode", "brand", "stock_uom"):
|
2014-03-28 08:25:00 +00:00
|
|
|
out[fieldname] = item.get(fieldname)
|
2014-04-11 11:21:27 +00:00
|
|
|
|
2014-02-10 09:17:54 +00:00
|
|
|
return out
|
2014-04-11 11:21:27 +00:00
|
|
|
|
2017-11-23 07:35:15 +00:00
|
|
|
|
2014-10-03 11:06:43 +00:00
|
|
|
def get_default_income_account(args, item):
|
|
|
|
return (item.income_account
|
|
|
|
or args.income_account
|
2015-02-24 12:42:17 +00:00
|
|
|
or frappe.db.get_value("Item Group", item.item_group, "default_income_account"))
|
2014-10-03 11:06:43 +00:00
|
|
|
|
|
|
|
def get_default_expense_account(args, item):
|
|
|
|
return (item.expense_account
|
|
|
|
or args.expense_account
|
2015-02-24 12:42:17 +00:00
|
|
|
or frappe.db.get_value("Item Group", item.item_group, "default_expense_account"))
|
2014-10-03 11:06:43 +00:00
|
|
|
|
|
|
|
def get_default_cost_center(args, item):
|
2016-03-09 11:32:59 +00:00
|
|
|
return (frappe.db.get_value("Project", args.get("project"), "cost_center")
|
2016-01-15 11:29:26 +00:00
|
|
|
or (item.selling_cost_center if args.get("customer") else item.buying_cost_center)
|
2015-09-27 07:38:01 +00:00
|
|
|
or frappe.db.get_value("Item Group", item.item_group, "default_cost_center")
|
|
|
|
or args.get("cost_center"))
|
2014-10-03 11:06:43 +00:00
|
|
|
|
2014-04-03 09:00:42 +00:00
|
|
|
def get_price_list_rate(args, item_doc, out):
|
2016-02-15 06:12:18 +00:00
|
|
|
meta = frappe.get_meta(args.parenttype or args.doctype)
|
2014-02-10 09:17:54 +00:00
|
|
|
|
|
|
|
if meta.get_field("currency"):
|
|
|
|
validate_price_list(args)
|
2017-07-25 08:35:01 +00:00
|
|
|
if args.price_list:
|
|
|
|
validate_conversion_rate(args, meta)
|
2014-02-10 09:17:54 +00:00
|
|
|
|
2016-01-15 11:29:26 +00:00
|
|
|
price_list_rate = get_price_list_rate_for(args.price_list, item_doc.name)
|
|
|
|
|
|
|
|
# variant
|
2014-10-03 11:06:43 +00:00
|
|
|
if not price_list_rate and item_doc.variant_of:
|
2016-01-15 11:29:26 +00:00
|
|
|
price_list_rate = get_price_list_rate_for(args.price_list, item_doc.variant_of)
|
2015-09-03 04:59:38 +00:00
|
|
|
|
2016-01-15 11:29:26 +00:00
|
|
|
# insert in database
|
2014-10-03 11:06:43 +00:00
|
|
|
if not price_list_rate:
|
2015-08-03 07:48:54 +00:00
|
|
|
if args.price_list and args.rate:
|
|
|
|
insert_item_price(args)
|
2014-10-03 11:06:43 +00:00
|
|
|
return {}
|
2014-04-11 11:21:27 +00:00
|
|
|
|
2014-02-10 09:17:54 +00:00
|
|
|
out.price_list_rate = flt(price_list_rate) * flt(args.plc_conversion_rate) \
|
|
|
|
/ flt(args.conversion_rate)
|
2017-12-08 09:27:38 +00:00
|
|
|
if not args.price_list_uom_dependant:
|
2017-12-06 13:47:04 +00:00
|
|
|
out.price_list_rate = flt(out.price_list_rate * (args.conversion_factor or 1.0))
|
2017-04-10 13:45:57 +00:00
|
|
|
|
2016-01-19 10:15:49 +00:00
|
|
|
if not out.price_list_rate and args.transaction_type=="buying":
|
2014-02-10 09:17:54 +00:00
|
|
|
from erpnext.stock.doctype.item.item import get_last_purchase_details
|
2014-04-11 11:21:27 +00:00
|
|
|
out.update(get_last_purchase_details(item_doc.name,
|
2016-01-15 11:29:26 +00:00
|
|
|
args.name, args.conversion_rate))
|
2014-04-11 11:21:27 +00:00
|
|
|
|
2015-08-03 07:48:54 +00:00
|
|
|
def insert_item_price(args):
|
|
|
|
"""Insert Item Price if Price List and Price List Rate are specified and currency is the same"""
|
|
|
|
if frappe.db.get_value("Price List", args.price_list, "currency") == args.currency \
|
|
|
|
and cint(frappe.db.get_single_value("Stock Settings", "auto_insert_price_list_rate_if_missing")):
|
|
|
|
if frappe.has_permission("Item Price", "write"):
|
2015-09-02 06:02:07 +00:00
|
|
|
price_list_rate = args.rate / args.conversion_factor \
|
|
|
|
if args.get("conversion_factor") else args.rate
|
2016-12-30 09:36:54 +00:00
|
|
|
|
2015-08-03 07:48:54 +00:00
|
|
|
item_price = frappe.get_doc({
|
|
|
|
"doctype": "Item Price",
|
|
|
|
"price_list": args.price_list,
|
|
|
|
"item_code": args.item_code,
|
|
|
|
"currency": args.currency,
|
2015-09-02 06:02:07 +00:00
|
|
|
"price_list_rate": price_list_rate
|
2015-08-03 07:48:54 +00:00
|
|
|
})
|
2016-12-30 09:36:54 +00:00
|
|
|
|
2016-06-25 12:24:25 +00:00
|
|
|
name = frappe.db.get_value('Item Price', {'item_code': args.item_code, 'price_list': args.price_list, 'currency': args.currency}, 'name')
|
2016-12-30 09:36:54 +00:00
|
|
|
|
2016-06-24 11:41:15 +00:00
|
|
|
if name:
|
|
|
|
item_price = frappe.get_doc('Item Price', name)
|
|
|
|
item_price.price_list_rate = price_list_rate
|
2016-12-30 09:36:54 +00:00
|
|
|
item_price.save()
|
2016-06-24 11:41:15 +00:00
|
|
|
frappe.msgprint(_("Item Price updated for {0} in Price List {1}").format(args.item_code,
|
|
|
|
args.price_list))
|
2016-12-30 09:36:54 +00:00
|
|
|
else:
|
2016-06-24 11:41:15 +00:00
|
|
|
item_price.insert()
|
|
|
|
frappe.msgprint(_("Item Price added for {0} in Price List {1}").format(args.item_code,
|
|
|
|
args.price_list))
|
2015-08-03 07:48:54 +00:00
|
|
|
|
2016-01-15 11:29:26 +00:00
|
|
|
def get_price_list_rate_for(price_list, item_code):
|
2014-10-03 11:06:43 +00:00
|
|
|
return frappe.db.get_value("Item Price",
|
2016-01-15 11:29:26 +00:00
|
|
|
{"price_list": price_list, "item_code": item_code}, "price_list_rate")
|
2014-10-03 11:06:43 +00:00
|
|
|
|
2014-02-10 09:17:54 +00:00
|
|
|
def validate_price_list(args):
|
|
|
|
if args.get("price_list"):
|
2014-04-11 11:21:27 +00:00
|
|
|
if not frappe.db.get_value("Price List",
|
2016-01-19 10:15:49 +00:00
|
|
|
{"name": args.price_list, args.transaction_type: 1, "enabled": 1}):
|
2016-12-30 09:36:54 +00:00
|
|
|
throw(_("Price List {0} is disabled or does not exist").format(args.price_list))
|
2017-04-11 06:49:24 +00:00
|
|
|
elif not args.get("supplier"):
|
2014-02-10 09:17:54 +00:00
|
|
|
throw(_("Price List not selected"))
|
2014-04-11 11:21:27 +00:00
|
|
|
|
2014-02-10 09:17:54 +00:00
|
|
|
def validate_conversion_rate(args, meta):
|
2014-09-29 06:47:03 +00:00
|
|
|
from erpnext.controllers.accounts_controller import validate_conversion_rate
|
2014-04-11 11:21:27 +00:00
|
|
|
|
2015-08-25 07:19:40 +00:00
|
|
|
if (not args.conversion_rate
|
|
|
|
and args.currency==frappe.db.get_value("Company", args.company, "default_currency")):
|
|
|
|
args.conversion_rate = 1.0
|
|
|
|
|
2014-02-10 09:17:54 +00:00
|
|
|
# validate currency conversion rate
|
2014-04-11 11:21:27 +00:00
|
|
|
validate_conversion_rate(args.currency, args.conversion_rate,
|
2014-02-10 09:17:54 +00:00
|
|
|
meta.get_label("conversion_rate"), args.company)
|
2014-04-11 11:21:27 +00:00
|
|
|
|
|
|
|
args.conversion_rate = flt(args.conversion_rate,
|
|
|
|
get_field_precision(meta.get_field("conversion_rate"),
|
2014-02-14 10:17:51 +00:00
|
|
|
frappe._dict({"fields": args})))
|
2014-04-11 11:21:27 +00:00
|
|
|
|
2014-02-10 09:17:54 +00:00
|
|
|
# validate price list currency conversion rate
|
|
|
|
if not args.get("price_list_currency"):
|
|
|
|
throw(_("Price List Currency not selected"))
|
|
|
|
else:
|
2014-04-11 11:21:27 +00:00
|
|
|
validate_conversion_rate(args.price_list_currency, args.plc_conversion_rate,
|
2014-02-10 09:17:54 +00:00
|
|
|
meta.get_label("plc_conversion_rate"), args.company)
|
2014-04-11 11:21:27 +00:00
|
|
|
|
|
|
|
args.plc_conversion_rate = flt(args.plc_conversion_rate,
|
|
|
|
get_field_precision(meta.get_field("plc_conversion_rate"),
|
2014-02-14 10:17:51 +00:00
|
|
|
frappe._dict({"fields": args})))
|
2014-04-11 11:21:27 +00:00
|
|
|
|
2014-04-03 09:00:42 +00:00
|
|
|
def get_party_item_code(args, item_doc, out):
|
2016-01-19 10:15:49 +00:00
|
|
|
if args.transaction_type=="selling" and args.customer:
|
2014-12-26 06:11:15 +00:00
|
|
|
customer_item_code = item_doc.get("customer_items", {"customer_name": args.customer})
|
2014-02-10 09:17:54 +00:00
|
|
|
out.customer_item_code = customer_item_code[0].ref_code if customer_item_code else None
|
2016-01-21 16:58:47 +00:00
|
|
|
|
2016-01-19 10:15:49 +00:00
|
|
|
if args.transaction_type=="buying" and args.supplier:
|
2014-12-26 06:11:15 +00:00
|
|
|
item_supplier = item_doc.get("supplier_items", {"supplier": args.supplier})
|
2014-02-10 09:17:54 +00:00
|
|
|
out.supplier_part_no = item_supplier[0].supplier_part_no if item_supplier else None
|
2014-04-11 11:21:27 +00:00
|
|
|
|
2015-08-18 09:59:42 +00:00
|
|
|
def get_pos_profile_item_details(company, args, pos_profile=None):
|
2014-02-14 10:17:51 +00:00
|
|
|
res = frappe._dict()
|
2014-04-11 11:21:27 +00:00
|
|
|
|
2015-08-18 09:59:42 +00:00
|
|
|
if not pos_profile:
|
2017-11-28 10:41:15 +00:00
|
|
|
pos_profile = get_pos_profile(company, args.get('pos_profile'))
|
2014-04-11 11:21:27 +00:00
|
|
|
|
2015-08-18 09:59:42 +00:00
|
|
|
if pos_profile:
|
2014-02-10 09:17:54 +00:00
|
|
|
for fieldname in ("income_account", "cost_center", "warehouse", "expense_account"):
|
2015-08-18 09:59:42 +00:00
|
|
|
if not args.get(fieldname) and pos_profile.get(fieldname):
|
|
|
|
res[fieldname] = pos_profile.get(fieldname)
|
2014-04-11 11:21:27 +00:00
|
|
|
|
2014-02-10 09:17:54 +00:00
|
|
|
if res.get("warehouse"):
|
2016-02-25 13:29:20 +00:00
|
|
|
res.actual_qty = get_bin_details(args.item_code,
|
2014-02-10 09:17:54 +00:00
|
|
|
res.warehouse).get("actual_qty")
|
2014-04-11 11:21:27 +00:00
|
|
|
|
2014-02-10 09:17:54 +00:00
|
|
|
return res
|
|
|
|
|
2015-08-18 09:59:42 +00:00
|
|
|
@frappe.whitelist()
|
2017-11-28 10:41:15 +00:00
|
|
|
def get_pos_profile(company, pos_profile=None, user=None):
|
|
|
|
if pos_profile:
|
|
|
|
return frappe.get_doc('POS Profile', pos_profile)
|
|
|
|
|
|
|
|
if not user:
|
|
|
|
user = frappe.session['user']
|
|
|
|
|
|
|
|
pos_profile = frappe.db.sql("""select pf.*
|
|
|
|
from
|
|
|
|
`tabPOS Profile` pf, `tabPOS Profile User` pfu
|
|
|
|
where
|
|
|
|
pfu.parent = pf.name and pfu.user = %s and pf.company = %s
|
|
|
|
and pf.disabled = 0 and pfu.default=1""", (user, company), as_dict=1)
|
2014-04-11 11:21:27 +00:00
|
|
|
|
2017-04-03 07:31:11 +00:00
|
|
|
if not pos_profile:
|
2017-11-28 10:41:15 +00:00
|
|
|
pos_profile = frappe.db.sql("""select pf.*
|
|
|
|
from
|
|
|
|
`tabPOS Profile` pf left join `tabPOS Profile User` pfu
|
|
|
|
on
|
|
|
|
pf.name = pfu.parent
|
|
|
|
where
|
|
|
|
ifnull(pfu.user, '') = '' and pf.company = %s
|
|
|
|
and pf.disabled = 0""", (company), as_dict=1)
|
2014-04-11 11:21:27 +00:00
|
|
|
|
2015-08-18 09:59:42 +00:00
|
|
|
return pos_profile and pos_profile[0] or None
|
2014-04-11 11:21:27 +00:00
|
|
|
|
2016-10-25 17:45:39 +00:00
|
|
|
def get_serial_nos_by_fifo(args):
|
2015-09-03 04:59:38 +00:00
|
|
|
if frappe.db.get_single_value("Stock Settings", "automatically_set_serial_nos_based_on_fifo"):
|
|
|
|
return "\n".join(frappe.db.sql_list("""select name from `tabSerial No`
|
2015-10-22 09:41:44 +00:00
|
|
|
where item_code=%(item_code)s and warehouse=%(warehouse)s
|
2015-09-03 04:59:38 +00:00
|
|
|
order by timestamp(purchase_date, purchase_time) asc limit %(qty)s""", {
|
|
|
|
"item_code": args.item_code,
|
|
|
|
"warehouse": args.warehouse,
|
2017-02-10 08:57:11 +00:00
|
|
|
"qty": abs(cint(args.stock_qty))
|
2015-09-03 04:59:38 +00:00
|
|
|
}))
|
2014-02-28 06:00:47 +00:00
|
|
|
|
2014-02-14 10:17:51 +00:00
|
|
|
@frappe.whitelist()
|
2014-02-10 09:17:54 +00:00
|
|
|
def get_conversion_factor(item_code, uom):
|
2014-10-07 09:59:58 +00:00
|
|
|
variant_of = frappe.db.get_value("Item", item_code, "variant_of")
|
|
|
|
filters = {"parent": item_code, "uom": uom}
|
|
|
|
if variant_of:
|
2015-10-07 06:25:01 +00:00
|
|
|
filters["parent"] = ("in", (item_code, variant_of))
|
2014-02-26 07:05:33 +00:00
|
|
|
return {"conversion_factor": frappe.db.get_value("UOM Conversion Detail",
|
2014-10-07 09:59:58 +00:00
|
|
|
filters, "conversion_factor")}
|
2014-02-28 06:00:47 +00:00
|
|
|
|
2014-02-14 10:17:51 +00:00
|
|
|
@frappe.whitelist()
|
2014-02-10 09:17:54 +00:00
|
|
|
def get_projected_qty(item_code, warehouse):
|
2014-04-11 11:21:27 +00:00
|
|
|
return {"projected_qty": frappe.db.get_value("Bin",
|
2014-02-10 09:17:54 +00:00
|
|
|
{"item_code": item_code, "warehouse": warehouse}, "projected_qty")}
|
2014-02-28 06:00:47 +00:00
|
|
|
|
2014-02-14 10:17:51 +00:00
|
|
|
@frappe.whitelist()
|
2016-02-25 13:29:20 +00:00
|
|
|
def get_bin_details(item_code, warehouse):
|
2014-04-11 11:21:27 +00:00
|
|
|
return frappe.db.get_value("Bin", {"item_code": item_code, "warehouse": warehouse},
|
2018-02-09 07:42:07 +00:00
|
|
|
["projected_qty", "actual_qty"], as_dict=True) \
|
|
|
|
or {"projected_qty": 0, "actual_qty": 0}
|
2016-11-13 15:49:09 +00:00
|
|
|
|
|
|
|
@frappe.whitelist()
|
2017-02-10 08:57:11 +00:00
|
|
|
def get_serial_no_details(item_code, warehouse, stock_qty, serial_no):
|
|
|
|
args = frappe._dict({"item_code":item_code, "warehouse":warehouse, "stock_qty":stock_qty, "serial_no":serial_no})
|
2016-11-13 15:49:09 +00:00
|
|
|
serial_no = get_serial_no(args)
|
|
|
|
return {'serial_no': serial_no}
|
2016-12-30 09:36:54 +00:00
|
|
|
|
2016-11-13 15:49:09 +00:00
|
|
|
@frappe.whitelist()
|
2017-02-10 08:57:11 +00:00
|
|
|
def get_bin_details_and_serial_nos(item_code, warehouse, stock_qty=None, serial_no=None):
|
2016-11-13 15:49:09 +00:00
|
|
|
bin_details_and_serial_nos = {}
|
|
|
|
bin_details_and_serial_nos.update(get_bin_details(item_code, warehouse))
|
2017-02-10 08:57:11 +00:00
|
|
|
if stock_qty > 0:
|
|
|
|
bin_details_and_serial_nos.update(get_serial_no_details(item_code, warehouse, stock_qty, serial_no))
|
2016-11-13 15:49:09 +00:00
|
|
|
return bin_details_and_serial_nos
|
2014-07-01 12:15:15 +00:00
|
|
|
|
2015-03-10 09:49:29 +00:00
|
|
|
@frappe.whitelist()
|
2017-04-20 09:51:01 +00:00
|
|
|
def get_batch_qty(batch_no, warehouse, item_code):
|
2017-04-25 08:28:57 +00:00
|
|
|
from erpnext.stock.doctype.batch import batch
|
2015-03-10 09:34:28 +00:00
|
|
|
if batch_no:
|
2017-04-20 09:51:01 +00:00
|
|
|
return {'actual_batch_qty': batch.get_batch_qty(batch_no, warehouse)}
|
2015-07-24 09:46:25 +00:00
|
|
|
|
2014-07-01 12:15:15 +00:00
|
|
|
@frappe.whitelist()
|
2016-01-15 11:29:26 +00:00
|
|
|
def apply_price_list(args, as_doc=False):
|
|
|
|
"""Apply pricelist on a document-like dict object and return as
|
|
|
|
{'parent': dict, 'children': list}
|
|
|
|
|
|
|
|
:param args: See below
|
|
|
|
:param as_doc: Updates value in the passed dict
|
|
|
|
|
2014-07-01 12:15:15 +00:00
|
|
|
args = {
|
2016-01-15 11:29:26 +00:00
|
|
|
"doctype": "",
|
|
|
|
"name": "",
|
|
|
|
"items": [{"doctype": "", "name": "", "item_code": "", "brand": "", "item_group": ""}, ...],
|
2014-07-01 12:15:15 +00:00
|
|
|
"conversion_rate": 1.0,
|
|
|
|
"selling_price_list": None,
|
|
|
|
"price_list_currency": None,
|
2017-12-06 13:47:04 +00:00
|
|
|
"price_list_uom_dependant": None,
|
2014-07-01 12:15:15 +00:00
|
|
|
"plc_conversion_rate": 1.0,
|
2016-01-15 11:29:26 +00:00
|
|
|
"doctype": "",
|
|
|
|
"name": "",
|
2014-07-01 12:15:15 +00:00
|
|
|
"supplier": None,
|
|
|
|
"transaction_date": None,
|
|
|
|
"conversion_rate": 1.0,
|
|
|
|
"buying_price_list": None,
|
|
|
|
"ignore_pricing_rule": 0/1
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
args = process_args(args)
|
|
|
|
|
|
|
|
parent = get_price_list_currency_and_exchange_rate(args)
|
|
|
|
children = []
|
|
|
|
|
2016-01-15 11:29:26 +00:00
|
|
|
if "items" in args:
|
|
|
|
item_list = args.get("items")
|
2014-07-01 12:15:15 +00:00
|
|
|
args.update(parent)
|
|
|
|
|
|
|
|
for item in item_list:
|
|
|
|
args_copy = frappe._dict(args.copy())
|
|
|
|
args_copy.update(item)
|
|
|
|
item_details = apply_price_list_on_item(args_copy)
|
|
|
|
children.append(item_details)
|
|
|
|
|
2016-01-15 11:29:26 +00:00
|
|
|
if as_doc:
|
2017-12-06 13:47:04 +00:00
|
|
|
args.price_list_currency = parent.price_list_currency,
|
2016-01-15 11:29:26 +00:00
|
|
|
args.plc_conversion_rate = parent.plc_conversion_rate
|
|
|
|
if args.get('items'):
|
|
|
|
for i, item in enumerate(args.get('items')):
|
|
|
|
for fieldname in children[i]:
|
|
|
|
# if the field exists in the original doc
|
|
|
|
# update the value
|
|
|
|
if fieldname in item and fieldname not in ("name", "doctype"):
|
|
|
|
item[fieldname] = children[i][fieldname]
|
|
|
|
return args
|
|
|
|
else:
|
|
|
|
return {
|
|
|
|
"parent": parent,
|
|
|
|
"children": children
|
|
|
|
}
|
2014-07-01 12:15:15 +00:00
|
|
|
|
|
|
|
def apply_price_list_on_item(args):
|
|
|
|
item_details = frappe._dict()
|
|
|
|
item_doc = frappe.get_doc("Item", args.item_code)
|
|
|
|
get_price_list_rate(args, item_doc, item_details)
|
2016-01-15 11:29:26 +00:00
|
|
|
|
2014-07-01 12:15:15 +00:00
|
|
|
item_details.update(get_pricing_rule_for_item(args))
|
2016-01-15 11:29:26 +00:00
|
|
|
|
2014-07-01 12:15:15 +00:00
|
|
|
return item_details
|
|
|
|
|
|
|
|
def get_price_list_currency(price_list):
|
2015-03-18 06:10:39 +00:00
|
|
|
if price_list:
|
|
|
|
result = frappe.db.get_value("Price List", {"name": price_list,
|
|
|
|
"enabled": 1}, ["name", "currency"], as_dict=True)
|
2014-07-01 12:15:15 +00:00
|
|
|
|
2015-03-18 06:10:39 +00:00
|
|
|
if not result:
|
2016-12-30 09:36:54 +00:00
|
|
|
throw(_("Price List {0} is disabled or does not exist").format(price_list))
|
2014-07-01 12:15:15 +00:00
|
|
|
|
2015-03-18 06:10:39 +00:00
|
|
|
return result.currency
|
2014-07-01 12:15:15 +00:00
|
|
|
|
2017-12-06 13:47:04 +00:00
|
|
|
def get_price_list_uom_dependant(price_list):
|
|
|
|
if price_list:
|
|
|
|
result = frappe.db.get_value("Price List", {"name": price_list,
|
|
|
|
"enabled": 1}, ["name", "price_not_uom_dependant"], as_dict=True)
|
|
|
|
|
|
|
|
if not result:
|
|
|
|
throw(_("Price List {0} is disabled or does not exist").format(price_list))
|
|
|
|
|
|
|
|
return result.price_not_uom_dependant
|
|
|
|
|
|
|
|
|
2014-07-01 12:15:15 +00:00
|
|
|
def get_price_list_currency_and_exchange_rate(args):
|
2015-11-27 09:07:40 +00:00
|
|
|
if not args.price_list:
|
|
|
|
return {}
|
|
|
|
|
2014-07-01 12:15:15 +00:00
|
|
|
price_list_currency = get_price_list_currency(args.price_list)
|
2017-12-06 13:47:04 +00:00
|
|
|
price_list_uom_dependant = get_price_list_uom_dependant(args.price_list)
|
2014-07-01 12:15:15 +00:00
|
|
|
plc_conversion_rate = args.plc_conversion_rate
|
2018-02-12 09:48:57 +00:00
|
|
|
company_currency = get_company_currency(args.company)
|
2014-07-01 12:15:15 +00:00
|
|
|
|
2015-05-11 11:19:17 +00:00
|
|
|
if (not plc_conversion_rate) or (price_list_currency and args.price_list_currency \
|
|
|
|
and price_list_currency != args.price_list_currency):
|
2017-03-14 11:29:11 +00:00
|
|
|
# cksgb 19/09/2016: added args.transaction_date as posting_date argument for get_exchange_rate
|
2018-02-12 09:48:57 +00:00
|
|
|
plc_conversion_rate = get_exchange_rate(price_list_currency, company_currency,
|
2016-12-09 06:44:47 +00:00
|
|
|
args.transaction_date) or plc_conversion_rate
|
2014-07-01 12:15:15 +00:00
|
|
|
|
2016-01-15 11:29:26 +00:00
|
|
|
return frappe._dict({
|
2014-07-01 12:15:15 +00:00
|
|
|
"price_list_currency": price_list_currency,
|
2017-12-06 13:47:04 +00:00
|
|
|
"price_list_uom_dependant": price_list_uom_dependant,
|
2014-07-01 12:15:15 +00:00
|
|
|
"plc_conversion_rate": plc_conversion_rate
|
2016-01-15 11:29:26 +00:00
|
|
|
})
|
2014-11-05 14:44:53 +00:00
|
|
|
|
|
|
|
@frappe.whitelist()
|
|
|
|
def get_default_bom(item_code=None):
|
|
|
|
if item_code:
|
|
|
|
bom = frappe.db.get_value("BOM", {"docstatus": 1, "is_default": 1, "is_active": 1, "item": item_code})
|
|
|
|
if bom:
|
|
|
|
return bom
|
2016-04-22 11:52:22 +00:00
|
|
|
|
2016-03-09 10:01:04 +00:00
|
|
|
def get_valuation_rate(item_code, warehouse=None):
|
2016-03-07 09:02:23 +00:00
|
|
|
item = frappe.get_doc("Item", item_code)
|
|
|
|
if item.is_stock_item:
|
|
|
|
if not warehouse:
|
|
|
|
warehouse = item.default_warehouse
|
2016-04-22 11:52:22 +00:00
|
|
|
|
|
|
|
return frappe.db.get_value("Bin", {"item_code": item_code, "warehouse": warehouse},
|
2016-03-07 09:02:23 +00:00
|
|
|
["valuation_rate"], as_dict=True) or {"valuation_rate": 0}
|
2016-04-22 11:52:22 +00:00
|
|
|
|
2016-03-07 09:02:23 +00:00
|
|
|
elif not item.is_stock_item:
|
2017-03-06 11:02:57 +00:00
|
|
|
valuation_rate =frappe.db.sql("""select sum(base_net_amount) / sum(qty*conversion_factor)
|
2016-04-22 11:52:22 +00:00
|
|
|
from `tabPurchase Invoice Item`
|
2016-03-07 09:02:23 +00:00
|
|
|
where item_code = %s and docstatus=1""", item_code)
|
2016-04-22 11:52:22 +00:00
|
|
|
|
2016-03-07 09:02:23 +00:00
|
|
|
if valuation_rate:
|
|
|
|
return {"valuation_rate": valuation_rate[0][0] or 0.0}
|
|
|
|
else:
|
|
|
|
return {"valuation_rate": 0.0}
|
2016-04-22 11:52:22 +00:00
|
|
|
|
2016-02-26 05:39:20 +00:00
|
|
|
def get_gross_profit(out):
|
2016-02-26 12:32:55 +00:00
|
|
|
if out.valuation_rate:
|
|
|
|
out.update({
|
2017-02-10 08:57:11 +00:00
|
|
|
"gross_profit": ((out.base_rate - out.valuation_rate) * out.stock_qty)
|
2016-02-26 12:32:55 +00:00
|
|
|
})
|
2016-04-22 11:52:22 +00:00
|
|
|
|
2016-02-25 13:29:20 +00:00
|
|
|
return out
|
2016-01-21 10:40:22 +00:00
|
|
|
|
2016-11-13 15:49:09 +00:00
|
|
|
@frappe.whitelist()
|
2017-08-28 11:49:28 +00:00
|
|
|
def get_serial_no(args, serial_nos=None):
|
|
|
|
serial_no = None
|
2016-11-13 15:49:09 +00:00
|
|
|
if isinstance(args, basestring):
|
|
|
|
args = json.loads(args)
|
|
|
|
args = frappe._dict(args)
|
|
|
|
|
2017-04-03 08:47:08 +00:00
|
|
|
if args.get('doctype') == 'Sales Invoice' and not args.get('update_stock'):
|
|
|
|
return ""
|
|
|
|
|
2017-02-10 08:57:11 +00:00
|
|
|
if args.get('warehouse') and args.get('stock_qty') and args.get('item_code'):
|
2016-12-30 09:36:54 +00:00
|
|
|
|
2016-11-13 15:49:09 +00:00
|
|
|
if frappe.get_value('Item', {'item_code': args.item_code}, "has_serial_no") == 1:
|
2017-02-10 08:57:11 +00:00
|
|
|
args = json.dumps({"item_code": args.get('item_code'),"warehouse": args.get('warehouse'),"stock_qty": args.get('stock_qty')})
|
2016-11-13 15:49:09 +00:00
|
|
|
args = process_args(args)
|
|
|
|
serial_no = get_serial_nos_by_fifo(args)
|
2017-08-28 11:49:28 +00:00
|
|
|
|
|
|
|
if not serial_no and serial_nos:
|
|
|
|
# For POS
|
|
|
|
serial_no = serial_nos
|
|
|
|
|
|
|
|
return serial_no
|