added get_supplier_details and commonified invoice functions
This commit is contained in:
parent
21d324c597
commit
49dd7bee87
@ -156,10 +156,10 @@ erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.exte
|
|||||||
},
|
},
|
||||||
|
|
||||||
customer: function() {
|
customer: function() {
|
||||||
if(this.frm.updating_customer_details)
|
if(this.frm.updating_party_details)
|
||||||
return;
|
return;
|
||||||
erpnext.selling.get_customer_details(this.frm,
|
erpnext.selling.get_party_details(this.frm,
|
||||||
"erpnext.accounts.doctype.sales_invoice.sales_invoice.get_customer_details",
|
"erpnext.accounts.doctype.sales_invoice.sales_invoice.get_party_details",
|
||||||
{
|
{
|
||||||
posting_date: this.frm.doc.posting_date,
|
posting_date: this.frm.doc.posting_date,
|
||||||
company: this.frm.doc.company,
|
company: this.frm.doc.company,
|
||||||
|
@ -15,6 +15,8 @@ from webnotes.model.bean import getlist
|
|||||||
from webnotes.model.code import get_obj
|
from webnotes.model.code import get_obj
|
||||||
from webnotes import _, msgprint
|
from webnotes import _, msgprint
|
||||||
|
|
||||||
|
from erpnext.accounts.party import get_party_account, get_due_date
|
||||||
|
|
||||||
month_map = {'Monthly': 1, 'Quarterly': 3, 'Half-yearly': 6, 'Yearly': 12}
|
month_map = {'Monthly': 1, 'Quarterly': 3, 'Half-yearly': 6, 'Yearly': 12}
|
||||||
|
|
||||||
from erpnext.controllers.selling_controller import SellingController
|
from erpnext.controllers.selling_controller import SellingController
|
||||||
@ -149,7 +151,7 @@ class DocType(SellingController):
|
|||||||
self.set_pos_fields(for_validate)
|
self.set_pos_fields(for_validate)
|
||||||
|
|
||||||
if not self.doc.debit_to:
|
if not self.doc.debit_to:
|
||||||
self.doc.debit_to = get_customer_account(self.doc.company, self.doc.customer)
|
self.doc.debit_to = get_party_account(self.doc.company, self.doc.customer, "Customer")
|
||||||
if not self.doc.due_date:
|
if not self.doc.due_date:
|
||||||
self.doc.due_date = get_due_date(self.doc.posting_date, self.doc.customer,
|
self.doc.due_date = get_due_date(self.doc.posting_date, self.doc.customer,
|
||||||
self.doc.debit_to, self.doc.company)
|
self.doc.debit_to, self.doc.company)
|
||||||
@ -844,59 +846,6 @@ def assign_task_to_owner(inv, msg, users):
|
|||||||
}
|
}
|
||||||
assign_to.add(args)
|
assign_to.add(args)
|
||||||
|
|
||||||
@webnotes.whitelist()
|
|
||||||
def get_customer_details(company, customer, debit_to, posting_date):
|
|
||||||
if not webnotes.has_permission("Customer", "read", customer):
|
|
||||||
webnotes.throw("No Permission")
|
|
||||||
|
|
||||||
from erpnext.selling.doctype.customer.customer import get_customer_details
|
|
||||||
|
|
||||||
if customer:
|
|
||||||
debit_to = get_customer_account(company, customer)
|
|
||||||
elif debit_to:
|
|
||||||
customer = webnotes.conn.get_value('Account',debit_to, 'master_name')
|
|
||||||
|
|
||||||
out = {
|
|
||||||
"customer": customer,
|
|
||||||
"debit_to": debit_to,
|
|
||||||
"due_date": get_due_date(posting_date, customer, debit_to, company)
|
|
||||||
}
|
|
||||||
out.update(get_customer_details(customer))
|
|
||||||
return out
|
|
||||||
|
|
||||||
def get_customer_account(company, customer):
|
|
||||||
if not company:
|
|
||||||
webnotes.throw(_("Please select company first."))
|
|
||||||
|
|
||||||
if customer:
|
|
||||||
acc_head = webnotes.conn.get_value("Account", {"master_name":customer,
|
|
||||||
"master_type":"Customer", "company": company})
|
|
||||||
|
|
||||||
if not acc_head:
|
|
||||||
webnotes.throw(_("Customer has no account head in selected Company. Open the customer record and create an Account Head first."))
|
|
||||||
|
|
||||||
return acc_head
|
|
||||||
|
|
||||||
def get_due_date(posting_date, customer, debit_to, company):
|
|
||||||
"""Set Due Date = Posting Date + Credit Days"""
|
|
||||||
due_date = None
|
|
||||||
if posting_date:
|
|
||||||
credit_days = 0
|
|
||||||
if debit_to:
|
|
||||||
credit_days = webnotes.conn.get_value("Account", debit_to, "credit_days")
|
|
||||||
if customer and not credit_days:
|
|
||||||
credit_days = webnotes.conn.get_value("Customer", customer, "credit_days")
|
|
||||||
if company and not credit_days:
|
|
||||||
credit_days = webnotes.conn.get_value("Company", company, "credit_days")
|
|
||||||
|
|
||||||
if credit_days:
|
|
||||||
due_date = add_days(posting_date, credit_days)
|
|
||||||
else:
|
|
||||||
due_date = posting_date
|
|
||||||
|
|
||||||
return due_date
|
|
||||||
|
|
||||||
|
|
||||||
@webnotes.whitelist()
|
@webnotes.whitelist()
|
||||||
def get_bank_cash_account(mode_of_payment):
|
def get_bank_cash_account(mode_of_payment):
|
||||||
val = webnotes.conn.get_value("Mode of Payment", mode_of_payment, "default_account")
|
val = webnotes.conn.get_value("Mode of Payment", mode_of_payment, "default_account")
|
||||||
|
85
erpnext/accounts/party.py
Normal file
85
erpnext/accounts/party.py
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
# 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 webnotes
|
||||||
|
from webnotes import _
|
||||||
|
|
||||||
|
@webnotes.whitelist()
|
||||||
|
def get_party_details(party=None, account=None, party_type="Customer"):
|
||||||
|
if not webnotes.has_permission(party_type, "read", party):
|
||||||
|
webnotes.throw("No Permission")
|
||||||
|
|
||||||
|
if party_type=="Customer":
|
||||||
|
get_party_details = webnotes.get_attr("erpnext.selling.doctype.customer.customer.get_customer_details")
|
||||||
|
else:
|
||||||
|
get_party_details = webnotes.get_attr("erpnext.buying.doctype.supplier.supplier.get_supplier_details")
|
||||||
|
|
||||||
|
if party:
|
||||||
|
account = get_party_account(company, party, party_type)
|
||||||
|
elif account:
|
||||||
|
party = webnotes.conn.get_value('Account', account, 'master_name')
|
||||||
|
|
||||||
|
account_fieldname = "debit_to" if party_type=="Customer" else "credit_to"
|
||||||
|
|
||||||
|
out = {
|
||||||
|
party_type.lower(): party,
|
||||||
|
account_fieldname : account,
|
||||||
|
"due_date": get_due_date(posting_date, party, party_type, account, company)
|
||||||
|
}
|
||||||
|
out.update(get_party_details(party))
|
||||||
|
return out
|
||||||
|
|
||||||
|
def get_party_account(company, party, party_type):
|
||||||
|
if not company:
|
||||||
|
webnotes.throw(_("Please select company first."))
|
||||||
|
|
||||||
|
if party:
|
||||||
|
acc_head = webnotes.conn.get_value("Account", {"master_name":party,
|
||||||
|
"master_type": party_type, "company": company})
|
||||||
|
|
||||||
|
if not acc_head:
|
||||||
|
create_party_account(party, party_type, company)
|
||||||
|
|
||||||
|
return acc_head
|
||||||
|
|
||||||
|
def get_due_date(posting_date, party, party_type, account, company):
|
||||||
|
"""Set Due Date = Posting Date + Credit Days"""
|
||||||
|
due_date = None
|
||||||
|
if posting_date:
|
||||||
|
credit_days = 0
|
||||||
|
if debit_to:
|
||||||
|
credit_days = webnotes.conn.get_value("Account", account, "credit_days")
|
||||||
|
if party and not credit_days:
|
||||||
|
credit_days = webnotes.conn.get_value(party_type, party, "credit_days")
|
||||||
|
if company and not credit_days:
|
||||||
|
credit_days = webnotes.conn.get_value("Company", company, "credit_days")
|
||||||
|
|
||||||
|
due_date = add_days(posting_date, credit_days) if credit_days else posting_date
|
||||||
|
|
||||||
|
return due_date
|
||||||
|
|
||||||
|
def create_party_account(party, party_type, company):
|
||||||
|
if not company:
|
||||||
|
webnotes.throw(_("Company is required"))
|
||||||
|
|
||||||
|
company_details = webnotes.conn.get_value("Company", company,
|
||||||
|
["abbr", "receivables_group", "payables_group"], as_dict=True)
|
||||||
|
if not webnotes.conn.exists("Account", (party + " - " + abbr)):
|
||||||
|
parent_account = company_details.receivables_group \
|
||||||
|
if party_type=="Customer" else company_details.payables_group
|
||||||
|
|
||||||
|
# create
|
||||||
|
account = webnotes.bean({
|
||||||
|
"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"
|
||||||
|
}).insert(ignore_permissions=True)
|
||||||
|
|
||||||
|
msgprint(_("Account Created") + ": " + account.doc.name)
|
@ -62,42 +62,11 @@ erpnext.buying.BuyingController = erpnext.TransactionController.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
supplier: function() {
|
supplier: function() {
|
||||||
if(this.frm.doc.supplier || this.frm.doc.credit_to) {
|
erpnext.utils.get_party_details(this.frm);
|
||||||
if(!this.frm.doc.company) {
|
|
||||||
this.frm.set_value("supplier", null);
|
|
||||||
msgprint(wn._("Please specify Company"));
|
|
||||||
} else {
|
|
||||||
var me = this;
|
|
||||||
var buying_price_list = this.frm.doc.buying_price_list;
|
|
||||||
|
|
||||||
return this.frm.call({
|
|
||||||
doc: this.frm.doc,
|
|
||||||
method: "set_supplier_defaults",
|
|
||||||
freeze: true,
|
|
||||||
callback: function(r) {
|
|
||||||
if(!r.exc) {
|
|
||||||
if(me.frm.doc.buying_price_list !== buying_price_list) me.buying_price_list();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
supplier_address: function() {
|
supplier_address: function() {
|
||||||
var me = this;
|
erpnext.utils.get_address_display(this.frm);
|
||||||
if (this.frm.doc.supplier) {
|
|
||||||
return wn.call({
|
|
||||||
doc: this.frm.doc,
|
|
||||||
method: "set_supplier_address",
|
|
||||||
freeze: true,
|
|
||||||
args: {
|
|
||||||
supplier: this.frm.doc.supplier,
|
|
||||||
address: this.frm.doc.supplier_address,
|
|
||||||
contact: this.frm.doc.contact_person
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
contact_person: function() {
|
contact_person: function() {
|
||||||
|
@ -225,7 +225,6 @@ def make_purchase_invoice(source_name, target_doclist=None):
|
|||||||
def set_missing_values(source, target):
|
def set_missing_values(source, target):
|
||||||
bean = webnotes.bean(target)
|
bean = webnotes.bean(target)
|
||||||
bean.run_method("set_missing_values")
|
bean.run_method("set_missing_values")
|
||||||
bean.run_method("set_supplier_defaults")
|
|
||||||
|
|
||||||
def update_item(obj, target, source_parent):
|
def update_item(obj, target, source_parent):
|
||||||
target.import_amount = flt(obj.import_amount) - flt(obj.billed_amt)
|
target.import_amount = flt(obj.import_amount) - flt(obj.billed_amt)
|
||||||
|
@ -8,7 +8,7 @@ import webnotes.defaults
|
|||||||
from webnotes.utils import cint
|
from webnotes.utils import cint
|
||||||
from webnotes import msgprint, _
|
from webnotes import msgprint, _
|
||||||
from webnotes.model.doc import make_autoname
|
from webnotes.model.doc 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
|
||||||
|
|
||||||
@ -47,88 +47,20 @@ class DocType(TransactionBase):
|
|||||||
self.update_contact()
|
self.update_contact()
|
||||||
|
|
||||||
# create account head
|
# create account head
|
||||||
self.create_account_head()
|
create_party_account(self.doc.name, "Supplier", self.doc.company)
|
||||||
|
|
||||||
# update credit days and limit in account
|
# update credit days and limit in account
|
||||||
self.update_credit_days_limit()
|
self.update_credit_days_limit()
|
||||||
|
|
||||||
def get_payables_group(self):
|
|
||||||
g = webnotes.conn.sql("select payables_group from tabCompany where name=%s", self.doc.company)
|
|
||||||
g = g and g[0][0] or ''
|
|
||||||
if not g:
|
|
||||||
msgprint("Update Company master, assign a default group for Payables")
|
|
||||||
raise Exception
|
|
||||||
return g
|
|
||||||
|
|
||||||
def add_account(self, ac, par, abbr):
|
|
||||||
ac_bean = webnotes.bean({
|
|
||||||
"doctype": "Account",
|
|
||||||
'account_name':ac,
|
|
||||||
'parent_account':par,
|
|
||||||
'group_or_ledger':'Group',
|
|
||||||
'company':self.doc.company,
|
|
||||||
"freeze_account": "No",
|
|
||||||
})
|
|
||||||
ac_bean.ignore_permissions = True
|
|
||||||
ac_bean.insert()
|
|
||||||
|
|
||||||
msgprint(_("Created Group ") + ac)
|
|
||||||
|
|
||||||
def get_company_abbr(self):
|
def get_company_abbr(self):
|
||||||
return webnotes.conn.sql("select abbr from tabCompany where name=%s", self.doc.company)[0][0]
|
return webnotes.conn.sql("select abbr from tabCompany where name=%s", self.doc.company)[0][0]
|
||||||
|
|
||||||
def get_parent_account(self, abbr):
|
|
||||||
if (not self.doc.supplier_type):
|
|
||||||
msgprint("Supplier Type is mandatory")
|
|
||||||
raise Exception
|
|
||||||
|
|
||||||
if not webnotes.conn.sql("select name from tabAccount where name=%s and debit_or_credit = 'Credit' and ifnull(is_pl_account, 'No') = 'No'", (self.doc.supplier_type + " - " + abbr)):
|
|
||||||
|
|
||||||
# if not group created , create it
|
|
||||||
self.add_account(self.doc.supplier_type, self.get_payables_group(), abbr)
|
|
||||||
|
|
||||||
return self.doc.supplier_type + " - " + abbr
|
|
||||||
|
|
||||||
def validate(self):
|
def validate(self):
|
||||||
#validation for Naming Series mandatory field...
|
#validation for Naming Series mandatory field...
|
||||||
if webnotes.defaults.get_global_default('supp_master_name') == 'Naming Series':
|
if webnotes.defaults.get_global_default('supp_master_name') == 'Naming Series':
|
||||||
if not self.doc.naming_series:
|
if not self.doc.naming_series:
|
||||||
msgprint("Series is Mandatory.", raise_exception=1)
|
msgprint("Series is Mandatory.", raise_exception=1)
|
||||||
|
|
||||||
def create_account_head(self):
|
|
||||||
if self.doc.company :
|
|
||||||
abbr = self.get_company_abbr()
|
|
||||||
parent_account = self.get_parent_account(abbr)
|
|
||||||
|
|
||||||
if not webnotes.conn.sql("select name from tabAccount where name=%s", (self.doc.name + " - " + abbr)):
|
|
||||||
ac_bean = webnotes.bean({
|
|
||||||
"doctype": "Account",
|
|
||||||
'account_name': self.doc.name,
|
|
||||||
'parent_account': parent_account,
|
|
||||||
'group_or_ledger':'Ledger',
|
|
||||||
'company': self.doc.company,
|
|
||||||
'account_type': '',
|
|
||||||
'tax_rate': '0',
|
|
||||||
'master_type': 'Supplier',
|
|
||||||
'master_name': self.doc.name,
|
|
||||||
"freeze_account": "No"
|
|
||||||
})
|
|
||||||
ac_bean.ignore_permissions = True
|
|
||||||
ac_bean.insert()
|
|
||||||
|
|
||||||
msgprint(_("Created Account Head: ") + ac_bean.doc.name)
|
|
||||||
else:
|
|
||||||
self.check_parent_account(parent_account, abbr)
|
|
||||||
else :
|
|
||||||
msgprint("Please select Company under which you want to create account head")
|
|
||||||
|
|
||||||
def check_parent_account(self, parent_account, abbr):
|
|
||||||
if webnotes.conn.get_value("Account", self.doc.name + " - " + abbr,
|
|
||||||
"parent_account") != parent_account:
|
|
||||||
ac = webnotes.bean("Account", self.doc.name + " - " + abbr)
|
|
||||||
ac.doc.parent_account = parent_account
|
|
||||||
ac.save()
|
|
||||||
|
|
||||||
def get_contacts(self,nm):
|
def get_contacts(self,nm):
|
||||||
if nm:
|
if nm:
|
||||||
contact_details =webnotes.conn.convert_to_lists(webnotes.conn.sql("select name, CONCAT(IFNULL(first_name,''),' ',IFNULL(last_name,'')),contact_no,email_id from `tabContact` where supplier = '%s'"%nm))
|
contact_details =webnotes.conn.convert_to_lists(webnotes.conn.sql("select name, CONCAT(IFNULL(first_name,''),' ',IFNULL(last_name,'')),contact_no,email_id from `tabContact` where supplier = '%s'"%nm))
|
||||||
|
@ -7,6 +7,7 @@ from webnotes import _, msgprint
|
|||||||
from webnotes.utils import flt, _round
|
from webnotes.utils import flt, _round
|
||||||
from erpnext.buying.utils import get_item_details
|
from erpnext.buying.utils import get_item_details
|
||||||
from erpnext.setup.utils import get_company_currency
|
from erpnext.setup.utils import get_company_currency
|
||||||
|
from erpnext.buying.doctype.supplier.supplier import get_supplier_details
|
||||||
|
|
||||||
from erpnext.controllers.stock_controller import StockController
|
from erpnext.controllers.stock_controller import StockController
|
||||||
|
|
||||||
@ -31,10 +32,8 @@ class BuyingController(StockController):
|
|||||||
self.set_price_list_currency("Buying")
|
self.set_price_list_currency("Buying")
|
||||||
|
|
||||||
# set contact and address details for supplier, if they are not mentioned
|
# set contact and address details for supplier, if they are not mentioned
|
||||||
if self.doc.supplier and not (self.doc.contact_person and self.doc.supplier_address):
|
if self.doc.supplier:
|
||||||
for fieldname, val in self.get_supplier_defaults().items():
|
self.doc.update_if_not_set(get_supplier_details(self.doc.supplier))
|
||||||
if not self.doc.fields.get(fieldname) and self.meta.get_field(fieldname):
|
|
||||||
self.doc.fields[fieldname] = val
|
|
||||||
|
|
||||||
self.set_missing_item_details(get_item_details)
|
self.set_missing_item_details(get_item_details)
|
||||||
if self.doc.fields.get("__islocal"):
|
if self.doc.fields.get("__islocal"):
|
||||||
|
@ -35,17 +35,10 @@ class SellingController(StockController):
|
|||||||
def set_missing_lead_customer_details(self):
|
def set_missing_lead_customer_details(self):
|
||||||
from erpnext.selling.doctype.customer.customer import get_customer_details
|
from erpnext.selling.doctype.customer.customer import get_customer_details
|
||||||
if self.doc.customer:
|
if self.doc.customer:
|
||||||
if not (self.doc.contact_person and self.doc.customer_address and self.doc.customer_name):
|
self.doc.update_if_not_set(get_customer_details(self.doc.customer))
|
||||||
for fieldname, val in get_customer_details(self.doc.customer).iteritems():
|
|
||||||
if not self.doc.fields.get(fieldname) and self.meta.get_field(fieldname):
|
|
||||||
self.doc.fields[fieldname] = val
|
|
||||||
|
|
||||||
elif self.doc.lead:
|
elif self.doc.lead:
|
||||||
if not (self.doc.customer_address and self.doc.customer_name and \
|
self.doc.update_if_not_set(self.get_lead_defaults())
|
||||||
self.doc.contact_display):
|
|
||||||
for fieldname, val in self.get_lead_defaults().items():
|
|
||||||
if not self.doc.fields.get(fieldname) and self.meta.get_field(fieldname):
|
|
||||||
self.doc.fields[fieldname] = val
|
|
||||||
|
|
||||||
def set_price_list_and_item_details(self):
|
def set_price_list_and_item_details(self):
|
||||||
self.set_price_list_currency("Selling")
|
self.set_price_list_currency("Selling")
|
||||||
|
@ -2,27 +2,43 @@
|
|||||||
// License: GNU General Public License v3. See license.txt
|
// License: GNU General Public License v3. See license.txt
|
||||||
|
|
||||||
wn.provide("erpnext.utils");
|
wn.provide("erpnext.utils");
|
||||||
erpnext.utils.get_customer_details = function(frm, method, args) {
|
erpnext.utils.get_party_details = function(frm, method, args) {
|
||||||
if(!method)
|
if(!method) {
|
||||||
method = "erpnext.selling.doctype.customer.customer.get_customer_details";
|
if(frm.doc.customer) {
|
||||||
if(!args)
|
method = "erpnext.selling.doctype.customer.customer.get_customer_details";
|
||||||
args = { customer: frm.doc.customer };
|
} else {
|
||||||
|
method = "erpnext.buying.doctype.supplier.supplier.get_supplier_details";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!args) {
|
||||||
|
if(frm.doc.customer) {
|
||||||
|
args = { customer: frm.doc.customer };
|
||||||
|
} else {
|
||||||
|
args = { supplier: frm.doc.supplier };
|
||||||
|
}
|
||||||
|
}
|
||||||
wn.call({
|
wn.call({
|
||||||
method: method,
|
method: method,
|
||||||
args: args,
|
args: args,
|
||||||
callback: function(r) {
|
callback: function(r) {
|
||||||
if(r.message) {
|
if(r.message) {
|
||||||
frm.updating_customer_details = true;
|
frm.updating_party_details = true;
|
||||||
frm.set_value(r.message);
|
frm.set_value(r.message);
|
||||||
frm.updating_customer_details = false;
|
frm.updating_party_details = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
erpnext.utils.get_address_display = function(frm, address_field) {
|
erpnext.utils.get_address_display = function(frm, address_field) {
|
||||||
if(frm.updating_customer_details) return;
|
if(frm.updating_party_details) return;
|
||||||
if(!address_field) address_field = "customer_address";
|
if(!address_field) {
|
||||||
|
if(frm.doc.customer) {
|
||||||
|
address_field = "customer_address";
|
||||||
|
} else {
|
||||||
|
address_field = "supplier_address";
|
||||||
|
}
|
||||||
|
}
|
||||||
wn.call({
|
wn.call({
|
||||||
method: "erpnext.utilities.doctype.address.address.get_address_display",
|
method: "erpnext.utilities.doctype.address.address.get_address_display",
|
||||||
args: {address: frm.doc[address_field] },
|
args: {address: frm.doc[address_field] },
|
||||||
@ -34,7 +50,7 @@ erpnext.utils.get_address_display = function(frm, address_field) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
erpnext.utils.get_contact_details = function(frm) {
|
erpnext.utils.get_contact_details = function(frm) {
|
||||||
if(frm.updating_customer_details) return;
|
if(frm.updating_party_details) return;
|
||||||
wn.call({
|
wn.call({
|
||||||
method: "erpnext.utilities.doctype.contact.contact.get_contact_details",
|
method: "erpnext.utilities.doctype.contact.contact.get_contact_details",
|
||||||
args: {address: frm.doc.contact_person },
|
args: {address: frm.doc.contact_person },
|
||||||
|
@ -12,6 +12,7 @@ import webnotes.defaults
|
|||||||
from erpnext.utilities.transaction_base import TransactionBase
|
from erpnext.utilities.transaction_base import TransactionBase
|
||||||
from erpnext.utilities.doctype.address.address import get_address_display
|
from erpnext.utilities.doctype.address.address import get_address_display
|
||||||
from erpnext.utilities.doctype.contact.contact import get_contact_details
|
from erpnext.utilities.doctype.contact.contact import get_contact_details
|
||||||
|
from erpnext.accounts.party import create_party_account
|
||||||
|
|
||||||
class DocType(TransactionBase):
|
class DocType(TransactionBase):
|
||||||
def __init__(self, doc, doclist=[]):
|
def __init__(self, doc, doclist=[]):
|
||||||
@ -29,14 +30,6 @@ class DocType(TransactionBase):
|
|||||||
|
|
||||||
def get_company_abbr(self):
|
def get_company_abbr(self):
|
||||||
return webnotes.conn.get_value('Company', self.doc.company, 'abbr')
|
return webnotes.conn.get_value('Company', self.doc.company, 'abbr')
|
||||||
|
|
||||||
def get_receivables_group(self):
|
|
||||||
g = webnotes.conn.sql("select receivables_group from tabCompany where name=%s", self.doc.company)
|
|
||||||
g = g and g[0][0] or ''
|
|
||||||
if not g:
|
|
||||||
msgprint("Update Company master, assign a default group for Receivables")
|
|
||||||
raise Exception
|
|
||||||
return g
|
|
||||||
|
|
||||||
def validate_values(self):
|
def validate_values(self):
|
||||||
if webnotes.defaults.get_global_default('cust_master_name') == 'Naming Series' and not self.doc.naming_series:
|
if webnotes.defaults.get_global_default('cust_master_name') == 'Naming Series' and not self.doc.naming_series:
|
||||||
@ -57,29 +50,6 @@ class DocType(TransactionBase):
|
|||||||
webnotes.conn.sql("""update `tabContact` set customer_name=%s, modified=NOW()
|
webnotes.conn.sql("""update `tabContact` set customer_name=%s, modified=NOW()
|
||||||
where customer=%s""", (self.doc.customer_name, self.doc.name))
|
where customer=%s""", (self.doc.customer_name, self.doc.name))
|
||||||
|
|
||||||
def create_account_head(self):
|
|
||||||
if self.doc.company :
|
|
||||||
abbr = self.get_company_abbr()
|
|
||||||
if not webnotes.conn.exists("Account", (self.doc.name + " - " + abbr)):
|
|
||||||
parent_account = self.get_receivables_group()
|
|
||||||
# create
|
|
||||||
ac_bean = webnotes.bean({
|
|
||||||
"doctype": "Account",
|
|
||||||
'account_name': self.doc.name,
|
|
||||||
'parent_account': parent_account,
|
|
||||||
'group_or_ledger':'Ledger',
|
|
||||||
'company':self.doc.company,
|
|
||||||
'master_type':'Customer',
|
|
||||||
'master_name':self.doc.name,
|
|
||||||
"freeze_account": "No"
|
|
||||||
})
|
|
||||||
ac_bean.ignore_permissions = True
|
|
||||||
ac_bean.insert()
|
|
||||||
|
|
||||||
msgprint(_("Account Head") + ": " + ac_bean.doc.name + _(" created"))
|
|
||||||
else :
|
|
||||||
msgprint(_("Please Select Company under which you want to create account head"))
|
|
||||||
|
|
||||||
def update_credit_days_limit(self):
|
def update_credit_days_limit(self):
|
||||||
webnotes.conn.sql("""update tabAccount set credit_days = %s, credit_limit = %s
|
webnotes.conn.sql("""update tabAccount set credit_days = %s, credit_limit = %s
|
||||||
where master_type='Customer' and master_name = %s""",
|
where master_type='Customer' and master_name = %s""",
|
||||||
@ -113,7 +83,8 @@ class DocType(TransactionBase):
|
|||||||
self.update_contact()
|
self.update_contact()
|
||||||
|
|
||||||
# create account head
|
# create account head
|
||||||
self.create_account_head()
|
create_party_account(self.doc.name, "Customer", self.doc.company)
|
||||||
|
|
||||||
# update credit days and limit in account
|
# update credit days and limit in account
|
||||||
self.update_credit_days_limit()
|
self.update_credit_days_limit()
|
||||||
#create address and contact from lead
|
#create address and contact from lead
|
||||||
|
@ -6,7 +6,7 @@ cur_frm.cscript.fname = "installed_item_details";
|
|||||||
|
|
||||||
|
|
||||||
wn.ui.form.on_change("Installation Note", "customer",
|
wn.ui.form.on_change("Installation Note", "customer",
|
||||||
function(frm) { erpnext.utils.get_customer_details(frm); });
|
function(frm) { erpnext.utils.get_party_details(frm); });
|
||||||
|
|
||||||
wn.ui.form.on_change("Installation Note", "customer_address",
|
wn.ui.form.on_change("Installation Note", "customer_address",
|
||||||
function(frm) { erpnext.utils.get_address_display(frm); });
|
function(frm) { erpnext.utils.get_address_display(frm); });
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
{% include 'utilities/doctype/sms_control/sms_control.js' %};
|
{% include 'utilities/doctype/sms_control/sms_control.js' %};
|
||||||
|
|
||||||
wn.ui.form.on_change("Opportunity", "customer", function(frm) {
|
wn.ui.form.on_change("Opportunity", "customer", function(frm) {
|
||||||
erpnext.utils.get_customer_details(frm) });
|
erpnext.utils.get_party_details(frm) });
|
||||||
wn.ui.form.on_change("Opportunity", "customer_address", erpnext.utils.get_address_display);
|
wn.ui.form.on_change("Opportunity", "customer_address", erpnext.utils.get_address_display);
|
||||||
wn.ui.form.on_change("Opportunity", "contact_person", erpnext.utils.get_contact_details);
|
wn.ui.form.on_change("Opportunity", "contact_person", erpnext.utils.get_contact_details);
|
||||||
|
|
||||||
|
@ -104,7 +104,7 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
customer: function() {
|
customer: function() {
|
||||||
erpnext.utils.get_customer_details(this.frm);
|
erpnext.utils.get_party_details(this.frm);
|
||||||
},
|
},
|
||||||
|
|
||||||
customer_address: function() {
|
customer_address: function() {
|
||||||
|
@ -301,7 +301,6 @@ def make_purchase_invoice(source_name, target_doclist=None):
|
|||||||
def set_missing_values(source, target):
|
def set_missing_values(source, target):
|
||||||
bean = webnotes.bean(target)
|
bean = webnotes.bean(target)
|
||||||
bean.run_method("set_missing_values")
|
bean.run_method("set_missing_values")
|
||||||
bean.run_method("set_supplier_defaults")
|
|
||||||
|
|
||||||
doclist = get_mapped_doclist("Purchase Receipt", source_name, {
|
doclist = get_mapped_doclist("Purchase Receipt", source_name, {
|
||||||
"Purchase Receipt": {
|
"Purchase Receipt": {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
wn.provide("erpnext.support");
|
wn.provide("erpnext.support");
|
||||||
|
|
||||||
wn.ui.form.on_change("Customer Issue", "customer", function(frm) {
|
wn.ui.form.on_change("Customer Issue", "customer", function(frm) {
|
||||||
erpnext.utils.get_customer_details(frm) });
|
erpnext.utils.get_party_details(frm) });
|
||||||
wn.ui.form.on_change("Customer Issue", "customer_address",
|
wn.ui.form.on_change("Customer Issue", "customer_address",
|
||||||
erpnext.utils.get_address_display);
|
erpnext.utils.get_address_display);
|
||||||
wn.ui.form.on_change("Customer Issue", "contact_person",
|
wn.ui.form.on_change("Customer Issue", "contact_person",
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
wn.provide("erpnext.support");
|
wn.provide("erpnext.support");
|
||||||
|
|
||||||
wn.ui.form.on_change("Maintenance Schedule", "customer", function(frm) {
|
wn.ui.form.on_change("Maintenance Schedule", "customer", function(frm) {
|
||||||
erpnext.utils.get_customer_details(frm) });
|
erpnext.utils.get_party_details(frm) });
|
||||||
wn.ui.form.on_change("Maintenance Schedule", "customer_address",
|
wn.ui.form.on_change("Maintenance Schedule", "customer_address",
|
||||||
erpnext.utils.get_address_display);
|
erpnext.utils.get_address_display);
|
||||||
wn.ui.form.on_change("Maintenance Schedule", "contact_person",
|
wn.ui.form.on_change("Maintenance Schedule", "contact_person",
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
wn.provide("erpnext.support");
|
wn.provide("erpnext.support");
|
||||||
|
|
||||||
wn.ui.form.on_change("Maintenance Visit", "customer", function(frm) {
|
wn.ui.form.on_change("Maintenance Visit", "customer", function(frm) {
|
||||||
erpnext.utils.get_customer_details(frm) });
|
erpnext.utils.get_party_details(frm) });
|
||||||
wn.ui.form.on_change("Maintenance Visit", "customer_address",
|
wn.ui.form.on_change("Maintenance Visit", "customer_address",
|
||||||
erpnext.utils.get_address_display);
|
erpnext.utils.get_address_display);
|
||||||
wn.ui.form.on_change("Maintenance Visit", "contact_person",
|
wn.ui.form.on_change("Maintenance Visit", "contact_person",
|
||||||
|
@ -45,16 +45,6 @@ class TransactionBase(StatusUpdater):
|
|||||||
break
|
break
|
||||||
|
|
||||||
return self._party_type_and_name
|
return self._party_type_and_name
|
||||||
|
|
||||||
def get_supplier_defaults(self):
|
|
||||||
from erpnext.buying.doctype.supplier.supplier import get_supplier_details
|
|
||||||
return get_supplier_details(self.doc.supplier)
|
|
||||||
|
|
||||||
def set_supplier_defaults(self):
|
|
||||||
from erpnext.buying.doctype.supplier.supplier import get_supplier_details
|
|
||||||
for fieldname, val in get_supplier_details(self.doc.supplier).iteritems():
|
|
||||||
if self.meta.get_field(fieldname):
|
|
||||||
self.doc.fields[fieldname] = val
|
|
||||||
|
|
||||||
def get_lead_defaults(self):
|
def get_lead_defaults(self):
|
||||||
out = self.get_default_address_and_contact("lead")
|
out = self.get_default_address_and_contact("lead")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user