[selling/buying] [fixes] updated js files of various doctypes related to selling/g/buying

This commit is contained in:
Anand Doshi
2013-05-27 19:29:07 +05:30
parent 149b461e62
commit fc77718a3d
21 changed files with 451 additions and 1290 deletions

View File

@@ -17,10 +17,28 @@
cur_frm.cscript.tname = "Purchase Invoice Item";
cur_frm.cscript.fname = "entries";
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.PurchaseInvoiceController = erpnext.buying.BuyingController.extend({
wn.provide("erpnext.accounts");
erpnext.accounts.PurchaseInvoiceController = erpnext.buying.BuyingController.extend({
setup: function() {
this._super();
},
onload: function() {
this._super();
if(!this.frm.doc.__islocal) {
// show credit_to in print format
if(!this.frm.doc.supplier && this.frm.doc.credit_to) {
this.frm.set_df_property("credit_to", "print_hide", 0);
}
}
},
refresh: function(doc) {
this._super();
@@ -34,6 +52,20 @@ erpnext.buying.PurchaseInvoiceController = erpnext.buying.BuyingController.exten
cur_frm.cscript.is_opening(doc);
},
credit_to: function() {
this.supplier();
},
write_off_amount: function() {
this.calculate_outstanding_amount();
this.frm.refresh_fields();
},
allocated_amount: function() {
this.calculate_total_advance();
this.frm.refresh_fields();
},
});
// for backward compatibility: combine new and previous states
@@ -55,23 +87,6 @@ cur_frm.fields_dict.contact_person.on_new = function(dn) {
}
cur_frm.cscript.credit_to = function(doc,dt,dn) {
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);
}
cur_frm.fields_dict['entries'].grid.onrowadd = function(doc, cdt, cdn){
cl = getchildren('Purchase Invoice Item', doc.name, cur_frm.cscript.fname, doc.doctype);
@@ -95,17 +110,6 @@ cur_frm.cscript.is_opening = function(doc, dt, dn) {
if (doc.is_opening == 'Yes') unhide_field('aging_date');
}
cur_frm.cscript.write_off_amount = function(doc) {
doc.total_amount_to_pay = flt(doc.grand_total) - flt(doc.write_off_amount);
doc.outstanding_amount = flt(doc.total_amount_to_pay) - flt(doc.total_advance);
refresh_many(['outstanding_amount', 'total_amount_to_pay']);
}
cur_frm.cscript.recalculate = function(doc, cdt, cdn) {
cur_frm.cscript.calculate_tax(doc,cdt,cdn);
calc_total_advance(doc,cdt,cdn);
}
cur_frm.cscript.get_items = function(doc, dt, dn) {
var callback = function(r,rt) {
unhide_field(['supplier_address', 'contact_person']);
@@ -114,11 +118,6 @@ cur_frm.cscript.get_items = function(doc, dt, dn) {
$c_obj(make_doclist(dt,dn),'pull_details','',callback);
}
cur_frm.cscript.allocated_amount = function(doc,cdt,cdn) {
calc_total_advance(doc, cdt, cdn);
}
cur_frm.cscript.make_bank_voucher = function() {
wn.call({
method: "accounts.doctype.journal_voucher.journal_voucher.get_default_bank_cash_account",
@@ -204,21 +203,6 @@ cur_frm.cscript.cost_center = function(doc, cdt, cdn){
refresh_field('entries');
}
calc_total_advance = function(doc,cdt,cdn) {
var doc = locals[doc.doctype][doc.name];
var el = getchildren('Purchase Invoice Advance',doc.name,'advance_allocation_details')
var total_advance = 0;
for(var i in el) {
if (! el[i].allocated_amount == 0) {
total_advance += flt(el[i].allocated_amount);
}
}
doc.total_amount_to_pay = flt(doc.grand_total) - flt(doc.write_off_amount);
doc.total_advance = flt(total_advance);
doc.outstanding_amount = flt(doc.total_amount_to_pay) - flt(total_advance);
refresh_many(['total_advance','outstanding_amount', 'total_amount_to_pay']);
}
cur_frm.cscript.make_jv = function(doc, dt, dn, bank_account) {
var jv = wn.model.make_new_doc_and_get_name('Journal Voucher');
jv = locals['Journal Voucher'][jv];

View File

@@ -22,17 +22,20 @@ cur_frm.cscript.sales_team_fname = "sales_team";
// print heading
cur_frm.pformat.print_heading = 'Invoice';
wn.require('app/selling/doctype/sales_common/sales_common.js');
wn.require('app/accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.js');
wn.require('app/utilities/doctype/sms_control/sms_control.js');
wn.require('app/selling/doctype/sales_common/sales_common.js');
erpnext.selling.SalesInvoiceController = erpnext.selling.SellingController.extend({
wn.provide("erpnext.accounts");
erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.extend({
onload: function() {
this._super();
// show debit_to in print format
if(!this.frm.doc.customer && this.frm.doc.debit_to) {
this.frm.set_df_property("debit_to", "print_hide", 0);
if(!this.frm.doc.__islocal) {
// show debit_to in print format
if(!this.frm.doc.customer && this.frm.doc.debit_to) {
this.frm.set_df_property("debit_to", "print_hide", 0);
}
}
},
@@ -41,10 +44,6 @@ erpnext.selling.SalesInvoiceController = erpnext.selling.SellingController.exten
cur_frm.cscript.is_opening(doc, dt, dn);
// Show / Hide button
cur_frm.clear_custom_buttons();
// if (!cur_frm.cscript.is_onload) cur_frm.cscript.hide_price_list_currency(doc, dt, dn);
if(doc.docstatus==1) {
cur_frm.add_custom_button('View Ledger', cur_frm.cscript.view_ledger_entry);
cur_frm.add_custom_button('Send SMS', cur_frm.cscript.send_sms);
@@ -78,10 +77,39 @@ erpnext.selling.SalesInvoiceController = erpnext.selling.SellingController.exten
debit_to: function() {
this.customer();
},
allocated_amount: function() {
this.calculate_total_advance();
this.frm.refresh_fields();
},
write_off_outstanding_amount_automatically: function() {
if(cint(this.frm.doc.write_off_outstanding_amount_automatically)) {
wn.model.round_floats_in(this.frm.doc, ["grand_total", "paid_amount"]);
this.frm.set_value("write_off_amount",
flt(this.frm.doc.grand_total - this.frm.doc.paid_amount), precision("write_off_amount"));
}
this.frm.runclientscript("write_off_amount");
// TODO doubt?
// if write off amount = grand total - paid amount
// then why is outstanding amount = grand total - write off amount - paid amount - advance
// when write off amount already is grand total - paid amount!
},
write_off_amount: function() {
this.calculate_outstanding_amount();
this.frm.refresh_fields();
},
paid_amount: function() {
this.write_off_outstanding_amount_automatically();
},
});
// for backward compatibility: combine new and previous states
$.extend(cur_frm.cscript, new erpnext.selling.SalesInvoiceController({frm: cur_frm}));
$.extend(cur_frm.cscript, new erpnext.accounts.SalesInvoiceController({frm: cur_frm}));
// Hide Fields
// ------------
@@ -129,35 +157,10 @@ cur_frm.cscript.update_stock = function(doc, dt, dn) {
cur_frm.cscript.hide_fields(doc, dt, dn);
}
cur_frm.cscript.warehouse = function(doc, cdt , cdn) {
var d = locals[cdt][cdn];
if (!d.item_code) { msgprint("please enter item code first"); return };
if (d.warehouse) {
arg = "{'item_code':'" + d.item_code + "','warehouse':'" + d.warehouse +"'}";
get_server_fields('get_actual_qty',arg,'entries',doc,cdt,cdn,1);
}
}
cur_frm.cscript.customer_address = cur_frm.cscript.contact_person = function(doc,dt,dn) {
if(doc.customer) get_server_fields('get_customer_address', JSON.stringify({customer: doc.customer, address: doc.customer_address, contact: doc.contact_person}),'', doc, dt, dn, 1);
}
cur_frm.cscript.write_off_outstanding_amount_automatically = function(doc) {
if (doc.write_off_outstanding_amount_automatically == 1)
doc.write_off_amount = flt(doc.grand_total) - flt(doc.paid_amount);
doc.outstanding_amount = flt(doc.grand_total) - flt(doc.paid_amount) - flt(doc.write_off_amount);
refresh_field(['write_off_amount', 'outstanding_amount']);
}
cur_frm.cscript.paid_amount = function(doc) {
cur_frm.cscript.write_off_outstanding_amount_automatically(doc);
}
cur_frm.cscript.write_off_amount = function(doc) {
cur_frm.cscript.write_off_outstanding_amount_automatically(doc);
}
cur_frm.fields_dict['entries'].grid.onrowadd = function(doc, cdt, cdn){
cl = getchildren('Sales Invoice Item', doc.name, cur_frm.cscript.fname, doc.doctype);
@@ -193,12 +196,6 @@ cur_frm.cscript.get_items = function(doc, dt, dn) {
// Allocated Amount in advances table
// -----------------------------------
cur_frm.cscript.allocated_amount = function(doc,cdt,cdn){
cur_frm.cscript.calc_adjustment_amount(doc,cdt,cdn);
}
//Make Delivery Note Button
//-----------------------------
@@ -363,19 +360,6 @@ cur_frm.cscript.cost_center = function(doc, cdt, cdn){
refresh_field(cur_frm.cscript.fname);
}
cur_frm.cscript.calc_adjustment_amount = function(doc,cdt,cdn) {
var doc = locals[doc.doctype][doc.name];
var el = getchildren('Sales Invoice Advance',doc.name,'advance_adjustment_details');
var total_adjustment_amt = 0
for(var i in el) {
total_adjustment_amt += flt(el[i].allocated_amount)
}
doc.total_advance = flt(total_adjustment_amt);
doc.outstanding_amount = flt(doc.grand_total) - flt(total_adjustment_amt) - flt(doc.paid_amount) - flt(doc.write_off_amount);
refresh_many(['total_advance','outstanding_amount']);
}
// Make Journal Voucher
// --------------------
cur_frm.cscript.make_jv = function(doc, dt, dn, bank_account) {

View File

@@ -599,15 +599,6 @@ class DocType(SellingController):
get_obj('Stock Ledger', 'Stock Ledger').update_stock(self.values)
def get_actual_qty(self,args):
args = eval(args)
actual_qty = webnotes.conn.sql("select actual_qty from `tabBin` where item_code = '%s' and warehouse = '%s'" % (args['item_code'], args['warehouse']), as_dict=1)
ret = {
'actual_qty' : actual_qty and flt(actual_qty[0]['actual_qty']) or 0
}
return ret
def make_gl_entries(self):
from accounts.general_ledger import make_gl_entries, merge_similar_entries