aii: default account from company

This commit is contained in:
Nabin Hait
2013-03-19 18:18:52 +05:30
parent fbafced1e4
commit 80abad2ee0
11 changed files with 130 additions and 50 deletions

View File

@@ -400,12 +400,14 @@ class DocType(SellingController):
if stock_ledger_entries:
for item in self.doclist.get({"parentfield": "delivery_note_details"}):
buying_amount = get_buying_amount(item.item_code, item.warehouse, -1*item.qty,
self.doc.doctype, self.doc.name, item.name, stock_ledger_entries,
item_sales_bom)
item.buying_amount = buying_amount > 0 and buying_amount or 0
webnotes.conn.set_value("Delivery Note Item", item.name, "buying_amount",
item.buying_amount)
if item.item_code in self.stock_items or \
(item_sales_bom and item_sales_bom.get(item.item_code)):
buying_amount = get_buying_amount(item.item_code, item.warehouse, -1*item.qty,
self.doc.doctype, self.doc.name, item.name, stock_ledger_entries,
item_sales_bom)
item.buying_amount = buying_amount > 0 and buying_amount or 0
webnotes.conn.set_value("Delivery Note Item", item.name, "buying_amount",
item.buying_amount)
self.validate_warehouse()
@@ -420,7 +422,7 @@ class DocType(SellingController):
if not cint(webnotes.defaults.get_global_default("auto_inventory_accounting")):
return
against_stock_account = "Stock Delivered But Not Billed - %s" % (self.company_abbr,)
against_stock_account = self.get_default_account("stock_delivered_but_not_billed")
total_buying_amount = self.get_total_buying_amount()
super(DocType, self).make_gl_entries(against_stock_account, -1*total_buying_amount)

View File

@@ -318,7 +318,7 @@ class DocType(BuyingController):
if not cint(webnotes.defaults.get_global_default("auto_inventory_accounting")):
return
against_stock_account = "Stock Received But Not Billed - %s" % (self.company_abbr,)
against_stock_account = self.get_default_account("stock_received_but_not_billed")
total_valuation_amount = self.get_total_valuation_amount()
super(DocType, self).make_gl_entries(against_stock_account, total_valuation_amount)

View File

@@ -18,6 +18,47 @@ wn.require("public/app/js/controllers/stock_controller.js");
wn.provide("erpnext.stock");
erpnext.stock.StockEntry = erpnext.stock.StockController.extend({
onload: function() {
this.set_default_account();
},
set_default_account: function() {
var me = this;
if (sys_defaults.auto_inventory_accounting && !this.frm.doc.expense_adjustment_account) {
if (this.frm.doc.purpose == "Sales Return")
account_for = "stock_delivered_but_not_billed";
else if (this.frm.doc.purpose == "Purchase Return")
account_for = "stock_received_but_not_billed";
else account_for = "stock_adjustment_account";
this.frm.call({
method: "controllers.accounts_controller.get_default_account",
args: {
"account_for": account_for,
"company": this.frm.doc.company
},
callback: function(r) {
if (!r.exc) me.frm.set_value("expense_adjustment_account", r.message);
}
});
}
},
setup: function() {
var me = this;
if (sys_defaults.auto_inventory_accounting) {
this.frm.add_fetch("company", "expense_adjustment_account", "stock_adjustment_account");
this.frm.fields_dict["expense_adjustment_account"].get_query = function() {
return {
"query": "accounts.utils.get_account_list",
"filters": { "company": me.frm.doc.company }
}
}
}
},
onload_post_render: function() {
if(this.frm.doc.__islocal && (this.frm.doc.production_order || this.frm.doc.bom_no)
&& !getchildren('Stock Entry Detail', this.frm.doc.name, 'mtn_details').length) {
@@ -234,11 +275,4 @@ cur_frm.cscript.validate_items = function(doc) {
cur_frm.fields_dict.customer.get_query = erpnext.utils.customer_query;
cur_frm.fields_dict.supplier.get_query = erpnext.utils.supplier_query;
cur_frm.fields_dict["expense_adjustment_account"].get_query = function(doc) {
return {
"query": "accounts.utils.get_account_list",
"filters": { "company": doc.company }
}
}
cur_frm.fields_dict.supplier.get_query = erpnext.utils.supplier_query;

View File

@@ -18,10 +18,44 @@ wn.require("public/app/js/controllers/stock_controller.js");
wn.provide("erpnext.stock");
erpnext.stock.StockReconciliation = erpnext.stock.StockController.extend({
setup: function() {
this.frm.add_fetch("company", "stock_adjustment_account", "expense_account");
onload: function() {
this.set_default_expense_account();
},
set_default_expense_account: function() {
var me = this;
if (sys_defaults.auto_inventory_accounting && !this.frm.doc.expense_account) {
this.frm.call({
method: "controllers.accounts_controller.get_default_account",
args: {
"account_for": "stock_adjustment_account",
"company": this.frm.doc.company
},
callback: function(r) {
if (!r.exc) me.frm.set_value("expense_account", r.message);
}
});
}
},
setup: function() {
var me = this;
this.frm.add_fetch("company", "expense_account", "stock_adjustment_account");
this.frm.fields_dict["expense_account"].get_query = function() {
return {
"query": "accounts.utils.get_account_list",
"filters": {
"is_pl_account": "Yes",
"debit_or_credit": "Debit",
"company": me.frm.doc.company
}
}
}
},
refresh: function() {
if(this.frm.doc.docstatus===0) {
this.show_download_template();
@@ -126,15 +160,4 @@ erpnext.stock.StockReconciliation = erpnext.stock.StockController.extend({
},
});
cur_frm.cscript = new erpnext.stock.StockReconciliation({frm: cur_frm});
cur_frm.fields_dict["expense_account"].get_query = function(doc) {
return {
"query": "accounts.utils.get_account_list",
"filters": {
"is_pl_account": "Yes",
"debit_or_credit": "Debit",
"company": doc.company
}
}
}
cur_frm.cscript = new erpnext.stock.StockReconciliation({frm: cur_frm});