merge, update bean validations

This commit is contained in:
Rushabh Mehta 2013-03-01 19:09:06 +05:30
commit 213b180060
26 changed files with 156 additions and 143 deletions

View File

@ -33,6 +33,21 @@ erpnext.buying.PurchaseInvoiceController = erpnext.buying.BuyingController.exten
}
cur_frm.cscript.is_opening(doc);
},
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 && doc.supplier) cur_frm.cscript.supplier(doc, dt, dn);
}
me.update_item_details(doc, dt, dn, callback2);
}
// TODO: improve this
if(this.frm.doc.__islocal && this.frm.fields_dict.price_list_name
&& this.frm.doc.price_list_name) {
this.price_list_name(callback1);
}
}
});
@ -46,16 +61,6 @@ cur_frm.cscript.onload = function(doc,dt,dn) {
if(!doc.posting_date) set_multiple(dt,dn,{posting_date:get_today()});
}
cur_frm.cscript.onload_post_render = function(doc, dt, dn) {
var callback = function(doc, dt, dn) {
if(doc.__islocal && doc.supplier) cur_frm.cscript.supplier(doc,dt,dn);
}
// defined in purchase_common.js
cur_frm.cscript.update_item_details(doc, dt, dn, callback);
}
cur_frm.cscript.supplier = function(doc,dt,dn) {
var callback = function(r,rt) {
var doc = locals[cur_frm.doctype][cur_frm.docname];

View File

@ -518,16 +518,17 @@ class DocType(BuyingController):
def on_update(self):
pass
def update_raw_material_cost(self):
if self.sub_contracted_items:
for d in self.doclist.get({"parentfield": "entries"}):
rm_cost = webnotes.conn.sql(""" select raw_material_cost / quantity
from `tabBOM` where item = %s and is_default = 1 and docstatus = 1
and is_active = 1 """, (d.item_code,))
rm_cost = rm_cost and flt(rm_cost[0][0]) or 0
rm_cost = webnotes.conn.sql(""" select raw_material_cost / quantity
from `tabBOM` where item = %s and is_default = 1 and docstatus = 1
and is_active = 1 """, (d.item_code,))
rm_cost = rm_cost and flt(rm_cost[0][0]) or 0
d.conversion_factor = d.conversion_factor or webnotes.conn.get_value(
"UOM Conversion Detail", {"parent": d.item_code, "uom": d.uom},
"conversion_factor") or 1
d.conversion_factor = d.conversion_factor or webnotes.conn.get_value(
"UOM Conversion Detail", {"parent": d.item_code, "uom": d.uom},
"conversion_factor") or 1
d.rm_supp_cost = rm_cost * flt(d.qty) * flt(d.conversion_factor)
d.rm_supp_cost = rm_cost * flt(d.qty) * flt(d.conversion_factor)

View File

@ -160,6 +160,12 @@ def import_vouchers(common_values, data, start_idx, import_type):
raise Exception
doclist = Bean([jv]+details)
# validate datatype
from core.page.data_import_tool.data_import_tool import check_record
for d in doclist:
check_record(d.fields, d.parenttype)
doclist.submit()
messages.append("""<p style='color: green'>[row #%s]

View File

@ -51,18 +51,9 @@ erpnext.buying.BuyingController = erpnext.utils.Controller.extend({
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));
price_list_name: function(callback_fn) {
var me = this;
if(this.frm.doc.price_list_name) {
@ -77,6 +68,8 @@ erpnext.buying.BuyingController = erpnext.utils.Controller.extend({
callback: function(r) {
if(!r.exc) {
me.price_list_currency();
if (callback_fn) callback_fn(me.frm.doc, me.frm.doc.doctype,
me.frm.doc.name);
}
}
});
@ -89,6 +82,7 @@ erpnext.buying.BuyingController = erpnext.utils.Controller.extend({
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",
@ -140,12 +134,15 @@ erpnext.buying.BuyingController = erpnext.utils.Controller.extend({
},
price_list_currency: function() {
this.set_dynamic_labels();
this.frm.toggle_reqd("plc_conversion_rate",
!!(this.frm.doc.price_list_name && this.frm.doc.price_list_currency));
this.set_dynamic_labels();
if(this.frm.doc.price_list_currency === this.get_company_currency())
this.frm.set_value("plc_conversion_rate", 1.0);
else if(this.frm.doc.price_list_currency === this.frm.doc.currency)
this.frm.set_value("plc_conversion_rate", this.frm.doc.conversion_rate || 1.0);
this.frm.set_value("plc_conversion_rate", this.frm.doc.conversion_rate || 1.0);
},
set_dynamic_labels: function(doc, dt, dn) {

View File

@ -40,12 +40,22 @@ erpnext.buying.PurchaseOrderController = erpnext.buying.BuyingController.extend(
},
onload_post_render: function(doc, dt, dn) {
var callback = function(doc, dt, dn) {
if(doc.__islocal) cur_frm.cscript.get_default_schedule_date(doc);
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 && this.frm.fields_dict.price_list_name
&& this.frm.doc.price_list_name) {
this.price_list_name(callback1);
}
this.update_item_details(doc, dt, dn, callback);
}
});
var new_cscript = new erpnext.buying.PurchaseOrderController({frm: cur_frm});
@ -53,7 +63,7 @@ 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) {
cur_frm.cscript.onload = function(doc, cdt, cdn) {
// set missing values in parent doc
set_missing_values(doc, {
fiscal_year: sys_defaults.fiscal_year,

View File

@ -27,12 +27,25 @@ erpnext.buying.SupplierQuotationController = erpnext.buying.BuyingController.ext
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);
}
},
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 && this.frm.fields_dict.price_list_name
&& this.frm.doc.price_list_name) {
this.price_list_name(callback);
}
}
});
var new_cscript = new erpnext.buying.SupplierQuotationController({frm: cur_frm});

View File

@ -53,7 +53,7 @@ def get_item_details(args):
"qty": 0,
"stock_uom": item.stock_uom,
"uom": item.stock_uom,
"conversion_factor": 1,
"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"})))),

View File

@ -331,7 +331,12 @@ class BuyingController(AccountsController):
# update valuation rate
def update_valuation_rate(self, parentfield):
for d in self.doclist.get({"parentfield": parentfield}):
if d.qty:
d.conversion_factor = d.conversion_factor or webnotes.conn.get_value(
"UOM Conversion Detail", {"parent": d.item_code, "uom": d.uom},
"conversion_factor") or 1
if d.item_code and d.qty:
# if no item code, which is sometimes the case in purchase invoice,
# then it is not possible to track valuation against it
d.valuation_rate = (flt(d.purchase_rate or d.rate)
+ (flt(d.item_tax_amount) + flt(d.rm_supp_cost)) / flt(d.qty)
) / flt(d.conversion_factor)

View File

@ -23,9 +23,10 @@ erpnext.desktop.render = function() {
module.name = m;
module.label = wn._(module.label);
module.gradient_css = wn.get_gradient_css(module.color, 45);
module._link = module.link.toLowerCase().replace("/", "-");
$module_icon = $(repl('\
<div id="module-icon-%(link)s" class="case-wrapper" \
<div id="module-icon-%(_link)s" class="case-wrapper" \
data-name="%(name)s" data-link="%(link)s">\
<div class="case-border" style="%(gradient_css)s">\
<i class="%(icon)s"></i>\
@ -84,7 +85,7 @@ erpnext.desktop.show_pending_notifications = function() {
add_circle('module-icon-messages', 'unread_messages', 'Unread Messages');
add_circle('module-icon-support-home', 'open_support_tickets', 'Open Support Tickets');
add_circle('module-icon-todo', 'things_todo', 'Things To Do');
add_circle('module-icon-calendar', 'todays_events', 'Todays Events');
add_circle('module-icon-calendar-event', 'todays_events', 'Todays Events');
add_circle('module-icon-projects-home', 'open_tasks', 'Open Tasks');
add_circle('module-icon-questions', 'unanswered_questions', 'Unanswered Questions');
add_circle('module-icon-selling-home', 'open_leads', 'Open Leads');

View File

@ -16,12 +16,8 @@
from __future__ import unicode_literals
import webnotes
import webnotes.default
from webnotes.utils import cint, cstr, date_diff, formatdate, getdate, now
from webnotes.model import db_exists
from webnotes.model.bean import copy_doclist
from webnotes import form, msgprint
from webnotes.utils import cint, cstr, formatdate, getdate
from webnotes import msgprint
sql = webnotes.conn.sql
@ -49,13 +45,8 @@ class DocType:
# get date list inbetween from date and to date
def date_diff_list(self):
import datetime
#get from date
att_fr_date = self.doc.att_fr_date and self.doc.att_fr_date or ''
#get to date
att_to_date = self.doc.att_to_date and self.doc.att_to_date or ''
if att_to_date:
if self.doc.att_to_date:
r = (getdate(self.doc.att_to_date)+datetime.timedelta(days=1)-getdate(self.doc.att_fr_date)).days
else:
r = 1
@ -65,6 +56,7 @@ class DocType:
return dt
def get_att_data(self):
import webnotes.defaults
fy = webnotes.defaults.get_global_default('fiscal_year')
comp = webnotes.defaults.get_user_default('company')

View File

@ -33,6 +33,7 @@ def execute(filters=None):
for leave_type in leave_types:
columns.append(leave_type + " Allocated:Float")
columns.append(leave_type + " Taken:Float")
columns.append(leave_type + " Balance:Float")
data = {}
for d in allocations:
@ -52,5 +53,6 @@ def execute(filters=None):
tmp = data.get((fiscal_year, employee.name, leave_type), webnotes._dict())
row.append(tmp.allocation or 0)
row.append(tmp.leaves or 0)
row.append((tmp.allocation or 0) - (tmp.leaves or 0))
return columns, result

View File

@ -0,0 +1,9 @@
import webnotes
def execute():
for w in webnotes.conn.sql("""select name from `tabWarehouse` where docstatus=2"""):
try:
webnotes.delete_doc("Warehouse", w[0])
except webnotes.ValidationError:
pass

View File

View File

@ -0,0 +1,6 @@
import webnotes
def execute():
webnotes.conn.sql("""update `tabPurchase Order Item` set prevdoc_doctype = 'Material Request'
where prevdoc_doctype = 'Purchase Request'""")
webnotes.conn.sql("""update `tabSupplier Quotation Item`
set prevdoc_doctype = 'Material Request' where prevdoc_doctype = 'Purchase Request'""")

View File

@ -201,4 +201,6 @@ patch_list = [
'execute:webnotes.reload_doc("accounts", "Print Format", "Sales Invoice Spartan") # 2013-02-26',
"execute:(not webnotes.conn.exists('Role', 'Projects Manager')) and webnotes.doc({'doctype':'Role', 'role_name':'Projects Manager'}).insert()",
"execute:(not webnotes.conn.exists('UOM', 'Hour')) and webnotes.doc({'uom_name': 'Unit', 'doctype': 'UOM', 'name': 'Hour'}).insert()",
"patches.february_2013.p09_remove_cancelled_warehouses",
"patches.march_2013.update_po_prevdoc_doctype",
]

View File

@ -23,10 +23,10 @@ class DocType:
def set_status(self):
self.doc.status = {
"0": "Draft",
"1": "Submitted",
"2": "Cancelled"
}[str(self.doc.docstatus or 0)]
0: "Draft",
1: "Submitted",
2: "Cancelled"
}[self.doc.docstatus or 0]
if self.doc.time_log_batch:
self.doc.status="Batched for Billing"

View File

@ -40,7 +40,7 @@ def get_price_list_currency(args):
if isinstance(args, basestring):
args = json.loads(args)
result = webnotes.conn.sql("""select ref_currency from `tabItem Price`
result = webnotes.conn.sql("""select distinct ref_currency from `tabItem Price`
where price_list_name=%s and `%s`=1""" % ("%s", args.get("use_for")),
(args.get("price_list_name"),))
if result and len(result)==1:

View File

@ -55,7 +55,7 @@ def get_todays_events():
SELECT COUNT(*) FROM `tabEvent`
WHERE owner = %s
AND event_type != 'Cancel'
AND event_date = %s""", (
AND %s between date(starts_on) and date(ends_on)""", (
webnotes.session.user, nowdate()))
return todays_events[0][0]

View File

@ -1,15 +1,17 @@
[
{
"creation": "2013-01-10 16:34:25",
"creation": "2013-03-01 08:21:54",
"docstatus": 0,
"modified": "2013-01-29 13:40:32",
"modified": "2013-03-01 08:22:16",
"modified_by": "Administrator",
"owner": "harshada@webnotestech.com"
},
{
"allow_attach": 1,
"autoname": "field:batch_id",
"doctype": "DocType",
"document_type": "Master",
"max_attachments": 5,
"module": "Stock",
"name": "__common__"
},
@ -105,6 +107,15 @@
"oldfieldtype": "Small Text",
"read_only": 1
},
{
"doctype": "DocField",
"fieldname": "file_list",
"fieldtype": "Text",
"hidden": 1,
"label": "File List",
"no_copy": 1,
"print_hide": 1
},
{
"doctype": "DocPerm"
}

View File

@ -22,13 +22,11 @@ cur_frm.cscript.refresh = function(doc) {
if ((!doc.__islocal) && (doc.is_stock_item == 'Yes')) {
var callback = function(r, rt) {
var enabled = (r.message == 'exists') ? false : true;
var enabled = (r.message == 'exists') ? false : true;
cur_frm.toggle_enable(['has_serial_no', 'is_stock_item', 'valuation_method'], enabled);
}
$c_obj(make_doclist(doc.doctype, doc.name),'check_if_sle_exists','',callback);
}
cur_frm.cscript.hide_website_fields(doc);
}
cur_frm.cscript.item_code = function(doc) {

View File

@ -1,8 +1,8 @@
[
{
"creation": "2013-02-20 13:26:14",
"creation": "2013-02-21 14:54:43",
"docstatus": 0,
"modified": "2013-02-20 18:14:06",
"modified": "2013-02-28 10:43:02",
"modified_by": "Administrator",
"owner": "Administrator"
},
@ -28,13 +28,14 @@
"permlevel": 0
},
{
"amend": 0,
"doctype": "DocPerm",
"name": "__common__",
"parent": "Item",
"parentfield": "permissions",
"parenttype": "DocType",
"permlevel": 0,
"read": 1,
"report": 1,
"submit": 0
},
{
@ -596,7 +597,6 @@
"label": "Price Lists and Rates"
},
{
"depends_on": "eval:doc.is_sales_item==\"Yes\"",
"description": "Create a price list from Price List master and enter standard ref rates against each of them. On selection of a price list in Quotation, Sales Order or Delivery Note, corresponding ref rate will be fetched for this item.",
"doctype": "DocField",
"fieldname": "ref_rate_details",
@ -812,76 +812,27 @@
"fieldtype": "Text Editor",
"label": "Website Description"
},
{
"cancel": 0,
"create": 0,
"doctype": "DocPerm",
"permlevel": 1,
"report": 0,
"role": "Material Manager",
"write": 0
},
{
"cancel": 0,
"create": 0,
"doctype": "DocPerm",
"permlevel": 0,
"report": 1,
"role": "Material Manager",
"write": 0
},
{
"cancel": 0,
"create": 0,
"doctype": "DocPerm",
"permlevel": 1,
"report": 0,
"role": "Material User",
"write": 0
},
{
"cancel": 0,
"create": 0,
"doctype": "DocPerm",
"permlevel": 0,
"report": 1,
"role": "Material User",
"write": 0
},
{
"cancel": 1,
"create": 1,
"doctype": "DocPerm",
"permlevel": 0,
"report": 1,
"role": "Material Master Manager",
"write": 1
},
{
"amend": 0,
"cancel": 0,
"create": 0,
"doctype": "DocPerm",
"permlevel": 1,
"report": 0,
"role": "Material Master Manager",
"role": "Material Manager",
"write": 0
},
{
"cancel": 1,
"create": 1,
"doctype": "DocPerm",
"permlevel": 0,
"report": 1,
"role": "System Manager",
"write": 1
},
{
"amend": 0,
"cancel": 0,
"create": 0,
"doctype": "DocPerm",
"permlevel": 1,
"report": 0,
"role": "System Manager",
"role": "Material User",
"write": 0
}
]

View File

@ -37,6 +37,18 @@ erpnext.buying.PurchaseReceiptController = erpnext.buying.BuyingController.exten
if(wn.boot.control_panel.country == 'India') {
unhide_field(['challan_no', 'challan_date']);
}
},
onload_post_render: function(doc, dt, dn) {
var me = this;
var callback = function(doc, dt, dn) {
me.update_item_details(doc, dt, dn, function(r,rt) { });
}
// TODO: improve this
if(this.frm.doc.__islocal && this.frm.fields_dict.price_list_name
&& this.frm.doc.price_list_name) {
this.price_list_name(callback);
}
}
});
@ -45,7 +57,6 @@ var new_cscript = new erpnext.buying.PurchaseReceiptController({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) {
if(!doc.fiscal_year && doc.__islocal){ wn.model.set_default_values(doc);}
if (!doc.posting_date) doc.posting_date = dateutil.obj_to_str(new Date());
@ -53,15 +64,6 @@ cur_frm.cscript.onload = function(doc, cdt, cdn) {
if (!doc.status) doc.status = 'Draft';
}
cur_frm.cscript.onload_post_render = function(doc, dt, dn) {
var callback = function(doc, dt, dn) {
// defined in purchase_common.js
cur_frm.cscript.update_item_details(doc, dt, dn, function(r,rt) { });
}
cur_frm.cscript.dynamic_label(doc, dt, dn, callback);
}
//Supplier
cur_frm.cscript.supplier = function(doc,dt,dn) {
if (doc.supplier) {
get_server_fields('get_default_supplier_address',

View File

@ -214,7 +214,8 @@ class DocType(BuyingController):
def validate_inspection(self):
for d in getlist(self.doclist, 'purchase_receipt_details'): #Enter inspection date for all items that require inspection
ins_reqd = sql("select inspection_required from `tabItem` where name = %s", (d.item_code), as_dict = 1)
ins_reqd = sql("select inspection_required from `tabItem` where name = %s",
(d.item_code,), as_dict = 1)
ins_reqd = ins_reqd and ins_reqd[0]['inspection_required'] or 'No'
if ins_reqd == 'Yes' and not d.qa_no:
msgprint("Item: " + d.item_code + " requires QA Inspection. Please enter QA No or report to authorized person to create Quality Inspection")
@ -289,17 +290,17 @@ class DocType(BuyingController):
self.make_gl_entries()
def validate_for_subcontracting(self):
if self.sub_contracted_items and self.purchase_items and not self.doc.is_subcontracted:
if not self.doc.is_subcontracted and self.sub_contracted_items:
webnotes.msgprint(_("""Please enter whether Purchase Recipt is made for subcontracting
or purchasing, in 'Is Subcontracted' field"""), raise_exception=1)
if self.doc.is_subcontracted and not self.doc.supplier_warehouse:
if self.doc.is_subcontracted=="Yes" and not self.doc.supplier_warehouse:
webnotes.msgprint(_("Please Enter Supplier Warehouse for subcontracted Items"),
raise_exception=1)
def update_raw_materials_supplied(self):
self.doclist = self.doc.clear_table(self.doclist, 'pr_raw_material_details')
if self.sub_contracted_items:
if self.doc.is_subcontracted=="Yes":
for item in self.doclist.get({"parentfield": "purchase_receipt_details"}):
if item.item_code in self.sub_contracted_items:
self.add_bom_items(item)

View File

@ -102,8 +102,7 @@ erpnext.StockBalance = erpnext.StockAnalytics.extend({
for(var i=0, j=data.length; i<j; i++) {
var sl = data[i];
sl.posting_datetime = sl.posting_date + " " + sl.posting_time;
var posting_datetime = dateutil.str_to_obj(sl.posting_datetime);
var sl_posting_date = dateutil.str_to_obj(sl.posting_date);
if(me.is_default("warehouse") ? true : me.warehouse == sl.warehouse) {
var item = me.item_by_name[sl.item_code];
@ -115,10 +114,10 @@ erpnext.StockBalance = erpnext.StockAnalytics.extend({
var qty_diff = sl.qty;
var value_diff = me.get_value_diff(wh, sl, is_fifo);
if(posting_datetime < from_date) {
if(sl_posting_date < from_date) {
item.opening_qty += qty_diff;
item.opening_value += value_diff;
} else if(posting_datetime <= to_date) {
} else if(sl_posting_date <= to_date) {
var ignore_inflow_outflow = this.is_default("warehouse")
&& sl.voucher_type=="Stock Entry"
&& this.stock_entry_map[sl.voucher_no].purpose=="Material Transfer";

View File

@ -36,6 +36,7 @@ class SupportMailbox(POP3Mailbox):
return
thread_id = mail.get_thread_id()
ticket = None
new_ticket = False
if thread_id and webnotes.conn.exists("Support Ticket", thread_id):
ticket = webnotes.bean("Support Ticket", thread_id)
@ -52,16 +53,17 @@ class SupportMailbox(POP3Mailbox):
"status": "Open"
}])
ticket.insert()
if cint(self.email_settings.send_autoreply):
if "mailer-daemon" not in mail.from_email.lower():
self.send_auto_reply(ticket.doc)
new_ticket = True
mail.save_attachments_in_doc(ticket.doc)
make(content=mail.content, sender=mail.from_email, subject = ticket.doc.subject,
doctype="Support Ticket", name=ticket.doc.name,
lead = ticket.doc.lead, contact=ticket.doc.contact, date=mail.date)
if new_ticket and cint(self.email_settings.send_autoreply) and \
"mailer-daemon" not in mail.from_email.lower():
self.send_auto_reply(ticket.doc)
def send_auto_reply(self, d):
signature = self.email_settings.fields.get('support_signature') or ''

View File

@ -75,7 +75,7 @@ class TransactionBase(DocListController):
details = webnotes.conn.sql("select name, address_line1, address_line2, city, country, pincode, state, phone, fax from `tabAddress` where %s and docstatus != 2 order by is_primary_address desc limit 1" % cond, as_dict = 1)
extract = lambda x: details and details[0] and details[0].get(x,'') or ''
address_fields = [('','address_line1'),('\n','address_line2'),('\n','city'),(' ','pincode'),('\n','state'),('\n','country'),('\nPhone: ','phone'),('\nFax: ', 'fax')]
address_fields = [('','address_line1'),('\n','address_line2'),('\n','city'),('\n','state'),(' ','pincode'),('\n','country'),('\nPhone: ','phone'),('\nFax: ', 'fax')]
address_display = ''.join([a[0]+extract(a[1]) for a in address_fields if extract(a[1])])
if address_display.startswith('\n'): address_display = address_display[1:]