aii: default account from company
This commit is contained in:
parent
fbafced1e4
commit
80abad2ee0
@ -444,6 +444,9 @@ class DocType(BuyingController):
|
||||
|
||||
# item gl entries
|
||||
stock_item_and_auto_inventory_accounting = False
|
||||
if auto_inventory_accounting:
|
||||
stock_acocunt = self.get_default_account("stock_received_but_not_billed")
|
||||
|
||||
for item in self.doclist.get({"parentfield": "entries"}):
|
||||
if auto_inventory_accounting and item.item_code in self.stock_items:
|
||||
if flt(item.valuation_rate):
|
||||
@ -455,7 +458,7 @@ class DocType(BuyingController):
|
||||
|
||||
gl_entries.append(
|
||||
self.get_gl_dict({
|
||||
"account": "Stock Received But Not Billed - %s" % (self.company_abbr,),
|
||||
"account": stock_acocunt,
|
||||
"against": self.doc.credit_to,
|
||||
"debit": flt(item.valuation_rate) * flt(item.conversion_factor) \
|
||||
* flt(item.qty),
|
||||
@ -480,7 +483,7 @@ class DocType(BuyingController):
|
||||
# this will balance out valuation amount included in cost of goods sold
|
||||
gl_entries.append(
|
||||
self.get_gl_dict({
|
||||
"account": "Expenses Included In Valuation - %s" % (self.company_abbr,),
|
||||
"account": self.get_default_account("expenses_included_in_valuation"),
|
||||
"cost_center": "Auto Inventory Accounting - %s" % self.company_abbr,
|
||||
"against": self.doc.credit_to,
|
||||
"credit": valuation_tax,
|
||||
|
@ -704,9 +704,9 @@ class DocType(SellingController):
|
||||
|
||||
if auto_inventory_accounting:
|
||||
if cint(self.doc.is_pos) and cint(self.doc.update_stock):
|
||||
stock_account = self.get_stock_in_hand_account()
|
||||
stock_account = self.get_default_account("stock_in_hand_account")
|
||||
else:
|
||||
stock_account = "Stock Delivered But Not Billed - %s" % (self.company_abbr,)
|
||||
stock_account = self.get_default_account("stock_delivered_but_not_billed")
|
||||
|
||||
for item in self.doclist.get({"parentfield": "entries"}):
|
||||
# income account gl entries
|
||||
@ -794,7 +794,8 @@ class DocType(SellingController):
|
||||
stock_ledger_entries = item_sales_bom = None
|
||||
|
||||
for item in self.doclist.get({"parentfield": "entries"}):
|
||||
if item.item_code in self.stock_items:
|
||||
if item.item_code in self.stock_items or \
|
||||
(item_sales_bom and item_sales_bom.get(item.item_code)):
|
||||
item.buying_amount = self.get_item_buying_amount(item, stock_ledger_entries,
|
||||
item_sales_bom)
|
||||
webnotes.conn.set_value("Sales Invoice Item", item.name,
|
||||
|
@ -71,15 +71,15 @@ class AccountsController(TransactionBase):
|
||||
"advance_amount": flt(d.amount),
|
||||
"allocate_amount": 0
|
||||
})
|
||||
|
||||
def get_stock_in_hand_account(self):
|
||||
stock_in_hand_account = webnotes.conn.get_value("Company", self.doc.company, "stock_in_hand_account")
|
||||
if not stock_in_hand_account:
|
||||
msgprint(_("Missing") + ": "
|
||||
+ _(webnotes.get_doctype("company").get_label("stock_in_hand_account")
|
||||
+ " " + _("for Company") + " " + self.doc.company), raise_exception=True)
|
||||
|
||||
return stock_in_hand_account
|
||||
def get_default_account(self, account_for):
|
||||
account = webnotes.conn.get_value("Company", self.doc.company, account_for)
|
||||
if not account:
|
||||
msgprint(_("Please mention default account for '") +
|
||||
_(webnotes.get_doctype("company").get_label(account_for) +
|
||||
_("' in Company: ") + self.doc.company), raise_exception=True)
|
||||
|
||||
return account
|
||||
|
||||
@property
|
||||
def stock_items(self):
|
||||
@ -88,7 +88,7 @@ class AccountsController(TransactionBase):
|
||||
self._stock_items = [r[0] for r in webnotes.conn.sql("""select name
|
||||
from `tabItem` where name in (%s) and is_stock_item='Yes'""" % \
|
||||
(", ".join((["%s"]*len(item_codes))),), item_codes)]
|
||||
|
||||
|
||||
return self._stock_items
|
||||
|
||||
@property
|
||||
@ -96,4 +96,9 @@ class AccountsController(TransactionBase):
|
||||
if not hasattr(self, "_abbr"):
|
||||
self._abbr = webnotes.conn.get_value("Company", self.doc.company, "abbr")
|
||||
|
||||
return self._abbr
|
||||
return self._abbr
|
||||
|
||||
|
||||
@webnotes.whitelist()
|
||||
def get_default_account(account_for, company):
|
||||
return webnotes.conn.get_value("Company", company, account_for)
|
@ -20,7 +20,7 @@ from controllers.accounts_controller import AccountsController
|
||||
|
||||
class StockController(AccountsController):
|
||||
def make_gl_entries(self, against_stock_account, amount, cost_center=None):
|
||||
stock_in_hand_account = self.get_stock_in_hand_account()
|
||||
stock_in_hand_account = self.get_default_account("stock_in_hand_account")
|
||||
|
||||
if amount:
|
||||
gl_entries = [
|
||||
|
@ -214,6 +214,11 @@ class DocType:
|
||||
"Stock Adjustment - " + self.doc.abbr):
|
||||
webnotes.conn.set(self.doc, "stock_adjustment_account", "Stock Adjustment - " +
|
||||
self.doc.abbr)
|
||||
|
||||
if not self.doc.expenses_included_in_valuation and webnotes.conn.exists("Account",
|
||||
"Expenses Included In Valuation - " + self.doc.abbr):
|
||||
webnotes.conn.set(self.doc, "expenses_included_in_valuation",
|
||||
"Expenses Included In Valuation - " + self.doc.abbr)
|
||||
|
||||
# Create default cost center
|
||||
# ---------------------------------------------------
|
||||
|
@ -2,7 +2,7 @@
|
||||
{
|
||||
"creation": "2013-02-27 09:38:05",
|
||||
"docstatus": 0,
|
||||
"modified": "2013-03-18 16:34:04",
|
||||
"modified": "2013-03-19 12:52:00",
|
||||
"modified_by": "Administrator",
|
||||
"owner": "Administrator"
|
||||
},
|
||||
@ -194,6 +194,13 @@
|
||||
"label": "Stock Adjustment Account",
|
||||
"options": "Account"
|
||||
},
|
||||
{
|
||||
"doctype": "DocField",
|
||||
"fieldname": "expenses_included_in_valuation",
|
||||
"fieldtype": "Link",
|
||||
"label": "Expenses Included In Valuation",
|
||||
"options": "Account"
|
||||
},
|
||||
{
|
||||
"doctype": "DocField",
|
||||
"fieldname": "col_break23",
|
||||
|
@ -1,8 +1,8 @@
|
||||
[
|
||||
{
|
||||
"creation": "2013-02-19 12:28:27",
|
||||
"creation": "2013-02-21 14:54:43",
|
||||
"docstatus": 0,
|
||||
"modified": "2013-02-20 14:09:00",
|
||||
"modified": "2013-03-19 14:46:49",
|
||||
"modified_by": "Administrator",
|
||||
"owner": "Administrator"
|
||||
},
|
||||
@ -403,7 +403,7 @@
|
||||
"fieldname": "emp_created_by",
|
||||
"fieldtype": "Select",
|
||||
"label": "Employee Records to be created by ",
|
||||
"options": "\nNaming Series\nEmployee Number"
|
||||
"options": "Naming Series\nEmployee Number"
|
||||
},
|
||||
{
|
||||
"doctype": "DocField",
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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;
|
@ -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});
|
Loading…
x
Reference in New Issue
Block a user