feat: Merge taxes from mapped docs (#38346)
* feat: Merge taxes from mapped docs * chore: ci failures
This commit is contained in:
parent
4feecb69d8
commit
9b1c22250f
@ -843,7 +843,7 @@ erpnext.utils.map_current_doc = function(opts) {
|
|||||||
freeze_message: __("Mapping {0} ...", [opts.source_doctype]),
|
freeze_message: __("Mapping {0} ...", [opts.source_doctype]),
|
||||||
callback: function(r) {
|
callback: function(r) {
|
||||||
if(!r.exc) {
|
if(!r.exc) {
|
||||||
var doc = frappe.model.sync(r.message);
|
frappe.model.sync(r.message);
|
||||||
cur_frm.dirty();
|
cur_frm.dirty();
|
||||||
cur_frm.refresh();
|
cur_frm.refresh();
|
||||||
}
|
}
|
||||||
@ -870,6 +870,11 @@ erpnext.utils.map_current_doc = function(opts) {
|
|||||||
target: opts.target,
|
target: opts.target,
|
||||||
date_field: opts.date_field || undefined,
|
date_field: opts.date_field || undefined,
|
||||||
setters: opts.setters,
|
setters: opts.setters,
|
||||||
|
data_fields: [{
|
||||||
|
fieldname: 'merge_taxes',
|
||||||
|
fieldtype: 'Check',
|
||||||
|
label: __('Merge taxes from multiple documents'),
|
||||||
|
}],
|
||||||
get_query: opts.get_query,
|
get_query: opts.get_query,
|
||||||
add_filters_group: 1,
|
add_filters_group: 1,
|
||||||
allow_child_item_selection: opts.allow_child_item_selection,
|
allow_child_item_selection: opts.allow_child_item_selection,
|
||||||
@ -883,10 +888,7 @@ erpnext.utils.map_current_doc = function(opts) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
opts.source_name = values;
|
opts.source_name = values;
|
||||||
if (opts.allow_child_item_selection) {
|
opts.args = args;
|
||||||
// args contains filtered child docnames
|
|
||||||
opts.args = args;
|
|
||||||
}
|
|
||||||
d.dialog.hide();
|
d.dialog.hide();
|
||||||
_map();
|
_map();
|
||||||
},
|
},
|
||||||
|
|||||||
@ -1124,8 +1124,39 @@ def get_item_wise_returned_qty(pr_doc):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def merge_taxes(source_taxes, target_doc):
|
||||||
|
from erpnext.accounts.doctype.pos_invoice_merge_log.pos_invoice_merge_log import (
|
||||||
|
update_item_wise_tax_detail,
|
||||||
|
)
|
||||||
|
|
||||||
|
existing_taxes = target_doc.get("taxes") or []
|
||||||
|
idx = 1
|
||||||
|
for tax in source_taxes:
|
||||||
|
found = False
|
||||||
|
for t in existing_taxes:
|
||||||
|
if t.account_head == tax.account_head and t.cost_center == tax.cost_center:
|
||||||
|
t.tax_amount = flt(t.tax_amount) + flt(tax.tax_amount_after_discount_amount)
|
||||||
|
t.base_tax_amount = flt(t.base_tax_amount) + flt(tax.base_tax_amount_after_discount_amount)
|
||||||
|
update_item_wise_tax_detail(t, tax)
|
||||||
|
found = True
|
||||||
|
|
||||||
|
if not found:
|
||||||
|
tax.charge_type = "Actual"
|
||||||
|
tax.idx = idx
|
||||||
|
idx += 1
|
||||||
|
tax.included_in_print_rate = 0
|
||||||
|
tax.dont_recompute_tax = 1
|
||||||
|
tax.row_id = ""
|
||||||
|
tax.tax_amount = tax.tax_amount_after_discount_amount
|
||||||
|
tax.base_tax_amount = tax.base_tax_amount_after_discount_amount
|
||||||
|
tax.item_wise_tax_detail = tax.item_wise_tax_detail
|
||||||
|
existing_taxes.append(tax)
|
||||||
|
|
||||||
|
target_doc.set("taxes", existing_taxes)
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def make_purchase_invoice(source_name, target_doc=None):
|
def make_purchase_invoice(source_name, target_doc=None, args=None):
|
||||||
from erpnext.accounts.party import get_payment_terms_template
|
from erpnext.accounts.party import get_payment_terms_template
|
||||||
|
|
||||||
doc = frappe.get_doc("Purchase Receipt", source_name)
|
doc = frappe.get_doc("Purchase Receipt", source_name)
|
||||||
@ -1142,6 +1173,10 @@ def make_purchase_invoice(source_name, target_doc=None):
|
|||||||
)
|
)
|
||||||
doc.run_method("onload")
|
doc.run_method("onload")
|
||||||
doc.run_method("set_missing_values")
|
doc.run_method("set_missing_values")
|
||||||
|
|
||||||
|
if args and args.get("merge_taxes"):
|
||||||
|
merge_taxes(source.get("taxes") or [], doc)
|
||||||
|
|
||||||
doc.run_method("calculate_taxes_and_totals")
|
doc.run_method("calculate_taxes_and_totals")
|
||||||
doc.set_payment_schedule()
|
doc.set_payment_schedule()
|
||||||
|
|
||||||
@ -1205,7 +1240,11 @@ def make_purchase_invoice(source_name, target_doc=None):
|
|||||||
if not doc.get("is_return")
|
if not doc.get("is_return")
|
||||||
else get_pending_qty(d)[0] > 0,
|
else get_pending_qty(d)[0] > 0,
|
||||||
},
|
},
|
||||||
"Purchase Taxes and Charges": {"doctype": "Purchase Taxes and Charges", "add_if_empty": True},
|
"Purchase Taxes and Charges": {
|
||||||
|
"doctype": "Purchase Taxes and Charges",
|
||||||
|
"add_if_empty": True,
|
||||||
|
"ignore": args.get("merge_taxes") if args else 0,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
target_doc,
|
target_doc,
|
||||||
set_missing_values,
|
set_missing_values,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user