Merge branch 'master' of github.com:webnotes/erpnext into dev

Conflicts:
	erpnext/stock/doctype/delivery_note/delivery_note.py
	public/js/all-app.js
This commit is contained in:
Anand Doshi 2012-07-18 20:31:37 +05:30
commit 5756630efb
48 changed files with 194 additions and 52 deletions

View File

@ -90,8 +90,15 @@ cur_frm.cscript.supplier = function(doc,dt,dn) {
cur_frm.cscript.calc_amount(doc, 1);
}
if(doc.supplier) get_server_fields('get_default_supplier_address', JSON.stringify({supplier: doc.supplier}),'', doc, dt, dn, 1,callback);
if(doc.supplier) unhide_field(['supplier_address','contact_person']);
if (doc.supplier) {
get_server_fields('get_default_supplier_address',
JSON.stringify({ supplier: doc.supplier }),'', doc, dt, dn, 1, function(doc, dt, dn) {
cur_frm.refresh();
callback(doc, dt, dn);
});
unhide_field(['supplier_address','contact_person']);
}
}
cur_frm.cscript.supplier_address = cur_frm.cscript.contact_person = function(doc,dt,dn) {
@ -113,14 +120,19 @@ cur_frm.fields_dict.contact_person.on_new = function(dn) {
cur_frm.cscript.credit_to = function(doc,dt,dn) {
var callback = function(r,rt) {
var doc = locals[cur_frm.doctype][cur_frm.docname];
if(doc.supplier) get_server_fields('get_default_supplier_address', JSON.stringify({supplier: doc.supplier}),'', doc, dt, dn, 1);
if(doc.supplier) unhide_field(['supplier_address','contact_person']);
var callback = function(doc, dt, dn) {
var doc = locals[doc.doctype][doc.name];
if(doc.supplier) {
get_server_fields('get_default_supplier_address',
JSON.stringify({ supplier: doc.supplier }), '', doc, dt, dn, 1, function() {
cur_frm.refresh();
});
unhide_field(['supplier_address','contact_person']);
}
cur_frm.refresh();
}
get_server_fields('get_cust','','',doc,dt,dn,1,callback);
get_server_fields('get_cust', '', '', doc, dt, dn, 1, callback);
}

View File

@ -65,9 +65,6 @@ cur_frm.cscript.update_item_details = function(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',*/

View File

@ -68,12 +68,15 @@ cur_frm.cscript.refresh = function(doc, cdt, cdn) {
else $(cur_frm.fields_dict.contact_section.row.wrapper).toggle(false);
}
//Supplier
cur_frm.cscript.supplier = function(doc,dt,dn) {
if(doc.supplier) get_server_fields('get_default_supplier_address', JSON.stringify({supplier: doc.supplier}),'', doc, dt, dn, 1);
if(doc.supplier) $(cur_frm.fields_dict.contact_section.row.wrapper).toggle(true);
if (doc.supplier) {
get_server_fields('get_default_supplier_address',
JSON.stringify({ supplier: doc.supplier }),'', doc, dt, dn, 1, function() {
cur_frm.refresh();
});
$(cur_frm.fields_dict.contact_section.row.wrapper).toggle(true);
}
}
cur_frm.cscript.supplier_address = cur_frm.cscript.contact_person = function(doc,dt,dn) {

View File

@ -5,7 +5,7 @@
{
'creation': '2012-05-15 12:14:41',
'docstatus': 0,
'modified': '2012-05-31 13:18:29',
'modified': '2012-07-18 17:41:49',
'modified_by': u'Administrator',
'owner': u'Administrator'
},
@ -263,6 +263,19 @@
'search_index': 0
},
# DocField
{
'colour': u'White:FFF',
'description': u'This currency will get fetched in Purchase transactions of this supplier',
'doctype': u'DocField',
'fieldname': u'default_currency',
'fieldtype': u'Select',
'label': u'Default Currency',
'no_copy': 1,
'options': u'link:Currency',
'permlevel': 0
},
# DocField
{
'colour': u'White:FFF',

View File

@ -0,0 +1,76 @@
def repost_reserved_qty():
import webnotes
bins = webnotes.conn.sql("select item_code, warehouse, name, reserved_qty from `tabBin`")
for d in bins:
reserved_qty = webnotes.conn.sql("""
select sum((dnpi.qty/so_item.qty)*(so_item.qty - ifnull(so_item.delivered_qty, 0))), so.transaction_date
from `tabDelivery Note Packing Item` dnpi, `tabSales Order Item` so_item, `tabSales Order` so
where dnpi.parent = so.name
and so_item.parent = so.name
and dnpi.parenttype = 'Sales Order'
and dnpi.parent_detail_docname = so_item.name
and dnpi.parent_item = so_item.item_code
and so.docstatus = 1
and so.status != 'Stopped'
and dnpi.item_code = %s
and dnpi.warehouse = %s
""", (d[0], d[1]))
if flt(d[3]) != flt(reserved_qty[0][0]):
print d, reserved_qty
#webnotes.conn.sql("""
# update `tabBin` set reserved_qty = %s where name = %s
#""", (reserved_qty and reserved_qty[0][0] or 0, d[2]))
repost_reserved_qty()
def cleanup_wrong_sle():
sle = webnotes.conn.sql("""
select item_code, warehouse, voucher_no, name
from `tabStock Ledger Entry` sle
where voucher_type = 'Delivery Note'
and not exists(
select name from `tabDelivery Note Packing Item`
where item_code = sle.item_code
and qty = abs(sle.actual_qty)
and parent = sle.voucher_no
) and not exists (
select name from `tabDelivery Note Item`
where item_code = sle.item_code
and qty = abs(sle.actual_qty)
and parent = sle.voucher_no
)
""")
if sle:
print sle
# for d in sle:
# webnotes.conn.sql("update `tabStock Ledger Entry` set is_cancelled = 'Yes' where name = %s", d[3])
# create_comment(d[3])
# repost_bin(d[0], d[1])
def create_comment(dn):
from webnotes.model.doc import Document
cmt = Document('Comment')
for arg in ['comment', 'comment_by', 'comment_by_fullname', 'comment_doctype', \
'comment_docname']:
cmt.fields[arg] = args[arg]
cmt.comment = 'Cancelled by administrator due to wrong entry in packing list'
cmt.comment_by = 'Administrator'
cmt.comment_by_fullname = 'Administrator'
cmt.comment_doctype = 'Stock Ledger Entry'
cmt.comment_docname = dn
cmt.save(1)
def repost_bin(item, wh):
from webnotes.model.code import get_obj
bin = webnotes.conn.sql("select name from `tabBin` \
where item_code = %s and warehouse = %s", (item, wh))
get_obj('Bin', bin[0][0]).update_entries_after(posting_date = '2012-07-01', posting_time = '12:05')
def execute():
repost_reserved_qty()
cleanup_wrong_sle()

View File

@ -3,9 +3,9 @@
# These values are common in all dictionaries
{
'creation': '2012-05-15 12:14:51',
'creation': '2012-07-18 16:07:05',
'docstatus': 0,
'modified': '2012-05-31 11:41:06',
'modified': '2012-07-18 17:11:25',
'modified_by': u'Administrator',
'owner': u'Administrator'
},
@ -368,6 +368,19 @@
'permlevel': 0
},
# DocField
{
'colour': u'White:FFF',
'description': u'This currency will get fetched in Sales transactions of this customer',
'doctype': u'DocField',
'fieldname': u'default_currency',
'fieldtype': u'Select',
'label': u'Default Currency',
'no_copy': 1,
'options': u'link:Currency',
'permlevel': 0
},
# DocField
{
'colour': u'White:FFF',

View File

@ -410,7 +410,7 @@ class DocType(TransactionBase):
if self.has_sales_bom(d.item_code):
for p in getlist(obj.doclist, 'packing_details'):
if p.parent_detail_docname == d.name:
if p.parent_detail_docname == d.name and p.parent_item == d.item_code:
# the packing details table's qty is already multiplied with parent's qty
il.append({
'warehouse': p.warehouse,
@ -522,7 +522,9 @@ class DocType(TransactionBase):
if [d.item_code, d.name] not in parent_items:
parent_items.append([d.item_code, d.name])
self.cleanup_packing_list(obj, parent_items)
obj.doclist = self.cleanup_packing_list(obj, parent_items)
return obj.doclist
def cleanup_packing_list(self, obj, parent_items):
"""Remove all those child items which are no longer present in main item table"""
@ -532,7 +534,8 @@ class DocType(TransactionBase):
# mark for deletion from doclist
delete_list.append(d.name)
if not delete_list: return
if not delete_list:
return obj.doclist
# delete from doclist
obj.doclist = filter(lambda d: d.name not in delete_list, obj.doclist)
@ -543,6 +546,8 @@ class DocType(TransactionBase):
where name in (%s)"""
% (", ".join(["%s"] * len(delete_list))),
tuple(delete_list))
return obj.doclist
# Get total in words
# ==================================================================

View File

@ -325,7 +325,7 @@ class DocType(TransactionBase):
sales_com_obj.validate_max_discount(self,'sales_order_details')
# this is to verify that the allocated % of sales persons is 100%
sales_com_obj.get_allocated_sum(self)
sales_com_obj.make_packing_list(self,'sales_order_details')
self.doclist = sales_com_obj.make_packing_list(self,'sales_order_details')
# get total in words
dcc = TransactionBase().get_company_currency(self.doc.company)

View File

@ -34,7 +34,7 @@ wn.doclistviews['Sales Order'] = wn.views.ListView.extend({
if (order_type === 'sales') {
me.render_icon(parent, 'icon-tag', data.order_type);
me.render_bar_graph(parent, data, 'per_billed', 'Delivered');
me.render_bar_graph(parent, data, 'per_delivered', 'Delivered');
} else if (order_type === 'maintenance') {
me.render_icon(parent, 'icon-wrench', data.order_type);
}

View File

@ -404,9 +404,8 @@ class DocType(TransactionBase):
def on_update(self):
get_obj('Sales Common').make_packing_list(self,'delivery_note_details')
self.doclist = get_obj('Sales Common').make_packing_list(self,'delivery_note_details')
sl = get_obj('Stock Ledger')
sl.scrub_serial_nos(self)
sl.scrub_serial_nos(self, 'packing_details')

View File

@ -64,11 +64,15 @@ cur_frm.cscript.refresh = function(doc, cdt, cdn) {
}
}
//Supplier
cur_frm.cscript.supplier = function(doc,dt,dn) {
if(doc.supplier) get_server_fields('get_default_supplier_address', JSON.stringify({supplier: doc.supplier}),'', doc, dt, dn, 1);
if(doc.supplier) $(cur_frm.fields_dict.contact_section.row.wrapper).toggle(true);
if (doc.supplier) {
get_server_fields('get_default_supplier_address',
JSON.stringify({ supplier: doc.supplier }),'', doc, dt, dn, 1, function() {
cur_frm.refresh();
});
$(cur_frm.fields_dict.contact_section.row.wrapper).toggle(true);
}
}
cur_frm.cscript.supplier_address = cur_frm.cscript.contact_person = function(doc,dt,dn) {

View File

@ -6,6 +6,7 @@ wn.doclistviews['Purchase Receipt'] = wn.views.ListView.extend({
"`tabPurchase Receipt`.supplier_name",
"group_concat(`tabPurchase Receipt Item`.prevdoc_docname) as purchase_order_no",
]);
this.group_by = "`tabPurchase Receipt`.name";
},
prepare_data: function(data) {
this._super(data);

View File

@ -116,22 +116,32 @@ class TransactionBase:
contact_mobile = details and details[0]['mobile_no'] or ''
return contact_display, contact_name, contact_email, contact_mobile
# Get Customer Details
# -----------------------
def get_customer_details(self, name):
customer_details = webnotes.conn.sql("select customer_name, customer_group, territory, default_sales_partner, default_commission_rate, default_price_list from tabCustomer where name = '%s' and docstatus != 2" %(name), as_dict = 1)
def get_customer_details(self, name):
"""
Get customer details like name, group, territory
and other such defaults
"""
customer_details = webnotes.conn.sql("""\
select
customer_name, customer_group, territory,
default_sales_partner, default_commission_rate, default_currency,
default_price_list
from `tabCustomer`
where name = %s and docstatus < 2""", name, as_dict=1)
if customer_details:
self.doc.customer_name = customer_details[0]['customer_name'] or ''
self.doc.customer_group = customer_details[0]['customer_group'] or ''
self.doc.territory = customer_details[0]['territory'] or ''
self.doc.sales_partner = customer_details[0]['default_sales_partner'] or ''
self.doc.commission_rate = customer_details[0]['default_commission_rate'] or ''
def_price_list = customer_details[0]['default_price_list'] or ''
if not def_price_list:
cg_price_list = webnotes.conn.sql("select default_price_list from `tabCustomer Group` where name = %s", customer_details[0]['customer_group'])
def_price_list = cg_price_list and cg_price_list[0][0] or ''
self.doc.price_list_name = def_price_list or self.doc.price_list_name
for f in ['customer_name', 'customer_group', 'territory']:
self.doc.fields[f] = customer_details[0][f] or self.doc.fields.get(f)
# fields prepended with default in Customer doctype
for f in ['sales_partner', 'commission_rate', 'currency']:
self.doc.fields[f] = customer_details[0]["default_%s" % f] or self.doc.fields.get(f)
# optionally fetch default price list from Customer Group
self.doc.price_list_name = (customer_details[0]['default_price_list']
or webnotes.conn.get_value('Customer Group', self.doc.customer_group,
'default_price_list')
or self.doc.fields.get('price_list_name'))
# Get Customer Shipping Address
# -----------------------
def get_shipping_address(self, name):
@ -194,7 +204,7 @@ class TransactionBase:
contact_text, contact_name, contact_email, contact_mobile = self.get_contact_text(contact_name=args['contact'])
ret = {
'supplier_address' : address_name,
'address_display' : address_text,
'address_display' : address_text,
'contact_person' : contact_name,
'contact_display' : contact_text,
'contact_email' : contact_email,
@ -204,12 +214,20 @@ class TransactionBase:
# Get Supplier Details
# -----------------------
def get_supplier_details(self, name):
supplier_details = webnotes.conn.sql("select supplier_name from tabSupplier where name = '%s' and docstatus != 2" %(name), as_dict = 1)
ret = {
'supplier_name' : supplier_details and supplier_details[0]['supplier_name'] or ''
}
return ret
def get_supplier_details(self, name):
supplier_details = webnotes.conn.sql("""\
select supplier_name, default_currency
from `tabSupplier`
where name = %s and docstatus < 2""", name, as_dict=1)
if supplier_details:
return {
'supplier_name': (supplier_details[0]['supplier_name']
or self.doc.fields.get('supplier_name')),
'currency': (supplier_details[0]['default_currency']
or self.doc.fields.get('currency')),
}
else:
return {}
# Get Sales Person Details of Customer
# ------------------------------------

View File

@ -972,7 +972,7 @@ this.listview.parent=this;this.wrapper=this.$page.find('.wnlist-area');this.page
<hr>\
<p><button class="btn btn-info btn-small" list_view_doc="%(doctype)s">\
Make a new %(doctype_label)s</button>\
</p></div>',{doctype_label:get_doctype_label(this.doctype),doctype:this.doctype});return no_result_message;},render_row:function(row,data){data.doctype=this.doctype;this.listview.render(row,data,this);},get_query_fields:function(){return this.listview.fields;},get_args:function(){return{doctype:this.doctype,fields:this.get_query_fields(),filters:this.filter_list.get_filters(),docstatus:this.can_submit?$.map(this.$page.find('.show-docstatus :checked'),function(inp){return $(inp).attr('data-docstatus')}):[],order_by:this.listview.order_by||undefined,}},add_delete_option:function(){var me=this;if(this.can_delete){this.add_button('Delete',function(){me.delete_items();},'icon-remove');$('<div style="padding: 4px"><input type="checkbox" name="select-all" />\
</p></div>',{doctype_label:get_doctype_label(this.doctype),doctype:this.doctype});return no_result_message;},render_row:function(row,data){data.doctype=this.doctype;this.listview.render(row,data,this);},get_query_fields:function(){return this.listview.fields;},get_args:function(){return{doctype:this.doctype,fields:this.get_query_fields(),filters:this.filter_list.get_filters(),docstatus:this.can_submit?$.map(this.$page.find('.show-docstatus :checked'),function(inp){return $(inp).attr('data-docstatus')}):[],order_by:this.listview.order_by||undefined,group_by:this.listview.group_by||undefined,}},add_delete_option:function(){var me=this;if(this.can_delete){this.add_button('Delete',function(){me.delete_items();},'icon-remove');$('<div style="padding: 4px"><input type="checkbox" name="select-all" />\
Select all</div>').insertBefore(this.$page.find('.result-list'));this.$page.find('[name="select-all"]').click(function(){me.$page.find('.list-delete').attr('checked',$(this).attr('checked')||false);})}},delete_items:function(){var me=this;var dl=$.map(me.$page.find('.list-delete:checked'),function(e){return $(e).data('name');});if(!dl.length)
return;if(!confirm('This is PERMANENT action and you cannot undo. Continue?')){return;}
me.set_working(true);wn.call({method:'webnotes.widgets.doclistview.delete_items',args:{items:dl,doctype:me.doctype},callback:function(){me.set_working(false);me.refresh();}})},init_stats:function(){var me=this
@ -1713,7 +1713,7 @@ this.appframe.add_button('Amend',function(){cur_frm.amend_doc()},'icon-pencil');
*/
wn.provide('_f');_f.frms={};_f.Frm=function(doctype,parent,in_form){this.docname='';this.doctype=doctype;this.display=0;var me=this;this.is_editable={};this.opendocs={};this.sections=[];this.grids=[];this.cscript={};this.pformat={};this.fetch_dict={};this.parent=parent;this.tinymce_id_list=[];this.setup_meta(doctype);this.in_form=in_form?true:false;var me=this;$(document).bind('rename',function(event,dt,old_name,new_name){if(dt==me.doctype)
me.rename_notify(dt,old_name,new_name)});}
_f.Frm.prototype.check_doctype_conflict=function(docname){var me=this;if(this.doctype=='DocType'&&docname=='DocType'){msgprint('Allowing DocType, DocType. Be careful!')}else if(this.doctype=='DocType'){if(wn.views.formview[docname]){msgprint("Cannot open DocType when its instance is open")
_f.Frm.prototype.check_doctype_conflict=function(docname){var me=this;if(this.doctype=='DocType'&&docname=='DocType'){msgprint('Allowing DocType, DocType. Be careful!')}else if(this.doctype=='DocType'){if(wn.views.formview[docname]||wn.pages['List/'+docname]){msgprint("Cannot open DocType when its instance is open")
throw'doctype open conflict'}}else{if(wn.views.formview.DocType&&wn.views.formview.DocType.frm.opendocs[this.doctype]){msgprint("Cannot open instance when its DocType is open")
throw'doctype open conflict'}}}
_f.Frm.prototype.setup=function(){var me=this;this.fields=[];this.fields_dict={};this.wrapper=this.parent;this.setup_print_layout();this.saved_wrapper=$a(this.wrapper,'div');this.setup_std_layout();this.setup_client_script();this.setup_done=true;}
@ -1778,7 +1778,8 @@ return 1}
_f.Frm.prototype.refresh=function(docname){if(docname){if(this.docname!=docname&&(!this.meta.in_dialog||this.in_form)&&!this.meta.istable)
scroll(0,0);this.docname=docname;}
if(!this.meta.istable){cur_frm=this;this.parent.cur_frm=this;}
if(this.docname){if(!this.check_doc_perm())return;this.doc=get_local(this.doctype,this.docname);if(!this.setup_done)this.setup();this.runclientscript('set_perm',this.doctype,this.docname);cur_frm.cscript.is_onload=false;if(!this.opendocs[this.docname]){cur_frm.cscript.is_onload=true;this.setnewdoc(this.docname);}
if(this.docname){if(!this.check_doc_perm())return;if(!this.opendocs[this.docname]){this.check_doctype_conflict(this.docname);}
this.doc=get_local(this.doctype,this.docname);if(!this.setup_done)this.setup();this.runclientscript('set_perm',this.doctype,this.docname);cur_frm.cscript.is_onload=false;if(!this.opendocs[this.docname]){cur_frm.cscript.is_onload=true;this.setnewdoc(this.docname);}
if(this.doc.__islocal)
this.is_editable[this.docname]=1;this.editable=this.is_editable[this.docname];if(!this.doc.__archived&&(this.editable||(!this.editable&&this.meta.istable))){if(this.print_wrapper){$dh(this.print_wrapper);$ds(this.page_layout.wrapper);}
if(!this.meta.istable){this.refresh_header();this.sidebar&&this.sidebar.refresh();}
@ -1799,7 +1800,7 @@ _f.Frm.prototype.refresh_dependency=function(){var me=this;var doc=locals[this.d
dep_dict[guardian]=[];dep_dict[guardian][dep_dict[guardian].length]=f;has_dep=true;}}
if(!has_dep)return;for(var i=me.fields.length-1;i>=0;i--){var f=me.fields[i];f.guardian_has_value=true;if(f.df.depends_on){var v=doc[f.df.depends_on];if(f.df.depends_on.substr(0,5)=='eval:'){f.guardian_has_value=eval(f.df.depends_on.substr(5));}else if(f.df.depends_on.substr(0,3)=='fn:'){f.guardian_has_value=me.runclientscript(f.df.depends_on.substr(3),me.doctype,me.docname);}else{if(v||(v==0&&!v.substr)){}else{f.guardian_has_value=false;}}
if(f.guardian_has_value){if(f.grid)f.grid.show();else $ds(f.wrapper);}else{if(f.grid)f.grid.hide();else $dh(f.wrapper);}}}}
_f.Frm.prototype.setnewdoc=function(docname){this.check_doctype_conflict(docname);if(this.opendocs[docname]){this.docname=docname;return;}
_f.Frm.prototype.setnewdoc=function(docname){if(this.opendocs[docname]){this.docname=docname;return;}
Meta.make_local_dt(this.doctype,docname);this.docname=docname;var me=this;var viewname=docname;if(this.meta.issingle)viewname=this.doctype;this.runclientscript('onload',this.doctype,this.docname);this.is_editable[docname]=1;if(this.meta.read_only_onload)this.is_editable[docname]=0;this.opendocs[docname]=true;}
_f.Frm.prototype.edit_doc=function(){this.is_editable[this.docname]=true;this.refresh();}
_f.Frm.prototype.show_doc=function(dn){this.refresh(dn);}