mirror of
https://github.com/frappe/erpnext.git
synced 2026-02-13 01:34:10 +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)
# Conflicts:
# erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
This commit is contained in:
@@ -38,7 +38,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 import get_warehouse_account_map
|
from erpnext.stock import get_warehouse_account_map
|
||||||
from erpnext.stock.doctype.purchase_receipt.purchase_receipt import (
|
from erpnext.stock.doctype.purchase_receipt.purchase_receipt import (
|
||||||
@@ -2083,6 +2083,19 @@ def make_purchase_receipt(source_name, target_doc=None, args=None):
|
|||||||
if isinstance(args, str):
|
if isinstance(args, str):
|
||||||
args = json.loads(args)
|
args = json.loads(args)
|
||||||
|
|
||||||
|
def post_parent_process(source_parent, target_parent):
|
||||||
|
remove_items_with_zero_qty(target_parent)
|
||||||
|
set_missing_values(source_parent, target_parent)
|
||||||
|
|
||||||
|
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):
|
||||||
target.qty = flt(obj.qty) - flt(obj.received_qty)
|
target.qty = flt(obj.qty) - flt(obj.received_qty)
|
||||||
target.received_qty = flt(obj.qty) - flt(obj.received_qty)
|
target.received_qty = flt(obj.qty) - flt(obj.received_qty)
|
||||||
@@ -2122,7 +2135,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,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -979,7 +979,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