mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-05 05:09:11 +00:00
Merge branch 'webshop' of github.com:webnotes/erpnext into responsive
Conflicts: selling/doctype/quotation/quotation.js
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -69,17 +69,6 @@ class DocType(BuyingController):
|
||||
msgprint(_("Hey there! You need to put at least one item in \
|
||||
the item table."), raise_exception=True)
|
||||
|
||||
|
||||
def get_default_schedule_date( self, obj):
|
||||
for d in getlist( obj.doclist, obj.fname):
|
||||
item = sql("select lead_time_days from `tabItem` where name = '%s' and (ifnull(end_of_life,'')='' or end_of_life = '0000-00-00' or end_of_life > now())" % cstr(d.item_code) , as_dict = 1)
|
||||
ltd = item and cint(item[0]['lead_time_days']) or 0
|
||||
if ltd and obj.doc.transaction_date:
|
||||
if d.fields.has_key('lead_time_date') or obj.doc.doctype == 'Material Request':
|
||||
d.lead_time_date = cstr(add_days( obj.doc.transaction_date, cint(ltd)))
|
||||
if not d.fields.has_key('prevdoc_docname') or (d.fields.has_key('prevdoc_docname') and not d.prevdoc_docname):
|
||||
d.schedule_date = cstr( add_days( obj.doc.transaction_date, cint(ltd)))
|
||||
|
||||
# Client Trigger functions
|
||||
#------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -447,28 +436,4 @@ class DocType(BuyingController):
|
||||
for d in getlist(obj.doclist, obj.fname):
|
||||
if d.prevdoc_doctype and d.prevdoc_docname:
|
||||
dt = sql("select transaction_date from `tab%s` where name = '%s'" % (d.prevdoc_doctype, d.prevdoc_docname))
|
||||
d.prevdoc_date = dt and dt[0][0].strftime('%Y-%m-%d') or ''
|
||||
|
||||
@webnotes.whitelist()
|
||||
def get_uom_details(args=None):
|
||||
"""fetches details on change of UOM"""
|
||||
if not args:
|
||||
return {}
|
||||
|
||||
if isinstance(args, basestring):
|
||||
import json
|
||||
args = json.loads(args)
|
||||
|
||||
uom = webnotes.conn.sql("""select conversion_factor
|
||||
from `tabUOM Conversion Detail` where parent = %s and uom = %s""",
|
||||
(args['item_code'], args['uom']), as_dict=1)
|
||||
|
||||
if not uom: return {}
|
||||
|
||||
conversion_factor = args.get("conversion_factor") or \
|
||||
flt(uom[0]["conversion_factor"])
|
||||
|
||||
return {
|
||||
"conversion_factor": conversion_factor,
|
||||
"qty": flt(args["stock_qty"]) / conversion_factor,
|
||||
}
|
||||
d.prevdoc_date = dt and dt[0][0].strftime('%Y-%m-%d') or ''
|
||||
@@ -21,8 +21,8 @@ cur_frm.cscript.fname = "po_details";
|
||||
cur_frm.cscript.other_fname = "purchase_tax_details";
|
||||
|
||||
wn.require('app/accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.js');
|
||||
wn.require('app/buying/doctype/purchase_common/purchase_common.js');
|
||||
wn.require('app/utilities/doctype/sms_control/sms_control.js');
|
||||
wn.require('app/buying/doctype/purchase_common/purchase_common.js');
|
||||
|
||||
erpnext.buying.PurchaseOrderController = erpnext.buying.BuyingController.extend({
|
||||
refresh: function(doc, cdt, cdn) {
|
||||
@@ -39,54 +39,10 @@ erpnext.buying.PurchaseOrderController = erpnext.buying.BuyingController.extend(
|
||||
cur_frm.add_custom_button('Unstop Purchase Order', cur_frm.cscript['Unstop Purchase Order']);
|
||||
|
||||
},
|
||||
|
||||
onload_post_render: function(doc, dt, dn) {
|
||||
var me = this;
|
||||
var callback1 = function(doc, dt, dn) {
|
||||
var callback2 = function(doc, dt, dn) {
|
||||
if(doc.__islocal) cur_frm.cscript.get_default_schedule_date(doc);
|
||||
}
|
||||
me.update_item_details(doc, dt, dn, callback2);
|
||||
}
|
||||
|
||||
// TODO: improve this
|
||||
if(this.frm.doc.__islocal) {
|
||||
if (this.frm.fields_dict.price_list_name && this.frm.doc.price_list_name) {
|
||||
this.price_list_name(callback1);
|
||||
} else {
|
||||
callback1(doc, dt, dn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
var new_cscript = new erpnext.buying.PurchaseOrderController({frm: cur_frm});
|
||||
|
||||
// for backward compatibility: combine new and previous states
|
||||
$.extend(cur_frm.cscript, new_cscript);
|
||||
|
||||
cur_frm.cscript.onload = function(doc, cdt, cdn) {
|
||||
// set missing values in parent doc
|
||||
set_missing_values(doc, {
|
||||
fiscal_year: sys_defaults.fiscal_year,
|
||||
conversion_rate: 1,
|
||||
currency: sys_defaults.currency,
|
||||
status: "Draft",
|
||||
transaction_date: get_today(),
|
||||
is_subcontracted: "No"
|
||||
});
|
||||
}
|
||||
|
||||
cur_frm.cscript.supplier = function(doc,dt,dn) {
|
||||
if (doc.supplier) {
|
||||
get_server_fields('get_default_supplier_address',
|
||||
JSON.stringify({ supplier: doc.supplier }),'', doc, dt, dn, 1, function() {
|
||||
cur_frm.refresh();
|
||||
});
|
||||
$(cur_frm.fields_dict.contact_section.row.wrapper).toggle(true);
|
||||
}
|
||||
}
|
||||
$.extend(cur_frm.cscript, new erpnext.buying.PurchaseOrderController({frm: cur_frm}));
|
||||
|
||||
cur_frm.cscript.supplier_address = cur_frm.cscript.contact_person = function(doc,dt,dn) {
|
||||
if(doc.supplier) get_server_fields('get_supplier_address', JSON.stringify({supplier: doc.supplier, address: doc.supplier_address, contact: doc.contact_person}),'', doc, dt, dn, 1);
|
||||
@@ -111,10 +67,6 @@ cur_frm.fields_dict.contact_person.on_new = function(dn) {
|
||||
locals['Contact'][dn].supplier_name = locals[cur_frm.doctype][cur_frm.docname].supplier_name;
|
||||
}
|
||||
|
||||
cur_frm.cscript.transaction_date = function(doc,cdt,cdn){
|
||||
if(doc.__islocal){ cur_frm.cscript.get_default_schedule_date(doc); }
|
||||
}
|
||||
|
||||
cur_frm.fields_dict['po_details'].grid.get_field('project_name').get_query = function(doc, cdt, cdn) {
|
||||
return 'SELECT `tabProject`.name FROM `tabProject` \
|
||||
WHERE `tabProject`.status not in ("Completed", "Cancelled") \
|
||||
|
||||
@@ -65,10 +65,6 @@ class DocType(BuyingController):
|
||||
self.validate_for_subcontracting()
|
||||
self.update_raw_materials_supplied("po_raw_material_details")
|
||||
|
||||
|
||||
def get_default_schedule_date(self):
|
||||
get_obj(dt = 'Purchase Common').get_default_schedule_date(self)
|
||||
|
||||
def validate_fiscal_year(self):
|
||||
get_obj(dt = 'Purchase Common').validate_fiscal_year(self.doc.fiscal_year,self.doc.transaction_date,'PO Date')
|
||||
|
||||
@@ -101,7 +97,6 @@ class DocType(BuyingController):
|
||||
"""[['Supplier Quotation', 'Purchase Order'],
|
||||
['Supplier Quotation Item', 'Purchase Order Item'],
|
||||
['Purchase Taxes and Charges', 'Purchase Taxes and Charges']]""")
|
||||
self.get_default_schedule_date()
|
||||
for d in getlist(self.doclist, 'po_details'):
|
||||
if d.prevdoc_detail_docname and not d.schedule_date:
|
||||
d.schedule_date = webnotes.conn.get_value("Material Request Item",
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
[
|
||||
{
|
||||
"creation": "2013-03-25 16:01:24",
|
||||
"creation": "2013-05-21 16:16:39",
|
||||
"docstatus": 0,
|
||||
"modified": "2013-02-18 13:37:11",
|
||||
"modified": "2013-05-28 12:20:33",
|
||||
"modified_by": "Administrator",
|
||||
"owner": "Administrator"
|
||||
},
|
||||
@@ -65,43 +65,48 @@
|
||||
"search_index": 1
|
||||
},
|
||||
{
|
||||
"depends_on": "supplier",
|
||||
"doctype": "DocField",
|
||||
"fieldname": "supplier_name",
|
||||
"fieldtype": "Data",
|
||||
"hidden": 1,
|
||||
"hidden": 0,
|
||||
"in_list_view": 1,
|
||||
"label": "Name",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"depends_on": "supplier",
|
||||
"doctype": "DocField",
|
||||
"fieldname": "address_display",
|
||||
"fieldtype": "Small Text",
|
||||
"hidden": 1,
|
||||
"hidden": 0,
|
||||
"label": "Address",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"depends_on": "supplier",
|
||||
"doctype": "DocField",
|
||||
"fieldname": "contact_display",
|
||||
"fieldtype": "Small Text",
|
||||
"hidden": 1,
|
||||
"hidden": 0,
|
||||
"label": "Contact",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"depends_on": "supplier",
|
||||
"doctype": "DocField",
|
||||
"fieldname": "contact_mobile",
|
||||
"fieldtype": "Text",
|
||||
"hidden": 1,
|
||||
"hidden": 0,
|
||||
"label": "Mobile No",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"depends_on": "supplier",
|
||||
"doctype": "DocField",
|
||||
"fieldname": "contact_email",
|
||||
"fieldtype": "Text",
|
||||
"hidden": 1,
|
||||
"hidden": 0,
|
||||
"label": "Contact Email",
|
||||
"print_hide": 1,
|
||||
"read_only": 1
|
||||
@@ -554,6 +559,7 @@
|
||||
"oldfieldtype": "Text Editor"
|
||||
},
|
||||
{
|
||||
"depends_on": "supplier",
|
||||
"doctype": "DocField",
|
||||
"fieldname": "contact_section",
|
||||
"fieldtype": "Section Break",
|
||||
@@ -808,7 +814,6 @@
|
||||
"cancel": 0,
|
||||
"create": 0,
|
||||
"doctype": "DocPerm",
|
||||
"match": "",
|
||||
"permlevel": 1,
|
||||
"report": 0,
|
||||
"role": "Material User",
|
||||
@@ -831,7 +836,6 @@
|
||||
"cancel": 0,
|
||||
"create": 0,
|
||||
"doctype": "DocPerm",
|
||||
"match": "",
|
||||
"permlevel": 1,
|
||||
"report": 0,
|
||||
"role": "Purchase Manager",
|
||||
@@ -854,7 +858,6 @@
|
||||
"cancel": 1,
|
||||
"create": 1,
|
||||
"doctype": "DocPerm",
|
||||
"match": "",
|
||||
"permlevel": 0,
|
||||
"report": 1,
|
||||
"role": "Purchase User",
|
||||
@@ -866,7 +869,6 @@
|
||||
"cancel": 0,
|
||||
"create": 0,
|
||||
"doctype": "DocPerm",
|
||||
"match": "",
|
||||
"permlevel": 1,
|
||||
"role": "All",
|
||||
"submit": 0
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
[
|
||||
{
|
||||
"creation": "2013-03-07 11:42:55",
|
||||
"creation": "2013-05-24 19:29:06",
|
||||
"docstatus": 0,
|
||||
"modified": "2013-05-22 11:59:52",
|
||||
"modified": "2013-05-28 12:13:21",
|
||||
"modified_by": "Administrator",
|
||||
"owner": "Administrator"
|
||||
},
|
||||
@@ -361,7 +361,7 @@
|
||||
"oldfieldtype": "Currency",
|
||||
"print_hide": 1,
|
||||
"print_width": "100px",
|
||||
"read_only": 0,
|
||||
"read_only": 1,
|
||||
"width": "100px"
|
||||
},
|
||||
{
|
||||
|
||||
@@ -26,48 +26,15 @@ wn.require('app/buying/doctype/purchase_common/purchase_common.js');
|
||||
erpnext.buying.SupplierQuotationController = erpnext.buying.BuyingController.extend({
|
||||
refresh: function() {
|
||||
this._super();
|
||||
|
||||
|
||||
if (this.frm.doc.docstatus === 1) {
|
||||
cur_frm.add_custom_button("Make Purchase Order", cur_frm.cscript.make_purchase_order);
|
||||
}
|
||||
},
|
||||
|
||||
onload_post_render: function(doc, dt, dn) {
|
||||
var me = this;
|
||||
var callback = function(doc, dt, dn) {
|
||||
cur_frm.cscript.load_taxes(me.frm.doc);
|
||||
}
|
||||
|
||||
// TODO: improve this
|
||||
if(this.frm.doc.__islocal) {
|
||||
if (this.frm.fields_dict.price_list_name && this.frm.doc.price_list_name) {
|
||||
this.price_list_name(callback);
|
||||
} else {
|
||||
callback(doc, dt, dn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
});
|
||||
|
||||
var new_cscript = new erpnext.buying.SupplierQuotationController({frm: cur_frm});
|
||||
|
||||
// for backward compatibility: combine new and previous states
|
||||
$.extend(cur_frm.cscript, new_cscript);
|
||||
|
||||
|
||||
cur_frm.cscript.onload = function(doc, dt, dn) {
|
||||
// set missing values in parent doc
|
||||
set_missing_values(doc, {
|
||||
fiscal_year: sys_defaults.fiscal_year,
|
||||
conversion_rate: 1,
|
||||
currency: sys_defaults.currency,
|
||||
status: "Draft",
|
||||
transaction_date: get_today(),
|
||||
is_subcontracted: "No"
|
||||
});
|
||||
}
|
||||
$.extend(cur_frm.cscript, new erpnext.buying.SupplierQuotationController({frm: cur_frm}));
|
||||
|
||||
cur_frm.cscript.make_purchase_order = function() {
|
||||
var new_po_name = wn.model.make_new_doc_and_get_name("Purchase Order");
|
||||
@@ -82,15 +49,6 @@ cur_frm.cscript.make_purchase_order = function() {
|
||||
}, function(r, rt) { loaddoc("Purchase Order", new_po_name) });
|
||||
}
|
||||
|
||||
cur_frm.cscript.supplier = function(doc, dt, dn) {
|
||||
if (doc.supplier) {
|
||||
get_server_fields('get_default_supplier_address',
|
||||
JSON.stringify({ supplier: doc.supplier }), '', doc, dt, dn, 1,
|
||||
function() { cur_frm.refresh(); });
|
||||
cur_frm.cscript.toggle_contact_section(doc);
|
||||
}
|
||||
}
|
||||
|
||||
cur_frm.cscript.uom = function(doc, cdt, cdn) {
|
||||
// no need to trigger updation of stock uom, as this field doesn't exist in supplier quotation
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
[
|
||||
{
|
||||
"creation": "2013-03-25 16:01:25",
|
||||
"creation": "2013-05-21 16:16:45",
|
||||
"docstatus": 0,
|
||||
"modified": "2013-02-18 13:40:17",
|
||||
"modified": "2013-05-28 12:19:41",
|
||||
"modified_by": "Administrator",
|
||||
"owner": "Administrator"
|
||||
},
|
||||
@@ -65,43 +65,48 @@
|
||||
"search_index": 1
|
||||
},
|
||||
{
|
||||
"depends_on": "supplier",
|
||||
"doctype": "DocField",
|
||||
"fieldname": "supplier_name",
|
||||
"fieldtype": "Data",
|
||||
"hidden": 1,
|
||||
"hidden": 0,
|
||||
"in_list_view": 1,
|
||||
"label": "Name",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"depends_on": "supplier",
|
||||
"doctype": "DocField",
|
||||
"fieldname": "address_display",
|
||||
"fieldtype": "Small Text",
|
||||
"hidden": 1,
|
||||
"hidden": 0,
|
||||
"label": "Address",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"depends_on": "supplier",
|
||||
"doctype": "DocField",
|
||||
"fieldname": "contact_display",
|
||||
"fieldtype": "Small Text",
|
||||
"hidden": 1,
|
||||
"hidden": 0,
|
||||
"label": "Contact",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"depends_on": "supplier",
|
||||
"doctype": "DocField",
|
||||
"fieldname": "contact_mobile",
|
||||
"fieldtype": "Text",
|
||||
"hidden": 1,
|
||||
"hidden": 0,
|
||||
"label": "Mobile No",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"depends_on": "supplier",
|
||||
"doctype": "DocField",
|
||||
"fieldname": "contact_email",
|
||||
"fieldtype": "Text",
|
||||
"hidden": 1,
|
||||
"hidden": 0,
|
||||
"label": "Contact Email",
|
||||
"print_hide": 1,
|
||||
"read_only": 1
|
||||
@@ -520,6 +525,7 @@
|
||||
"oldfieldtype": "Text Editor"
|
||||
},
|
||||
{
|
||||
"depends_on": "supplier",
|
||||
"doctype": "DocField",
|
||||
"fieldname": "contact_section",
|
||||
"fieldtype": "Section Break",
|
||||
@@ -723,7 +729,6 @@
|
||||
"cancel": 0,
|
||||
"create": 0,
|
||||
"doctype": "DocPerm",
|
||||
"match": "",
|
||||
"permlevel": 1,
|
||||
"report": 0,
|
||||
"role": "All",
|
||||
|
||||
167
buying/utils.py
167
buying/utils.py
@@ -16,6 +16,7 @@
|
||||
|
||||
from __future__ import unicode_literals
|
||||
import webnotes
|
||||
from webnotes import msgprint, _
|
||||
from webnotes.utils import getdate, flt, add_days
|
||||
import json
|
||||
|
||||
@@ -29,7 +30,11 @@ def get_item_details(args):
|
||||
"warehouse": None,
|
||||
"supplier": None,
|
||||
"transaction_date": None,
|
||||
"conversion_rate": 1.0
|
||||
"conversion_rate": 1.0,
|
||||
"price_list_name": None,
|
||||
"price_list_currency": None,
|
||||
"plc_conversion_rate": 1.0,
|
||||
"is_subcontracted": "Yes" / "No"
|
||||
}
|
||||
"""
|
||||
if isinstance(args, basestring):
|
||||
@@ -37,86 +42,102 @@ def get_item_details(args):
|
||||
|
||||
args = webnotes._dict(args)
|
||||
|
||||
item_wrapper = webnotes.bean("Item", args.item_code)
|
||||
item = item_wrapper.doc
|
||||
item_bean = webnotes.bean("Item", args.item_code)
|
||||
item = item_bean.doc
|
||||
|
||||
from stock.utils import validate_end_of_life
|
||||
validate_end_of_life(item.name, item.end_of_life)
|
||||
_validate_item_details(args, item)
|
||||
|
||||
# fetch basic values
|
||||
out = webnotes._dict()
|
||||
out.update({
|
||||
"item_name": item.item_name,
|
||||
"item_group": item.item_group,
|
||||
"brand": item.brand,
|
||||
"description": item.description,
|
||||
"qty": 0,
|
||||
"stock_uom": item.stock_uom,
|
||||
"uom": item.stock_uom,
|
||||
"conversion_factor": 1.0,
|
||||
"warehouse": args.warehouse or item.default_warehouse,
|
||||
"item_tax_rate": json.dumps(dict(([d.tax_type, d.tax_rate] for d in
|
||||
item_wrapper.doclist.get({"parentfield": "item_tax"})))),
|
||||
"batch_no": None,
|
||||
"expense_head": item.purchase_account,
|
||||
"cost_center": item.cost_center
|
||||
})
|
||||
out = _get_basic_details(args, item_bean)
|
||||
|
||||
if args.supplier:
|
||||
item_supplier = item_wrapper.doclist.get({"parentfield": "item_supplier_details",
|
||||
"supplier": args.supplier})
|
||||
if item_supplier:
|
||||
out["supplier_part_no"] = item_supplier[0].supplier_part_no
|
||||
out.supplier_part_no = _get_supplier_part_no(args, item_bean)
|
||||
|
||||
if out.warehouse:
|
||||
out.projected_qty = webnotes.conn.get_value("Bin", {"item_code": item.name,
|
||||
"warehouse": out.warehouse}, "projected_qty")
|
||||
out.projected_qty = get_projected_qty(item.name, out.warehouse)
|
||||
|
||||
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)
|
||||
|
||||
# set zero
|
||||
out.purchase_ref_rate = out.discount_rate = out.purchase_rate = \
|
||||
out.import_ref_rate = out.import_rate = 0.0
|
||||
meta = webnotes.get_doctype(args.doctype)
|
||||
|
||||
if meta.get_field("currency"):
|
||||
out.purchase_ref_rate = out.discount_rate = out.purchase_rate = \
|
||||
out.import_ref_rate = out.import_rate = 0.0
|
||||
out.update(_get_price_list_rate(args, item_bean, meta))
|
||||
|
||||
if args.doctype == "Material Request":
|
||||
out.min_order_qty = flt(item.min_order_qty)
|
||||
|
||||
if args.doctype in ["Purchase Order", "Purchase Invoice", "Purchase Receipt",
|
||||
"Supplier Quotation"]:
|
||||
# try fetching from price list
|
||||
if args.price_list_name and args.price_list_currency:
|
||||
rates_as_per_price_list = get_rates_as_per_price_list(args, item_wrapper.doclist)
|
||||
if rates_as_per_price_list:
|
||||
out.update(rates_as_per_price_list)
|
||||
|
||||
# if not found, fetch from last purchase transaction
|
||||
if not out.purchase_rate:
|
||||
last_purchase = get_last_purchase_details(item.name, args.docname, args.conversion_rate)
|
||||
if last_purchase:
|
||||
out.update(last_purchase)
|
||||
|
||||
return out
|
||||
|
||||
def get_rates_as_per_price_list(args, item_doclist=None):
|
||||
if not item_doclist:
|
||||
item_doclist = webnotes.bean("Item", args.item_code).doclist
|
||||
|
||||
result = item_doclist.get({"parentfield": "ref_rate_details",
|
||||
"price_list_name": args.price_list_name, "ref_currency": args.price_list_currency,
|
||||
"buying": 1})
|
||||
def _get_basic_details(args, item_bean):
|
||||
item = item_bean.doc
|
||||
|
||||
out = webnotes._dict({
|
||||
"description": item.description_html or item.description,
|
||||
"qty": 0.0,
|
||||
"uom": item.stock_uom,
|
||||
"conversion_factor": 1.0,
|
||||
"warehouse": args.warehouse or item.default_warehouse,
|
||||
"item_tax_rate": json.dumps(dict(([d.tax_type, d.tax_rate] for d in
|
||||
item_bean.doclist.get({"parentfield": "item_tax"})))),
|
||||
"batch_no": None,
|
||||
"expense_head": item.purchase_account,
|
||||
"cost_center": item.cost_center
|
||||
})
|
||||
|
||||
for fieldname in ("item_name", "item_group", "brand", "stock_uom"):
|
||||
out[fieldname] = item.fields.get(fieldname)
|
||||
|
||||
return out
|
||||
|
||||
def _get_price_list_rate(args, item_bean, meta):
|
||||
from utilities.transaction_base import validate_currency
|
||||
item = item_bean.doc
|
||||
out = webnotes._dict()
|
||||
|
||||
# try fetching from price list
|
||||
if args.price_list_name and args.price_list_currency:
|
||||
price_list_rate = item_bean.doclist.get({
|
||||
"parentfield": "ref_rate_details",
|
||||
"price_list_name": args.price_list_name,
|
||||
"ref_currency": args.price_list_currency,
|
||||
"buying": 1})
|
||||
if price_list_rate:
|
||||
out.import_ref_rate = \
|
||||
flt(price_list_rate[0].ref_rate * args.plc_conversion_rate / args.conversion_rate)
|
||||
|
||||
if result:
|
||||
purchase_ref_rate = flt(result[0].ref_rate) * flt(args.plc_conversion_rate)
|
||||
conversion_rate = flt(args.conversion_rate) or 1.0
|
||||
return webnotes._dict({
|
||||
"purchase_ref_rate": purchase_ref_rate,
|
||||
"purchase_rate": purchase_ref_rate,
|
||||
"rate": purchase_ref_rate,
|
||||
"discount_rate": 0,
|
||||
"import_ref_rate": purchase_ref_rate / conversion_rate,
|
||||
"import_rate": purchase_ref_rate / conversion_rate
|
||||
})
|
||||
else:
|
||||
return webnotes._dict()
|
||||
# if not found, fetch from last purchase transaction
|
||||
if not out.import_ref_rate:
|
||||
last_purchase = get_last_purchase_details(item.name, args.docname, args.conversion_rate)
|
||||
if last_purchase:
|
||||
out.update(last_purchase)
|
||||
|
||||
if out.import_ref_rate or out.import_rate:
|
||||
validate_currency(args, item, meta)
|
||||
|
||||
return out
|
||||
|
||||
def _get_supplier_part_no(args, item_bean):
|
||||
item_supplier = item_bean.doclist.get({"parentfield": "item_supplier_details",
|
||||
"supplier": args.supplier})
|
||||
|
||||
return item_supplier and item_supplier[0].supplier_part_no or None
|
||||
|
||||
def _validate_item_details(args, item):
|
||||
from utilities.transaction_base import validate_item_fetch
|
||||
validate_item_fetch(args, item)
|
||||
|
||||
# validate if purchase item or subcontracted item
|
||||
if item.is_purchase_item != "Yes":
|
||||
msgprint(_("Item") + (" %s: " % item.name) + _("not a purchase item"),
|
||||
raise_exception=True)
|
||||
|
||||
if args.is_subcontracted == "Yes" and item.is_sub_contracted_item != "Yes":
|
||||
msgprint(_("Item") + (" %s: " % item.name) +
|
||||
_("not a sub-contracted item.") +
|
||||
_("Please select a sub-contracted item or do not sub-contract the transaction."),
|
||||
raise_exception=True)
|
||||
|
||||
def get_last_purchase_details(item_code, doc_name, conversion_rate=1.0):
|
||||
"""returns last purchase details in stock uom"""
|
||||
@@ -177,4 +198,14 @@ def get_last_purchase_details(item_code, doc_name, conversion_rate=1.0):
|
||||
"rate": out.purchase_rate
|
||||
})
|
||||
|
||||
return out
|
||||
return out
|
||||
|
||||
@webnotes.whitelist()
|
||||
def get_conversion_factor(item_code, uom):
|
||||
return {"conversion_factor": webnotes.conn.get_value("UOM Conversion Detail",
|
||||
{"parent": item_code, "uom": uom})}
|
||||
|
||||
@webnotes.whitelist()
|
||||
def get_projected_qty(item_code, warehouse):
|
||||
return webnotes.conn.get_value("Bin", {"item_code": item_code,
|
||||
"warehouse": warehouse}, "projected_qty")
|
||||
Reference in New Issue
Block a user