[fix] apply Tax Rule for lead
This commit is contained in:
parent
79a415e3b8
commit
2f957f27b0
@ -299,8 +299,12 @@ def set_taxes(party, party_type, posting_date, company, customer_group=None, sup
|
|||||||
else:
|
else:
|
||||||
args.update(get_party_details(party, party_type))
|
args.update(get_party_details(party, party_type))
|
||||||
|
|
||||||
if party_type=="Customer":
|
if party_type in ("Customer", "Lead"):
|
||||||
args.update({"tax_type": "Sales"})
|
args.update({"tax_type": "Sales"})
|
||||||
|
|
||||||
|
if party_type=='Lead':
|
||||||
|
args['customer'] = None
|
||||||
|
del args['lead']
|
||||||
else:
|
else:
|
||||||
args.update({"tax_type": "Purchase"})
|
args.update({"tax_type": "Purchase"})
|
||||||
|
|
||||||
|
@ -51,7 +51,10 @@ class SellingController(StockController):
|
|||||||
|
|
||||||
elif getattr(self, "lead", None):
|
elif getattr(self, "lead", None):
|
||||||
from erpnext.crm.doctype.lead.lead import get_lead_details
|
from erpnext.crm.doctype.lead.lead import get_lead_details
|
||||||
self.update_if_missing(get_lead_details(self.lead))
|
self.update_if_missing(get_lead_details(
|
||||||
|
self.lead,
|
||||||
|
posting_date=self.get('transaction_date') or self.get('posting_date'),
|
||||||
|
company=self.company))
|
||||||
|
|
||||||
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")
|
||||||
|
@ -10,6 +10,7 @@ from frappe.model.mapper import get_mapped_doc
|
|||||||
|
|
||||||
from erpnext.controllers.selling_controller import SellingController
|
from erpnext.controllers.selling_controller import SellingController
|
||||||
from erpnext.utilities.address_and_contact import load_address_and_contact
|
from erpnext.utilities.address_and_contact import load_address_and_contact
|
||||||
|
from erpnext.accounts.party import set_taxes
|
||||||
|
|
||||||
sender_field = "email_id"
|
sender_field = "email_id"
|
||||||
|
|
||||||
@ -58,7 +59,7 @@ class Lead(SellingController):
|
|||||||
def check_email_id_is_unique(self):
|
def check_email_id_is_unique(self):
|
||||||
if self.email_id:
|
if self.email_id:
|
||||||
# validate email is unique
|
# validate email is unique
|
||||||
duplicate_leads = frappe.db.sql_list("""select name from tabLead
|
duplicate_leads = frappe.db.sql_list("""select name from tabLead
|
||||||
where email_id=%s and name!=%s""", (self.email_id, self.name))
|
where email_id=%s and name!=%s""", (self.email_id, self.name))
|
||||||
|
|
||||||
if duplicate_leads:
|
if duplicate_leads:
|
||||||
@ -138,7 +139,7 @@ def make_quotation(source_name, target_doc=None):
|
|||||||
return target_doc
|
return target_doc
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_lead_details(lead):
|
def get_lead_details(lead, posting_date=None, company=None):
|
||||||
if not lead: return {}
|
if not lead: return {}
|
||||||
|
|
||||||
from erpnext.accounts.party import set_address_details
|
from erpnext.accounts.party import set_address_details
|
||||||
@ -158,4 +159,9 @@ def get_lead_details(lead):
|
|||||||
|
|
||||||
set_address_details(out, lead, "Lead")
|
set_address_details(out, lead, "Lead")
|
||||||
|
|
||||||
|
taxes_and_charges = set_taxes(None, 'Lead', posting_date, company,
|
||||||
|
billing_address=out.get('customer_address'), shipping_address=out.get('shipping_address_name'))
|
||||||
|
if taxes_and_charges:
|
||||||
|
out['taxes_and_charges'] = taxes_and_charges
|
||||||
|
|
||||||
return out
|
return out
|
||||||
|
@ -69,37 +69,59 @@ erpnext.utils.get_address_display = function(frm, address_field, display_field,
|
|||||||
if(r.message) {
|
if(r.message) {
|
||||||
frm.set_value(display_field, r.message)
|
frm.set_value(display_field, r.message)
|
||||||
}
|
}
|
||||||
|
|
||||||
if(frappe.meta.get_docfield(frm.doc.doctype, "taxes") && !is_your_company_address) {
|
|
||||||
if(!erpnext.utils.validate_mandatory(frm, "Customer/Supplier",
|
|
||||||
frm.doc.customer || frm.doc.supplier, address_field)) return;
|
|
||||||
|
|
||||||
if(!erpnext.utils.validate_mandatory(frm, "Posting/Transaction Date",
|
erpnext.utils.set_taxes(frm, address_field, display_field, is_your_company_address);
|
||||||
frm.doc.posting_date || frm.doc.transaction_date, address_field)) return;
|
|
||||||
} else return;
|
|
||||||
|
|
||||||
frappe.call({
|
|
||||||
method: "erpnext.accounts.party.set_taxes",
|
|
||||||
args: {
|
|
||||||
"party": frm.doc.customer || frm.doc.supplier,
|
|
||||||
"party_type": (frm.doc.customer ? "Customer" : "Supplier"),
|
|
||||||
"posting_date": frm.doc.posting_date || frm.doc.transaction_date,
|
|
||||||
"company": frm.doc.company,
|
|
||||||
"billing_address": ((frm.doc.customer) ? (frm.doc.customer_address) : (frm.doc.supplier_address)),
|
|
||||||
"shipping_address": frm.doc.shipping_address_name
|
|
||||||
},
|
|
||||||
callback: function(r) {
|
|
||||||
if(r.message){
|
|
||||||
frm.set_value("taxes_and_charges", r.message)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
frm.set_value(display_field, null);
|
frm.set_value(display_field, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
erpnext.utils.set_taxes = function(frm, address_field, display_field, is_your_company_address) {
|
||||||
|
if(frappe.meta.get_docfield(frm.doc.doctype, "taxes") && !is_your_company_address) {
|
||||||
|
if(!erpnext.utils.validate_mandatory(frm, "Lead/Customer/Supplier",
|
||||||
|
frm.doc.customer || frm.doc.supplier || frm.doc.lead, address_field)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!erpnext.utils.validate_mandatory(frm, "Posting/Transaction Date",
|
||||||
|
frm.doc.posting_date || frm.doc.transaction_date, address_field)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var party_type, party;
|
||||||
|
if (frm.doc.lead) {
|
||||||
|
party_type = 'Lead';
|
||||||
|
party = frm.doc.lead;
|
||||||
|
} else if (frm.doc.customer) {
|
||||||
|
party_type = 'Customer';
|
||||||
|
party = frm.doc.customer;
|
||||||
|
} else if (frm.doc.supplier) {
|
||||||
|
party_type = 'Supplier';
|
||||||
|
party = frm.doc.supplier;
|
||||||
|
}
|
||||||
|
|
||||||
|
frappe.call({
|
||||||
|
method: "erpnext.accounts.party.set_taxes",
|
||||||
|
args: {
|
||||||
|
"party": party,
|
||||||
|
"party_type": party_type,
|
||||||
|
"posting_date": frm.doc.posting_date || frm.doc.transaction_date,
|
||||||
|
"company": frm.doc.company,
|
||||||
|
"billing_address": ((frm.doc.customer || frm.doc.lead) ? (frm.doc.customer_address) : (frm.doc.supplier_address)),
|
||||||
|
"shipping_address": frm.doc.shipping_address_name
|
||||||
|
},
|
||||||
|
callback: function(r) {
|
||||||
|
if(r.message){
|
||||||
|
frm.set_value("taxes_and_charges", r.message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
erpnext.utils.get_contact_details = function(frm) {
|
erpnext.utils.get_contact_details = function(frm) {
|
||||||
|
@ -25,7 +25,7 @@ erpnext.selling.QuotationController = erpnext.selling.SellingController.extend({
|
|||||||
cur_frm.add_custom_button(__('Lost'),
|
cur_frm.add_custom_button(__('Lost'),
|
||||||
cur_frm.cscript['Declare Order Lost'], __("Status"));
|
cur_frm.cscript['Declare Order Lost'], __("Status"));
|
||||||
}
|
}
|
||||||
|
|
||||||
cur_frm.page.set_inner_btn_group_as_primary(__("Make"));
|
cur_frm.page.set_inner_btn_group_as_primary(__("Make"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,7 +47,7 @@ erpnext.selling.QuotationController = erpnext.selling.SellingController.extend({
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.toggle_reqd_lead_customer();
|
this.toggle_reqd_lead_customer();
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
quotation_to: function() {
|
quotation_to: function() {
|
||||||
@ -96,7 +96,11 @@ erpnext.selling.QuotationController = erpnext.selling.SellingController.extend({
|
|||||||
var me = this;
|
var me = this;
|
||||||
frappe.call({
|
frappe.call({
|
||||||
method: "erpnext.crm.doctype.lead.lead.get_lead_details",
|
method: "erpnext.crm.doctype.lead.lead.get_lead_details",
|
||||||
args: { "lead": this.frm.doc.lead },
|
args: {
|
||||||
|
'lead': this.frm.doc.lead,
|
||||||
|
'posting_date': this.frm.doc.transaction_date,
|
||||||
|
'company': this.frm.doc.company,
|
||||||
|
},
|
||||||
callback: function(r) {
|
callback: function(r) {
|
||||||
if(r.message) {
|
if(r.message) {
|
||||||
me.frm.updating_party_details = true;
|
me.frm.updating_party_details = true;
|
||||||
@ -166,6 +170,6 @@ frappe.ui.form.on("Quotation Item", "items_on_form_rendered", function(frm, cdt,
|
|||||||
|
|
||||||
frappe.ui.form.on("Quotation Item", "stock_balance", function(frm, cdt, cdn) {
|
frappe.ui.form.on("Quotation Item", "stock_balance", function(frm, cdt, cdn) {
|
||||||
var d = frappe.model.get_doc(cdt, cdn);
|
var d = frappe.model.get_doc(cdt, cdn);
|
||||||
frappe.route_options = {"item_code": d.item_code};
|
frappe.route_options = {"item_code": d.item_code};
|
||||||
frappe.set_route("query-report", "Stock Balance");
|
frappe.set_route("query-report", "Stock Balance");
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user