fixes merge conflict

This commit is contained in:
Nabin Hait
2013-01-21 17:30:35 +05:30
136 changed files with 3652 additions and 3278 deletions

View File

@@ -18,6 +18,245 @@
// ------
// cur_frm.cscript.tname - Details table name
// cur_frm.cscript.fname - Details fieldname
wn.provide("erpnext.buying");
erpnext.buying.BuyingController = erpnext.utils.Controller.extend({
setup: function() {
var me = this;
if(this.frm.fields_dict.price_list_name) {
this.frm.fields_dict.price_list_name.get_query = function() {
return repl("select distinct price_list_name from `tabItem Price` \
where buying = 1 and price_list_name like \"%s%%\"");
};
}
if(this.frm.fields_dict.price_list_currency) {
this.frm.fields_dict.price_list_currency.get_query = function() {
return repl("select distinct ref_currency from `tabItem Price` \
where price_list_name=\"%(price_list_name)s\" and buying = 1 \
and ref_currency like \"%s%%\"",
{price_list_name: me.frm.doc.price_list_name});
};
}
},
refresh: function() {
this.frm.clear_custom_buttons();
erpnext.hide_naming_series();
if(this.frm.fields_dict.supplier)
this.frm.toggle_display("contact_section", this.frm.doc.supplier);
if(this.frm.fields_dict.currency)
this.set_dynamic_labels();
// TODO: improve this
if(this.frm.doc.__islocal && this.frm.fields_dict.price_list_name
&& this.frm.doc.price_list_name && this.frm.doc.price_list_currency) {
this.price_list_name();
}
},
price_list_name: function() {
this.frm.toggle_reqd(["price_list_currency", "plc_conversion_rate"],
!!(this.frm.doc.price_list_name));
var me = this;
if(this.frm.doc.price_list_name) {
// set price list currency
this.frm.call({
method: "setup.utils.get_price_list_currency",
args: {args: {
price_list_name: this.frm.doc.price_list_name,
use_for: "buying"
}},
callback: function(r) {
if(!r.exc) {
// for now, setting it as 1.0
if(me.frm.doc.price_list_currency === me.get_company_currency())
me.frm.set_value("plc_conversion_rate", 1.0);
else if(me.frm.doc.price_list_currency === me.frm.doc.currency)
me.frm.set_value("plc_conversion_rate", me.frm.doc.conversion_rate);
if(r.message.price_list_currency)
me.price_list_currency();
}
}
});
}
},
item_code: function(doc, cdt, cdn) {
var me = this;
var item = locals[cdt][cdn];
if(item.item_code) {
this.frm.call({
method: "buying.utils.get_item_details",
child: item,
args: {
args: {
doctype: me.frm.doc.doctype,
docname: me.frm.doc.name,
item_code: item.item_code,
warehouse: item.warehouse,
supplier: me.frm.doc.supplier,
conversion_rate: me.frm.doc.conversion_rate,
price_list_name: me.frm.doc.price_list_name,
price_list_currency: me.frm.doc.price_list_currency,
plc_conversion_rate: me.frm.doc.plc_conversion_rate
}
},
});
}
},
update_item_details: function(doc, dt, dn, callback) {
if(!this.frm.doc.__islocal) return;
var me = this;
var children = getchildren(this.tname, this.frm.doc.name, this.fname);
if(children && children.length) {
this.frm.call({
doc: me.frm.doc,
method: "update_item_details",
callback: function(r) {
if(!r.exc) {
refresh_field(me.fname);
me.load_defaults(me.frm.doc, dt, dn, callback);
}
}
})
} else {
this.load_taxes(doc, dt, dn, callback);
}
},
currency: function() {
this.set_dynamic_labels();
},
company: function() {
this.set_dynamic_labels();
},
price_list_currency: function() {
this.set_dynamic_labels();
if(this.frm.doc.price_list_currency === this.get_company_currency()) {
this.frm.set_value("plc_conversion_rate", 1.0);
}
},
set_dynamic_labels: function(doc, dt, dn) {
var company_currency = this.get_company_currency();
this.change_form_labels(company_currency);
this.change_grid_labels(company_currency);
},
change_form_labels: function(company_currency) {
var me = this;
var field_label_map = {};
var setup_field_label_map = function(fields_list, currency) {
$.each(fields_list, function(i, fname) {
var docfield = wn.meta.get_docfield(me.frm.doc.doctype, fname);
if(docfield) {
var label = wn._((docfield.label || "")).replace(/\([^\)]*\)/g, "");
field_label_map[fname] = label.trim() + " (" + currency + ")";
}
});
}
setup_field_label_map(["net_total", "total_tax", "grand_total", "in_words",
"other_charges_added", "other_charges_deducted",
"outstanding_amount", "total_advance", "total_amount_to_pay", "rounded_total"],
company_currency);
setup_field_label_map(["net_total_import", "grand_total_import", "in_words_import",
"other_charges_added_import", "other_charges_deducted_import"], this.frm.doc.currency);
setup_field_label_map(["conversion_rate"], "1 " + this.frm.doc.currency
+ " = [?] " + company_currency);
if(this.frm.doc.price_list_currency && this.frm.doc.price_list_currency!=company_currency) {
setup_field_label_map(["plc_conversion_rate"], "1 " + this.frm.doc.price_list_currency
+ " = [?] " + company_currency);
}
// toggle fields
this.frm.toggle_display(["conversion_rate", "net_total", "grand_total",
"in_words", "other_charges_added", "other_charges_deducted"],
this.frm.doc.currency != company_currency);
// set labels
$.each(field_label_map, function(fname, label) {
me.frm.fields_dict[fname].set_label(label);
});
},
change_grid_labels: function(company_currency) {
var me = this;
var field_label_map = {};
var setup_field_label_map = function(fields_list, currency, parentfield) {
var grid_doctype = me.frm.fields_dict[parentfield].grid.doctype;
$.each(fields_list, function(i, fname) {
var docfield = wn.meta.get_docfield(grid_doctype, fname);
if(docfield) {
field_label_map[grid_doctype + "-" + fname] =
docfield.label + " (" + currency + ")";
}
});
}
setup_field_label_map(["purchase_rate", "purchase_ref_rate", "amount", "rate"],
company_currency, this.fname);
setup_field_label_map(["import_rate", "import_ref_rate", "import_amount"],
this.frm.doc.currency, this.fname);
setup_field_label_map(["tax_amount", "total"], company_currency, this.other_fname);
if(this.frm.fields_dict["advance_allocation_details"]) {
setup_field_label_map(["advance_amount", "allocated_amount"], company_currency,
"advance_allocation_details");
}
// toggle columns
var item_grid = this.frm.fields_dict[this.fname].grid;
var hide = this.frm.doc.currency == company_currency;
$.each(["purchase_rate", "purchase_ref_rate", "amount", "rate"], function(i, fname) {
if(wn.meta.get_docfield(item_grid.doctype, fname))
item_grid.set_column_disp(fname, hide);
});
// set labels
var $wrapper = $(this.frm.wrapper);
$.each(field_label_map, function(fname, label) {
$wrapper.find('[data-grid-fieldname="'+fname+'"]').text(label);
});
},
get_company_currency: function() {
return (wn.boot.company[this.frm.doc.company].default_currency ||
sys_defaults['currency']);
}
});
// to save previous state of cur_frm.cscript
var prev_cscript = {};
$.extend(prev_cscript, cur_frm.cscript);
cur_frm.cscript = new erpnext.buying.BuyingController({frm: cur_frm});
// for backward compatibility: combine new and previous states
$.extend(cur_frm.cscript, prev_cscript);
var tname = cur_frm.cscript.tname;
var fname = cur_frm.cscript.fname;
@@ -64,100 +303,6 @@ cur_frm.cscript.load_defaults = function(doc, dt, dn, callback) {
cur_frm.cscript.load_taxes(doc, dt, dn, callback);
}
// Update existing item details
cur_frm.cscript.update_item_details = function(doc, dt, dn, callback) {
if(!cur_frm.doc.__islocal) { return; }
var children = getchildren(cur_frm.cscript.tname, doc.name, cur_frm.cscript.fname);
if(children) {
$c_obj(make_doclist(doc.doctype, doc.name), 'get_item_details', '',
function(r, rt) {
if(!r.exc) {
refresh_field(cur_frm.cscript.fname);
doc = locals[doc.doctype][doc.name];
cur_frm.cscript.load_defaults(doc, dt, dn, callback);
}
});
} else {
cur_frm.cscript.load_taxes(doc, dt, dn, callback);
}
}
var set_dynamic_label_par = function(doc, cdt, cdn, base_curr) {
//parent flds
par_cols_base = {'net_total': 'Net Total', 'total_tax': 'Total Tax', 'grand_total': 'Grand Total', /*'rounded_total': 'Rounded Total',*/
'in_words': 'In Words', 'other_charges_added': 'Taxes and Charges Added', 'other_charges_deducted': 'Taxes and Charges Deducted'}
par_cols_import = {'net_total_import': 'Net Total', 'grand_total_import': 'Grand Total', 'in_words_import': 'In Words',
'other_charges_added_import': 'Taxes and Charges Added', 'other_charges_deducted_import': 'Taxes and Charges Deducted'};
for (d in par_cols_base) cur_frm.fields_dict[d].label_area.innerHTML = par_cols_base[d]+' (' + base_curr + ')';
for (d in par_cols_import) cur_frm.fields_dict[d].label_area.innerHTML = par_cols_import[d]+' (' + doc.currency + ')';
cur_frm.fields_dict['conversion_rate'].label_area.innerHTML = "Conversion Rate (" + doc.currency +' -> '+ base_curr + ')';
if (doc.doctype == 'Purchase Invoice') {
cur_frm.fields_dict['outstanding_amount'].label_area.innerHTML = 'Outstanding Amount (' + base_curr + ')';
cur_frm.fields_dict['total_advance'].label_area.innerHTML = 'Total Advance (Incl. TDS) (' + base_curr + ')';
cur_frm.fields_dict['total_amount_to_pay'].label_area.innerHTML = 'Total Amount To Pay (' + base_curr + ')';
} else cur_frm.fields_dict['rounded_total'].label_area.innerHTML = 'Rounded Total (' + base_curr + ')';
}
var set_dynamic_label_child = function(doc, cdt, cdn, base_curr) {
// item table flds
item_cols_base = {'purchase_ref_rate': 'Ref Rate', 'amount': 'Amount'};
item_cols_import = {'import_rate': 'Rate', 'import_ref_rate': 'Ref Rate', 'import_amount': 'Amount'};
for (d in item_cols_base) $('[data-grid-fieldname="'+cur_frm.cscript.tname+'-'+d+'"]').html(item_cols_base[d]+' ('+base_curr+')');
for (d in item_cols_import) $('[data-grid-fieldname="'+cur_frm.cscript.tname+'-'+d+'"]').html(item_cols_import[d]+' ('+doc.currency+')');
var hide = (doc.currency == sys_defaults['currency']) ? false : true;
for (f in item_cols_base) {
cur_frm.fields_dict[cur_frm.cscript.fname].grid.set_column_disp(f, hide);
}
if (doc.doctype == 'Purchase Invoice') {
$('[data-grid-fieldname="'+cur_frm.cscript.tname+'-rate"]').html('Rate ('+base_curr+')');
cur_frm.fields_dict[cur_frm.cscript.fname].grid.set_column_disp('rate', hide);
// advance table flds
adv_cols = {'advance_amount': 'Advance Amount', 'allocated_amount': 'Allocated Amount'}
for (d in adv_cols) $('[data-grid-fieldname="Purchase Invoice Advance-'+d+'"]').html(adv_cols[d]+' ('+base_curr+')');
}
else {
$('[data-grid-fieldname="'+cur_frm.cscript.tname+'-purchase_rate"]').html('Rate ('+base_curr+')');
cur_frm.fields_dict[cur_frm.cscript.fname].grid.set_column_disp('purchase_rate', hide);
}
//tax table flds
tax_cols = {'tax_amount': 'Amount', 'total': 'Aggregate Total'};
for (d in tax_cols) $('[data-grid-fieldname="Purchase Taxes and Charges-'+d+'"]').html(tax_cols[d]+' ('+base_curr+')');
}
// Change label dynamically based on currency
//------------------------------------------------------------------
cur_frm.cscript.dynamic_label = function(doc, cdt, cdn, callback1) {
var base_currency = wn.boot.company[doc.company].default_currency || sys_defaults['currency'];
if (doc.currency === base_currency) {
set_multiple(cdt, cdn, {conversion_rate:1});
hide_field(['conversion_rate', 'net_total_import','grand_total_import',
'in_words_import', 'other_charges_added_import', 'other_charges_deducted_import']);
} else {
unhide_field(['conversion_rate', 'net_total_import','grand_total_import',
'in_words_import', 'other_charges_added_import', 'other_charges_deducted_import']);
}
set_dynamic_label_par(doc, cdt, cdn, base_currency);
set_dynamic_label_child(doc, cdt, cdn, base_currency);
if (callback1) callback1(doc, cdt, cdn);
}
cur_frm.cscript.currency = function(doc, cdt, cdn) {
cur_frm.cscript.dynamic_label(doc, cdt, cdn);
}
cur_frm.cscript.company = cur_frm.cscript.currency;
// ======================== Conversion Rate ==========================================
cur_frm.cscript.conversion_rate = function(doc,cdt,cdn) {
cur_frm.cscript.calc_amount( doc, 1);
@@ -177,18 +322,6 @@ cur_frm.fields_dict[fname].grid.get_field("item_code").get_query = function(doc,
}
}
//==================== Get Item Code Details =====================================================
cur_frm.cscript.item_code = function(doc,cdt,cdn) {
var d = locals[cdt][cdn];
if (d.item_code) {
temp = {
item_code: d.item_code || '',
warehouse: d.warehouse || ''
}
get_server_fields('get_item_details', JSON.stringify(temp), fname, doc, cdt, cdn, 1);
}
}
//==================== Update Stock Qty ==========================================================
cur_frm.cscript.update_stock_qty = function(doc,cdt,cdn){
d = locals[cdt][cdn]
@@ -651,10 +784,6 @@ var calculate_outstanding = function(doc) {
}
cur_frm.cscript.toggle_contact_section = function(doc) {
cur_frm.toggle_display("contact_section", doc.supplier);
}
cur_frm.cscript.project_name = function(doc, cdt, cdn) {
var item_doc = locals[cdt][cdn];
if (item_doc.project_name) {

View File

@@ -23,11 +23,12 @@ from webnotes.model.wrapper import getlist
from webnotes.model.code import get_obj
from webnotes import msgprint, _
from buying.utils import get_last_purchase_details
sql = webnotes.conn.sql
from utilities.transaction_base import TransactionBase
class DocType(TransactionBase):
from controllers.buying_controller import BuyingController
class DocType(BuyingController):
def __init__(self, doc, doclist=None):
self.doc = doc
self.doclist = doclist
@@ -104,80 +105,6 @@ class DocType(TransactionBase):
r = sql("select terms from `tabTerms and Conditions` where name = %s", obj.doc.tc_name)
if r: obj.doc.terms = r[0][0]
# Get Item Details
def get_item_details(self, obj, arg =''):
import json
arg = json.loads(arg)
item = sql("select item_name,item_group, brand, description, min_order_qty, stock_uom, default_warehouse,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())", (arg['item_code']), as_dict = 1)
tax = sql("select tax_type, tax_rate from `tabItem Tax` where parent = %s" , arg['item_code'])
t = {}
for x in tax: t[x[0]] = flt(x[1])
# get warehouse
if arg['warehouse']:
wh = arg['warehouse']
else:
wh = item and item[0]['default_warehouse'] or ''
ret = {
'item_name': item and item[0]['item_name'] or '',
'item_group': item and item[0]['item_group'] or '',
'brand': item and item[0]['brand'] or '',
'description': item and item[0]['description'] or '',
'qty': 0,
'uom': item and item[0]['stock_uom'] or '',
'stock_uom': item and item[0]['stock_uom'] or '',
'conversion_factor': '1',
'warehouse': wh,
'item_tax_rate': json.dumps(t),
'batch_no': '',
'discount_rate': 0
}
# get min_order_qty from item
if obj.doc.doctype == 'Purchase Request':
ret['min_order_qty'] = item and flt(item[0]['min_order_qty']) or 0
# get projected qty from bin
if ret['warehouse']:
bin = sql("select projected_qty from `tabBin` where item_code = %s and warehouse = %s", (arg['item_code'], ret['warehouse']), as_dict=1)
ret['projected_qty'] = bin and flt(bin[0]['projected_qty']) or 0
# get schedule date, lead time date
if obj.doc.transaction_date and item and item[0]['lead_time_days']:
ret['schedule_date'] = cstr(add_days(obj.doc.transaction_date, cint(item[0]['lead_time_days'])))
ret['lead_time_date'] = cstr(add_days(obj.doc.transaction_date, cint(item[0]['lead_time_days'])))
# get last purchase rate as per stock uom and default currency for following list of doctypes
if obj.doc.doctype in ['Purchase Order', 'Purchase Receipt']:
last_purchase_details, last_purchase_date = self.get_last_purchase_details(arg['item_code'], obj.doc.name)
if last_purchase_details:
# updates ret with purchase_ref_rate, discount_rate, purchase_rate
conversion_rate = flt(obj.doc.fields.get('conversion_rate'))
ret.update(last_purchase_details)
ret.update({
'import_ref_rate': flt(last_purchase_details['purchase_ref_rate']) / conversion_rate,
'import_rate': flt(last_purchase_details['purchase_rate']) / conversion_rate,
})
else:
# set these values as blank in the form
ret.update({
'purchase_ref_rate': 0,
'discount_rate': 0,
'purchase_rate': 0,
'import_ref_rate': 0,
'import_rate': 0,
})
if obj.doc.doctype == 'Purchase Order':
supplier_part_no = webnotes.conn.sql("""\
select supplier_part_no from `tabItem Supplier`
where parent = %s and parenttype = 'Item' and
supplier = %s""", (arg['item_code'], obj.doc.supplier))
if supplier_part_no and supplier_part_no[0][0]:
ret['supplier_part_no'] = supplier_part_no[0][0]
return ret
# Get Available Qty at Warehouse
def get_bin_details( self, arg = ''):
@@ -193,14 +120,15 @@ class DocType(TransactionBase):
import webnotes.utils
this_purchase_date = webnotes.utils.getdate(obj.doc.fields.get('posting_date') or obj.doc.fields.get('transaction_date'))
for d in getlist(obj.doclist,obj.fname):
# get last purchase details
last_purchase_details, last_purchase_date = self.get_last_purchase_details(d.item_code, obj.doc.name)
last_purchase_details = get_last_purchase_details(d.item_code, obj.doc.name)
# compare last purchase date and this transaction's date
last_purchase_rate = None
if last_purchase_date > this_purchase_date:
if last_purchase_details and \
(last_purchase_details.purchase_date > this_purchase_date):
last_purchase_rate = last_purchase_details['purchase_rate']
elif is_submit == 1:
# even if this transaction is the latest one, it should be submitted
@@ -219,7 +147,7 @@ class DocType(TransactionBase):
for d in getlist(obj.doclist, obj.fname):
if d.item_code:
last_purchase_details, last_purchase_date = self.get_last_purchase_details(d.item_code, doc_name)
last_purchase_details = get_last_purchase_details(d.item_code, doc_name)
if last_purchase_details:
d.purchase_ref_rate = last_purchase_details['purchase_ref_rate'] * (flt(d.conversion_factor) or 1.0)
@@ -237,58 +165,6 @@ class DocType(TransactionBase):
d.purchase_ref_rate = d.purchase_rate = d.import_ref_rate \
= d.import_rate = item_last_purchase_rate
def get_last_purchase_details(self, item_code, doc_name):
import webnotes
import webnotes.utils
# get last purchase order item details
last_po_item = webnotes.conn.sql("""\
select po.name, po.transaction_date, po_item.conversion_factor, po_item.purchase_ref_rate,
po_item.discount_rate, po_item.purchase_rate
from `tabPurchase Order` po, `tabPurchase Order Item` po_item
where po.docstatus = 1 and po_item.item_code = %s and po.name != %s and
po.name = po_item.parent
order by po.transaction_date desc, po.name desc
limit 1""", (item_code, doc_name), as_dict=1)
# get last purchase receipt item details
last_pr_item = webnotes.conn.sql("""\
select pr.name, pr.posting_date, pr.posting_time, pr_item.conversion_factor,
pr_item.purchase_ref_rate, pr_item.discount_rate, pr_item.purchase_rate
from `tabPurchase Receipt` pr, `tabPurchase Receipt Item` pr_item
where pr.docstatus = 1 and pr_item.item_code = %s and pr.name != %s and
pr.name = pr_item.parent
order by pr.posting_date desc, pr.posting_time desc, pr.name desc
limit 1""", (item_code, doc_name), as_dict=1)
# get the latest of the two
po_date_obj = webnotes.utils.getdate(last_po_item and last_po_item[0]['transaction_date'] or '2000-01-01')
pr_date_obj = webnotes.utils.getdate(last_pr_item and last_pr_item[0]['posting_date'] or '2000-01-01')
# if both exists, return true
both_exists = last_po_item and last_pr_item
# get the last purchased item, by comparing dates
if (both_exists and po_date_obj > pr_date_obj) or (not both_exists and last_po_item):
last_purchase_item = last_po_item[0]
last_purchase_date = po_date_obj
elif both_exists or (not both_exists and last_pr_item):
last_purchase_item = last_pr_item[0]
last_purchase_date = pr_date_obj
else:
# if none exists
return None, webnotes.utils.getdate('2000-01-01')
# prepare last purchase details, dividing by conversion factor
conversion_factor = flt(last_purchase_item['conversion_factor'])
last_purchase_details = {
'purchase_ref_rate': flt(last_purchase_item['purchase_ref_rate']) / conversion_factor,
'purchase_rate': flt(last_purchase_item['purchase_rate']) / conversion_factor,
'discount_rate': flt(last_purchase_item['discount_rate']),
}
return last_purchase_details, last_purchase_date
# validation
# -------------------------------------------------------------------------------------------------------
@@ -380,74 +256,6 @@ class DocType(TransactionBase):
else:
chk_dupl_itm.append(f)
# validate conversion rate
def validate_conversion_rate(self, obj):
default_currency = TransactionBase().get_company_currency(obj.doc.company)
if not default_currency:
msgprint('Message: Please enter default currency in Company Master')
raise Exception
if obj.doc.conversion_rate == 0:
msgprint('Conversion Rate cannot be 0', raise_exception=1)
elif not obj.doc.conversion_rate:
msgprint('Please specify Conversion Rate', raise_exception=1)
elif obj.doc.currency == default_currency and \
flt(obj.doc.conversion_rate) != 1.00:
msgprint("""Conversion Rate should be equal to 1.00, \
since the specified Currency and the company's currency \
are same""", raise_exception=1)
elif obj.doc.currency != default_currency and \
flt(obj.doc.conversion_rate) == 1.00:
msgprint("""Conversion Rate should not be equal to 1.00, \
since the specified Currency and the company's currency \
are different""", raise_exception=1)
def validate_doc(self, obj, prevdoc_doctype, prevdoc_docname):
if prevdoc_docname :
get_name = sql("select name from `tab%s` where name = '%s'" %
(prevdoc_doctype, prevdoc_docname))
name = get_name and get_name[0][0] or ''
if name: #check for incorrect docname
dt = sql("select company, docstatus from `tab%s` where name = '%s'" %
(prevdoc_doctype, name))
company_name = dt and cstr(dt[0][0]) or ''
docstatus = dt and dt[0][1] or 0
# check for docstatus
if (docstatus != 1):
msgprint(cstr(prevdoc_doctype) + ": " + cstr(prevdoc_docname) +
" is not Submitted Document.")
raise Exception
# check for company
if (company_name != obj.doc.company):
msgprint(cstr(prevdoc_doctype) + ": " + cstr(prevdoc_docname) +
" does not belong to the Company: " + cstr(obj.doc.company))
raise Exception
if prevdoc_doctype in ['Purchase Order', 'Purchase Receipt']:
dt = sql("select supplier, currency from `tab%s` where name = '%s'" %
(prevdoc_doctype, name))
supplier = dt and dt[0][0] or ''
currency = dt and dt[0][1] or ''
# check for supplier
if (supplier != obj.doc.supplier):
msgprint("Purchase Order: " + cstr(prevdoc_docname) + " supplier :" +
cstr(supplier) + " does not match with supplier of current document.")
raise Exception
# check for curency
if (currency != obj.doc.currency):
msgprint("Purchase Order: " + cstr(prevdoc_docname) + " currency :" +
cstr(currency) + " does not match with currency of current document.")
raise Exception
else: # if not name than
msgprint(cstr(prevdoc_doctype) + ": " + cstr(prevdoc_docname) +
" is not a valid " + cstr(prevdoc_doctype))
raise Exception
def validate_reference_value(self, obj):
ref_doc = []
for d in getlist(obj.doclist, obj.fname):

View File

@@ -14,6 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
wn.provide("erpnext.buying");
cur_frm.cscript.tname = "Purchase Order Item";
cur_frm.cscript.fname = "po_details";
cur_frm.cscript.other_fname = "purchase_tax_details";
@@ -22,6 +24,35 @@ wn.require('app/accounts/doctype/purchase_taxes_and_charges_master/purchase_taxe
wn.require('app/buying/doctype/purchase_common/purchase_common.js');
wn.require('app/utilities/doctype/sms_control/sms_control.js');
erpnext.buying.PurchaseOrderController = erpnext.buying.BuyingController.extend({
refresh: function(doc, cdt, cdn) {
this._super();
if(doc.docstatus == 1 && doc.status != 'Stopped'){
cur_frm.add_custom_button('Send SMS', cur_frm.cscript['Send SMS']);
if(flt(doc.per_received, 2) < 100) cur_frm.add_custom_button('Make Purchase Receipt', cur_frm.cscript['Make Purchase Receipt']);
if(flt(doc.per_billed, 2) < 100) cur_frm.add_custom_button('Make Invoice', cur_frm.cscript['Make Purchase Invoice']);
if(flt(doc.per_billed, 2) < 100 || doc.per_received < 100) cur_frm.add_custom_button('Stop', cur_frm.cscript['Stop Purchase Order']);
}
if(doc.docstatus == 1 && doc.status == 'Stopped')
cur_frm.add_custom_button('Unstop Purchase Order', cur_frm.cscript['Unstop Purchase Order']);
},
onload_post_render: function(doc, dt, dn) {
var callback = function(doc, dt, dn) {
if(doc.__islocal) cur_frm.cscript.get_default_schedule_date(doc);
}
this.update_item_details(doc, dt, dn, callback);
}
});
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, {
@@ -34,32 +65,6 @@ cur_frm.cscript.onload = function(doc, cdt, cdn) {
});
}
cur_frm.cscript.onload_post_render = function(doc, dt, dn) {
var callback = function(doc, dt, dn) {
if(doc.__islocal) cur_frm.cscript.get_default_schedule_date(doc);
}
cur_frm.cscript.update_item_details(doc, dt, dn, callback);
}
cur_frm.cscript.refresh = function(doc, cdt, cdn) {
cur_frm.clear_custom_buttons();
erpnext.hide_naming_series();
cur_frm.cscript.dynamic_label(doc, cdt, cdn);
if(doc.docstatus == 1 && doc.status != 'Stopped'){
cur_frm.add_custom_button('Send SMS', cur_frm.cscript['Send SMS']);
if(flt(doc.per_received, 2) < 100) cur_frm.add_custom_button('Make Purchase Receipt', cur_frm.cscript['Make Purchase Receipt']);
if(flt(doc.per_billed, 2) < 100) cur_frm.add_custom_button('Make Invoice', cur_frm.cscript['Make Purchase Invoice']);
if(flt(doc.per_billed, 2) < 100 || doc.per_received < 100) cur_frm.add_custom_button('Stop', cur_frm.cscript['Stop Purchase Order']);
}
if(doc.docstatus == 1 && doc.status == 'Stopped')
cur_frm.add_custom_button('Unstop Purchase Order', cur_frm.cscript['Unstop Purchase Order']);
cur_frm.cscript.toggle_contact_section(doc);
}
cur_frm.cscript.supplier = function(doc,dt,dn) {
if (doc.supplier) {
get_server_fields('get_default_supplier_address',

View File

@@ -17,30 +17,60 @@
from __future__ import unicode_literals
import webnotes
from webnotes.utils import cstr, date_diff, flt, get_defaults, now
from webnotes.model import db_exists
from webnotes.model.doc import addchild, make_autoname
from webnotes.model.wrapper import getlist, copy_doclist
from webnotes.utils import cstr, flt, get_defaults
from webnotes.model.doc import addchild
from webnotes.model.wrapper import getlist
from webnotes.model.code import get_obj
from webnotes import msgprint
from buying.utils import get_last_purchase_details
from setup.utils import get_company_currency
sql = webnotes.conn.sql
from utilities.transaction_base import TransactionBase
class DocType(TransactionBase):
from controllers.buying_controller import BuyingController
class DocType(BuyingController):
def __init__(self, doc, doclist=[]):
self.doc = doc
self.doclist = doclist
self.defaults = get_defaults()
self.tname = 'Purchase Order Item'
self.fname = 'po_details'
# Validate
def validate(self):
super(DocType, self).validate()
self.validate_fiscal_year()
# Autoname
# ---------
def autoname(self):
self.doc.name = make_autoname(self.doc.naming_series+'.#####')
if not self.doc.status:
self.doc.status = "Draft"
import utilities
utilities.validate_status(self.doc.status, ["Draft", "Submitted", "Stopped",
"Cancelled"])
# Step 2:=> get Purchase Common Obj
pc_obj = get_obj(dt='Purchase Common')
# Step 3:=> validate mandatory
pc_obj.validate_mandatory(self)
# Step 4:=> validate for items
pc_obj.validate_for_items(self)
# Get po date
pc_obj.get_prevdoc_date(self)
# validate_doc
self.validate_doc(pc_obj)
# Check for stopped status
self.check_for_stopped_status(pc_obj)
# get total in words
dcc = get_company_currency(self.doc.company)
self.doc.in_words = pc_obj.get_total_in_words(dcc, self.doc.grand_total)
self.doc.in_words_import = pc_obj.get_total_in_words(self.doc.currency, self.doc.grand_total_import)
def get_default_schedule_date(self):
get_obj(dt = 'Purchase Common').get_default_schedule_date(self)
@@ -48,27 +78,6 @@ class DocType(TransactionBase):
def validate_fiscal_year(self):
get_obj(dt = 'Purchase Common').validate_fiscal_year(self.doc.fiscal_year,self.doc.transaction_date,'PO Date')
# Get Item Details
def get_item_details(self, arg =''):
import json
if arg:
return get_obj(dt='Purchase Common').get_item_details(self,arg)
else:
obj = get_obj('Purchase Common')
for doc in self.doclist:
if doc.fields.get('item_code'):
temp = {
'item_code': doc.fields.get('item_code'),
'warehouse': doc.fields.get('warehouse')
}
ret = obj.get_item_details(self, json.dumps(temp))
for r in ret:
if not doc.fields.get(r):
doc.fields[r] = ret[r]
# get available qty at warehouse
def get_bin_details(self, arg = ''):
return get_obj(dt='Purchase Common').get_bin_details(arg)
@@ -80,7 +89,7 @@ class DocType(TransactionBase):
pcomm = get_obj('Purchase Common')
for d in getlist(self.doclist, 'po_details'):
if d.item_code and not d.purchase_rate:
last_purchase_details, last_purchase_date = pcomm.get_last_purchase_details(d.item_code, self.doc.name)
last_purchase_details = get_last_purchase_details(d.item_code, self.doc.name)
if last_purchase_details:
conversion_factor = d.conversion_factor or 1.0
conversion_rate = self.doc.fields.get('conversion_rate') or 1.0
@@ -125,44 +134,6 @@ class DocType(TransactionBase):
pc_obj.check_for_stopped_status( d.prevdoc_doctype, d.prevdoc_docname)
# Validate
def validate(self):
self.validate_fiscal_year()
if not self.doc.status:
self.doc.status = "Draft"
import utilities
utilities.validate_status(self.doc.status, ["Draft", "Submitted", "Stopped",
"Cancelled"])
# Step 2:=> get Purchase Common Obj
pc_obj = get_obj(dt='Purchase Common')
# Step 3:=> validate mandatory
pc_obj.validate_mandatory(self)
# Step 4:=> validate for items
pc_obj.validate_for_items(self)
# Step 5:=> validate conversion rate
pc_obj.validate_conversion_rate(self)
# Get po date
pc_obj.get_prevdoc_date(self)
# validate_doc
self.validate_doc(pc_obj)
# Check for stopped status
self.check_for_stopped_status(pc_obj)
# get total in words
dcc = TransactionBase().get_company_currency(self.doc.company)
self.doc.in_words = pc_obj.get_total_in_words(dcc, self.doc.grand_total)
self.doc.in_words_import = pc_obj.get_total_in_words(self.doc.currency, self.doc.grand_total_import)
def update_bin(self, is_submit, is_stopped = 0):
pc_obj = get_obj('Purchase Common')
for d in getlist(self.doclist, 'po_details'):
@@ -237,10 +208,6 @@ class DocType(TransactionBase):
# Step 3 :=> Check For Approval Authority
get_obj('Authorization Control').validate_approving_authority(self.doc.doctype, self.doc.company, self.doc.grand_total)
# Step 4 :=> Update Current PO No. in Supplier as last_purchase_order.
update_supplier = webnotes.conn.set_value("Supplier", self.doc.supplier,
"last_purchase_order", self.doc.name)
# Step 5 :=> Update last purchase rate
purchase_controller.update_last_purchase_rate(self, is_submit = 1)

View File

@@ -2,18 +2,19 @@
{
"owner": "Administrator",
"docstatus": 0,
"creation": "2012-08-06 20:00:37",
"creation": "2013-01-18 12:46:59",
"modified_by": "Administrator",
"modified": "2012-12-03 17:10:41"
"modified": "2013-01-18 13:24:20"
},
{
"document_type": "Transaction",
"is_submittable": 1,
"allow_attach": 1,
"search_fields": "status, transaction_date, supplier,grand_total",
"autoname": "naming_series:",
"module": "Buying",
"doctype": "DocType",
"read_only_onload": 1,
"document_type": "Transaction",
"search_fields": "status, transaction_date, supplier,grand_total",
"name": "__common__"
},
{
@@ -35,45 +36,34 @@
"name": "Purchase Order",
"doctype": "DocType"
},
{
"oldfieldtype": "Column Break",
"doctype": "DocField",
"width": "50%",
"fieldname": "column_break0",
"fieldtype": "Column Break",
"permlevel": 0
},
{
"print_hide": 1,
"description": "To manage multiple series please go to Setup > Manage Series",
"no_copy": 1,
"oldfieldtype": "Select",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Series",
"oldfieldname": "naming_series",
"permlevel": 0,
"options": "\nPO",
"fieldname": "naming_series",
"fieldtype": "Select",
"reqd": 1,
"options": "\nPO"
"permlevel": 0
},
{
"print_hide": 1,
"description": "Supplier (vendor) name as entered in supplier master",
"oldfieldtype": "Link",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Supplier",
"oldfieldname": "supplier",
"permlevel": 0,
"trigger": "Client",
"fieldname": "supplier",
"fieldtype": "Link",
"search_index": 1,
"reqd": 1,
"in_filter": 1,
"options": "Supplier"
"options": "Supplier",
"in_filter": 1
},
{
"doctype": "DocField",
@@ -118,6 +108,7 @@
},
{
"print_hide": 0,
"print_width": "50%",
"oldfieldtype": "Column Break",
"doctype": "DocField",
"width": "50%",
@@ -128,21 +119,18 @@
{
"description": "The date at which current entry is made in system.",
"oldfieldtype": "Date",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Purchase Order Date",
"oldfieldname": "transaction_date",
"trigger": "Client",
"fieldname": "transaction_date",
"fieldtype": "Date",
"search_index": 1,
"reqd": 1,
"in_filter": 1,
"permlevel": 0
"permlevel": 0,
"in_filter": 1
},
{
"oldfieldtype": "Section Break",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Items",
"fieldname": "items",
@@ -156,101 +144,139 @@
"doctype": "DocField",
"label": "Purchase Order Items",
"oldfieldname": "po_details",
"options": "Purchase Order Item",
"permlevel": 0,
"fieldname": "po_details",
"fieldtype": "Table",
"permlevel": 0
"options": "Purchase Order Item"
},
{
"doctype": "DocField",
"options": "Simple",
"fieldname": "section_break0",
"permlevel": 0,
"fieldname": "sb_last_purchase",
"fieldtype": "Section Break",
"options": "Simple"
},
{
"print_hide": 0,
"oldfieldtype": "Button",
"doctype": "DocField",
"label": "Get Last Purchase Rate",
"fieldname": "get_last_purchase_rate",
"fieldtype": "Button",
"permlevel": 0
},
{
"print_width": "50%",
"doctype": "DocField",
"width": "50%",
"fieldname": "column_break2",
"fieldtype": "Column Break",
"permlevel": 0
},
{
"print_hide": 1,
"no_copy": 1,
"oldfieldtype": "Currency",
"doctype": "DocField",
"label": "Net Total*",
"oldfieldname": "net_total",
"fieldname": "net_total",
"fieldtype": "Currency",
"reqd": 0,
"permlevel": 1
},
{
"print_hide": 1,
"no_copy": 0,
"oldfieldtype": "Currency",
"doctype": "DocField",
"label": "Net Total (Import)",
"oldfieldname": "net_total_import",
"fieldname": "net_total_import",
"fieldtype": "Currency",
"permlevel": 1
},
{
"print_hide": 0,
"oldfieldtype": "Button",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Get Last Purchase Rate",
"trigger": "Client",
"fieldname": "get_last_purchase_rate",
"fieldtype": "Button",
"permlevel": 0
},
{
"oldfieldtype": "Button",
"doctype": "DocField",
"label": "Re-Calculate Values",
"trigger": "Client",
"fieldname": "recalculate_values",
"fieldtype": "Button",
"permlevel": 0
},
{
"doctype": "DocField",
"fieldname": "section_break0",
"fieldtype": "Section Break",
"permlevel": 0
},
{
"print_hide": 1,
"description": "You can make a purchase order from multiple Purchase Requests. Select Purchase Requests one by one and click on the button below.",
"no_copy": 1,
"oldfieldtype": "Link",
"doctype": "DocField",
"label": "Select Purchase Request",
"oldfieldname": "indent_no",
"options": "Purchase Request",
"fieldname": "indent_no",
"fieldtype": "Link",
"hidden": 0,
"permlevel": 0
},
{
"print_hide": 1,
"no_copy": 0,
"oldfieldtype": "Button",
"doctype": "DocField",
"label": "Get Items",
"permlevel": 0,
"fieldname": "get_items",
"fieldtype": "Button",
"hidden": 0,
"options": "get_indent_details"
},
{
"print_width": "50%",
"doctype": "DocField",
"width": "50%",
"fieldname": "column_break3",
"fieldtype": "Column Break",
"permlevel": 0
},
{
"print_hide": 1,
"description": "You can make a purchase order from multiple Supplier Quotations. Select Supplier Quotations one by one and click on the button below.",
"no_copy": 1,
"doctype": "DocField",
"label": "Select Supplier Quotation",
"permlevel": 0,
"fieldname": "supplier_quotation",
"fieldtype": "Link",
"options": "Supplier Quotation"
},
{
"print_hide": 1,
"doctype": "DocField",
"label": "Get Items",
"permlevel": 0,
"fieldname": "get_supplier_quotation_items",
"fieldtype": "Button",
"options": "get_supplier_quotation_items"
},
{
"doctype": "DocField",
"label": "Currency & Price List",
"fieldname": "price_list_and_currency",
"fieldtype": "Section Break",
"permlevel": 0
},
{
"doctype": "DocField",
"fieldname": "cb_currency",
"fieldtype": "Column Break",
"permlevel": 0
},
{
"print_hide": 1,
"description": "Supplier's currency",
"no_copy": 0,
"oldfieldtype": "Select",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Currency",
"oldfieldname": "currency",
"permlevel": 0,
"options": "link:Currency",
"fieldname": "currency",
"fieldtype": "Select",
"reqd": 1,
"options": "link:Currency"
"permlevel": 0
},
{
"print_hide": 1,
"description": "Rate at which supplier's currency is converted to company's base currency",
"no_copy": 1,
"oldfieldtype": "Currency",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Conversion Rate",
"label": "Exchange Rate",
"oldfieldname": "conversion_rate",
"default": "1",
"trigger": "Client",
"fieldname": "conversion_rate",
"fieldtype": "Float",
"reqd": 1,
@@ -258,56 +284,43 @@
"permlevel": 0
},
{
"print_hide": 1,
"description": "You can make a purchase order from multiple Purchase Requests. Select Purchase Requests one by one and click on the button below.",
"no_copy": 1,
"oldfieldtype": "Link",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Select Purchase Request",
"oldfieldname": "indent_no",
"fieldname": "cb_price_list",
"fieldtype": "Column Break",
"permlevel": 0
},
{
"print_hide": 1,
"description": "Consider this Price List for fetching rate. (only which have \"For Buying\" as checked)",
"doctype": "DocField",
"label": "Price List",
"permlevel": 0,
"fieldname": "indent_no",
"fieldname": "price_list_name",
"fieldtype": "Link",
"hidden": 0,
"options": "Purchase Request"
"options": "Price List"
},
{
"print_hide": 1,
"no_copy": 0,
"oldfieldtype": "Button",
"depends_on": "price_list_name",
"doctype": "DocField",
"label": "Get Items",
"options": "get_indent_details",
"fieldname": "get_items",
"fieldtype": "Button",
"hidden": 0,
"permlevel": 0
},
{
"print_hide": 1,
"description": "You can make a purchase order from multiple Supplier Quotations. Select Supplier Quotations one by one and click on the button below.",
"no_copy": 1,
"doctype": "DocField",
"label": "Select Supplier Quotation",
"options": "Supplier Quotation",
"fieldname": "supplier_quotation",
"label": "Price List Currency",
"permlevel": 0,
"fieldname": "price_list_currency",
"fieldtype": "Link",
"permlevel": 0
"options": "Currency"
},
{
"print_hide": 1,
"depends_on": "price_list_name",
"doctype": "DocField",
"label": "Get Items",
"options": "get_supplier_quotation_items",
"fieldname": "get_supplier_quotation_items",
"fieldtype": "Button",
"label": "Price List Exchange Rate",
"fieldname": "plc_conversion_rate",
"fieldtype": "Float",
"permlevel": 0
},
{
"print_hide": 0,
"oldfieldtype": "Section Break",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Taxes",
"fieldname": "taxes",
@@ -319,7 +332,6 @@
"description": "If you have created a standard template in Purchase Taxes and Charges Master, select one and click on the button below.",
"no_copy": 1,
"oldfieldtype": "Link",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Purchase Taxes and Charges",
"oldfieldname": "purchase_other_charges",
@@ -333,10 +345,10 @@
"oldfieldtype": "Button",
"doctype": "DocField",
"label": "Get Tax Detail",
"options": "get_purchase_tax_details",
"permlevel": 0,
"fieldname": "get_tax_detail",
"fieldtype": "Button",
"permlevel": 0
"options": "get_purchase_tax_details"
},
{
"no_copy": 0,
@@ -344,17 +356,16 @@
"doctype": "DocField",
"label": "Purchase Taxes and Charges",
"oldfieldname": "purchase_tax_details",
"options": "Purchase Taxes and Charges",
"permlevel": 0,
"fieldname": "purchase_tax_details",
"fieldtype": "Table",
"permlevel": 0
"options": "Purchase Taxes and Charges"
},
{
"print_hide": 1,
"oldfieldtype": "Button",
"doctype": "DocField",
"label": "Calculate Tax",
"trigger": "Client",
"fieldname": "calculate_tax",
"fieldtype": "Button",
"permlevel": 0
@@ -369,112 +380,25 @@
"fieldtype": "HTML",
"permlevel": 0
},
{
"print_hide": 1,
"no_copy": 1,
"oldfieldtype": "Currency",
"doctype": "DocField",
"label": "Total Tax*",
"oldfieldname": "total_tax",
"fieldname": "total_tax",
"fieldtype": "Currency",
"permlevel": 1
},
{
"oldfieldtype": "Section Break",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Totals",
"fieldname": "totals",
"fieldtype": "Section Break",
"permlevel": 0
},
{
"print_hide": 1,
"no_copy": 1,
"oldfieldtype": "Currency",
"doctype": "DocField",
"label": "Grand Total",
"oldfieldname": "grand_total",
"fieldname": "grand_total",
"fieldtype": "Currency",
"permlevel": 1
},
{
"print_hide": 1,
"oldfieldtype": "Currency",
"doctype": "DocField",
"label": "Rounded Total",
"oldfieldname": "rounded_total",
"fieldname": "rounded_total",
"fieldtype": "Currency",
"permlevel": 1
},
{
"print_hide": 1,
"description": "In Words will be visible once you save the Purchase Order.",
"oldfieldtype": "Data",
"colour": "White:FFF",
"doctype": "DocField",
"label": "In Words",
"oldfieldname": "in_words",
"fieldname": "in_words",
"fieldtype": "Data",
"permlevel": 1
},
{
"print_hide": 1,
"no_copy": 0,
"oldfieldtype": "Currency",
"doctype": "DocField",
"label": "Taxes and Charges Added",
"oldfieldname": "other_charges_added",
"fieldname": "other_charges_added",
"label": "Net Total (Import)",
"oldfieldname": "net_total_import",
"fieldname": "net_total_import",
"fieldtype": "Currency",
"permlevel": 1
},
{
"print_hide": 1,
"no_copy": 0,
"oldfieldtype": "Currency",
"doctype": "DocField",
"label": "Taxes and Charges Deducted",
"oldfieldname": "other_charges_deducted",
"fieldname": "other_charges_deducted",
"fieldtype": "Currency",
"permlevel": 1
},
{
"print_hide": 0,
"oldfieldtype": "Column Break",
"doctype": "DocField",
"fieldname": "column_break4",
"fieldtype": "Column Break",
"permlevel": 0
},
{
"print_hide": 1,
"no_copy": 0,
"oldfieldtype": "Currency",
"doctype": "DocField",
"label": "Grand Total (Import)",
"oldfieldname": "grand_total_import",
"fieldname": "grand_total_import",
"fieldtype": "Currency",
"permlevel": 1,
"report_hide": 0
},
{
"print_hide": 1,
"oldfieldtype": "Data",
"colour": "White:FFF",
"doctype": "DocField",
"label": "In Words(Import)",
"oldfieldname": "in_words_import",
"fieldname": "in_words_import",
"fieldtype": "Data",
"permlevel": 1
},
{
"print_hide": 1,
"no_copy": 0,
@@ -499,6 +423,113 @@
"permlevel": 1,
"report_hide": 0
},
{
"print_hide": 1,
"no_copy": 0,
"oldfieldtype": "Currency",
"doctype": "DocField",
"label": "Grand Total (Import)",
"oldfieldname": "grand_total_import",
"fieldname": "grand_total_import",
"fieldtype": "Currency",
"permlevel": 1,
"report_hide": 0
},
{
"print_hide": 1,
"oldfieldtype": "Data",
"doctype": "DocField",
"label": "In Words(Import)",
"oldfieldname": "in_words_import",
"fieldname": "in_words_import",
"fieldtype": "Data",
"permlevel": 1
},
{
"print_hide": 0,
"oldfieldtype": "Column Break",
"doctype": "DocField",
"fieldname": "column_break4",
"fieldtype": "Column Break",
"permlevel": 0
},
{
"print_hide": 1,
"no_copy": 1,
"oldfieldtype": "Currency",
"doctype": "DocField",
"label": "Net Total*",
"oldfieldname": "net_total",
"fieldname": "net_total",
"fieldtype": "Currency",
"reqd": 0,
"permlevel": 1
},
{
"print_hide": 1,
"no_copy": 0,
"oldfieldtype": "Currency",
"doctype": "DocField",
"label": "Taxes and Charges Added",
"oldfieldname": "other_charges_added",
"fieldname": "other_charges_added",
"fieldtype": "Currency",
"permlevel": 1
},
{
"print_hide": 1,
"no_copy": 0,
"oldfieldtype": "Currency",
"doctype": "DocField",
"label": "Taxes and Charges Deducted",
"oldfieldname": "other_charges_deducted",
"fieldname": "other_charges_deducted",
"fieldtype": "Currency",
"permlevel": 1
},
{
"print_hide": 1,
"no_copy": 1,
"oldfieldtype": "Currency",
"doctype": "DocField",
"label": "Total Tax*",
"oldfieldname": "total_tax",
"fieldname": "total_tax",
"fieldtype": "Currency",
"permlevel": 1
},
{
"print_hide": 1,
"no_copy": 1,
"oldfieldtype": "Currency",
"doctype": "DocField",
"label": "Grand Total",
"oldfieldname": "grand_total",
"fieldname": "grand_total",
"fieldtype": "Currency",
"permlevel": 1
},
{
"print_hide": 1,
"oldfieldtype": "Currency",
"doctype": "DocField",
"label": "Rounded Total",
"oldfieldname": "rounded_total",
"fieldname": "rounded_total",
"fieldtype": "Currency",
"permlevel": 1
},
{
"print_hide": 1,
"description": "In Words will be visible once you save the Purchase Order.",
"oldfieldtype": "Data",
"doctype": "DocField",
"label": "In Words",
"oldfieldname": "in_words",
"fieldname": "in_words",
"fieldtype": "Data",
"permlevel": 1
},
{
"oldfieldtype": "Section Break",
"doctype": "DocField",
@@ -507,47 +538,35 @@
"fieldtype": "Section Break",
"permlevel": 0
},
{
"print_hide": 1,
"oldfieldtype": "Select",
"allow_on_submit": 1,
"doctype": "DocField",
"label": "Letter Head",
"oldfieldname": "letter_head",
"options": "link:Letter Head",
"fieldname": "letter_head",
"fieldtype": "Select",
"permlevel": 0
},
{
"print_hide": 1,
"oldfieldtype": "Link",
"doctype": "DocField",
"label": "Select Terms and Conditions",
"oldfieldname": "tc_name",
"options": "Terms and Conditions",
"permlevel": 0,
"fieldname": "tc_name",
"fieldtype": "Link",
"permlevel": 0
"options": "Terms and Conditions"
},
{
"oldfieldtype": "Button",
"doctype": "DocField",
"label": "Get Terms and Conditions",
"options": "get_tc_details",
"permlevel": 0,
"fieldname": "get_terms",
"fieldtype": "Button",
"permlevel": 0
"options": "get_tc_details"
},
{
"print_hide": 1,
"oldfieldtype": "HTML",
"doctype": "DocField",
"label": "Terms and Conditions HTML",
"options": "You can add Terms and Notes that will be printed in the Transaction",
"permlevel": 0,
"fieldname": "terms_html",
"fieldtype": "HTML",
"permlevel": 0
"options": "You can add Terms and Notes that will be printed in the Transaction"
},
{
"oldfieldtype": "Text Editor",
@@ -569,20 +588,26 @@
"print_hide": 1,
"doctype": "DocField",
"label": "Supplier Address",
"options": "Address",
"permlevel": 0,
"fieldname": "supplier_address",
"fieldtype": "Link",
"permlevel": 0,
"options": "Address",
"in_filter": 1
},
{
"doctype": "DocField",
"fieldname": "cb_contact",
"fieldtype": "Column Break",
"permlevel": 0
},
{
"print_hide": 1,
"doctype": "DocField",
"label": "Contact Person",
"options": "Contact",
"permlevel": 0,
"fieldname": "contact_person",
"fieldtype": "Link",
"permlevel": 0,
"options": "Contact",
"in_filter": 1
},
{
@@ -597,7 +622,6 @@
"print_hide": 1,
"no_copy": 1,
"oldfieldtype": "Select",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Status",
"oldfieldname": "status",
@@ -614,10 +638,10 @@
"default": "No",
"doctype": "DocField",
"label": "Is Subcontracted",
"options": "\nYes\nNo",
"permlevel": 0,
"fieldname": "is_subcontracted",
"fieldtype": "Select",
"permlevel": 0
"options": "\nYes\nNo"
},
{
"print_hide": 1,
@@ -631,6 +655,18 @@
"hidden": 1,
"permlevel": 1
},
{
"print_hide": 1,
"oldfieldtype": "Select",
"allow_on_submit": 1,
"doctype": "DocField",
"label": "Letter Head",
"oldfieldname": "letter_head",
"permlevel": 0,
"fieldname": "letter_head",
"fieldtype": "Select",
"options": "link:Letter Head"
},
{
"print_hide": 1,
"no_copy": 1,
@@ -662,7 +698,6 @@
"description": "Select the relevant company name if you have multiple companies",
"no_copy": 0,
"oldfieldtype": "Link",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Company",
"oldfieldname": "company",
@@ -671,8 +706,8 @@
"fieldtype": "Link",
"search_index": 1,
"reqd": 1,
"in_filter": 1,
"options": "Company"
"options": "Company",
"in_filter": 1
},
{
"print_hide": 1,
@@ -693,15 +728,14 @@
"print_hide": 1,
"no_copy": 1,
"oldfieldtype": "Link",
"colour": "White:FFF",
"allow_on_submit": 1,
"doctype": "DocField",
"label": "Select Print Heading",
"oldfieldname": "select_print_heading",
"permlevel": 0,
"options": "Print Heading",
"fieldname": "select_print_heading",
"fieldtype": "Link",
"options": "Print Heading",
"permlevel": 0,
"report_hide": 1
},
{
@@ -715,6 +749,7 @@
},
{
"print_hide": 1,
"print_width": "50%",
"oldfieldtype": "Column Break",
"doctype": "DocField",
"width": "50%",
@@ -727,7 +762,6 @@
"description": "% of materials received against this Purchase Order",
"no_copy": 1,
"oldfieldtype": "Currency",
"colour": "White:FFF",
"doctype": "DocField",
"label": "% Received",
"oldfieldname": "per_received",
@@ -741,7 +775,6 @@
"description": "% of materials billed against this Purchase Order.",
"no_copy": 1,
"oldfieldtype": "Currency",
"colour": "White:FFF",
"doctype": "DocField",
"label": "% Billed",
"oldfieldname": "per_billed",
@@ -754,7 +787,6 @@
"print_hide": 0,
"no_copy": 1,
"oldfieldtype": "Text",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Payment Terms",
"oldfieldname": "payment_terms",
@@ -777,7 +809,6 @@
"print_hide": 1,
"no_copy": 1,
"oldfieldtype": "Data",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Cancel Reason",
"oldfieldname": "cancel_reason",
@@ -791,7 +822,6 @@
"print_hide": 1,
"description": "Required raw materials issued to the supplier for producing a sub - contracted item.",
"oldfieldtype": "Section Break",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Raw Material Details",
"fieldname": "raw_material_details",
@@ -806,10 +836,10 @@
"doctype": "DocField",
"label": "Purchase Order Items Supplied",
"oldfieldname": "po_raw_material_details",
"options": "Purchase Order Item Supplied",
"permlevel": 1,
"fieldname": "po_raw_material_details",
"fieldtype": "Table",
"permlevel": 1
"options": "Purchase Order Item Supplied"
},
{
"print_hide": 1,
@@ -827,26 +857,28 @@
"doctype": "DocPerm",
"submit": 1,
"write": 1,
"report": 1,
"role": "Purchase User",
"cancel": 1,
"permlevel": 0
},
{
"doctype": "DocPerm",
"role": "All",
"permlevel": 1
"permlevel": 1,
"doctype": "DocPerm"
},
{
"doctype": "DocPerm",
"role": "Supplier",
"report": 1,
"permlevel": 0,
"match": "supplier"
},
{
"doctype": "DocPerm",
"write": 1,
"role": "All",
"permlevel": 2
"permlevel": 2,
"doctype": "DocPerm"
},
{
"amend": 0,
@@ -864,6 +896,7 @@
"doctype": "DocPerm",
"submit": 1,
"write": 1,
"report": 1,
"role": "Purchase Manager",
"cancel": 1,
"permlevel": 0
@@ -884,6 +917,7 @@
"doctype": "DocPerm",
"submit": 0,
"write": 0,
"report": 1,
"role": "Material User",
"cancel": 0,
"permlevel": 0

View File

@@ -19,6 +19,31 @@ cur_frm.cscript.fname = "indent_details";
wn.require('app/buying/doctype/purchase_common/purchase_common.js');
wn.require('app/utilities/doctype/sms_control/sms_control.js');
erpnext.buying.PurchaseRequestController = erpnext.buying.BuyingController.extend({
refresh: function(doc) {
this._super();
if(doc.docstatus == 1 && doc.status != 'Stopped'){
cur_frm.add_custom_button("Make Supplier Quotation", cur_frm.cscript.make_supplier_quotation);
if(flt(doc.per_ordered, 2) < 100) {
cur_frm.add_custom_button('Make Purchase Order', cur_frm.cscript['Make Purchase Order']);
cur_frm.add_custom_button('Stop Purchase Request', cur_frm.cscript['Stop Purchase Request']);
}
cur_frm.add_custom_button('Send SMS', cur_frm.cscript.send_sms);
}
if(doc.docstatus == 1 && doc.status == 'Stopped')
cur_frm.add_custom_button('Unstop Purchase Request', cur_frm.cscript['Unstop Purchase Request'])
}
});
var new_cscript = new erpnext.buying.PurchaseRequestController({frm: cur_frm});
// for backward compatibility: combine new and previous states
$.extend(cur_frm.cscript, new_cscript);
//========================== On Load =================================================
cur_frm.cscript.onload = function(doc, cdt, cdn) {
@@ -43,26 +68,6 @@ cur_frm.cscript.get_item_defaults = function(doc) {
}
}
//======================= Refresh =====================================
cur_frm.cscript.refresh = function(doc, cdt, cdn) {
cur_frm.clear_custom_buttons();
erpnext.hide_naming_series();
if(doc.docstatus == 1 && doc.status != 'Stopped'){
cur_frm.add_custom_button("Make Supplier Quotation", cur_frm.cscript.make_supplier_quotation);
if(flt(doc.per_ordered, 2) < 100) {
cur_frm.add_custom_button('Make Purchase Order', cur_frm.cscript['Make Purchase Order']);
cur_frm.add_custom_button('Stop Purchase Request', cur_frm.cscript['Stop Purchase Request']);
}
cur_frm.add_custom_button('Send SMS', cur_frm.cscript.send_sms);
}
if(doc.docstatus == 1 && doc.status == 'Stopped')
cur_frm.add_custom_button('Unstop Purchase Request', cur_frm.cscript['Unstop Purchase Request'])
}
//======================= transaction date =============================
cur_frm.cscript.transaction_date = function(doc,cdt,cdn){
if(doc.__islocal){

View File

@@ -17,18 +17,16 @@
from __future__ import unicode_literals
import webnotes
from webnotes.utils import cstr, date_diff, flt, get_defaults, now
from webnotes.model import db_exists
from webnotes.model.doc import make_autoname
from webnotes.model.wrapper import getlist, copy_doclist
from webnotes.utils import cstr, flt, get_defaults
from webnotes.model.wrapper import getlist
from webnotes.model.code import get_obj
from webnotes import msgprint
sql = webnotes.conn.sql
class DocType:
from controllers.buying_controller import BuyingController
class DocType(BuyingController):
def __init__(self, doc, doclist=[]):
self.doc = doc
self.doclist = doclist
@@ -36,12 +34,6 @@ class DocType:
self.tname = 'Purchase Request Item'
self.fname = 'indent_details'
# Autoname
# ---------
def autoname(self):
self.doc.name = make_autoname(self.doc.naming_series+'.#####')
def get_default_schedule_date(self):
get_obj(dt = 'Purchase Common').get_default_schedule_date(self)
@@ -102,25 +94,6 @@ class DocType:
def validate_fiscal_year(self):
get_obj(dt = 'Purchase Common').validate_fiscal_year(self.doc.fiscal_year,self.doc.transaction_date,'Purchase Request Date')
# get item details
# ---------------------------------
def get_item_details(self, arg =''):
if arg:
return get_obj(dt='Purchase Common').get_item_details(self,arg)
else:
obj = get_obj('Purchase Common')
for doc in self.doclist:
if doc.fields.get('item_code'):
temp = {
'item_code': doc.fields.get('item_code'),
'warehouse': doc.fields.get('warehouse')
}
ret = obj.get_item_details(self, json.dumps(temp))
for r in ret:
if not doc.fields.get(r):
doc.fields[r] = ret[r]
# GET TERMS & CONDITIONS
#-----------------------------
def get_tc_details(self):
@@ -138,6 +111,8 @@ class DocType:
# Validate
# ---------------------
def validate(self):
super(DocType, self).validate()
self.validate_schedule_date()
self.validate_fiscal_year()

View File

@@ -2,13 +2,14 @@
{
"owner": "Administrator",
"docstatus": 0,
"creation": "2012-07-03 13:29:58",
"creation": "2012-12-03 17:56:31",
"modified_by": "Administrator",
"modified": "2012-12-03 17:10:41"
"modified": "2013-01-15 15:34:47"
},
{
"is_submittable": 1,
"autoname": "naming_series:",
"allow_attach": 1,
"is_submittable": 1,
"allow_print": 0,
"search_fields": "status,transaction_date,sales_order_no",
"module": "Buying",
@@ -28,6 +29,7 @@
"parent": "Purchase Request",
"read": 1,
"doctype": "DocPerm",
"report": 1,
"parenttype": "DocType",
"parentfield": "permissions"
},
@@ -40,7 +42,6 @@
"description": "To manage multiple series please go to Setup > Manage Series",
"no_copy": 1,
"oldfieldtype": "Select",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Series",
"oldfieldname": "naming_series",
@@ -52,14 +53,13 @@
},
{
"description": "The date at which current entry is made in system.",
"print_width": "100px",
"no_copy": 1,
"oldfieldtype": "Date",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Transaction Date",
"oldfieldname": "transaction_date",
"width": "100px",
"trigger": "Client",
"fieldname": "transaction_date",
"fieldtype": "Date",
"search_index": 1,
@@ -69,7 +69,6 @@
},
{
"oldfieldtype": "Section Break",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Items",
"fieldname": "items",
@@ -79,7 +78,6 @@
{
"no_copy": 0,
"oldfieldtype": "Table",
"colour": "White:FFF",
"allow_on_submit": 1,
"doctype": "DocField",
"label": "Purchase Requisition Details",
@@ -97,6 +95,7 @@
"permlevel": 0
},
{
"print_width": "50%",
"doctype": "DocField",
"width": "50%",
"fieldname": "column_break4",
@@ -106,9 +105,9 @@
{
"permlevel": 0,
"description": "One or multiple Sales Order no which generated this Purchase Requisition",
"print_width": "100px",
"no_copy": 1,
"oldfieldtype": "Data",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Sales Order No",
"oldfieldname": "sales_order_no",
@@ -118,6 +117,7 @@
"options": "Sales Order"
},
{
"print_width": "50%",
"doctype": "DocField",
"width": "50%",
"fieldname": "column_break5",
@@ -136,7 +136,6 @@
"description": "Filing in Additional Information about the Purchase Requisition will help you analyze your data better.",
"default": "Give additional details about the indent.",
"oldfieldtype": "Section Break",
"colour": "White:FFF",
"doctype": "DocField",
"label": "More Info",
"fieldname": "more_info",
@@ -144,6 +143,7 @@
"permlevel": 0
},
{
"print_width": "50%",
"oldfieldtype": "Column Break",
"doctype": "DocField",
"width": "50%",
@@ -154,9 +154,9 @@
{
"print_hide": 1,
"description": "Select the relevant company name if you have multiple companies",
"print_width": "150px",
"permlevel": 0,
"oldfieldtype": "Link",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Company",
"oldfieldname": "company",
@@ -170,9 +170,9 @@
},
{
"print_hide": 1,
"print_width": "150px",
"permlevel": 0,
"oldfieldtype": "Select",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Fiscal Year",
"oldfieldname": "fiscal_year",
@@ -186,9 +186,9 @@
},
{
"description": "Name of the entity who has requested for the Purchase Requisition",
"print_width": "100px",
"no_copy": 1,
"oldfieldtype": "Data",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Requested By",
"oldfieldname": "requested_by",
@@ -202,7 +202,6 @@
"description": "After cancelling the Purchase Requisition, a dialog box will ask you reason for cancellation which will be reflected in this field",
"no_copy": 1,
"oldfieldtype": "Data",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Cancel Reason",
"oldfieldname": "cancel_reason",
@@ -211,6 +210,7 @@
"permlevel": 1
},
{
"print_width": "50%",
"oldfieldtype": "Column Break",
"doctype": "DocField",
"width": "50%",
@@ -220,8 +220,8 @@
},
{
"print_hide": 1,
"oldfieldtype": "Select",
"allow_on_submit": 1,
"oldfieldtype": "Select",
"doctype": "DocField",
"label": "Letter Head",
"oldfieldname": "letter_head",
@@ -233,9 +233,9 @@
{
"print_hide": 1,
"permlevel": 1,
"print_width": "100px",
"no_copy": 1,
"oldfieldtype": "Select",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Status",
"oldfieldname": "status",
@@ -252,7 +252,6 @@
"description": "% of materials ordered against this Purchase Requisition",
"no_copy": 1,
"oldfieldtype": "Currency",
"colour": "White:FFF",
"doctype": "DocField",
"label": "% Ordered",
"oldfieldname": "per_ordered",
@@ -262,6 +261,7 @@
},
{
"print_hide": 1,
"print_width": "150px",
"no_copy": 1,
"oldfieldtype": "Data",
"doctype": "DocField",
@@ -275,6 +275,7 @@
{
"print_hide": 1,
"description": "The date at which current entry is corrected in the system.",
"print_width": "100px",
"no_copy": 1,
"oldfieldtype": "Date",
"doctype": "DocField",
@@ -287,6 +288,7 @@
},
{
"print_hide": 0,
"print_width": "150px",
"no_copy": 1,
"oldfieldtype": "Small Text",
"doctype": "DocField",
@@ -346,22 +348,6 @@
"hidden": 1,
"permlevel": 0
},
{
"amend": 1,
"create": 1,
"doctype": "DocPerm",
"submit": 1,
"write": 1,
"role": "Purchase User",
"cancel": 1,
"permlevel": 0,
"match": ""
},
{
"doctype": "DocPerm",
"role": "Purchase User",
"permlevel": 1
},
{
"amend": 0,
"create": 0,
@@ -421,5 +407,24 @@
"role": "Material User",
"cancel": 1,
"permlevel": 0
},
{
"amend": 1,
"create": 1,
"doctype": "DocPerm",
"submit": 1,
"write": 1,
"role": "Purchase User",
"cancel": 1,
"permlevel": 0
},
{
"amend": 0,
"create": 0,
"doctype": "DocPerm",
"submit": 0,
"role": "Purchase User",
"cancel": 0,
"permlevel": 1
}
]

View File

@@ -9,15 +9,15 @@
{
"section_style": "Simple",
"is_submittable": 1,
"doctype": "DocType",
"search_fields": "item_code, report_date, purchase_receipt_no, delivery_note_no",
"module": "Buying",
"_last_update": "1317365120",
"server_code_error": " ",
"print_outline": "Yes",
"autoname": "QAI/.######",
"name": "__common__",
"colour": "White:FFF",
"doctype": "DocType",
"_last_update": "1317365120",
"show_in_menu": 0,
"version": 38
},
@@ -51,6 +51,7 @@
"doctype": "DocPerm",
"submit": 1,
"write": 1,
"report": 1,
"cancel": 1,
"permlevel": 0
},
@@ -75,11 +76,11 @@
"no_copy": 1,
"doctype": "DocField",
"label": "Naming Series",
"permlevel": 0,
"options": "\nQAI/11-12/",
"fieldname": "naming_series",
"fieldtype": "Select",
"reqd": 1,
"options": "\nQAI/11-12/"
"permlevel": 0
},
{
"oldfieldtype": "Select",
@@ -87,12 +88,12 @@
"doctype": "DocField",
"label": "Inspection Type",
"oldfieldname": "inspection_type",
"permlevel": 0,
"trigger": "Client",
"fieldname": "inspection_type",
"fieldtype": "Select",
"reqd": 1,
"options": "\nIncoming\nOutgoing\nIn Process",
"permlevel": 0,
"in_filter": 1
},
{
@@ -161,21 +162,21 @@
"doctype": "DocField",
"label": "Item Serial No",
"oldfieldname": "item_serial_no",
"permlevel": 0,
"options": "Serial No",
"fieldname": "item_serial_no",
"fieldtype": "Link",
"hidden": 0,
"options": "Serial No"
"permlevel": 0
},
{
"oldfieldtype": "Link",
"doctype": "DocField",
"label": "Batch No",
"oldfieldname": "batch_no",
"permlevel": 0,
"options": "Batch",
"fieldname": "batch_no",
"fieldtype": "Link",
"options": "Batch"
"permlevel": 0
},
{
"oldfieldtype": "Link",
@@ -262,10 +263,10 @@
"oldfieldtype": "Section Break",
"doctype": "DocField",
"label": "Specification Details",
"permlevel": 0,
"options": "Simple",
"fieldname": "specification_details",
"fieldtype": "Section Break",
"options": "Simple"
"permlevel": 0
},
{
"doctype": "DocField",
@@ -280,9 +281,9 @@
"doctype": "DocField",
"label": "Quality Inspection Readings",
"oldfieldname": "qa_specification_details",
"permlevel": 0,
"options": "Quality Inspection Reading",
"fieldname": "qa_specification_details",
"fieldtype": "Table",
"options": "Quality Inspection Reading"
"permlevel": 0
}
]

View File

@@ -62,11 +62,6 @@ class DocType(TransactionBase):
if not self.doc.naming_series:
self.doc.naming_series = ''
# create address
addr_flds = [self.doc.address_line1, self.doc.address_line2, self.doc.city, self.doc.state, self.doc.country, self.doc.pincode]
address_line = "\n".join(filter(lambda x : (x!='' and x!=None),addr_flds))
webnotes.conn.set(self.doc,'address', address_line)
# create account head
self.create_account_head()
@@ -124,7 +119,16 @@ class DocType(TransactionBase):
if not sql("select name from tabAccount where name=%s", (self.doc.name + " - " + abbr)):
parent_account = self.get_parent_account(abbr)
arg = {'account_name':self.doc.name,'parent_account': parent_account, 'group_or_ledger':'Ledger', 'company':self.doc.company,'account_type':'','tax_rate':'0','master_type':'Supplier','master_name':self.doc.name,'address':self.doc.address}
arg = {
'account_name': self.doc.name,
'parent_account': parent_account,
'group_or_ledger':'Ledger',
'company': self.doc.company,
'account_type': '',
'tax_rate': '0',
'master_type': 'Supplier',
'master_name': self.doc.name,
}
# create
ac = get_obj('GL Control').add_ac(cstr(arg))
msgprint("Created Account Head: "+ac)

View File

@@ -7,13 +7,13 @@
"modified": "2012-12-27 14:02:18"
},
{
"autoname": "naming_series:",
"document_type": "Master",
"description": "Supplier of Goods or Services.",
"autoname": "naming_series:",
"allow_rename": 1,
"search_fields": "supplier_name,supplier_type",
"module": "Buying",
"doctype": "DocType",
"document_type": "Master",
"search_fields": "supplier_name,supplier_type",
"name": "__common__"
},
{
@@ -60,11 +60,11 @@
"doctype": "DocField",
"label": "Supplier Type",
"oldfieldname": "supplier_type",
"options": "Supplier Type",
"permlevel": 0,
"fieldname": "supplier_type",
"fieldtype": "Link",
"reqd": 1,
"permlevel": 0
"options": "Supplier Type"
},
{
"doctype": "DocField",
@@ -79,10 +79,10 @@
"doctype": "DocField",
"label": "Series",
"oldfieldname": "naming_series",
"options": "\nSUPP\nSUPP/10-11/",
"permlevel": 0,
"fieldname": "naming_series",
"fieldtype": "Select",
"permlevel": 0
"options": "\nSUPP\nSUPP/10-11/"
},
{
"oldfieldtype": "Column Break",
@@ -96,10 +96,10 @@
"depends_on": "eval:doc.__islocal",
"doctype": "DocField",
"label": "Address Desc",
"options": "<em>Addresses will appear only when you save the supplier</em>",
"permlevel": 0,
"fieldname": "address_desc",
"fieldtype": "HTML",
"permlevel": 0
"options": "<em>Addresses will appear only when you save the supplier</em>"
},
{
"doctype": "DocField",
@@ -119,10 +119,10 @@
"depends_on": "eval:doc.__islocal",
"doctype": "DocField",
"label": "Contact Desc",
"options": "<em>Contact Details will appear only when you save the supplier</em>",
"permlevel": 0,
"fieldname": "contact_desc",
"fieldtype": "HTML",
"permlevel": 0
"options": "<em>Contact Details will appear only when you save the supplier</em>"
},
{
"doctype": "DocField",
@@ -158,23 +158,23 @@
"doctype": "DocField",
"label": "Company",
"oldfieldname": "company",
"permlevel": 0,
"options": "Company",
"fieldname": "company",
"fieldtype": "Link",
"search_index": 0,
"reqd": 1,
"in_filter": 1,
"options": "Company"
"permlevel": 0,
"in_filter": 1
},
{
"description": "This currency will get fetched in Purchase transactions of this supplier",
"no_copy": 1,
"doctype": "DocField",
"label": "Default Currency",
"options": "link:Currency",
"permlevel": 0,
"fieldname": "default_currency",
"fieldtype": "Select",
"permlevel": 0
"options": "link:Currency"
},
{
"description": "Statutory info and other general information about your Supplier",
@@ -225,14 +225,15 @@
"doctype": "DocPerm",
"submit": 0,
"write": 0,
"report": 1,
"role": "Purchase Manager",
"cancel": 0,
"permlevel": 0
},
{
"doctype": "DocPerm",
"role": "Purchase Master Manager",
"permlevel": 1
"permlevel": 1,
"doctype": "DocPerm"
},
{
"amend": 0,
@@ -240,6 +241,7 @@
"doctype": "DocPerm",
"submit": 0,
"write": 1,
"report": 1,
"role": "Purchase Master Manager",
"cancel": 1,
"permlevel": 0

View File

@@ -23,6 +23,24 @@ 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');
erpnext.buying.SupplierQuotationController = erpnext.buying.BuyingController.extend({
refresh: function() {
this._super();
cur_frm.cscript.load_taxes(this.frm.doc);
if (this.frm.doc.docstatus === 1) {
cur_frm.add_custom_button("Make Purchase Order", cur_frm.cscript.make_purchase_order);
}
}
});
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, {
@@ -35,19 +53,6 @@ cur_frm.cscript.onload = function(doc, dt, dn) {
});
}
cur_frm.cscript.refresh = function(doc, dt, dn) {
erpnext.hide_naming_series();
cur_frm.cscript.dynamic_label(doc, dt, dn);
cur_frm.cscript.load_taxes(doc, dt, dn);
cur_frm.cscript.toggle_contact_section(doc);
cur_frm.clear_custom_buttons();
if (doc.docstatus === 1) {
cur_frm.add_custom_button("Make Purchase Order", cur_frm.cscript.make_purchase_order);
}
}
cur_frm.cscript.make_purchase_order = function() {
var new_po_name = wn.model.make_new_doc_and_get_name("Purchase Order");
$c("dt_map", {

View File

@@ -17,19 +17,17 @@
from __future__ import unicode_literals
import webnotes
from webnotes.model.code import get_obj
from utilities.transaction_base import TransactionBase
from setup.utils import get_company_currency
class DocType(TransactionBase):
from controllers.buying_controller import BuyingController
class DocType(BuyingController):
def __init__(self, doc, doclist=None):
self.doc, self.doclist = doc, doclist or []
self.tname, self.fname = "Supplier Quotation Item", "quotation_items"
def autoname(self):
"""autoname based on naming series value"""
from webnotes.model.doc import make_autoname
self.doc.name = make_autoname(self.doc.naming_series + ".#####")
def validate(self):
super(DocType, self).validate()
if not self.doc.status:
self.doc.status = "Draft"
@@ -53,22 +51,6 @@ class DocType(TransactionBase):
def on_trash(self):
pass
def get_item_details(self, args=None):
if args:
return get_obj(dt='Purchase Common').get_item_details(self, args)
else:
obj = get_obj('Purchase Common')
for doc in self.doclist:
if doc.fields.get('item_code'):
temp = {
'item_code': doc.fields.get('item_code'),
'warehouse': doc.fields.get('warehouse')
}
ret = obj.get_item_details(self, json.dumps(temp))
for r in ret:
if not doc.fields.get(r):
doc.fields[r] = ret[r]
def get_indent_details(self):
if self.doc.indent_no:
mapper = get_obj("DocType Mapper", "Purchase Request-Supplier Quotation")
@@ -96,12 +78,11 @@ class DocType(TransactionBase):
pc = get_obj('Purchase Common')
pc.validate_mandatory(self)
pc.validate_for_items(self)
pc.validate_conversion_rate(self)
pc.get_prevdoc_date(self)
pc.validate_reference_value(self)
def set_in_words(self):
pc = get_obj('Purchase Common')
company_currency = TransactionBase().get_company_currency(self.doc.company)
company_currency = get_company_currency(self.doc.company)
self.doc.in_words = pc.get_total_in_words(company_currency, self.doc.grand_total)
self.doc.in_words_import = pc.get_total_in_words(self.doc.currency, self.doc.grand_total_import)

View File

@@ -2,18 +2,19 @@
{
"owner": "Administrator",
"docstatus": 0,
"creation": "2012-08-06 11:15:46",
"creation": "2013-01-18 12:47:01",
"modified_by": "Administrator",
"modified": "2012-12-10 18:30:00"
"modified": "2013-01-18 13:25:50"
},
{
"document_type": "Transaction",
"is_submittable": 1,
"allow_attach": 1,
"search_fields": "status, transaction_date, supplier,grand_total",
"autoname": "naming_series:",
"module": "Buying",
"doctype": "DocType",
"read_only_onload": 1,
"document_type": "Transaction",
"search_fields": "status, transaction_date, supplier,grand_total",
"name": "__common__"
},
{
@@ -35,45 +36,34 @@
"name": "Supplier Quotation",
"doctype": "DocType"
},
{
"oldfieldtype": "Column Break",
"doctype": "DocField",
"width": "50%",
"fieldname": "column_break0",
"fieldtype": "Column Break",
"permlevel": 0
},
{
"print_hide": 1,
"description": "To manage multiple series please go to Setup > Manage Series",
"no_copy": 1,
"oldfieldtype": "Select",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Series",
"oldfieldname": "naming_series",
"permlevel": 0,
"options": "SQTN",
"fieldname": "naming_series",
"fieldtype": "Select",
"reqd": 1,
"options": "SQTN"
"permlevel": 0
},
{
"print_hide": 1,
"description": "Supplier (vendor) name as entered in supplier master",
"oldfieldtype": "Link",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Supplier",
"oldfieldname": "supplier",
"permlevel": 0,
"trigger": "Client",
"fieldname": "supplier",
"fieldtype": "Link",
"search_index": 1,
"reqd": 1,
"in_filter": 1,
"options": "Supplier"
"options": "Supplier",
"in_filter": 1
},
{
"doctype": "DocField",
@@ -118,6 +108,7 @@
},
{
"print_hide": 0,
"print_width": "50%",
"oldfieldtype": "Column Break",
"doctype": "DocField",
"width": "50%",
@@ -128,21 +119,18 @@
{
"description": "The date at which current entry is made in system.",
"oldfieldtype": "Date",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Quotation Date",
"oldfieldname": "transaction_date",
"trigger": "Client",
"fieldname": "transaction_date",
"fieldtype": "Date",
"search_index": 1,
"reqd": 1,
"in_filter": 1,
"permlevel": 0
"permlevel": 0,
"in_filter": 1
},
{
"oldfieldtype": "Section Break",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Items",
"fieldname": "items",
@@ -156,62 +144,62 @@
"doctype": "DocField",
"label": "Quotation Items",
"oldfieldname": "po_details",
"options": "Supplier Quotation Item",
"permlevel": 0,
"fieldname": "quotation_items",
"fieldtype": "Table",
"permlevel": 0
"options": "Supplier Quotation Item"
},
{
"doctype": "DocField",
"options": "Simple",
"permlevel": 0,
"fieldname": "section_break0",
"fieldtype": "Section Break",
"permlevel": 0
},
{
"doctype": "DocField",
"width": "50%",
"fieldname": "column_break2",
"fieldtype": "Column Break",
"permlevel": 0
},
{
"print_hide": 1,
"no_copy": 1,
"oldfieldtype": "Currency",
"doctype": "DocField",
"label": "Net Total*",
"oldfieldname": "net_total",
"fieldname": "net_total",
"fieldtype": "Currency",
"reqd": 0,
"permlevel": 1
},
{
"print_hide": 1,
"no_copy": 0,
"oldfieldtype": "Currency",
"doctype": "DocField",
"label": "Net Total (Import)",
"oldfieldname": "net_total_import",
"fieldname": "net_total_import",
"fieldtype": "Currency",
"permlevel": 1
"options": "Simple"
},
{
"oldfieldtype": "Button",
"doctype": "DocField",
"label": "Re-Calculate Values",
"trigger": "Client",
"fieldname": "recalculate_values",
"fieldtype": "Button",
"permlevel": 0
},
{
"doctype": "DocField",
"width": "50%",
"fieldname": "column_break3",
"fieldtype": "Column Break",
"permlevel": 0,
"fieldname": "section_break_14",
"fieldtype": "Section Break",
"options": "Simple"
},
{
"print_hide": 1,
"description": "You can make a purchase order from multiple Purchase Requests. Select Purchase Requests one by one and click on the button below.",
"no_copy": 1,
"oldfieldtype": "Link",
"doctype": "DocField",
"label": "Select Purchase Request",
"oldfieldname": "indent_no",
"options": "Purchase Request",
"fieldname": "indent_no",
"fieldtype": "Link",
"hidden": 0,
"permlevel": 0
},
{
"oldfieldtype": "Button",
"doctype": "DocField",
"label": "Get Items",
"permlevel": 0,
"fieldname": "get_items",
"fieldtype": "Button",
"hidden": 0,
"options": "get_indent_details"
},
{
"doctype": "DocField",
"label": "Currency & Price List",
"fieldname": "currency_price_list",
"fieldtype": "Section Break",
"permlevel": 0
},
{
@@ -219,27 +207,24 @@
"description": "Supplier's currency",
"no_copy": 0,
"oldfieldtype": "Select",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Currency",
"oldfieldname": "currency",
"permlevel": 0,
"options": "link:Currency",
"fieldname": "currency",
"fieldtype": "Select",
"reqd": 1,
"options": "link:Currency"
"permlevel": 0
},
{
"print_hide": 1,
"description": "Rate at which supplier's currency is converted to company's base currency",
"no_copy": 1,
"oldfieldtype": "Currency",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Conversion Rate",
"label": "Exchange Rate",
"oldfieldname": "conversion_rate",
"default": "1",
"trigger": "Client",
"fieldname": "conversion_rate",
"fieldtype": "Currency",
"reqd": 1,
@@ -247,33 +232,44 @@
"permlevel": 0
},
{
"print_hide": 1,
"description": "You can make a purchase order from multiple Purchase Requests. Select Purchase Requests one by one and click on the button below.",
"no_copy": 1,
"oldfieldtype": "Link",
"colour": "White:FFF",
"print_width": "50%",
"doctype": "DocField",
"label": "Select Purchase Request",
"oldfieldname": "indent_no",
"permlevel": 0,
"fieldname": "indent_no",
"fieldtype": "Link",
"hidden": 0,
"options": "Purchase Request"
"width": "50%",
"fieldname": "cb_price_list",
"fieldtype": "Column Break",
"permlevel": 0
},
{
"oldfieldtype": "Button",
"print_hide": 1,
"description": "Consider this Price List for fetching rate. (only which have \"For Buying\" as checked)",
"doctype": "DocField",
"label": "Get Items",
"options": "get_indent_details",
"fieldname": "get_items",
"fieldtype": "Button",
"hidden": 0,
"label": "Price List",
"permlevel": 0,
"fieldname": "price_list_name",
"fieldtype": "Link",
"options": "Price List"
},
{
"print_hide": 1,
"depends_on": "price_list_name",
"doctype": "DocField",
"label": "Price List Currency",
"permlevel": 0,
"fieldname": "price_list_currency",
"fieldtype": "Link",
"options": "Currency"
},
{
"print_hide": 1,
"depends_on": "price_list_name",
"doctype": "DocField",
"label": "Price List Exchange Rate",
"fieldname": "plc_conversion_rate",
"fieldtype": "Float",
"permlevel": 0
},
{
"oldfieldtype": "Section Break",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Taxes",
"fieldname": "taxes",
@@ -285,7 +281,6 @@
"description": "If you have created a standard template in Purchase Taxes and Charges Master, select one and click on the button below.",
"no_copy": 1,
"oldfieldtype": "Link",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Purchase Taxes and Charges",
"oldfieldname": "purchase_other_charges",
@@ -299,10 +294,10 @@
"oldfieldtype": "Button",
"doctype": "DocField",
"label": "Get Tax Detail",
"options": "get_purchase_tax_details",
"permlevel": 0,
"fieldname": "get_tax_detail",
"fieldtype": "Button",
"permlevel": 0
"options": "get_purchase_tax_details"
},
{
"no_copy": 0,
@@ -310,17 +305,16 @@
"doctype": "DocField",
"label": "Purchase Taxes and Charges",
"oldfieldname": "purchase_tax_details",
"options": "Purchase Taxes and Charges",
"permlevel": 0,
"fieldname": "purchase_tax_details",
"fieldtype": "Table",
"permlevel": 0
"options": "Purchase Taxes and Charges"
},
{
"print_hide": 1,
"oldfieldtype": "Button",
"doctype": "DocField",
"label": "Calculate Tax",
"trigger": "Client",
"fieldname": "calculate_tax",
"fieldtype": "Button",
"permlevel": 0
@@ -335,112 +329,25 @@
"fieldtype": "HTML",
"permlevel": 0
},
{
"print_hide": 1,
"no_copy": 1,
"oldfieldtype": "Currency",
"doctype": "DocField",
"label": "Total Tax*",
"oldfieldname": "total_tax",
"fieldname": "total_tax",
"fieldtype": "Currency",
"permlevel": 1
},
{
"oldfieldtype": "Section Break",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Totals",
"fieldname": "totals",
"fieldtype": "Section Break",
"permlevel": 0
},
{
"print_hide": 1,
"no_copy": 1,
"oldfieldtype": "Currency",
"doctype": "DocField",
"label": "Grand Total",
"oldfieldname": "grand_total",
"fieldname": "grand_total",
"fieldtype": "Currency",
"permlevel": 1
},
{
"print_hide": 1,
"oldfieldtype": "Currency",
"doctype": "DocField",
"label": "Rounded Total",
"oldfieldname": "rounded_total",
"fieldname": "rounded_total",
"fieldtype": "Currency",
"permlevel": 1
},
{
"print_hide": 1,
"description": "In Words will be visible once you save the Purchase Order.",
"oldfieldtype": "Data",
"colour": "White:FFF",
"doctype": "DocField",
"label": "In Words",
"oldfieldname": "in_words",
"fieldname": "in_words",
"fieldtype": "Data",
"permlevel": 1
},
{
"print_hide": 1,
"no_copy": 0,
"oldfieldtype": "Currency",
"doctype": "DocField",
"label": "Taxes and Charges Added",
"oldfieldname": "other_charges_added",
"fieldname": "other_charges_added",
"label": "Net Total (Import)",
"oldfieldname": "net_total_import",
"fieldname": "net_total_import",
"fieldtype": "Currency",
"permlevel": 1
},
{
"print_hide": 1,
"no_copy": 0,
"oldfieldtype": "Currency",
"doctype": "DocField",
"label": "Taxes and Charges Deducted",
"oldfieldname": "other_charges_deducted",
"fieldname": "other_charges_deducted",
"fieldtype": "Currency",
"permlevel": 1
},
{
"print_hide": 0,
"oldfieldtype": "Column Break",
"doctype": "DocField",
"fieldname": "column_break4",
"fieldtype": "Column Break",
"permlevel": 0
},
{
"print_hide": 1,
"no_copy": 0,
"oldfieldtype": "Currency",
"doctype": "DocField",
"label": "Grand Total (Import)",
"oldfieldname": "grand_total_import",
"fieldname": "grand_total_import",
"fieldtype": "Currency",
"permlevel": 1,
"report_hide": 0
},
{
"print_hide": 1,
"oldfieldtype": "Data",
"colour": "White:FFF",
"doctype": "DocField",
"label": "In Words(Import)",
"oldfieldname": "in_words_import",
"fieldname": "in_words_import",
"fieldtype": "Data",
"permlevel": 1
},
{
"print_hide": 1,
"no_copy": 0,
@@ -465,6 +372,113 @@
"permlevel": 1,
"report_hide": 0
},
{
"print_hide": 1,
"no_copy": 0,
"oldfieldtype": "Currency",
"doctype": "DocField",
"label": "Grand Total (Import)",
"oldfieldname": "grand_total_import",
"fieldname": "grand_total_import",
"fieldtype": "Currency",
"permlevel": 1,
"report_hide": 0
},
{
"print_hide": 1,
"oldfieldtype": "Data",
"doctype": "DocField",
"label": "In Words(Import)",
"oldfieldname": "in_words_import",
"fieldname": "in_words_import",
"fieldtype": "Data",
"permlevel": 1
},
{
"print_hide": 0,
"oldfieldtype": "Column Break",
"doctype": "DocField",
"fieldname": "column_break4",
"fieldtype": "Column Break",
"permlevel": 0
},
{
"print_hide": 1,
"no_copy": 1,
"oldfieldtype": "Currency",
"doctype": "DocField",
"label": "Net Total*",
"oldfieldname": "net_total",
"fieldname": "net_total",
"fieldtype": "Currency",
"reqd": 0,
"permlevel": 1
},
{
"print_hide": 1,
"no_copy": 0,
"oldfieldtype": "Currency",
"doctype": "DocField",
"label": "Taxes and Charges Added",
"oldfieldname": "other_charges_added",
"fieldname": "other_charges_added",
"fieldtype": "Currency",
"permlevel": 1
},
{
"print_hide": 1,
"no_copy": 0,
"oldfieldtype": "Currency",
"doctype": "DocField",
"label": "Taxes and Charges Deducted",
"oldfieldname": "other_charges_deducted",
"fieldname": "other_charges_deducted",
"fieldtype": "Currency",
"permlevel": 1
},
{
"print_hide": 1,
"no_copy": 1,
"oldfieldtype": "Currency",
"doctype": "DocField",
"label": "Total Tax*",
"oldfieldname": "total_tax",
"fieldname": "total_tax",
"fieldtype": "Currency",
"permlevel": 1
},
{
"print_hide": 1,
"no_copy": 1,
"oldfieldtype": "Currency",
"doctype": "DocField",
"label": "Grand Total",
"oldfieldname": "grand_total",
"fieldname": "grand_total",
"fieldtype": "Currency",
"permlevel": 1
},
{
"print_hide": 1,
"oldfieldtype": "Currency",
"doctype": "DocField",
"label": "Rounded Total",
"oldfieldname": "rounded_total",
"fieldname": "rounded_total",
"fieldtype": "Currency",
"permlevel": 1
},
{
"print_hide": 1,
"description": "In Words will be visible once you save the Purchase Order.",
"oldfieldtype": "Data",
"doctype": "DocField",
"label": "In Words",
"oldfieldname": "in_words",
"fieldname": "in_words",
"fieldtype": "Data",
"permlevel": 1
},
{
"oldfieldtype": "Section Break",
"doctype": "DocField",
@@ -475,15 +489,15 @@
},
{
"print_hide": 1,
"allow_on_submit": 1,
"oldfieldtype": "Select",
"allow_on_submit": 1,
"doctype": "DocField",
"label": "Letter Head",
"oldfieldname": "letter_head",
"options": "link:Letter Head",
"permlevel": 0,
"fieldname": "letter_head",
"fieldtype": "Select",
"permlevel": 0
"options": "link:Letter Head"
},
{
"print_hide": 1,
@@ -491,29 +505,29 @@
"doctype": "DocField",
"label": "Select Terms and Conditions",
"oldfieldname": "tc_name",
"options": "Terms and Conditions",
"permlevel": 0,
"fieldname": "tc_name",
"fieldtype": "Link",
"permlevel": 0
"options": "Terms and Conditions"
},
{
"oldfieldtype": "Button",
"doctype": "DocField",
"label": "Get Terms and Conditions",
"options": "get_tc_details",
"permlevel": 0,
"fieldname": "get_terms",
"fieldtype": "Button",
"permlevel": 0
"options": "get_tc_details"
},
{
"print_hide": 1,
"oldfieldtype": "HTML",
"doctype": "DocField",
"label": "Terms and Conditions HTML",
"options": "You can add Terms and Notes that will be printed in the Transaction",
"permlevel": 0,
"fieldname": "terms_html",
"fieldtype": "HTML",
"permlevel": 0
"options": "You can add Terms and Notes that will be printed in the Transaction"
},
{
"oldfieldtype": "Text Editor",
@@ -535,20 +549,20 @@
"print_hide": 1,
"doctype": "DocField",
"label": "Supplier Address",
"options": "Address",
"permlevel": 0,
"fieldname": "supplier_address",
"fieldtype": "Link",
"permlevel": 0,
"options": "Address",
"in_filter": 1
},
{
"print_hide": 1,
"doctype": "DocField",
"label": "Contact Person",
"options": "Contact",
"permlevel": 0,
"fieldname": "contact_person",
"fieldtype": "Link",
"permlevel": 0,
"options": "Contact",
"in_filter": 1
},
{
@@ -563,7 +577,6 @@
"print_hide": 1,
"no_copy": 1,
"oldfieldtype": "Select",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Status",
"oldfieldname": "status",
@@ -580,10 +593,10 @@
"default": "No",
"doctype": "DocField",
"label": "Is Subcontracted",
"options": "\nYes\nNo",
"permlevel": 0,
"fieldname": "is_subcontracted",
"fieldtype": "Select",
"permlevel": 0
"options": "\nYes\nNo"
},
{
"print_hide": 1,
@@ -616,7 +629,6 @@
"description": "Select the relevant company name if you have multiple companies",
"no_copy": 0,
"oldfieldtype": "Link",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Company",
"oldfieldname": "company",
@@ -625,8 +637,8 @@
"fieldtype": "Link",
"search_index": 1,
"reqd": 1,
"in_filter": 1,
"options": "Company"
"options": "Company",
"in_filter": 1
},
{
"print_hide": 1,
@@ -647,19 +659,19 @@
"print_hide": 1,
"no_copy": 1,
"oldfieldtype": "Link",
"colour": "White:FFF",
"allow_on_submit": 1,
"doctype": "DocField",
"label": "Select Print Heading",
"oldfieldname": "select_print_heading",
"permlevel": 0,
"options": "Print Heading",
"fieldname": "select_print_heading",
"fieldtype": "Link",
"options": "Print Heading",
"permlevel": 0,
"report_hide": 1
},
{
"print_hide": 1,
"print_width": "50%",
"oldfieldtype": "Column Break",
"doctype": "DocField",
"width": "50%",
@@ -671,7 +683,6 @@
"print_hide": 1,
"no_copy": 1,
"oldfieldtype": "Data",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Cancel Reason",
"oldfieldname": "cancel_reason",
@@ -697,6 +708,7 @@
"doctype": "DocPerm",
"submit": 1,
"write": 1,
"report": 1,
"role": "Manufacturing Manager",
"cancel": 1,
"permlevel": 0
@@ -707,6 +719,7 @@
"doctype": "DocPerm",
"submit": 1,
"write": 1,
"report": 1,
"role": "Purchase Manager",
"cancel": 1,
"permlevel": 0
@@ -717,6 +730,7 @@
"doctype": "DocPerm",
"submit": 0,
"write": 1,
"report": 1,
"role": "Purchase User",
"cancel": 0,
"permlevel": 0
@@ -727,6 +741,7 @@
"doctype": "DocPerm",
"submit": 0,
"write": 0,
"report": 1,
"role": "Material User",
"cancel": 0,
"permlevel": 0
@@ -737,6 +752,7 @@
"doctype": "DocPerm",
"submit": 0,
"write": 0,
"report": 1,
"role": "Supplier",
"cancel": 0,
"permlevel": 0

180
buying/utils.py Normal file
View File

@@ -0,0 +1,180 @@
# ERPNext - web based ERP (http://erpnext.com)
# Copyright (C) 2012 Web Notes Technologies Pvt Ltd
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
import webnotes
from webnotes.utils import getdate, flt, add_days
import json
@webnotes.whitelist()
def get_item_details(args):
"""
args = {
"doctype": "",
"docname": "",
"item_code": "",
"warehouse": None,
"supplier": None,
"transaction_date": None,
"conversion_rate": 1.0
}
"""
if isinstance(args, basestring):
args = json.loads(args)
args = webnotes._dict(args)
item_wrapper = webnotes.model_wrapper("Item", args.item_code)
item = item_wrapper.doc
from stock.utils import validate_end_of_life
validate_end_of_life(item.name, item.end_of_life)
# 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,
"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": "ref_rate_details"})))),
"batch_no": None,
"expense_head": item.purchase_account,
"cost_center": item.cost_center
})
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
if out.warehouse:
out.projected_qty = webnotes.conn.get_value("Bin", {"item_code": item.name,
"warehouse": out.warehouse}, "projected_qty")
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
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.model_wrapper("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})
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()
def get_last_purchase_details(item_code, doc_name, conversion_rate=1.0):
"""returns last purchase details in stock uom"""
# get last purchase order item details
last_purchase_order = webnotes.conn.sql("""\
select po.name, po.transaction_date, po.conversion_rate,
po_item.conversion_factor, po_item.purchase_ref_rate,
po_item.discount_rate, po_item.purchase_rate
from `tabPurchase Order` po, `tabPurchase Order Item` po_item
where po.docstatus = 1 and po_item.item_code = %s and po.name != %s and
po.name = po_item.parent
order by po.transaction_date desc, po.name desc
limit 1""", (item_code, doc_name), as_dict=1)
# get last purchase receipt item details
last_purchase_receipt = webnotes.conn.sql("""\
select pr.name, pr.posting_date, pr.posting_time, pr.conversion_rate,
pr_item.conversion_factor, pr_item.purchase_ref_rate, pr_item.discount_rate,
pr_item.purchase_rate
from `tabPurchase Receipt` pr, `tabPurchase Receipt Item` pr_item
where pr.docstatus = 1 and pr_item.item_code = %s and pr.name != %s and
pr.name = pr_item.parent
order by pr.posting_date desc, pr.posting_time desc, pr.name desc
limit 1""", (item_code, doc_name), as_dict=1)
purchase_order_date = getdate(last_purchase_order and last_purchase_order[0].transaction_date \
or "1900-01-01")
purchase_receipt_date = getdate(last_purchase_receipt and \
last_purchase_receipt[0].posting_date or "1900-01-01")
if (purchase_order_date > purchase_receipt_date) or \
(last_purchase_order and not last_purchase_receipt):
# use purchase order
last_purchase = last_purchase_order[0]
purchase_date = purchase_order_date
elif (purchase_receipt_date > purchase_order_date) or \
(last_purchase_receipt and not last_purchase_order):
# use purchase receipt
last_purchase = last_purchase_receipt[0]
purchase_date = purchase_receipt_date
else:
return webnotes._dict()
conversion_factor = flt(last_purchase.conversion_factor)
out = webnotes._dict({
"purchase_ref_rate": flt(last_purchase.purchase_ref_rate) / conversion_factor,
"purchase_rate": flt(last_purchase.purchase_rate) / conversion_factor,
"discount_rate": flt(last_purchase.discount_rate),
"purchase_date": purchase_date
})
conversion_rate = flt(conversion_rate) or 1.0
out.update({
"import_ref_rate": out.purchase_ref_rate / conversion_rate,
"import_rate": out.purchase_rate / conversion_rate,
"rate": out.purchase_rate
})
return out