Deleted master_type, master_name, credit_days, credit_limit fields from account
Warehouse account is linked via Warehouse field now, instead of master_name field patch to copy warehouse value from master_name to warehouse party_type and party field added in GL Entry and Journal Voucher Detail
This commit is contained in:
parent
fbc3d25d13
commit
be8ec39678
@ -12,8 +12,7 @@ cur_frm.cscript.refresh = function(doc, cdt, cdn) {
|
|||||||
cur_frm.toggle_display('account_name', doc.__islocal);
|
cur_frm.toggle_display('account_name', doc.__islocal);
|
||||||
|
|
||||||
// hide fields if group
|
// hide fields if group
|
||||||
cur_frm.toggle_display(['account_type', 'master_type', 'master_name',
|
cur_frm.toggle_display(['account_type', 'tax_rate'], doc.group_or_ledger=='Ledger')
|
||||||
'credit_days', 'credit_limit', 'tax_rate'], doc.group_or_ledger=='Ledger')
|
|
||||||
|
|
||||||
// disable fields
|
// disable fields
|
||||||
cur_frm.toggle_enable(['account_name', 'group_or_ledger', 'company'], false);
|
cur_frm.toggle_enable(['account_name', 'group_or_ledger', 'company'], false);
|
||||||
@ -29,10 +28,7 @@ cur_frm.cscript.refresh = function(doc, cdt, cdn) {
|
|||||||
} else {
|
} else {
|
||||||
// credit days and type if customer or supplier
|
// credit days and type if customer or supplier
|
||||||
cur_frm.set_intro(null);
|
cur_frm.set_intro(null);
|
||||||
cur_frm.toggle_display(['credit_days', 'credit_limit'], in_list(['Customer', 'Supplier'],
|
|
||||||
doc.master_type));
|
|
||||||
|
|
||||||
cur_frm.cscript.master_type(doc, cdt, cdn);
|
|
||||||
cur_frm.cscript.account_type(doc, cdt, cdn);
|
cur_frm.cscript.account_type(doc, cdt, cdn);
|
||||||
|
|
||||||
// show / hide convert buttons
|
// show / hide convert buttons
|
||||||
@ -40,22 +36,13 @@ cur_frm.cscript.refresh = function(doc, cdt, cdn) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cur_frm.cscript.master_type = function(doc, cdt, cdn) {
|
|
||||||
cur_frm.toggle_display(['credit_days', 'credit_limit'], in_list(['Customer', 'Supplier'],
|
|
||||||
doc.master_type));
|
|
||||||
|
|
||||||
cur_frm.toggle_display('master_name', doc.account_type=='Warehouse' ||
|
|
||||||
in_list(['Customer', 'Supplier'], doc.master_type));
|
|
||||||
}
|
|
||||||
|
|
||||||
cur_frm.add_fetch('parent_account', 'report_type', 'report_type');
|
cur_frm.add_fetch('parent_account', 'report_type', 'report_type');
|
||||||
cur_frm.add_fetch('parent_account', 'root_type', 'root_type');
|
cur_frm.add_fetch('parent_account', 'root_type', 'root_type');
|
||||||
|
|
||||||
cur_frm.cscript.account_type = function(doc, cdt, cdn) {
|
cur_frm.cscript.account_type = function(doc, cdt, cdn) {
|
||||||
if(doc.group_or_ledger=='Ledger') {
|
if(doc.group_or_ledger=='Ledger') {
|
||||||
cur_frm.toggle_display(['tax_rate'], doc.account_type == 'Tax');
|
cur_frm.toggle_display(['tax_rate'], doc.account_type == 'Tax');
|
||||||
cur_frm.toggle_display('master_name', doc.account_type=='Warehouse' ||
|
cur_frm.toggle_display('warehouse', doc.account_type=='Warehouse');
|
||||||
in_list(['Customer', 'Supplier'], doc.master_type));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,20 +85,6 @@ cur_frm.cscript.convert_to_group = function(doc, cdt, cdn) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
cur_frm.fields_dict['master_name'].get_query = function(doc) {
|
|
||||||
if (doc.master_type || doc.account_type=="Warehouse") {
|
|
||||||
var dt = doc.master_type || "Warehouse";
|
|
||||||
return {
|
|
||||||
doctype: dt,
|
|
||||||
query: "erpnext.accounts.doctype.account.account.get_master_name",
|
|
||||||
filters: {
|
|
||||||
"master_type": dt,
|
|
||||||
"company": doc.company
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cur_frm.fields_dict['parent_account'].get_query = function(doc) {
|
cur_frm.fields_dict['parent_account'].get_query = function(doc) {
|
||||||
return {
|
return {
|
||||||
filters: {
|
filters: {
|
||||||
|
@ -117,43 +117,10 @@
|
|||||||
"permlevel": 0
|
"permlevel": 0
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "credit_days",
|
"fieldname": "warehouse",
|
||||||
"fieldtype": "Int",
|
|
||||||
"hidden": 1,
|
|
||||||
"label": "Credit Days",
|
|
||||||
"oldfieldname": "credit_days",
|
|
||||||
"oldfieldtype": "Int",
|
|
||||||
"permlevel": 0,
|
|
||||||
"print_hide": 1
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldname": "credit_limit",
|
|
||||||
"fieldtype": "Currency",
|
|
||||||
"hidden": 1,
|
|
||||||
"label": "Credit Limit",
|
|
||||||
"oldfieldname": "credit_limit",
|
|
||||||
"oldfieldtype": "Currency",
|
|
||||||
"options": "Company:company:default_currency",
|
|
||||||
"permlevel": 0,
|
|
||||||
"print_hide": 1
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"description": "If this Account represents a Customer, Supplier or Employee, set it here.",
|
|
||||||
"fieldname": "master_type",
|
|
||||||
"fieldtype": "Select",
|
|
||||||
"label": "Master Type",
|
|
||||||
"oldfieldname": "master_type",
|
|
||||||
"oldfieldtype": "Select",
|
|
||||||
"options": "\nSupplier\nCustomer\nEmployee",
|
|
||||||
"permlevel": 0
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldname": "master_name",
|
|
||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
"label": "Master Name",
|
"label": "Warehouse",
|
||||||
"oldfieldname": "master_name",
|
"options": "Warehouse",
|
||||||
"oldfieldtype": "Link",
|
|
||||||
"options": "[Select]",
|
|
||||||
"permlevel": 0
|
"permlevel": 0
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -210,7 +177,7 @@
|
|||||||
"icon": "icon-money",
|
"icon": "icon-money",
|
||||||
"idx": 1,
|
"idx": 1,
|
||||||
"in_create": 1,
|
"in_create": 1,
|
||||||
"modified": "2014-06-19 18:27:58.109303",
|
"modified": "2014-08-26 18:18:30.173409",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Accounts",
|
"module": "Accounts",
|
||||||
"name": "Account",
|
"name": "Account",
|
||||||
|
@ -20,11 +20,7 @@ class Account(Document):
|
|||||||
self.name = self.account_name.strip() + ' - ' + \
|
self.name = self.account_name.strip() + ' - ' + \
|
||||||
frappe.db.get_value("Company", self.company, "abbr")
|
frappe.db.get_value("Company", self.company, "abbr")
|
||||||
|
|
||||||
def get_address(self):
|
|
||||||
return {'address': frappe.db.get_value(self.master_type, self.master_name, "address")}
|
|
||||||
|
|
||||||
def validate(self):
|
def validate(self):
|
||||||
self.validate_master_name()
|
|
||||||
self.validate_parent()
|
self.validate_parent()
|
||||||
self.validate_root_details()
|
self.validate_root_details()
|
||||||
self.validate_mandatory()
|
self.validate_mandatory()
|
||||||
@ -32,13 +28,6 @@ class Account(Document):
|
|||||||
self.validate_frozen_accounts_modifier()
|
self.validate_frozen_accounts_modifier()
|
||||||
self.validate_balance_must_be_debit_or_credit()
|
self.validate_balance_must_be_debit_or_credit()
|
||||||
|
|
||||||
def validate_master_name(self):
|
|
||||||
if self.master_type in ('Customer', 'Supplier') or self.account_type == "Warehouse":
|
|
||||||
if not self.master_name:
|
|
||||||
msgprint(_("Please enter Master Name once the account is created."))
|
|
||||||
elif not frappe.db.exists(self.master_type or self.account_type, self.master_name):
|
|
||||||
throw(_("Invalid Master Name"))
|
|
||||||
|
|
||||||
def validate_parent(self):
|
def validate_parent(self):
|
||||||
"""Fetch Parent Details and validate parent account"""
|
"""Fetch Parent Details and validate parent account"""
|
||||||
if self.parent_account:
|
if self.parent_account:
|
||||||
@ -123,18 +112,19 @@ class Account(Document):
|
|||||||
return
|
return
|
||||||
|
|
||||||
if self.account_type == "Warehouse":
|
if self.account_type == "Warehouse":
|
||||||
old_warehouse = cstr(frappe.db.get_value("Account", self.name, "master_name"))
|
if not self.warehouse:
|
||||||
if old_warehouse != cstr(self.master_name):
|
throw(_("Warehouse is mandatory if account type is Warehouse"))
|
||||||
|
|
||||||
|
old_warehouse = cstr(frappe.db.get_value("Account", self.name, "warehouse"))
|
||||||
|
if old_warehouse != cstr(self.warehouse):
|
||||||
if old_warehouse:
|
if old_warehouse:
|
||||||
self.validate_warehouse(old_warehouse)
|
self.validate_warehouse(old_warehouse)
|
||||||
if self.master_name:
|
if self.warehouse:
|
||||||
self.validate_warehouse(self.master_name)
|
self.validate_warehouse(self.warehouse)
|
||||||
else:
|
|
||||||
throw(_("Master Name is mandatory if account type is Warehouse"))
|
|
||||||
|
|
||||||
def validate_warehouse(self, warehouse):
|
def validate_warehouse(self, warehouse):
|
||||||
if frappe.db.get_value("Stock Ledger Entry", {"warehouse": warehouse}):
|
if frappe.db.get_value("Stock Ledger Entry", {"warehouse": warehouse}):
|
||||||
throw(_("Stock entries exist against warehouse {0} cannot re-assign or modify 'Master Name'").format(warehouse))
|
throw(_("Stock entries exist against warehouse {0}, hence you cannot re-assign or modify Warehouse").format(warehouse))
|
||||||
|
|
||||||
def update_nsm_model(self):
|
def update_nsm_model(self):
|
||||||
"""update lft, rgt indices for nested set model"""
|
"""update lft, rgt indices for nested set model"""
|
||||||
@ -226,14 +216,6 @@ class Account(Document):
|
|||||||
from frappe.utils.nestedset import rebuild_tree
|
from frappe.utils.nestedset import rebuild_tree
|
||||||
rebuild_tree("Account", "parent_account")
|
rebuild_tree("Account", "parent_account")
|
||||||
|
|
||||||
def get_master_name(doctype, txt, searchfield, start, page_len, filters):
|
|
||||||
conditions = (" and company='%s'"% filters["company"].replace("'", "\'")) if doctype == "Warehouse" else ""
|
|
||||||
|
|
||||||
return frappe.db.sql("""select name from `tab%s` where %s like %s %s
|
|
||||||
order by name limit %s, %s""" %
|
|
||||||
(filters["master_type"], searchfield, "%s", conditions, "%s", "%s"),
|
|
||||||
("%%%s%%" % txt, start, page_len), as_list=1)
|
|
||||||
|
|
||||||
def get_parent_account(doctype, txt, searchfield, start, page_len, filters):
|
def get_parent_account(doctype, txt, searchfield, start, page_len, filters):
|
||||||
return frappe.db.sql("""select name from tabAccount
|
return frappe.db.sql("""select name from tabAccount
|
||||||
where group_or_ledger = 'Group' and docstatus != 2 and company = %s
|
where group_or_ledger = 'Group' and docstatus != 2 and company = %s
|
||||||
|
6
erpnext/accounts/doctype/account/test_records.json
Normal file
6
erpnext/accounts/doctype/account/test_records.json
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"doctype": "Account",
|
||||||
|
"name": "_Test Account 1"
|
||||||
|
}
|
||||||
|
]
|
@ -47,6 +47,20 @@
|
|||||||
"permlevel": 0,
|
"permlevel": 0,
|
||||||
"search_index": 1
|
"search_index": 1
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "party_type",
|
||||||
|
"fieldtype": "Select",
|
||||||
|
"label": "Party Type",
|
||||||
|
"options": "\nCustomer\nSupplier",
|
||||||
|
"permlevel": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "party",
|
||||||
|
"fieldtype": "Link",
|
||||||
|
"label": "Party",
|
||||||
|
"options": "[Select]",
|
||||||
|
"permlevel": 0
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "cost_center",
|
"fieldname": "cost_center",
|
||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
@ -189,7 +203,7 @@
|
|||||||
"icon": "icon-list",
|
"icon": "icon-list",
|
||||||
"idx": 1,
|
"idx": 1,
|
||||||
"in_create": 1,
|
"in_create": 1,
|
||||||
"modified": "2014-06-23 08:07:30.678730",
|
"modified": "2014-08-26 17:56:49.147121",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Accounts",
|
"module": "Accounts",
|
||||||
"name": "GL Entry",
|
"name": "GL Entry",
|
||||||
|
10
erpnext/accounts/doctype/gl_entry/test_gl_entry.py
Normal file
10
erpnext/accounts/doctype/gl_entry/test_gl_entry.py
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors and Contributors
|
||||||
|
# See license.txt
|
||||||
|
|
||||||
|
import frappe
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
test_records = frappe.get_test_records('GL Entry')
|
||||||
|
|
||||||
|
class TestGLEntry(unittest.TestCase):
|
||||||
|
pass
|
6
erpnext/accounts/doctype/gl_entry/test_records.json
Normal file
6
erpnext/accounts/doctype/gl_entry/test_records.json
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"doctype": "GL Entry",
|
||||||
|
"name": "_Test GL Entry 1"
|
||||||
|
}
|
||||||
|
]
|
@ -41,6 +41,18 @@ erpnext.accounts.JournalVoucher = frappe.ui.form.Controller.extend({
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
me.frm.set_query("party", "entries", function(doc, cdt, cdn) {
|
||||||
|
var jvd = frappe.get_doc(cdt, cdn);
|
||||||
|
if(!jvd.party_type) {
|
||||||
|
frappe.throw(__("Please enter Party Type first"));
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
doctype: jvd.party_type
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
$.each([["against_voucher", "Purchase Invoice", "credit_to"],
|
$.each([["against_voucher", "Purchase Invoice", "credit_to"],
|
||||||
["against_invoice", "Sales Invoice", "debit_to"]], function(i, opts) {
|
["against_invoice", "Sales Invoice", "debit_to"]], function(i, opts) {
|
||||||
me.frm.set_query(opts[0], "entries", function(doc, cdt, cdn) {
|
me.frm.set_query(opts[0], "entries", function(doc, cdt, cdn) {
|
||||||
|
@ -41,6 +41,20 @@
|
|||||||
"fieldtype": "Column Break",
|
"fieldtype": "Column Break",
|
||||||
"permlevel": 0
|
"permlevel": 0
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "party_type",
|
||||||
|
"fieldtype": "Select",
|
||||||
|
"label": "Party Type",
|
||||||
|
"options": "\nCustomer\nSupplier",
|
||||||
|
"permlevel": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "party",
|
||||||
|
"fieldtype": "Link",
|
||||||
|
"label": "Party",
|
||||||
|
"options": "[Select]",
|
||||||
|
"permlevel": 0
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "balance",
|
"fieldname": "balance",
|
||||||
"fieldtype": "Currency",
|
"fieldtype": "Currency",
|
||||||
@ -174,7 +188,7 @@
|
|||||||
],
|
],
|
||||||
"idx": 1,
|
"idx": 1,
|
||||||
"istable": 1,
|
"istable": 1,
|
||||||
"modified": "2014-08-20 12:19:55.049973",
|
"modified": "2014-08-26 17:56:34.294770",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Accounts",
|
"module": "Accounts",
|
||||||
"name": "Journal Voucher Detail",
|
"name": "Journal Voucher Detail",
|
||||||
|
@ -457,7 +457,7 @@ class TestSalesInvoice(unittest.TestCase):
|
|||||||
order by account asc, debit asc""", si.name, as_dict=1)
|
order by account asc, debit asc""", si.name, as_dict=1)
|
||||||
self.assertTrue(gl_entries)
|
self.assertTrue(gl_entries)
|
||||||
|
|
||||||
stock_in_hand = frappe.db.get_value("Account", {"master_name": "_Test Warehouse - _TC"})
|
stock_in_hand = frappe.db.get_value("Account", {"warehouse": "_Test Warehouse - _TC"})
|
||||||
|
|
||||||
expected_gl_entries = sorted([
|
expected_gl_entries = sorted([
|
||||||
[si.debit_to, 630.0, 0.0],
|
[si.debit_to, 630.0, 0.0],
|
||||||
|
@ -93,7 +93,7 @@ def validate_total_debit_credit(total_debit, total_credit):
|
|||||||
def validate_account_for_auto_accounting_for_stock(gl_map):
|
def validate_account_for_auto_accounting_for_stock(gl_map):
|
||||||
if gl_map[0].voucher_type=="Journal Voucher":
|
if gl_map[0].voucher_type=="Journal Voucher":
|
||||||
aii_accounts = [d[0] for d in frappe.db.sql("""select name from tabAccount
|
aii_accounts = [d[0] for d in frappe.db.sql("""select name from tabAccount
|
||||||
where account_type = 'Warehouse' and ifnull(master_name, '')!=''""")]
|
where account_type = 'Warehouse' and ifnull(warehouse, '')!=''""")]
|
||||||
|
|
||||||
for entry in gl_map:
|
for entry in gl_map:
|
||||||
if entry.account in aii_accounts:
|
if entry.account in aii_accounts:
|
||||||
|
@ -136,9 +136,6 @@ def get_party_account(company, party, party_type):
|
|||||||
acc_head = frappe.db.get_value("Account", {"master_name":party,
|
acc_head = frappe.db.get_value("Account", {"master_name":party,
|
||||||
"master_type": party_type, "company": company})
|
"master_type": party_type, "company": company})
|
||||||
|
|
||||||
if not acc_head:
|
|
||||||
create_party_account(party, party_type, company)
|
|
||||||
|
|
||||||
return acc_head
|
return acc_head
|
||||||
|
|
||||||
def get_due_date(posting_date, party, party_type, account, company):
|
def get_due_date(posting_date, party, party_type, account, company):
|
||||||
@ -157,29 +154,3 @@ def get_due_date(posting_date, party, party_type, account, company):
|
|||||||
|
|
||||||
return due_date
|
return due_date
|
||||||
|
|
||||||
def create_party_account(party, party_type, company):
|
|
||||||
if not company:
|
|
||||||
frappe.throw(_("Company is required"))
|
|
||||||
|
|
||||||
company_details = frappe.db.get_value("Company", company,
|
|
||||||
["abbr", "receivables_group", "payables_group"], as_dict=True)
|
|
||||||
if not frappe.db.exists("Account", (party.strip() + " - " + company_details.abbr)):
|
|
||||||
parent_account = company_details.receivables_group \
|
|
||||||
if party_type=="Customer" else company_details.payables_group
|
|
||||||
if not parent_account:
|
|
||||||
frappe.throw(_("Please enter Account Receivable/Payable group in company master"))
|
|
||||||
|
|
||||||
# create
|
|
||||||
account = frappe.get_doc({
|
|
||||||
"doctype": "Account",
|
|
||||||
'account_name': party,
|
|
||||||
'parent_account': parent_account,
|
|
||||||
'group_or_ledger':'Ledger',
|
|
||||||
'company': company,
|
|
||||||
'master_type': party_type,
|
|
||||||
'master_name': party,
|
|
||||||
"freeze_account": "No",
|
|
||||||
"report_type": "Balance Sheet"
|
|
||||||
}).insert(ignore_permissions=True)
|
|
||||||
|
|
||||||
frappe.msgprint(_("Account Created: {0}").format(account.name))
|
|
||||||
|
@ -244,8 +244,8 @@ def get_stock_and_account_difference(account_list=None, posting_date=None):
|
|||||||
|
|
||||||
difference = {}
|
difference = {}
|
||||||
|
|
||||||
account_warehouse = dict(frappe.db.sql("""select name, master_name from tabAccount
|
account_warehouse = dict(frappe.db.sql("""select name, warehouse from tabAccount
|
||||||
where account_type = 'Warehouse' and ifnull(master_name, '') != ''
|
where account_type = 'Warehouse' and ifnull(warehouse, '') != ''
|
||||||
and name in (%s)""" % ', '.join(['%s']*len(account_list)), account_list))
|
and name in (%s)""" % ', '.join(['%s']*len(account_list)), account_list))
|
||||||
|
|
||||||
for account, warehouse in account_warehouse.items():
|
for account, warehouse in account_warehouse.items():
|
||||||
@ -322,39 +322,6 @@ def get_actual_expense(args):
|
|||||||
and fiscal_year='%(fiscal_year)s' and company='%(company)s' %(condition)s
|
and fiscal_year='%(fiscal_year)s' and company='%(company)s' %(condition)s
|
||||||
""" % (args))[0][0]
|
""" % (args))[0][0]
|
||||||
|
|
||||||
def rename_account_for(dt, olddn, newdn, merge, company=None):
|
|
||||||
if not company:
|
|
||||||
companies = [d[0] for d in frappe.db.sql("select name from tabCompany")]
|
|
||||||
else:
|
|
||||||
companies = [company]
|
|
||||||
|
|
||||||
for company in companies:
|
|
||||||
old_account = get_account_for(dt, olddn, company)
|
|
||||||
if old_account:
|
|
||||||
new_account = None
|
|
||||||
if not merge:
|
|
||||||
if old_account == add_abbr_if_missing(olddn, company):
|
|
||||||
new_account = frappe.rename_doc("Account", old_account, newdn)
|
|
||||||
else:
|
|
||||||
existing_new_account = get_account_for(dt, newdn, company)
|
|
||||||
new_account = frappe.rename_doc("Account", old_account,
|
|
||||||
existing_new_account or newdn, merge=True if existing_new_account else False)
|
|
||||||
|
|
||||||
frappe.db.set_value("Account", new_account or old_account, "master_name", newdn)
|
|
||||||
|
|
||||||
def add_abbr_if_missing(dn, company):
|
|
||||||
from erpnext.setup.doctype.company.company import get_name_with_abbr
|
|
||||||
return get_name_with_abbr(dn, company)
|
|
||||||
|
|
||||||
def get_account_for(account_for_doctype, account_for, company):
|
|
||||||
if account_for_doctype in ["Customer", "Supplier"]:
|
|
||||||
account_for_field = "master_type"
|
|
||||||
elif account_for_doctype == "Warehouse":
|
|
||||||
account_for_field = "account_type"
|
|
||||||
|
|
||||||
return frappe.db.get_value("Account", {account_for_field: account_for_doctype,
|
|
||||||
"master_name": account_for, "company": company})
|
|
||||||
|
|
||||||
def get_currency_precision(currency=None):
|
def get_currency_precision(currency=None):
|
||||||
if not currency:
|
if not currency:
|
||||||
currency = frappe.db.get_value("Company",
|
currency = frappe.db.get_value("Company",
|
||||||
|
@ -4,11 +4,8 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
import frappe
|
import frappe
|
||||||
import frappe.defaults
|
import frappe.defaults
|
||||||
|
|
||||||
from frappe.utils import cint
|
|
||||||
from frappe import msgprint, _
|
from frappe import msgprint, _
|
||||||
from frappe.model.naming import make_autoname
|
from frappe.model.naming import make_autoname
|
||||||
from erpnext.accounts.party import create_party_account
|
|
||||||
|
|
||||||
from erpnext.utilities.transaction_base import TransactionBase
|
from erpnext.utilities.transaction_base import TransactionBase
|
||||||
|
|
||||||
@ -19,8 +16,6 @@ class Supplier(TransactionBase):
|
|||||||
def autoname(self):
|
def autoname(self):
|
||||||
supp_master_name = frappe.defaults.get_global_default('supp_master_name')
|
supp_master_name = frappe.defaults.get_global_default('supp_master_name')
|
||||||
if supp_master_name == 'Supplier Name':
|
if supp_master_name == 'Supplier Name':
|
||||||
if frappe.db.exists("Customer", self.supplier_name):
|
|
||||||
frappe.msgprint(_("A Customer exists with same name"), raise_exception=1)
|
|
||||||
self.name = self.supplier_name
|
self.name = self.supplier_name
|
||||||
else:
|
else:
|
||||||
self.name = make_autoname(self.naming_series + '.#####')
|
self.name = make_autoname(self.naming_series + '.#####')
|
||||||
@ -33,10 +28,6 @@ class Supplier(TransactionBase):
|
|||||||
frappe.db.sql("""update `tabContact` set supplier_name=%s, modified=NOW()
|
frappe.db.sql("""update `tabContact` set supplier_name=%s, modified=NOW()
|
||||||
where supplier=%s""", (self.supplier_name, self.name))
|
where supplier=%s""", (self.supplier_name, self.name))
|
||||||
|
|
||||||
def update_credit_days_limit(self):
|
|
||||||
frappe.db.sql("""update tabAccount set credit_days = %s where name = %s""",
|
|
||||||
(cint(self.credit_days), self.name + " - " + self.get_company_abbr()))
|
|
||||||
|
|
||||||
def on_update(self):
|
def on_update(self):
|
||||||
if not self.naming_series:
|
if not self.naming_series:
|
||||||
self.naming_series = ''
|
self.naming_series = ''
|
||||||
@ -44,12 +35,6 @@ class Supplier(TransactionBase):
|
|||||||
self.update_address()
|
self.update_address()
|
||||||
self.update_contact()
|
self.update_contact()
|
||||||
|
|
||||||
# create account head
|
|
||||||
create_party_account(self.name, "Supplier", self.company)
|
|
||||||
|
|
||||||
# update credit days and limit in account
|
|
||||||
self.update_credit_days_limit()
|
|
||||||
|
|
||||||
def get_company_abbr(self):
|
def get_company_abbr(self):
|
||||||
return frappe.db.sql("select abbr from tabCompany where name=%s", self.company)[0][0]
|
return frappe.db.sql("select abbr from tabCompany where name=%s", self.company)[0][0]
|
||||||
|
|
||||||
@ -88,10 +73,6 @@ class Supplier(TransactionBase):
|
|||||||
self.delete_supplier_contact()
|
self.delete_supplier_contact()
|
||||||
self.delete_supplier_account()
|
self.delete_supplier_account()
|
||||||
|
|
||||||
def before_rename(self, olddn, newdn, merge=False):
|
|
||||||
from erpnext.accounts.utils import rename_account_for
|
|
||||||
rename_account_for("Supplier", olddn, newdn, merge)
|
|
||||||
|
|
||||||
def after_rename(self, olddn, newdn, merge=False):
|
def after_rename(self, olddn, newdn, merge=False):
|
||||||
set_field = ''
|
set_field = ''
|
||||||
if frappe.defaults.get_global_default('supp_master_name') == 'Supplier Name':
|
if frappe.defaults.get_global_default('supp_master_name') == 'Supplier Name':
|
||||||
|
@ -282,6 +282,6 @@ def get_voucherwise_gl_entries(future_stock_vouchers, posting_date):
|
|||||||
return gl_entries
|
return gl_entries
|
||||||
|
|
||||||
def get_warehouse_account():
|
def get_warehouse_account():
|
||||||
warehouse_account = dict(frappe.db.sql("""select master_name, name from tabAccount
|
warehouse_account = dict(frappe.db.sql("""select warehouse, name from tabAccount
|
||||||
where account_type = 'Warehouse' and ifnull(master_name, '') != ''"""))
|
where account_type = 'Warehouse' and ifnull(warehouse, '') != ''"""))
|
||||||
return warehouse_account
|
return warehouse_account
|
||||||
|
10
erpnext/patches/v4_2/party_model.py
Normal file
10
erpnext/patches/v4_2/party_model.py
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
|
||||||
|
# License: GNU General Public License v3. See license.txt
|
||||||
|
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
import frappe
|
||||||
|
|
||||||
|
def execute():
|
||||||
|
frappe.reload_doc("accounts", "doctype", "account")
|
||||||
|
frappe.db.sql("""update tabAccount set warehouse=master_name
|
||||||
|
where ifnull(account_type, '') = 'Warehouse' and ifnull(master_name, '') != ''""")
|
@ -4,12 +4,11 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
import frappe
|
import frappe
|
||||||
from frappe.model.naming import make_autoname
|
from frappe.model.naming import make_autoname
|
||||||
from frappe import msgprint, _
|
from frappe import _
|
||||||
import frappe.defaults
|
import frappe.defaults
|
||||||
|
|
||||||
|
|
||||||
from erpnext.utilities.transaction_base import TransactionBase
|
from erpnext.utilities.transaction_base import TransactionBase
|
||||||
from erpnext.accounts.party import create_party_account
|
|
||||||
|
|
||||||
class Customer(TransactionBase):
|
class Customer(TransactionBase):
|
||||||
def get_feed(self):
|
def get_feed(self):
|
||||||
@ -18,8 +17,6 @@ class Customer(TransactionBase):
|
|||||||
def autoname(self):
|
def autoname(self):
|
||||||
cust_master_name = frappe.defaults.get_global_default('cust_master_name')
|
cust_master_name = frappe.defaults.get_global_default('cust_master_name')
|
||||||
if cust_master_name == 'Customer Name':
|
if cust_master_name == 'Customer Name':
|
||||||
if frappe.db.exists("Supplier", self.customer_name):
|
|
||||||
msgprint(_("A Supplier exists with same name"), raise_exception=1)
|
|
||||||
self.name = self.customer_name
|
self.name = self.customer_name
|
||||||
else:
|
else:
|
||||||
self.name = make_autoname(self.naming_series+'.#####')
|
self.name = make_autoname(self.naming_series+'.#####')
|
||||||
@ -46,11 +43,6 @@ class Customer(TransactionBase):
|
|||||||
frappe.db.sql("""update `tabContact` set customer_name=%s, modified=NOW()
|
frappe.db.sql("""update `tabContact` set customer_name=%s, modified=NOW()
|
||||||
where customer=%s""", (self.customer_name, self.name))
|
where customer=%s""", (self.customer_name, self.name))
|
||||||
|
|
||||||
def update_credit_days_limit(self):
|
|
||||||
frappe.db.sql("""update tabAccount set credit_days = %s, credit_limit = %s
|
|
||||||
where master_type='Customer' and master_name = %s""",
|
|
||||||
(self.credit_days or 0, self.credit_limit or 0, self.name))
|
|
||||||
|
|
||||||
def create_lead_address_contact(self):
|
def create_lead_address_contact(self):
|
||||||
if self.lead_name:
|
if self.lead_name:
|
||||||
if not frappe.db.get_value("Address", {"lead": self.lead_name, "customer": self.name}):
|
if not frappe.db.get_value("Address", {"lead": self.lead_name, "customer": self.name}):
|
||||||
@ -78,13 +70,6 @@ class Customer(TransactionBase):
|
|||||||
self.update_lead_status()
|
self.update_lead_status()
|
||||||
self.update_address()
|
self.update_address()
|
||||||
self.update_contact()
|
self.update_contact()
|
||||||
|
|
||||||
# create account head
|
|
||||||
create_party_account(self.name, "Customer", self.company)
|
|
||||||
|
|
||||||
# update credit days and limit in account
|
|
||||||
self.update_credit_days_limit()
|
|
||||||
#create address and contact from lead
|
|
||||||
self.create_lead_address_contact()
|
self.create_lead_address_contact()
|
||||||
|
|
||||||
def validate_name_with_customer_group(self):
|
def validate_name_with_customer_group(self):
|
||||||
@ -121,10 +106,6 @@ class Customer(TransactionBase):
|
|||||||
if self.lead_name:
|
if self.lead_name:
|
||||||
frappe.db.sql("update `tabLead` set status='Interested' where name=%s",self.lead_name)
|
frappe.db.sql("update `tabLead` set status='Interested' where name=%s",self.lead_name)
|
||||||
|
|
||||||
def before_rename(self, olddn, newdn, merge=False):
|
|
||||||
from erpnext.accounts.utils import rename_account_for
|
|
||||||
rename_account_for("Customer", olddn, newdn, merge)
|
|
||||||
|
|
||||||
def after_rename(self, olddn, newdn, merge=False):
|
def after_rename(self, olddn, newdn, merge=False):
|
||||||
set_field = ''
|
set_field = ''
|
||||||
if frappe.defaults.get_global_default('cust_master_name') == 'Customer Name':
|
if frappe.defaults.get_global_default('cust_master_name') == 'Customer Name':
|
||||||
|
@ -73,7 +73,7 @@ class TestDeliveryNote(unittest.TestCase):
|
|||||||
dn.get("delivery_note_details")[0].cost_center = "Main - _TC"
|
dn.get("delivery_note_details")[0].cost_center = "Main - _TC"
|
||||||
|
|
||||||
stock_in_hand_account = frappe.db.get_value("Account",
|
stock_in_hand_account = frappe.db.get_value("Account",
|
||||||
{"master_name": dn.get("delivery_note_details")[0].warehouse})
|
{"warehouse": dn.get("delivery_note_details")[0].warehouse})
|
||||||
|
|
||||||
from erpnext.accounts.utils import get_balance_on
|
from erpnext.accounts.utils import get_balance_on
|
||||||
prev_bal = get_balance_on(stock_in_hand_account, dn.posting_date)
|
prev_bal = get_balance_on(stock_in_hand_account, dn.posting_date)
|
||||||
@ -128,7 +128,7 @@ class TestDeliveryNote(unittest.TestCase):
|
|||||||
dn.get("delivery_note_details")[0].qty = 1
|
dn.get("delivery_note_details")[0].qty = 1
|
||||||
|
|
||||||
stock_in_hand_account = frappe.db.get_value("Account",
|
stock_in_hand_account = frappe.db.get_value("Account",
|
||||||
{"master_name": dn.get("delivery_note_details")[0].warehouse})
|
{"warehouse": dn.get("delivery_note_details")[0].warehouse})
|
||||||
|
|
||||||
from erpnext.accounts.utils import get_balance_on
|
from erpnext.accounts.utils import get_balance_on
|
||||||
prev_bal = get_balance_on(stock_in_hand_account, dn.posting_date)
|
prev_bal = get_balance_on(stock_in_hand_account, dn.posting_date)
|
||||||
|
@ -64,9 +64,9 @@ class TestPurchaseReceipt(unittest.TestCase):
|
|||||||
self.assertTrue(gl_entries)
|
self.assertTrue(gl_entries)
|
||||||
|
|
||||||
stock_in_hand_account = frappe.db.get_value("Account",
|
stock_in_hand_account = frappe.db.get_value("Account",
|
||||||
{"master_name": pr.get("purchase_receipt_details")[0].warehouse})
|
{"warehouse": pr.get("purchase_receipt_details")[0].warehouse})
|
||||||
fixed_asset_account = frappe.db.get_value("Account",
|
fixed_asset_account = frappe.db.get_value("Account",
|
||||||
{"master_name": pr.get("purchase_receipt_details")[1].warehouse})
|
{"warehouse": pr.get("purchase_receipt_details")[1].warehouse})
|
||||||
|
|
||||||
expected_values = {
|
expected_values = {
|
||||||
stock_in_hand_account: [375.0, 0.0],
|
stock_in_hand_account: [375.0, 0.0],
|
||||||
|
@ -48,7 +48,7 @@ class TestStockEntry(unittest.TestCase):
|
|||||||
mr.submit()
|
mr.submit()
|
||||||
|
|
||||||
stock_in_hand_account = frappe.db.get_value("Account", {"account_type": "Warehouse",
|
stock_in_hand_account = frappe.db.get_value("Account", {"account_type": "Warehouse",
|
||||||
"master_name": mr.get("mtn_details")[0].t_warehouse})
|
"warehouse": mr.get("mtn_details")[0].t_warehouse})
|
||||||
|
|
||||||
self.check_stock_ledger_entries("Stock Entry", mr.name,
|
self.check_stock_ledger_entries("Stock Entry", mr.name,
|
||||||
[["_Test Item", "_Test Warehouse - _TC", 50.0]])
|
[["_Test Item", "_Test Warehouse - _TC", 50.0]])
|
||||||
@ -83,7 +83,7 @@ class TestStockEntry(unittest.TestCase):
|
|||||||
[["_Test Item", "_Test Warehouse - _TC", -40.0]])
|
[["_Test Item", "_Test Warehouse - _TC", -40.0]])
|
||||||
|
|
||||||
stock_in_hand_account = frappe.db.get_value("Account", {"account_type": "Warehouse",
|
stock_in_hand_account = frappe.db.get_value("Account", {"account_type": "Warehouse",
|
||||||
"master_name": mi.get("mtn_details")[0].s_warehouse})
|
"warehouse": mi.get("mtn_details")[0].s_warehouse})
|
||||||
|
|
||||||
self.check_gl_entries("Stock Entry", mi.name,
|
self.check_gl_entries("Stock Entry", mi.name,
|
||||||
sorted([
|
sorted([
|
||||||
@ -119,10 +119,10 @@ class TestStockEntry(unittest.TestCase):
|
|||||||
[["_Test Item", "_Test Warehouse - _TC", -45.0], ["_Test Item", "_Test Warehouse 1 - _TC", 45.0]])
|
[["_Test Item", "_Test Warehouse - _TC", -45.0], ["_Test Item", "_Test Warehouse 1 - _TC", 45.0]])
|
||||||
|
|
||||||
stock_in_hand_account = frappe.db.get_value("Account", {"account_type": "Warehouse",
|
stock_in_hand_account = frappe.db.get_value("Account", {"account_type": "Warehouse",
|
||||||
"master_name": mtn.get("mtn_details")[0].s_warehouse})
|
"warehouse": mtn.get("mtn_details")[0].s_warehouse})
|
||||||
|
|
||||||
fixed_asset_account = frappe.db.get_value("Account", {"account_type": "Warehouse",
|
fixed_asset_account = frappe.db.get_value("Account", {"account_type": "Warehouse",
|
||||||
"master_name": mtn.get("mtn_details")[0].t_warehouse})
|
"warehouse": mtn.get("mtn_details")[0].t_warehouse})
|
||||||
|
|
||||||
|
|
||||||
self.check_gl_entries("Stock Entry", mtn.name,
|
self.check_gl_entries("Stock Entry", mtn.name,
|
||||||
@ -174,7 +174,7 @@ class TestStockEntry(unittest.TestCase):
|
|||||||
repack.submit()
|
repack.submit()
|
||||||
|
|
||||||
stock_in_hand_account = frappe.db.get_value("Account", {"account_type": "Warehouse",
|
stock_in_hand_account = frappe.db.get_value("Account", {"account_type": "Warehouse",
|
||||||
"master_name": repack.get("mtn_details")[1].t_warehouse})
|
"warehouse": repack.get("mtn_details")[1].t_warehouse})
|
||||||
|
|
||||||
self.check_gl_entries("Stock Entry", repack.name,
|
self.check_gl_entries("Stock Entry", repack.name,
|
||||||
sorted([
|
sorted([
|
||||||
|
@ -29,7 +29,7 @@ class Warehouse(Document):
|
|||||||
self.validate_parent_account()
|
self.validate_parent_account()
|
||||||
|
|
||||||
warehouse_account = frappe.db.get_value("Account",
|
warehouse_account = frappe.db.get_value("Account",
|
||||||
{"account_type": "Warehouse", "company": self.company, "master_name": self.name},
|
{"account_type": "Warehouse", "company": self.company, "warehouse": self.name},
|
||||||
["name", "parent_account"])
|
["name", "parent_account"])
|
||||||
|
|
||||||
if warehouse_account and warehouse_account[1] != self.create_account_under:
|
if warehouse_account and warehouse_account[1] != self.create_account_under:
|
||||||
@ -42,8 +42,7 @@ class Warehouse(Document):
|
|||||||
|
|
||||||
def create_account_head(self):
|
def create_account_head(self):
|
||||||
if cint(frappe.defaults.get_global_default("auto_accounting_for_stock")):
|
if cint(frappe.defaults.get_global_default("auto_accounting_for_stock")):
|
||||||
if not frappe.db.get_value("Account", {"account_type": "Warehouse",
|
if not self.get_account(self.name):
|
||||||
"master_name": self.name}):
|
|
||||||
if self.get("__islocal") or not frappe.db.get_value(
|
if self.get("__islocal") or not frappe.db.get_value(
|
||||||
"Stock Ledger Entry", {"warehouse": self.name}):
|
"Stock Ledger Entry", {"warehouse": self.name}):
|
||||||
self.validate_parent_account()
|
self.validate_parent_account()
|
||||||
@ -54,7 +53,7 @@ class Warehouse(Document):
|
|||||||
'group_or_ledger':'Ledger',
|
'group_or_ledger':'Ledger',
|
||||||
'company':self.company,
|
'company':self.company,
|
||||||
"account_type": "Warehouse",
|
"account_type": "Warehouse",
|
||||||
"master_name": self.name,
|
"warehouse": self.name,
|
||||||
"freeze_account": "No"
|
"freeze_account": "No"
|
||||||
})
|
})
|
||||||
ac_doc.ignore_permissions = True
|
ac_doc.ignore_permissions = True
|
||||||
@ -89,8 +88,7 @@ class Warehouse(Document):
|
|||||||
else:
|
else:
|
||||||
frappe.db.sql("delete from `tabBin` where name = %s", d['name'])
|
frappe.db.sql("delete from `tabBin` where name = %s", d['name'])
|
||||||
|
|
||||||
warehouse_account = frappe.db.get_value("Account",
|
warehouse_account = self.get_account(self.name)
|
||||||
{"account_type": "Warehouse", "master_name": self.name})
|
|
||||||
if warehouse_account:
|
if warehouse_account:
|
||||||
frappe.delete_doc("Account", warehouse_account)
|
frappe.delete_doc("Account", warehouse_account)
|
||||||
|
|
||||||
@ -112,11 +110,33 @@ class Warehouse(Document):
|
|||||||
|
|
||||||
frappe.db.sql("delete from `tabBin` where warehouse=%s", olddn)
|
frappe.db.sql("delete from `tabBin` where warehouse=%s", olddn)
|
||||||
|
|
||||||
from erpnext.accounts.utils import rename_account_for
|
self.rename_account_for(olddn, newdn, merge)
|
||||||
rename_account_for("Warehouse", olddn, newdn, merge, self.company)
|
|
||||||
|
|
||||||
return new_warehouse
|
return new_warehouse
|
||||||
|
|
||||||
|
def rename_account_for(self, olddn, newdn, merge):
|
||||||
|
old_account = self.get_account(olddn)
|
||||||
|
|
||||||
|
if old_account:
|
||||||
|
new_account = None
|
||||||
|
if not merge:
|
||||||
|
if old_account == self.add_abbr_if_missing(olddn):
|
||||||
|
new_account = frappe.rename_doc("Account", old_account, newdn)
|
||||||
|
else:
|
||||||
|
existing_new_account = self.get_account(newdn)
|
||||||
|
new_account = frappe.rename_doc("Account", old_account,
|
||||||
|
existing_new_account or newdn, merge=True if existing_new_account else False)
|
||||||
|
|
||||||
|
frappe.db.set_value("Account", new_account or old_account, "warehouse", newdn)
|
||||||
|
|
||||||
|
def add_abbr_if_missing(self, dn):
|
||||||
|
from erpnext.setup.doctype.company.company import get_name_with_abbr
|
||||||
|
return get_name_with_abbr(dn, self.company)
|
||||||
|
|
||||||
|
def get_account(self, warehouse):
|
||||||
|
return frappe.db.get_value("Account", {"account_type": "Warehouse",
|
||||||
|
"warehouse": warehouse, "company": self.company})
|
||||||
|
|
||||||
def after_rename(self, olddn, newdn, merge=False):
|
def after_rename(self, olddn, newdn, merge=False):
|
||||||
if merge:
|
if merge:
|
||||||
self.recalculate_bin_qty(newdn)
|
self.recalculate_bin_qty(newdn)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user