mirror of
https://github.com/frappe/erpnext.git
synced 2026-02-17 08:35:00 +00:00
fix: merge taxes in purchase receipt when get items from multiple purchase invoices (#51422)
* fix: merge taxes in purchase receipt when get items from multiple purchase invoices
* fix: make merge tax configurable
* chore: follow standard merge taxes method
* chore: follow standard merge taxes method
(cherry picked from commit 6fde0a6261)
This commit is contained in:
@@ -36,7 +36,7 @@ from erpnext.accounts.utils import get_account_currency, get_fiscal_year, update
|
|||||||
from erpnext.assets.doctype.asset.asset import is_cwip_accounting_enabled
|
from erpnext.assets.doctype.asset.asset import is_cwip_accounting_enabled
|
||||||
from erpnext.assets.doctype.asset_category.asset_category import get_asset_category_account
|
from erpnext.assets.doctype.asset_category.asset_category import get_asset_category_account
|
||||||
from erpnext.buying.utils import check_on_hold_or_closed_status
|
from erpnext.buying.utils import check_on_hold_or_closed_status
|
||||||
from erpnext.controllers.accounts_controller import validate_account_head
|
from erpnext.controllers.accounts_controller import merge_taxes, validate_account_head
|
||||||
from erpnext.controllers.buying_controller import BuyingController
|
from erpnext.controllers.buying_controller import BuyingController
|
||||||
from erpnext.stock.doctype.purchase_receipt.purchase_receipt import (
|
from erpnext.stock.doctype.purchase_receipt.purchase_receipt import (
|
||||||
update_billed_amount_based_on_po,
|
update_billed_amount_based_on_po,
|
||||||
@@ -2005,9 +2005,17 @@ def make_purchase_receipt(source_name, target_doc=None, args=None):
|
|||||||
args = json.loads(args)
|
args = json.loads(args)
|
||||||
|
|
||||||
def post_parent_process(source_parent, target_parent):
|
def post_parent_process(source_parent, target_parent):
|
||||||
for row in target_parent.get("items"):
|
remove_items_with_zero_qty(target_parent)
|
||||||
if row.get("qty") == 0:
|
set_missing_values(source_parent, target_parent)
|
||||||
target_parent.remove(row)
|
|
||||||
|
def remove_items_with_zero_qty(target_parent):
|
||||||
|
target_parent.items = [row for row in target_parent.get("items") if row.get("qty") != 0]
|
||||||
|
|
||||||
|
def set_missing_values(source_parent, target_parent):
|
||||||
|
target_parent.run_method("set_missing_values")
|
||||||
|
if args and args.get("merge_taxes"):
|
||||||
|
merge_taxes(source_parent, target_parent)
|
||||||
|
target_parent.run_method("calculate_taxes_and_totals")
|
||||||
|
|
||||||
def update_item(obj, target, source_parent):
|
def update_item(obj, target, source_parent):
|
||||||
from erpnext.controllers.sales_and_purchase_return import get_returned_qty_map_for_row
|
from erpnext.controllers.sales_and_purchase_return import get_returned_qty_map_for_row
|
||||||
@@ -2059,7 +2067,11 @@ def make_purchase_receipt(source_name, target_doc=None, args=None):
|
|||||||
"postprocess": update_item,
|
"postprocess": update_item,
|
||||||
"condition": lambda doc: abs(doc.received_qty) < abs(doc.qty) and select_item(doc),
|
"condition": lambda doc: abs(doc.received_qty) < abs(doc.qty) and select_item(doc),
|
||||||
},
|
},
|
||||||
"Purchase Taxes and Charges": {"doctype": "Purchase Taxes and Charges"},
|
"Purchase Taxes and Charges": {
|
||||||
|
"doctype": "Purchase Taxes and Charges",
|
||||||
|
"reset_value": not (args and args.get("merge_taxes")),
|
||||||
|
"ignore": args.get("merge_taxes") if args else 0,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
target_doc,
|
target_doc,
|
||||||
post_parent_process,
|
post_parent_process,
|
||||||
|
|||||||
@@ -994,7 +994,7 @@ erpnext.utils.map_current_doc = function (opts) {
|
|||||||
|
|
||||||
if (opts.source_doctype) {
|
if (opts.source_doctype) {
|
||||||
let data_fields = [];
|
let data_fields = [];
|
||||||
if (["Purchase Receipt", "Delivery Note"].includes(opts.source_doctype)) {
|
if (["Purchase Receipt", "Delivery Note", "Purchase Invoice"].includes(opts.source_doctype)) {
|
||||||
let target_meta = frappe.get_meta(cur_frm.doc.doctype);
|
let target_meta = frappe.get_meta(cur_frm.doc.doctype);
|
||||||
if (target_meta.fields.find((f) => f.fieldname === "taxes")) {
|
if (target_meta.fields.find((f) => f.fieldname === "taxes")) {
|
||||||
data_fields.push({
|
data_fields.push({
|
||||||
|
|||||||
Reference in New Issue
Block a user