fix: Add Taxes if missing via Update Items (#23705)

* fix: Add Taxes if missing via Update Items

* chore: PO Test for adding tax row via Update Items

* chore: SO Test for adding tax row via Update Items
This commit is contained in:
Marica
2020-10-22 16:28:41 +05:30
committed by GitHub
parent 203fc2b940
commit ab5d596959
4 changed files with 166 additions and 7 deletions

View File

@@ -1139,6 +1139,31 @@ def set_child_tax_template_and_map(item, child_item, parent_doc):
if child_item.get("item_tax_template"):
child_item.item_tax_rate = get_item_tax_map(parent_doc.get('company'), child_item.item_tax_template, as_json=True)
def add_taxes_from_tax_template(child_item, parent_doc):
add_taxes_from_item_tax_template = frappe.db.get_single_value("Accounts Settings", "add_taxes_from_item_tax_template")
if child_item.get("item_tax_rate") and add_taxes_from_item_tax_template:
tax_map = json.loads(child_item.get("item_tax_rate"))
for tax_type in tax_map:
tax_rate = flt(tax_map[tax_type])
taxes = parent_doc.get('taxes') or []
# add new row for tax head only if missing
found = any(tax.account_head == tax_type for tax in taxes)
if not found:
tax_row = parent_doc.append("taxes", {})
tax_row.update({
"description" : str(tax_type).split(' - ')[0],
"charge_type" : "On Net Total",
"account_head" : tax_type,
"rate" : tax_rate
})
if parent_doc.doctype == "Purchase Order":
tax_row.update({
"category" : "Total",
"add_deduct_tax" : "Add"
})
tax_row.db_insert()
def set_sales_order_defaults(parent_doctype, parent_doctype_name, child_docname, trans_item):
"""
Returns a Sales Order Item child item containing the default values
@@ -1153,6 +1178,7 @@ def set_sales_order_defaults(parent_doctype, parent_doctype_name, child_docname,
child_item.conversion_factor = flt(trans_item.get('conversion_factor')) or get_conversion_factor(item.item_code, item.stock_uom).get("conversion_factor") or 1.0
child_item.uom = item.stock_uom
set_child_tax_template_and_map(item, child_item, p_doc)
add_taxes_from_tax_template(child_item, p_doc)
child_item.warehouse = get_item_warehouse(item, p_doc, overwrite_warehouse=True)
if not child_item.warehouse:
frappe.throw(_("Cannot find {} for item {}. Please set the same in Item Master or Stock Settings.")
@@ -1176,6 +1202,7 @@ def set_purchase_order_defaults(parent_doctype, parent_doctype_name, child_docna
child_item.base_rate = 1 # Initiallize value will update in parent validation
child_item.base_amount = 1 # Initiallize value will update in parent validation
set_child_tax_template_and_map(item, child_item, p_doc)
add_taxes_from_tax_template(child_item, p_doc)
return child_item
def validate_and_delete_children(parent, data):