mirror of
https://github.com/frappe/erpnext.git
synced 2026-08-28 06:08:25 +00:00
refactor: pass typed arguments to get_item_details methods (#44230)
* refactor: pass proper types to get_item_details methods * chore: excempt previous commit from git blame
This commit is contained in:
@@ -62,6 +62,7 @@ from erpnext.setup.utils import get_exchange_rate
|
||||
from erpnext.stock.doctype.item.item import get_uom_conv_factor
|
||||
from erpnext.stock.doctype.packed_item.packed_item import make_packing_list
|
||||
from erpnext.stock.get_item_details import (
|
||||
ItemDetailsCtx,
|
||||
_get_item_tax_template,
|
||||
get_conversion_factor,
|
||||
get_item_details,
|
||||
@@ -752,24 +753,28 @@ class AccountsController(TransactionBase):
|
||||
|
||||
for item in self.get("items"):
|
||||
if item.get("item_code"):
|
||||
args = parent_dict.copy()
|
||||
args.update(item.as_dict())
|
||||
ctx: ItemDetailsCtx = ItemDetailsCtx(parent_dict.copy())
|
||||
ctx.update(item.as_dict())
|
||||
|
||||
args["doctype"] = self.doctype
|
||||
args["name"] = self.name
|
||||
args["child_doctype"] = item.doctype
|
||||
args["child_docname"] = item.name
|
||||
args["ignore_pricing_rule"] = (
|
||||
self.ignore_pricing_rule if hasattr(self, "ignore_pricing_rule") else 0
|
||||
ctx.update(
|
||||
{
|
||||
"doctype": self.doctype,
|
||||
"name": self.name,
|
||||
"child_doctype": item.doctype,
|
||||
"child_docname": item.name,
|
||||
"ignore_pricing_rule": (
|
||||
self.ignore_pricing_rule if hasattr(self, "ignore_pricing_rule") else 0
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
if not args.get("transaction_date"):
|
||||
args["transaction_date"] = args.get("posting_date")
|
||||
if not ctx.transaction_date:
|
||||
ctx.transaction_date = ctx.posting_date
|
||||
|
||||
if self.get("is_subcontracted"):
|
||||
args["is_subcontracted"] = self.is_subcontracted
|
||||
ctx.is_subcontracted = self.is_subcontracted
|
||||
|
||||
ret = get_item_details(args, self, for_validate=for_validate, overwrite_warehouse=False)
|
||||
ret = get_item_details(ctx, self, for_validate=for_validate, overwrite_warehouse=False)
|
||||
for fieldname, value in ret.items():
|
||||
if item.meta.get_field(fieldname) and value is not None:
|
||||
if item.get(fieldname) is None or fieldname in force_item_fields:
|
||||
@@ -3161,14 +3166,16 @@ def get_supplier_block_status(party_name):
|
||||
|
||||
|
||||
def set_child_tax_template_and_map(item, child_item, parent_doc):
|
||||
args = {
|
||||
"item_code": item.item_code,
|
||||
"posting_date": parent_doc.transaction_date,
|
||||
"tax_category": parent_doc.get("tax_category"),
|
||||
"company": parent_doc.get("company"),
|
||||
}
|
||||
ctx = ItemDetailsCtx(
|
||||
{
|
||||
"item_code": item.item_code,
|
||||
"posting_date": parent_doc.transaction_date,
|
||||
"tax_category": parent_doc.get("tax_category"),
|
||||
"company": parent_doc.get("company"),
|
||||
}
|
||||
)
|
||||
|
||||
child_item.item_tax_template = _get_item_tax_template(args, item.taxes)
|
||||
child_item.item_tax_template = _get_item_tax_template(ctx, item.taxes)
|
||||
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
|
||||
|
||||
@@ -14,7 +14,7 @@ from frappe.utils import nowdate, today, unique
|
||||
from pypika import Order
|
||||
|
||||
import erpnext
|
||||
from erpnext.stock.get_item_details import _get_item_tax_template
|
||||
from erpnext.stock.get_item_details import ItemDetailsCtx, _get_item_tax_template
|
||||
|
||||
|
||||
# searches for active employees
|
||||
@@ -813,14 +813,16 @@ def get_tax_template(doctype, txt, searchfield, start, page_len, filters):
|
||||
valid_from = filters.get("valid_from")
|
||||
valid_from = valid_from[1] if isinstance(valid_from, list) else valid_from
|
||||
|
||||
args = {
|
||||
"item_code": filters.get("item_code"),
|
||||
"posting_date": valid_from,
|
||||
"tax_category": filters.get("tax_category"),
|
||||
"company": company,
|
||||
}
|
||||
ctx = ItemDetailsCtx(
|
||||
{
|
||||
"item_code": filters.get("item_code"),
|
||||
"posting_date": valid_from,
|
||||
"tax_category": filters.get("tax_category"),
|
||||
"company": company,
|
||||
}
|
||||
)
|
||||
|
||||
taxes = _get_item_tax_template(args, taxes, for_validate=True)
|
||||
taxes = _get_item_tax_template(ctx, taxes, for_validate=True)
|
||||
return [(d,) for d in set(taxes)]
|
||||
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ from erpnext.controllers.accounts_controller import (
|
||||
validate_inclusive_tax,
|
||||
validate_taxes_and_charges,
|
||||
)
|
||||
from erpnext.stock.get_item_details import _get_item_tax_template
|
||||
from erpnext.stock.get_item_details import ItemDetailsCtx, _get_item_tax_template
|
||||
from erpnext.utilities.regional import temporary_flag
|
||||
|
||||
logger = frappe.logger(__name__)
|
||||
@@ -103,15 +103,17 @@ class calculate_taxes_and_totals:
|
||||
for item in self.doc.items:
|
||||
if item.item_code and item.get("item_tax_template"):
|
||||
item_doc = frappe.get_cached_doc("Item", item.item_code)
|
||||
args = {
|
||||
"net_rate": item.net_rate or item.rate,
|
||||
"base_net_rate": item.base_net_rate or item.base_rate,
|
||||
"tax_category": self.doc.get("tax_category"),
|
||||
"posting_date": self.doc.get("posting_date"),
|
||||
"bill_date": self.doc.get("bill_date"),
|
||||
"transaction_date": self.doc.get("transaction_date"),
|
||||
"company": self.doc.get("company"),
|
||||
}
|
||||
ctx = ItemDetailsCtx(
|
||||
{
|
||||
"net_rate": item.net_rate or item.rate,
|
||||
"base_net_rate": item.base_net_rate or item.base_rate,
|
||||
"tax_category": self.doc.get("tax_category"),
|
||||
"posting_date": self.doc.get("posting_date"),
|
||||
"bill_date": self.doc.get("bill_date"),
|
||||
"transaction_date": self.doc.get("transaction_date"),
|
||||
"company": self.doc.get("company"),
|
||||
}
|
||||
)
|
||||
|
||||
item_group = item_doc.item_group
|
||||
item_group_taxes = []
|
||||
@@ -127,7 +129,7 @@ class calculate_taxes_and_totals:
|
||||
# No validation if no taxes in item or item group
|
||||
continue
|
||||
|
||||
taxes = _get_item_tax_template(args, item_taxes + item_group_taxes, for_validate=True)
|
||||
taxes = _get_item_tax_template(ctx, item_taxes + item_group_taxes, for_validate=True)
|
||||
|
||||
if taxes:
|
||||
if item.item_tax_template not in taxes:
|
||||
|
||||
Reference in New Issue
Block a user