more updates to party
This commit is contained in:
parent
49dd7bee87
commit
24da761a17
@ -75,6 +75,19 @@ erpnext.accounts.PurchaseInvoice = erpnext.buying.BuyingController.extend({
|
||||
|
||||
this.is_opening(doc);
|
||||
},
|
||||
|
||||
supplier: function() {
|
||||
if(this.frm.updating_party_details)
|
||||
return;
|
||||
erpnext.selling.get_party_details(this.frm,
|
||||
"erpnext.accounts.party.get_party_details", {
|
||||
posting_date: this.frm.doc.posting_date,
|
||||
company: this.frm.doc.company,
|
||||
party: this.frm.doc.supplier,
|
||||
party_type: "Supplier",
|
||||
account: this.frm.doc.debit_to
|
||||
})
|
||||
},
|
||||
|
||||
credit_to: function() {
|
||||
this.supplier();
|
||||
|
@ -12,8 +12,9 @@ from erpnext.setup.utils import get_company_currency
|
||||
|
||||
import webnotes.defaults
|
||||
|
||||
|
||||
from erpnext.controllers.buying_controller import BuyingController
|
||||
from erpnext.accounts.party import get_party_account, get_due_date
|
||||
|
||||
class DocType(BuyingController):
|
||||
def __init__(self,d,dl):
|
||||
self.doc, self.doclist = d, dl
|
||||
@ -59,31 +60,16 @@ class DocType(BuyingController):
|
||||
self.update_valuation_rate("entries")
|
||||
self.validate_multiple_billing("Purchase Receipt", "pr_detail", "import_amount",
|
||||
"purchase_receipt_details")
|
||||
|
||||
def get_credit_to(self):
|
||||
ret = {}
|
||||
if self.doc.supplier:
|
||||
acc_head = webnotes.conn.sql("""select name, credit_days from `tabAccount`
|
||||
where (name = %s or (master_name = %s and master_type = 'supplier'))
|
||||
and docstatus != 2 and company = %s""",
|
||||
(cstr(self.doc.supplier) + " - " + self.company_abbr,
|
||||
self.doc.supplier, self.doc.company))
|
||||
|
||||
if acc_head and acc_head[0][0]:
|
||||
ret['credit_to'] = acc_head[0][0]
|
||||
if not self.doc.due_date:
|
||||
ret['due_date'] = add_days(cstr(self.doc.posting_date),
|
||||
acc_head and cint(acc_head[0][1]) or 0)
|
||||
elif not acc_head:
|
||||
msgprint("%s does not have an Account Head in %s. \
|
||||
You must first create it from the Supplier Master" % \
|
||||
(self.doc.supplier, self.doc.company))
|
||||
return ret
|
||||
|
||||
def set_supplier_defaults(self):
|
||||
self.doc.fields.update(self.get_credit_to())
|
||||
super(DocType, self).set_supplier_defaults()
|
||||
|
||||
def set_missing_values(self, for_validate=False):
|
||||
if not self.doc.credit_to:
|
||||
self.doc.credit_to = get_party_account(self.doc.company, self.doc.supplier, "Supplier")
|
||||
if not self.doc.due_date:
|
||||
self.doc.due_date = get_due_date(self.doc.posting_date, self.doc.supplier, "Supplier",
|
||||
self.doc.credit_to, self.doc.company)
|
||||
|
||||
super(DocType, self).set_missing_values(for_validate)
|
||||
|
||||
def get_advances(self):
|
||||
super(DocType, self).get_advances(self.doc.credit_to,
|
||||
"Purchase Invoice Advance", "advance_allocation_details", "debit")
|
||||
|
@ -159,12 +159,12 @@ erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.exte
|
||||
if(this.frm.updating_party_details)
|
||||
return;
|
||||
erpnext.selling.get_party_details(this.frm,
|
||||
"erpnext.accounts.doctype.sales_invoice.sales_invoice.get_party_details",
|
||||
{
|
||||
"erpnext.accounts.party.get_party_details", {
|
||||
posting_date: this.frm.doc.posting_date,
|
||||
company: this.frm.doc.company,
|
||||
customer: this.frm.doc.customer,
|
||||
debit_to: this.frm.doc.debit_to
|
||||
party: this.frm.doc.customer,
|
||||
party_type: "Customer",
|
||||
account: this.frm.doc.debit_to
|
||||
})
|
||||
},
|
||||
|
||||
|
@ -153,7 +153,7 @@ class DocType(SellingController):
|
||||
if not self.doc.debit_to:
|
||||
self.doc.debit_to = get_party_account(self.doc.company, self.doc.customer, "Customer")
|
||||
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, "Customer",
|
||||
self.doc.debit_to, self.doc.company)
|
||||
|
||||
super(DocType, self).set_missing_values(for_validate)
|
||||
|
@ -7,7 +7,7 @@ import webnotes
|
||||
from webnotes import _
|
||||
|
||||
@webnotes.whitelist()
|
||||
def get_party_details(party=None, account=None, party_type="Customer"):
|
||||
def get_party_details(party=None, account=None, party_type="Customer", company=None, posting_date=None):
|
||||
if not webnotes.has_permission(party_type, "read", party):
|
||||
webnotes.throw("No Permission")
|
||||
|
||||
@ -49,7 +49,7 @@ def get_due_date(posting_date, party, party_type, account, company):
|
||||
due_date = None
|
||||
if posting_date:
|
||||
credit_days = 0
|
||||
if debit_to:
|
||||
if account:
|
||||
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")
|
||||
@ -66,7 +66,7 @@ def create_party_account(party, party_type, company):
|
||||
|
||||
company_details = webnotes.conn.get_value("Company", company,
|
||||
["abbr", "receivables_group", "payables_group"], as_dict=True)
|
||||
if not webnotes.conn.exists("Account", (party + " - " + abbr)):
|
||||
if not webnotes.conn.exists("Account", (party + " - " + company_details.abbr)):
|
||||
parent_account = company_details.receivables_group \
|
||||
if party_type=="Customer" else company_details.payables_group
|
||||
|
||||
@ -82,4 +82,4 @@ def create_party_account(party, party_type, company):
|
||||
"freeze_account": "No"
|
||||
}).insert(ignore_permissions=True)
|
||||
|
||||
msgprint(_("Account Created") + ": " + account.doc.name)
|
||||
webnotes.msgprint(_("Account Created") + ": " + account.doc.name)
|
||||
|
@ -129,7 +129,7 @@ def get_dashboard_info(supplier):
|
||||
return out
|
||||
|
||||
@webnotes.whitelist()
|
||||
def get_supplier_details(supplier):
|
||||
def get_supplier_details(supplier, price_list=None, currency=None):
|
||||
if not webnotes.has_permission("Supplier", "read", supplier):
|
||||
webnotes.msgprint("No Permission", raise_exception=webnotes.PermissionError)
|
||||
|
||||
@ -143,7 +143,7 @@ def get_supplier_details(supplier):
|
||||
})
|
||||
|
||||
out.supplier_name = supplier.supplier_name
|
||||
out.currency = supplier.default_currency
|
||||
out.buying_price_list = supplier.default_price_list
|
||||
out.currency = supplier.default_currency or currency
|
||||
out.buying_price_list = supplier.default_price_list or price_list
|
||||
|
||||
return out
|
@ -33,7 +33,7 @@ class BuyingController(StockController):
|
||||
|
||||
# set contact and address details for supplier, if they are not mentioned
|
||||
if self.doc.supplier:
|
||||
self.doc.update_if_not_set(get_supplier_details(self.doc.supplier))
|
||||
self.doc.update_if_missing(get_supplier_details(self.doc.supplier))
|
||||
|
||||
self.set_missing_item_details(get_item_details)
|
||||
if self.doc.fields.get("__islocal"):
|
||||
|
@ -35,10 +35,10 @@ class SellingController(StockController):
|
||||
def set_missing_lead_customer_details(self):
|
||||
from erpnext.selling.doctype.customer.customer import get_customer_details
|
||||
if self.doc.customer:
|
||||
self.doc.update_if_not_set(get_customer_details(self.doc.customer))
|
||||
self.doc.update_if_missing(get_customer_details(self.doc.customer))
|
||||
|
||||
elif self.doc.lead:
|
||||
self.doc.update_if_not_set(self.get_lead_defaults())
|
||||
self.doc.update_if_missing(self.get_lead_defaults())
|
||||
|
||||
def set_price_list_and_item_details(self):
|
||||
self.set_price_list_currency("Selling")
|
||||
|
@ -12,6 +12,6 @@
|
||||
"public/js/feature_setup.js",
|
||||
"public/js/utils.js",
|
||||
"public/js/queries.js",
|
||||
"public/js/utils/customer_supplier.js"
|
||||
"public/js/utils/party.js"
|
||||
]
|
||||
}
|
@ -6,16 +6,25 @@ erpnext.utils.get_party_details = function(frm, method, args) {
|
||||
if(!method) {
|
||||
if(frm.doc.customer) {
|
||||
method = "erpnext.selling.doctype.customer.customer.get_customer_details";
|
||||
var price_list_field = "selling_price_list";
|
||||
} else {
|
||||
method = "erpnext.buying.doctype.supplier.supplier.get_supplier_details";
|
||||
var price_list_field = "buying_price_list";
|
||||
}
|
||||
}
|
||||
if(!args) {
|
||||
if(frm.doc.customer) {
|
||||
args = { customer: frm.doc.customer };
|
||||
args = {
|
||||
customer: frm.doc.customer,
|
||||
price_list: frm.doc.selling_price_list
|
||||
};
|
||||
} else {
|
||||
args = { supplier: frm.doc.supplier };
|
||||
args = {
|
||||
supplier: frm.doc.supplier,
|
||||
price_list: frm.doc.buying_price_list
|
||||
};
|
||||
}
|
||||
args.currency = frm.doc.currency;
|
||||
}
|
||||
wn.call({
|
||||
method: method,
|
@ -165,7 +165,7 @@ def get_dashboard_info(customer):
|
||||
return out
|
||||
|
||||
@webnotes.whitelist()
|
||||
def get_customer_details(customer):
|
||||
def get_customer_details(customer, price_list=None, currency=None):
|
||||
if not webnotes.has_permission("Customer", "read", customer):
|
||||
webnotes.throw("Not Permitted", webnotes.PermissionError)
|
||||
|
||||
@ -196,17 +196,20 @@ def get_customer_details(customer):
|
||||
out[f] = customer.get("default_" + f)
|
||||
|
||||
# price list
|
||||
from webnotes.defaults import get_defaults_for
|
||||
user_default_price_list = get_defaults_for(webnotes.session.user).get("selling_price_list")
|
||||
user_default_price_list = cstr(user_default_price_list) \
|
||||
if not isinstance(user_default_price_list, list) else ""
|
||||
out.selling_price_list = webnotes.conn.get_defaults("selling_price_list", webnotes.session.user)
|
||||
if isinstance(out.selling_price_list, list):
|
||||
out.selling_price_list = None
|
||||
|
||||
out.selling_price_list = user_default_price_list or customer.price_list or webnotes.conn.get_value("Customer Group",
|
||||
customer.customer_group, "default_price_list")
|
||||
out.selling_price_list = out.selling_price_list or customer.price_list \
|
||||
or webnotes.conn.get_value("Customer Group", customer.customer_group, "default_price_list")
|
||||
or price_list
|
||||
|
||||
if out.selling_price_list:
|
||||
out.price_list_currency = webnotes.conn.get_value("Price List", out.selling_price_list, "currency")
|
||||
|
||||
if not out.currency:
|
||||
out.currency = currency
|
||||
|
||||
# sales team
|
||||
out.sales_team = [{
|
||||
"sales_person": d.sales_person,
|
||||
|
Loading…
x
Reference in New Issue
Block a user