mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-13 10:11:20 +00:00
Apply default taxes on loading of document
This commit is contained in:
@@ -196,7 +196,7 @@ class SalesInvoice(SellingController):
|
|||||||
|
|
||||||
# fetch charges
|
# fetch charges
|
||||||
if self.taxes_and_charges and not len(self.get("taxes")):
|
if self.taxes_and_charges and not len(self.get("taxes")):
|
||||||
self.set_taxes("taxes", "taxes_and_charges")
|
self.set_taxes()
|
||||||
|
|
||||||
def get_advances(self):
|
def get_advances(self):
|
||||||
super(SalesInvoice, self).get_advances(self.debit_to, "Customer", self.customer,
|
super(SalesInvoice, self).get_advances(self.debit_to, "Customer", self.customer,
|
||||||
|
|||||||
@@ -140,30 +140,29 @@ class AccountsController(TransactionBase):
|
|||||||
"discount_percentage", "base_rate", "rate"]:
|
"discount_percentage", "base_rate", "rate"]:
|
||||||
item.set(field, ret.get(field))
|
item.set(field, ret.get(field))
|
||||||
|
|
||||||
def set_taxes(self, tax_parentfield, tax_master_field):
|
def set_taxes(self):
|
||||||
if not self.meta.get_field(tax_parentfield):
|
if not self.meta.get_field("taxes"):
|
||||||
return
|
return
|
||||||
|
|
||||||
tax_master_doctype = self.meta.get_field(tax_master_field).options
|
tax_master_doctype = self.meta.get_field("taxes_and_charges").options
|
||||||
|
|
||||||
if not self.get(tax_parentfield):
|
if not self.get("taxes"):
|
||||||
if not self.get(tax_master_field):
|
if not self.get("taxes_and_charges"):
|
||||||
# get the default tax master
|
# get the default tax master
|
||||||
self.set(tax_master_field, frappe.db.get_value(tax_master_doctype, {"is_default": 1}))
|
self.set("taxes_and_charges", frappe.db.get_value(tax_master_doctype, {"is_default": 1}))
|
||||||
|
|
||||||
self.append_taxes_from_master(tax_parentfield, tax_master_field, tax_master_doctype)
|
self.append_taxes_from_master(tax_master_doctype)
|
||||||
|
|
||||||
def append_taxes_from_master(self, tax_parentfield, tax_master_field, tax_master_doctype=None):
|
def append_taxes_from_master(self, tax_master_doctype=None):
|
||||||
if self.get(tax_master_field):
|
if self.get("taxes_and_charges"):
|
||||||
if not tax_master_doctype:
|
if not tax_master_doctype:
|
||||||
tax_master_doctype = self.meta.get_field(tax_master_field).options
|
tax_master_doctype = self.meta.get_field("taxes_and_charges").options
|
||||||
|
|
||||||
self.extend(tax_parentfield,
|
self.extend("taxes", get_taxes_and_charges(tax_master_doctype, self.get("taxes_and_charges")))
|
||||||
get_taxes_and_charges(tax_master_doctype, self.get(tax_master_field), tax_parentfield))
|
|
||||||
|
|
||||||
def set_other_charges(self):
|
def set_other_charges(self):
|
||||||
self.set("taxes", [])
|
self.set("taxes", [])
|
||||||
self.set_taxes("taxes", "taxes_and_charges")
|
self.set_taxes()
|
||||||
|
|
||||||
def validate_enabled_taxes_and_charges(self):
|
def validate_enabled_taxes_and_charges(self):
|
||||||
taxes_and_charges_doctype = self.meta.get_options("taxes_and_charges")
|
taxes_and_charges_doctype = self.meta.get_options("taxes_and_charges")
|
||||||
@@ -337,12 +336,17 @@ def get_tax_rate(account_head):
|
|||||||
return frappe.db.get_value("Account", account_head, "tax_rate")
|
return frappe.db.get_value("Account", account_head, "tax_rate")
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_taxes_and_charges(master_doctype, master_name, tax_parentfield):
|
def get_default_taxes_and_charges(master_doctype):
|
||||||
|
default_tax = frappe.db.get_value(master_doctype, {"is_default": 1})
|
||||||
|
return get_taxes_and_charges(master_doctype, default_tax)
|
||||||
|
|
||||||
|
@frappe.whitelist()
|
||||||
|
def get_taxes_and_charges(master_doctype, master_name):
|
||||||
from frappe.model import default_fields
|
from frappe.model import default_fields
|
||||||
tax_master = frappe.get_doc(master_doctype, master_name)
|
tax_master = frappe.get_doc(master_doctype, master_name)
|
||||||
|
|
||||||
taxes_and_charges = []
|
taxes_and_charges = []
|
||||||
for i, tax in enumerate(tax_master.get(tax_parentfield)):
|
for i, tax in enumerate(tax_master.get("taxes")):
|
||||||
tax = tax.as_dict()
|
tax = tax.as_dict()
|
||||||
|
|
||||||
for fieldname in default_fields:
|
for fieldname in default_fields:
|
||||||
|
|||||||
@@ -44,8 +44,6 @@ class BuyingController(StockController):
|
|||||||
self.update_if_missing(get_party_details(self.supplier, party_type="Supplier"))
|
self.update_if_missing(get_party_details(self.supplier, party_type="Supplier"))
|
||||||
|
|
||||||
self.set_missing_item_details()
|
self.set_missing_item_details()
|
||||||
if self.get("__islocal"):
|
|
||||||
self.set_taxes("taxes", "taxes_and_charges")
|
|
||||||
|
|
||||||
def set_supplier_from_item_default(self):
|
def set_supplier_from_item_default(self):
|
||||||
if self.meta.get_field("supplier") and not self.supplier:
|
if self.meta.get_field("supplier") and not self.supplier:
|
||||||
|
|||||||
@@ -42,8 +42,6 @@ class SellingController(StockController):
|
|||||||
# set contact and address details for customer, if they are not mentioned
|
# set contact and address details for customer, if they are not mentioned
|
||||||
self.set_missing_lead_customer_details()
|
self.set_missing_lead_customer_details()
|
||||||
self.set_price_list_and_item_details()
|
self.set_price_list_and_item_details()
|
||||||
if self.get("__islocal"):
|
|
||||||
self.set_taxes("taxes", "taxes_and_charges")
|
|
||||||
|
|
||||||
def set_missing_lead_customer_details(self):
|
def set_missing_lead_customer_details(self):
|
||||||
if getattr(self, "customer", None):
|
if getattr(self, "customer", None):
|
||||||
|
|||||||
@@ -41,6 +41,11 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
|
|||||||
|
|
||||||
onload_post_render: function() {
|
onload_post_render: function() {
|
||||||
var me = this;
|
var me = this;
|
||||||
|
if(this.frm.doc.__islocal && !(this.frm.doc.taxes || []).length
|
||||||
|
&& !(this.frm.doc.__onload ? this.frm.doc.__onload.load_after_mapping : false)) {
|
||||||
|
this.apply_default_taxes();
|
||||||
|
}
|
||||||
|
|
||||||
if(this.frm.doc.__islocal && this.frm.doc.company && this.frm.doc["items"] && !this.frm.doc.is_pos) {
|
if(this.frm.doc.__islocal && this.frm.doc.company && this.frm.doc["items"] && !this.frm.doc.is_pos) {
|
||||||
this.calculate_taxes_and_totals();
|
this.calculate_taxes_and_totals();
|
||||||
}
|
}
|
||||||
@@ -59,6 +64,23 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
|
|||||||
this.setup_sms();
|
this.setup_sms();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
apply_default_taxes: function() {
|
||||||
|
var me = this;
|
||||||
|
return frappe.call({
|
||||||
|
method: "erpnext.controllers.accounts_controller.get_default_taxes_and_charges",
|
||||||
|
args: {
|
||||||
|
"master_doctype": frappe.meta.get_docfield(me.frm.doc.doctype, "taxes_and_charges",
|
||||||
|
me.frm.doc.name).options
|
||||||
|
},
|
||||||
|
callback: function(r) {
|
||||||
|
if(!r.exc) {
|
||||||
|
me.frm.set_value("taxes", r.message);
|
||||||
|
me.calculate_taxes_and_totals();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
setup_sms: function() {
|
setup_sms: function() {
|
||||||
var me = this;
|
var me = this;
|
||||||
if(this.frm.doc.docstatus===1 && !in_list(["Lost", "Stopped"], this.frm.doc.status)) {
|
if(this.frm.doc.docstatus===1 && !in_list(["Lost", "Stopped"], this.frm.doc.status)) {
|
||||||
@@ -646,7 +668,6 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
|
|||||||
"master_doctype": frappe.meta.get_docfield(this.frm.doc.doctype, "taxes_and_charges",
|
"master_doctype": frappe.meta.get_docfield(this.frm.doc.doctype, "taxes_and_charges",
|
||||||
this.frm.doc.name).options,
|
this.frm.doc.name).options,
|
||||||
"master_name": this.frm.doc.taxes_and_charges,
|
"master_name": this.frm.doc.taxes_and_charges,
|
||||||
"tax_parentfield": "taxes"
|
|
||||||
},
|
},
|
||||||
callback: function(r) {
|
callback: function(r) {
|
||||||
if(!r.exc) {
|
if(!r.exc) {
|
||||||
|
|||||||
@@ -256,7 +256,7 @@ def set_taxes(quotation, cart_settings, billing_territory):
|
|||||||
quotation.set("taxes", [])
|
quotation.set("taxes", [])
|
||||||
|
|
||||||
# append taxes
|
# append taxes
|
||||||
quotation.append_taxes_from_master("taxes", "taxes_and_charges")
|
quotation.append_taxes_from_master()
|
||||||
|
|
||||||
def get_lead_or_customer():
|
def get_lead_or_customer():
|
||||||
customer = frappe.db.get_value("Contact", {"email_id": frappe.session.user}, "customer")
|
customer = frappe.db.get_value("Contact", {"email_id": frappe.session.user}, "customer")
|
||||||
|
|||||||
Reference in New Issue
Block a user