Get default tax template only if tax template not selected or template is for other company (#12492)
This commit is contained in:
parent
184491bbbe
commit
a2426fcc9e
@ -54,6 +54,7 @@ class AccountsController(TransactionBase):
|
|||||||
|
|
||||||
if self.meta.get_field("taxes_and_charges"):
|
if self.meta.get_field("taxes_and_charges"):
|
||||||
self.validate_enabled_taxes_and_charges()
|
self.validate_enabled_taxes_and_charges()
|
||||||
|
self.validate_tax_account_company()
|
||||||
|
|
||||||
self.validate_party()
|
self.validate_party()
|
||||||
self.validate_currency()
|
self.validate_currency()
|
||||||
@ -255,6 +256,14 @@ class AccountsController(TransactionBase):
|
|||||||
if frappe.db.get_value(taxes_and_charges_doctype, self.taxes_and_charges, "disabled"):
|
if frappe.db.get_value(taxes_and_charges_doctype, self.taxes_and_charges, "disabled"):
|
||||||
frappe.throw(_("{0} '{1}' is disabled").format(taxes_and_charges_doctype, self.taxes_and_charges))
|
frappe.throw(_("{0} '{1}' is disabled").format(taxes_and_charges_doctype, self.taxes_and_charges))
|
||||||
|
|
||||||
|
def validate_tax_account_company(self):
|
||||||
|
for d in self.get("taxes"):
|
||||||
|
if d.account_head:
|
||||||
|
tax_account_company = frappe.db.get_value("Account", d.account_head, "company")
|
||||||
|
if tax_account_company != self.company:
|
||||||
|
frappe.throw(_("Row #{0}: Account {1} does not belong to company {2}")
|
||||||
|
.format(d.idx, d.account_head, self.company))
|
||||||
|
|
||||||
def get_gl_dict(self, args, account_currency=None):
|
def get_gl_dict(self, args, account_currency=None):
|
||||||
"""this method populates the common properties of a gl entry record"""
|
"""this method populates the common properties of a gl entry record"""
|
||||||
|
|
||||||
@ -722,11 +731,15 @@ def get_tax_rate(account_head):
|
|||||||
return frappe.db.get_value("Account", account_head, ["tax_rate", "account_name"], as_dict=True)
|
return frappe.db.get_value("Account", account_head, ["tax_rate", "account_name"], as_dict=True)
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_default_taxes_and_charges(master_doctype, company=None):
|
def get_default_taxes_and_charges(master_doctype, tax_template=None, company=None):
|
||||||
if not company: return {}
|
if not company: return {}
|
||||||
|
|
||||||
default_tax = frappe.db.get_value(master_doctype,
|
if tax_template and company:
|
||||||
{"is_default": 1, "company": company})
|
tax_template_company = frappe.db.get_value(master_doctype, tax_template, "company")
|
||||||
|
if tax_template_company == company:
|
||||||
|
return
|
||||||
|
|
||||||
|
default_tax = frappe.db.get_value(master_doctype, {"is_default": 1, "company": company})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'taxes_and_charges': default_tax,
|
'taxes_and_charges': default_tax,
|
||||||
|
@ -232,7 +232,7 @@ def make_quotation(source_name, target_doc=None):
|
|||||||
quotation.conversion_rate = exchange_rate
|
quotation.conversion_rate = exchange_rate
|
||||||
|
|
||||||
# get default taxes
|
# get default taxes
|
||||||
taxes = get_default_taxes_and_charges("Sales Taxes and Charges Template", quotation.company)
|
taxes = get_default_taxes_and_charges("Sales Taxes and Charges Template", company=quotation.company)
|
||||||
if taxes.get('taxes'):
|
if taxes.get('taxes'):
|
||||||
quotation.update(taxes)
|
quotation.update(taxes)
|
||||||
|
|
||||||
|
@ -244,10 +244,11 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
|
|||||||
method: "erpnext.controllers.accounts_controller.get_default_taxes_and_charges",
|
method: "erpnext.controllers.accounts_controller.get_default_taxes_and_charges",
|
||||||
args: {
|
args: {
|
||||||
"master_doctype": taxes_and_charges_field.options,
|
"master_doctype": taxes_and_charges_field.options,
|
||||||
|
"tax_template": me.frm.doc.taxes_and_charges,
|
||||||
"company": me.frm.doc.company
|
"company": me.frm.doc.company
|
||||||
},
|
},
|
||||||
callback: function(r) {
|
callback: function(r) {
|
||||||
if(!r.exc) {
|
if(!r.exc && r.message) {
|
||||||
frappe.run_serially([
|
frappe.run_serially([
|
||||||
() => {
|
() => {
|
||||||
// directly set in doc, so as not to call triggers
|
// directly set in doc, so as not to call triggers
|
||||||
|
Loading…
Reference in New Issue
Block a user