mirror of
https://github.com/frappe/erpnext.git
synced 2026-04-30 20:18:27 +00:00
Merge pull request #43667 from frappe/version-15-hotfix
chore: release v15
This commit is contained in:
@@ -571,7 +571,7 @@ def make_payment_request(**args):
|
||||
)
|
||||
|
||||
party_type = args.get("party_type") or "Customer"
|
||||
party_account_currency = ref_doc.party_account_currency
|
||||
party_account_currency = ref_doc.get("party_account_currency")
|
||||
|
||||
if not party_account_currency:
|
||||
party_account = get_party_account(party_type, ref_doc.get(party_type.lower()), ref_doc.company)
|
||||
|
||||
@@ -60,7 +60,7 @@ class PeriodClosingVoucher(AccountsController):
|
||||
)
|
||||
if gle_count > 5000:
|
||||
frappe.enqueue(
|
||||
make_reverse_gl_entries,
|
||||
process_cancellation,
|
||||
voucher_type="Period Closing Voucher",
|
||||
voucher_no=self.name,
|
||||
queue="long",
|
||||
@@ -71,9 +71,7 @@ class PeriodClosingVoucher(AccountsController):
|
||||
alert=True,
|
||||
)
|
||||
else:
|
||||
make_reverse_gl_entries(voucher_type="Period Closing Voucher", voucher_no=self.name)
|
||||
|
||||
self.delete_closing_entries()
|
||||
process_cancellation(voucher_type="Period Closing Voucher", voucher_no=self.name)
|
||||
|
||||
def validate_future_closing_vouchers(self):
|
||||
if frappe.db.exists(
|
||||
@@ -86,12 +84,6 @@ class PeriodClosingVoucher(AccountsController):
|
||||
)
|
||||
)
|
||||
|
||||
def delete_closing_entries(self):
|
||||
closing_balance = frappe.qb.DocType("Account Closing Balance")
|
||||
frappe.qb.from_(closing_balance).delete().where(
|
||||
closing_balance.period_closing_voucher == self.name
|
||||
).run()
|
||||
|
||||
def validate_account_head(self):
|
||||
closing_account_type = frappe.get_cached_value("Account", self.closing_account_head, "root_type")
|
||||
|
||||
@@ -166,14 +158,7 @@ class PeriodClosingVoucher(AccountsController):
|
||||
closing_entries = self.get_grouped_gl_entries(get_opening_entries=get_opening_entries)
|
||||
if len(gl_entries + closing_entries) > 3000:
|
||||
frappe.enqueue(
|
||||
process_gl_entries,
|
||||
gl_entries=gl_entries,
|
||||
voucher_name=self.name,
|
||||
timeout=3000,
|
||||
)
|
||||
|
||||
frappe.enqueue(
|
||||
process_closing_entries,
|
||||
process_gl_and_closing_entries,
|
||||
gl_entries=gl_entries,
|
||||
closing_entries=closing_entries,
|
||||
voucher_name=self.name,
|
||||
@@ -187,8 +172,9 @@ class PeriodClosingVoucher(AccountsController):
|
||||
alert=True,
|
||||
)
|
||||
else:
|
||||
process_gl_entries(gl_entries, self.name)
|
||||
process_closing_entries(gl_entries, closing_entries, self.name, self.company, self.posting_date)
|
||||
process_gl_and_closing_entries(
|
||||
gl_entries, closing_entries, self.name, self.company, self.posting_date
|
||||
)
|
||||
|
||||
def get_grouped_gl_entries(self, get_opening_entries=False):
|
||||
closing_entries = []
|
||||
@@ -353,9 +339,10 @@ class PeriodClosingVoucher(AccountsController):
|
||||
|
||||
if get_opening_entries:
|
||||
query = query.where(
|
||||
gl_entry.posting_date.between(self.get("year_start_date"), self.posting_date)
|
||||
| gl_entry.is_opening
|
||||
== "Yes"
|
||||
( # noqa: UP034
|
||||
(gl_entry.posting_date.between(self.get("year_start_date"), self.posting_date))
|
||||
| (gl_entry.is_opening == "Yes")
|
||||
)
|
||||
)
|
||||
else:
|
||||
query = query.where(
|
||||
@@ -373,12 +360,16 @@ class PeriodClosingVoucher(AccountsController):
|
||||
return query.run(as_dict=1)
|
||||
|
||||
|
||||
def process_gl_entries(gl_entries, voucher_name):
|
||||
def process_gl_and_closing_entries(gl_entries, closing_entries, voucher_name, company, closing_date):
|
||||
from erpnext.accounts.doctype.account_closing_balance.account_closing_balance import (
|
||||
make_closing_entries,
|
||||
)
|
||||
from erpnext.accounts.general_ledger import make_gl_entries
|
||||
|
||||
try:
|
||||
if gl_entries:
|
||||
make_gl_entries(gl_entries, merge_entries=False)
|
||||
make_closing_entries(gl_entries + closing_entries, voucher_name, company, closing_date)
|
||||
frappe.db.set_value("Period Closing Voucher", voucher_name, "gle_processing_status", "Completed")
|
||||
except Exception as e:
|
||||
frappe.db.rollback()
|
||||
@@ -386,25 +377,21 @@ def process_gl_entries(gl_entries, voucher_name):
|
||||
frappe.db.set_value("Period Closing Voucher", voucher_name, "gle_processing_status", "Failed")
|
||||
|
||||
|
||||
def process_closing_entries(gl_entries, closing_entries, voucher_name, company, closing_date):
|
||||
from erpnext.accounts.doctype.account_closing_balance.account_closing_balance import (
|
||||
make_closing_entries,
|
||||
)
|
||||
|
||||
try:
|
||||
make_closing_entries(gl_entries + closing_entries, voucher_name, company, closing_date)
|
||||
except Exception as e:
|
||||
frappe.db.rollback()
|
||||
frappe.log_error(e)
|
||||
|
||||
|
||||
def make_reverse_gl_entries(voucher_type, voucher_no):
|
||||
def process_cancellation(voucher_type, voucher_no):
|
||||
from erpnext.accounts.general_ledger import make_reverse_gl_entries
|
||||
|
||||
try:
|
||||
make_reverse_gl_entries(voucher_type=voucher_type, voucher_no=voucher_no)
|
||||
delete_closing_entries(voucher_no)
|
||||
frappe.db.set_value("Period Closing Voucher", voucher_no, "gle_processing_status", "Completed")
|
||||
except Exception as e:
|
||||
frappe.db.rollback()
|
||||
frappe.log_error(e)
|
||||
frappe.db.set_value("Period Closing Voucher", voucher_no, "gle_processing_status", "Failed")
|
||||
|
||||
|
||||
def delete_closing_entries(voucher_no):
|
||||
closing_balance = frappe.qb.DocType("Account Closing Balance")
|
||||
frappe.qb.from_(closing_balance).delete().where(
|
||||
closing_balance.period_closing_voucher == voucher_no
|
||||
).run()
|
||||
|
||||
@@ -1131,6 +1131,12 @@ class TestPricingRule(FrappeTestCase):
|
||||
self.assertEqual(so.items[1].item_code, "_Test Item")
|
||||
self.assertEqual(so.items[1].qty, 3)
|
||||
|
||||
so = make_sales_order(item_code="_Test Item", qty=5, do_not_submit=1)
|
||||
so.items[0].qty = 1
|
||||
del so.items[-1]
|
||||
so.save()
|
||||
self.assertEqual(len(so.items), 1)
|
||||
|
||||
def test_apply_multiple_pricing_rules_for_discount_percentage_and_amount(self):
|
||||
frappe.delete_doc_if_exists("Pricing Rule", "_Test Pricing Rule 1")
|
||||
frappe.delete_doc_if_exists("Pricing Rule", "_Test Pricing Rule 2")
|
||||
|
||||
@@ -657,6 +657,9 @@ def get_product_discount_rule(pricing_rule, item_details, args=None, doc=None):
|
||||
if pricing_rule.round_free_qty:
|
||||
qty = math.floor(qty)
|
||||
|
||||
if not qty:
|
||||
return
|
||||
|
||||
free_item_data_args = {
|
||||
"item_code": free_item,
|
||||
"qty": qty,
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
import frappe
|
||||
from frappe import _
|
||||
from frappe.model.document import Document
|
||||
from frappe.query_builder import Criterion
|
||||
from frappe.query_builder.functions import IfNull
|
||||
|
||||
pricing_rule_fields = [
|
||||
"apply_on",
|
||||
@@ -162,22 +164,50 @@ class PromotionalScheme(Document):
|
||||
if self.is_new():
|
||||
return
|
||||
|
||||
transaction_exists = False
|
||||
docnames = []
|
||||
invalid_pricing_rule = self.get_invalid_pricing_rules()
|
||||
|
||||
# If user has changed applicable for
|
||||
if self.get_doc_before_save() and self.get_doc_before_save().applicable_for == self.applicable_for:
|
||||
if not invalid_pricing_rule:
|
||||
return
|
||||
|
||||
docnames = frappe.get_all("Pricing Rule", filters={"promotional_scheme": self.name})
|
||||
if frappe.db.exists(
|
||||
"Pricing Rule Detail",
|
||||
{
|
||||
"pricing_rule": ["in", invalid_pricing_rule],
|
||||
"docstatus": ["<", 2],
|
||||
},
|
||||
):
|
||||
raise_for_transaction_exists(self.name)
|
||||
|
||||
for docname in docnames:
|
||||
if frappe.db.exists("Pricing Rule Detail", {"pricing_rule": docname.name, "docstatus": ("<", 2)}):
|
||||
raise_for_transaction_exists(self.name)
|
||||
for doc in invalid_pricing_rule:
|
||||
frappe.delete_doc("Pricing Rule", doc)
|
||||
|
||||
if docnames and not transaction_exists:
|
||||
for docname in docnames:
|
||||
frappe.delete_doc("Pricing Rule", docname.name)
|
||||
frappe.msgprint(
|
||||
_("The following invalid Pricing Rules are deleted:")
|
||||
+ "<br><br><ul><li>"
|
||||
+ "</li><li>".join(invalid_pricing_rule)
|
||||
+ "</li></ul>"
|
||||
)
|
||||
|
||||
def get_invalid_pricing_rules(self):
|
||||
pr = frappe.qb.DocType("Pricing Rule")
|
||||
conditions = []
|
||||
conditions.append(pr.promotional_scheme == self.name)
|
||||
|
||||
if self.applicable_for:
|
||||
applicable_for = frappe.scrub(self.applicable_for)
|
||||
applicable_for_list = [d.get(applicable_for) for d in self.get(applicable_for)]
|
||||
|
||||
conditions.append(
|
||||
(IfNull(pr.applicable_for, "") != self.applicable_for)
|
||||
| (
|
||||
(IfNull(pr.applicable_for, "") == self.applicable_for)
|
||||
& IfNull(pr[applicable_for], "").notin(applicable_for_list)
|
||||
)
|
||||
)
|
||||
else:
|
||||
conditions.append(IfNull(pr.applicable_for, "") != "")
|
||||
|
||||
return frappe.qb.from_(pr).select(pr.name).where(Criterion.all(conditions)).run(pluck=True)
|
||||
|
||||
def on_update(self):
|
||||
self.validate()
|
||||
|
||||
@@ -90,6 +90,31 @@ class TestPromotionalScheme(unittest.TestCase):
|
||||
price_rules = frappe.get_all("Pricing Rule", filters={"promotional_scheme": ps.name})
|
||||
self.assertEqual(price_rules, [])
|
||||
|
||||
def test_change_applicable_for_values_in_promotional_scheme(self):
|
||||
ps = make_promotional_scheme(applicable_for="Customer", customer="_Test Customer")
|
||||
ps.append("customer", {"customer": "_Test Customer 2"})
|
||||
ps.save()
|
||||
|
||||
price_rules = frappe.get_all(
|
||||
"Pricing Rule", filters={"promotional_scheme": ps.name, "applicable_for": "Customer"}
|
||||
)
|
||||
self.assertTrue(len(price_rules), 2)
|
||||
|
||||
ps.set("customer", [])
|
||||
ps.append("customer", {"customer": "_Test Customer 2"})
|
||||
ps.save()
|
||||
|
||||
price_rules = frappe.get_all(
|
||||
"Pricing Rule",
|
||||
filters={
|
||||
"promotional_scheme": ps.name,
|
||||
"applicable_for": "Customer",
|
||||
"customer": "_Test Customer",
|
||||
},
|
||||
)
|
||||
self.assertEqual(price_rules, [])
|
||||
frappe.delete_doc("Promotional Scheme", ps.name)
|
||||
|
||||
def test_min_max_amount_configuration(self):
|
||||
ps = make_promotional_scheme()
|
||||
ps.price_discount_slabs[0].min_amount = 10
|
||||
|
||||
@@ -610,8 +610,6 @@ def get_tcs_amount(parties, inv, tax_details, vouchers, adv_vouchers):
|
||||
conditions.append(ple.voucher_no == ple.against_voucher_no)
|
||||
conditions.append(ple.company == inv.company)
|
||||
|
||||
(qb.from_(ple).select(Abs(Sum(ple.amount))).where(Criterion.all(conditions)).run(as_list=1))
|
||||
|
||||
advance_amt = (
|
||||
qb.from_(ple).select(Abs(Sum(ple.amount))).where(Criterion.all(conditions)).run()[0][0] or 0.0
|
||||
)
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
{
|
||||
"actions": [],
|
||||
"allow_rename": 1,
|
||||
"autoname": "format:UNREC-{#####}",
|
||||
"creation": "2023-08-22 10:26:34.421423",
|
||||
"default_view": "List",
|
||||
"doctype": "DocType",
|
||||
@@ -58,11 +56,10 @@
|
||||
"index_web_pages_for_search": 1,
|
||||
"is_submittable": 1,
|
||||
"links": [],
|
||||
"modified": "2023-08-28 17:42:50.261377",
|
||||
"modified": "2024-10-10 12:03:50.022444",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Unreconcile Payment",
|
||||
"naming_rule": "Expression",
|
||||
"owner": "Administrator",
|
||||
"permissions": [
|
||||
{
|
||||
|
||||
@@ -47,7 +47,7 @@ frappe.query_reports["Bank Reconciliation Statement"] = {
|
||||
},
|
||||
],
|
||||
formatter: function (value, row, column, data, default_formatter, filter) {
|
||||
if (column.fieldname == "payment_entry" && value == "Cheques and Deposits incorrectly cleared") {
|
||||
if (column.fieldname == "payment_entry" && value == __("Cheques and Deposits incorrectly cleared")) {
|
||||
column.link_onclick =
|
||||
"frappe.query_reports['Bank Reconciliation Statement'].open_utility_report()";
|
||||
}
|
||||
|
||||
@@ -469,10 +469,13 @@ def update_parent_account_names(accounts):
|
||||
|
||||
for d in accounts:
|
||||
if d.account_number:
|
||||
account_name = d.account_number + " - " + d.account_name
|
||||
account_key = d.account_number + " - " + d.account_name
|
||||
else:
|
||||
account_name = d.account_name
|
||||
name_to_account_map[d.name] = account_name
|
||||
account_key = d.account_name
|
||||
|
||||
d.account_key = account_key
|
||||
|
||||
name_to_account_map[d.name] = account_key
|
||||
|
||||
for account in accounts:
|
||||
if account.parent_account:
|
||||
@@ -505,33 +508,26 @@ def get_subsidiary_companies(company):
|
||||
|
||||
def get_accounts(root_type, companies):
|
||||
accounts = []
|
||||
added_accounts = []
|
||||
|
||||
for company in companies:
|
||||
for account in frappe.get_all(
|
||||
"Account",
|
||||
fields=[
|
||||
"name",
|
||||
"is_group",
|
||||
"company",
|
||||
"parent_account",
|
||||
"lft",
|
||||
"rgt",
|
||||
"root_type",
|
||||
"report_type",
|
||||
"account_name",
|
||||
"account_number",
|
||||
],
|
||||
filters={"company": company, "root_type": root_type},
|
||||
):
|
||||
if account.account_number:
|
||||
account_key = account.account_number + "-" + account.account_name
|
||||
else:
|
||||
account_key = account.account_name
|
||||
|
||||
if account_key not in added_accounts:
|
||||
accounts.append(account)
|
||||
added_accounts.append(account_key)
|
||||
accounts.extend(
|
||||
frappe.get_all(
|
||||
"Account",
|
||||
fields=[
|
||||
"name",
|
||||
"is_group",
|
||||
"company",
|
||||
"parent_account",
|
||||
"lft",
|
||||
"rgt",
|
||||
"root_type",
|
||||
"report_type",
|
||||
"account_name",
|
||||
"account_number",
|
||||
],
|
||||
filters={"company": company, "root_type": root_type},
|
||||
)
|
||||
)
|
||||
|
||||
return accounts
|
||||
|
||||
@@ -770,15 +766,17 @@ def add_total_row(out, root_type, balance_must_be, companies, company_currency):
|
||||
def filter_accounts(accounts, depth=10):
|
||||
parent_children_map = {}
|
||||
accounts_by_name = {}
|
||||
for d in accounts:
|
||||
if d.account_number:
|
||||
account_name = d.account_number + " - " + d.account_name
|
||||
else:
|
||||
account_name = d.account_name
|
||||
d["company_wise_opening_bal"] = defaultdict(float)
|
||||
accounts_by_name[account_name] = d
|
||||
added_accounts = []
|
||||
|
||||
parent_children_map.setdefault(d.parent_account or None, []).append(d)
|
||||
for d in accounts:
|
||||
if d.account_key in added_accounts:
|
||||
continue
|
||||
|
||||
added_accounts.append(d.account_key)
|
||||
d["company_wise_opening_bal"] = defaultdict(float)
|
||||
accounts_by_name[d.account_key] = d
|
||||
|
||||
parent_children_map.setdefault(d.parent_account_name or None, []).append(d)
|
||||
|
||||
filtered_accounts = []
|
||||
|
||||
@@ -790,7 +788,7 @@ def filter_accounts(accounts, depth=10):
|
||||
for child in children:
|
||||
child.indent = level
|
||||
filtered_accounts.append(child)
|
||||
add_to_list(child.name, level + 1)
|
||||
add_to_list(child.account_key, level + 1)
|
||||
|
||||
add_to_list(None, 0)
|
||||
|
||||
|
||||
@@ -390,6 +390,7 @@ def make_supplier_quotation_from_rfq(source_name, target_doc=None, for_supplier=
|
||||
"Request for Quotation": {
|
||||
"doctype": "Supplier Quotation",
|
||||
"validation": {"docstatus": ["=", 1]},
|
||||
"field_map": {"opportunity": "opportunity"},
|
||||
},
|
||||
"Request for Quotation Item": {
|
||||
"doctype": "Supplier Quotation Item",
|
||||
@@ -455,6 +456,7 @@ def create_rfq_items(sq_doc, supplier, data):
|
||||
"material_request",
|
||||
"material_request_item",
|
||||
"stock_qty",
|
||||
"uom",
|
||||
]:
|
||||
args[field] = data.get(field)
|
||||
|
||||
|
||||
@@ -473,6 +473,16 @@ class SellingController(StockController):
|
||||
raise_error_if_no_rate=False,
|
||||
)
|
||||
|
||||
if (
|
||||
not d.incoming_rate
|
||||
and self.get("return_against")
|
||||
and self.get("is_return")
|
||||
and get_valuation_method(d.item_code) == "Moving Average"
|
||||
):
|
||||
d.incoming_rate = get_rate_for_return(
|
||||
self.doctype, self.name, d.item_code, self.return_against, item_row=d
|
||||
)
|
||||
|
||||
# For internal transfers use incoming rate as the valuation rate
|
||||
if self.is_internal_transfer():
|
||||
if self.doctype == "Delivery Note" or self.get("update_stock"):
|
||||
|
||||
@@ -63,6 +63,21 @@ class StockController(AccountsController):
|
||||
self.set_rate_of_stock_uom()
|
||||
self.validate_internal_transfer()
|
||||
self.validate_putaway_capacity()
|
||||
self.reset_conversion_factor()
|
||||
|
||||
def reset_conversion_factor(self):
|
||||
for row in self.get("items"):
|
||||
if row.uom != row.stock_uom:
|
||||
continue
|
||||
|
||||
if row.conversion_factor != 1.0:
|
||||
row.conversion_factor = 1.0
|
||||
frappe.msgprint(
|
||||
_(
|
||||
"Conversion factor for item {0} has been reset to 1.0 as the uom {1} is same as stock uom {2}."
|
||||
).format(bold(row.item_code), bold(row.uom), bold(row.stock_uom)),
|
||||
alert=True,
|
||||
)
|
||||
|
||||
def validate_items_exist(self):
|
||||
if not self.get("items"):
|
||||
|
||||
@@ -158,11 +158,20 @@ class WorkOrder(Document):
|
||||
self.validate_operation_time()
|
||||
self.status = self.get_status()
|
||||
self.validate_workstation_type()
|
||||
self.reset_use_multi_level_bom()
|
||||
|
||||
validate_uom_is_integer(self, "stock_uom", ["qty", "produced_qty"])
|
||||
|
||||
self.set_required_items(reset_only_qty=len(self.get("required_items")))
|
||||
|
||||
def reset_use_multi_level_bom(self):
|
||||
if self.is_new():
|
||||
return
|
||||
|
||||
before_save_obj = self.get_doc_before_save()
|
||||
if before_save_obj.use_multi_level_bom != self.use_multi_level_bom:
|
||||
self.get_items_and_operations_from_bom()
|
||||
|
||||
def validate_workstation_type(self):
|
||||
for row in self.operations:
|
||||
if not row.workstation and not row.workstation_type:
|
||||
|
||||
@@ -678,6 +678,10 @@ erpnext.SerialBatchPackageSelector = class SerialNoBatchBundleUpdate {
|
||||
}
|
||||
|
||||
get_warehouse() {
|
||||
if (this.item?.is_rejected) {
|
||||
return this.item.rejected_warehouse;
|
||||
}
|
||||
|
||||
return this.item?.type_of_transaction === "Outward"
|
||||
? this.item.warehouse || this.item.s_warehouse
|
||||
: this.item.warehouse || this.item.t_warehouse;
|
||||
|
||||
@@ -369,24 +369,25 @@ def _make_sales_order(source_name, target_doc=None, ignore_permissions=False):
|
||||
if customer:
|
||||
target.customer = customer.name
|
||||
target.customer_name = customer.customer_name
|
||||
|
||||
# sales team
|
||||
if not target.get("sales_team"):
|
||||
for d in customer.get("sales_team") or []:
|
||||
target.append(
|
||||
"sales_team",
|
||||
{
|
||||
"sales_person": d.sales_person,
|
||||
"allocated_percentage": d.allocated_percentage or None,
|
||||
"commission_rate": d.commission_rate,
|
||||
},
|
||||
)
|
||||
|
||||
if source.referral_sales_partner:
|
||||
target.sales_partner = source.referral_sales_partner
|
||||
target.commission_rate = frappe.get_value(
|
||||
"Sales Partner", source.referral_sales_partner, "commission_rate"
|
||||
)
|
||||
|
||||
# sales team
|
||||
if not target.get("sales_team"):
|
||||
for d in customer.get("sales_team") or []:
|
||||
target.append(
|
||||
"sales_team",
|
||||
{
|
||||
"sales_person": d.sales_person,
|
||||
"allocated_percentage": d.allocated_percentage or None,
|
||||
"commission_rate": d.commission_rate,
|
||||
},
|
||||
)
|
||||
|
||||
target.flags.ignore_permissions = ignore_permissions
|
||||
target.run_method("set_missing_values")
|
||||
target.run_method("calculate_taxes_and_totals")
|
||||
|
||||
@@ -35,7 +35,7 @@ from erpnext.stock.doctype.stock_reservation_entry.stock_reservation_entry impor
|
||||
get_sre_reserved_qty_details_for_voucher,
|
||||
has_reserved_stock,
|
||||
)
|
||||
from erpnext.stock.get_item_details import get_default_bom, get_price_list_rate
|
||||
from erpnext.stock.get_item_details import get_bin_details, get_default_bom, get_price_list_rate
|
||||
from erpnext.stock.stock_balance import get_reserved_qty, update_bin_qty
|
||||
|
||||
form_grid_templates = {"items": "templates/form_grid/item_grid.html"}
|
||||
@@ -838,6 +838,9 @@ def make_material_request(source_name, target_doc=None):
|
||||
target.project = source_parent.project
|
||||
target.qty = get_remaining_qty(source)
|
||||
target.stock_qty = flt(target.qty) * flt(target.conversion_factor)
|
||||
target.actual_qty = get_bin_details(
|
||||
target.item_code, target.warehouse, source_parent.company, True
|
||||
).get("actual_qty", 0)
|
||||
|
||||
args = target.as_dict().copy()
|
||||
args.update(
|
||||
|
||||
@@ -30,6 +30,7 @@ from erpnext.selling.doctype.sales_order.sales_order import (
|
||||
)
|
||||
from erpnext.stock.doctype.item.test_item import make_item
|
||||
from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry
|
||||
from erpnext.stock.get_item_details import get_bin_details
|
||||
|
||||
|
||||
class TestSalesOrder(AccountsTestMixin, FrappeTestCase):
|
||||
@@ -96,6 +97,12 @@ class TestSalesOrder(AccountsTestMixin, FrappeTestCase):
|
||||
self.assertEqual(mr.material_request_type, "Purchase")
|
||||
self.assertEqual(len(mr.get("items")), len(so.get("items")))
|
||||
|
||||
for item in mr.get("items"):
|
||||
actual_qty = get_bin_details(item.item_code, item.warehouse, mr.company, True).get(
|
||||
"actual_qty", 0
|
||||
)
|
||||
self.assertEqual(flt(item.actual_qty), actual_qty)
|
||||
|
||||
def test_make_delivery_note(self):
|
||||
so = make_sales_order(do_not_submit=True)
|
||||
|
||||
|
||||
@@ -2039,6 +2039,47 @@ class TestDeliveryNote(FrappeTestCase):
|
||||
self.assertEqual(sn.status, "Delivered")
|
||||
self.assertEqual(sn.warranty_period, 100)
|
||||
|
||||
def test_batch_return_dn(self):
|
||||
from erpnext.stock.doctype.delivery_note.delivery_note import make_sales_return
|
||||
|
||||
item_code = make_item(
|
||||
"Test Batch Return DN Item 1",
|
||||
properties={
|
||||
"has_batch_no": 1,
|
||||
"valuation_method": "Moving Average",
|
||||
"create_new_batch": 1,
|
||||
"batch_number_series": "TBRDN1-.#####",
|
||||
"is_stock_item": 1,
|
||||
},
|
||||
).name
|
||||
|
||||
se = make_stock_entry(item_code=item_code, target="_Test Warehouse - _TC", qty=5, basic_rate=100)
|
||||
|
||||
batch_no = get_batch_from_bundle(se.items[0].serial_and_batch_bundle)
|
||||
dn = create_delivery_note(
|
||||
item_code=item_code,
|
||||
qty=5,
|
||||
rate=500,
|
||||
use_serial_batch_fields=1,
|
||||
batch_no=batch_no,
|
||||
)
|
||||
|
||||
dn_return = make_sales_return(dn.name)
|
||||
dn_return.save().submit()
|
||||
|
||||
self.assertEqual(dn_return.items[0].qty, 5 * -1)
|
||||
|
||||
returned_batch_no = get_batch_from_bundle(dn_return.items[0].serial_and_batch_bundle)
|
||||
self.assertEqual(batch_no, returned_batch_no)
|
||||
|
||||
stock_value_difference = frappe.db.get_value(
|
||||
"Stock Ledger Entry",
|
||||
{"voucher_no": dn_return.name, "voucher_type": "Delivery Note"},
|
||||
"stock_value_difference",
|
||||
)
|
||||
|
||||
self.assertEqual(stock_value_difference, 100.0 * 5)
|
||||
|
||||
|
||||
def create_delivery_note(**args):
|
||||
dn = frappe.new_doc("Delivery Note")
|
||||
|
||||
@@ -3657,6 +3657,21 @@ class TestPurchaseReceipt(FrappeTestCase):
|
||||
|
||||
self.assertEqual(data[0].get("bal_qty"), 50.0)
|
||||
|
||||
def test_same_stock_and_transaction_uom_conversion_factor(self):
|
||||
item_code = "Test Item for Same Stock and Transaction UOM Conversion Factor"
|
||||
create_item(item_code)
|
||||
|
||||
pr = make_purchase_receipt(
|
||||
item_code=item_code,
|
||||
qty=10,
|
||||
rate=100,
|
||||
stock_uom="Nos",
|
||||
transaction_uom="Nos",
|
||||
conversion_factor=10,
|
||||
)
|
||||
|
||||
self.assertEqual(pr.items[0].conversion_factor, 1.0)
|
||||
|
||||
|
||||
def prepare_data_for_internal_transfer():
|
||||
from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_internal_supplier
|
||||
|
||||
@@ -32,6 +32,12 @@ frappe.query_reports["Stock Ledger Invariant Check"] = {
|
||||
mandatory: 1,
|
||||
options: "Warehouse",
|
||||
},
|
||||
{
|
||||
fieldname: "show_incorrect_entries",
|
||||
fieldtype: "Check",
|
||||
label: "Show Incorrect Entries",
|
||||
default: 0,
|
||||
},
|
||||
],
|
||||
|
||||
formatter(value, row, column, data, default_formatter) {
|
||||
|
||||
@@ -5,7 +5,7 @@ import json
|
||||
|
||||
import frappe
|
||||
from frappe import _
|
||||
from frappe.utils import get_link_to_form, parse_json
|
||||
from frappe.utils import cint, flt, get_link_to_form, parse_json
|
||||
|
||||
SLE_FIELDS = (
|
||||
"name",
|
||||
@@ -36,7 +36,7 @@ def execute(filters=None):
|
||||
|
||||
def get_data(filters):
|
||||
sles = get_stock_ledger_entries(filters)
|
||||
return add_invariant_check_fields(sles)
|
||||
return add_invariant_check_fields(sles, filters)
|
||||
|
||||
|
||||
def get_stock_ledger_entries(filters):
|
||||
@@ -48,9 +48,12 @@ def get_stock_ledger_entries(filters):
|
||||
)
|
||||
|
||||
|
||||
def add_invariant_check_fields(sles):
|
||||
def add_invariant_check_fields(sles, filters):
|
||||
balance_qty = 0.0
|
||||
balance_stock_value = 0.0
|
||||
|
||||
incorrect_idx = 0
|
||||
precision = frappe.get_precision("Stock Ledger Entry", "actual_qty")
|
||||
for idx, sle in enumerate(sles):
|
||||
queue = json.loads(sle.stock_queue) if sle.stock_queue else []
|
||||
|
||||
@@ -95,6 +98,12 @@ def add_invariant_check_fields(sles):
|
||||
)
|
||||
sle.diff_value_diff = sle.stock_value_from_diff - sle.stock_value
|
||||
|
||||
if not incorrect_idx and filters.get("show_incorrect_entries"):
|
||||
if is_sle_has_correct_data(sle, precision):
|
||||
continue
|
||||
else:
|
||||
incorrect_idx = idx
|
||||
|
||||
if idx > 0:
|
||||
sle.fifo_stock_diff = sle.fifo_stock_value - sles[idx - 1].fifo_stock_value
|
||||
sle.fifo_difference_diff = sle.fifo_stock_diff - sle.stock_value_difference
|
||||
@@ -104,9 +113,23 @@ def add_invariant_check_fields(sles):
|
||||
"Batch", sle.batch_no, "use_batchwise_valuation", cache=True
|
||||
)
|
||||
|
||||
if filters.get("show_incorrect_entries"):
|
||||
if incorrect_idx > 0:
|
||||
sles = sles[cint(incorrect_idx) - 1 :]
|
||||
|
||||
return []
|
||||
|
||||
return sles
|
||||
|
||||
|
||||
def is_sle_has_correct_data(sle, precision):
|
||||
if flt(sle.difference_in_qty, precision) != 0.0 or flt(sle.diff_value_diff, precision) != 0:
|
||||
print(flt(sle.difference_in_qty, precision), flt(sle.diff_value_diff, precision))
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def get_columns():
|
||||
return [
|
||||
{
|
||||
|
||||
@@ -1074,6 +1074,15 @@ class update_entries_after:
|
||||
}
|
||||
)
|
||||
|
||||
if not rate and sle.voucher_type in ["Delivery Note", "Sales Invoice"]:
|
||||
rate = get_rate_for_return(
|
||||
sle.voucher_type,
|
||||
sle.voucher_no,
|
||||
sle.item_code,
|
||||
voucher_detail_no=sle.voucher_detail_no,
|
||||
sle=sle,
|
||||
)
|
||||
|
||||
else:
|
||||
rate = get_rate_for_return(
|
||||
sle.voucher_type,
|
||||
@@ -1731,6 +1740,9 @@ def get_valuation_rate(
|
||||
|
||||
# Get moving average rate of a specific batch number
|
||||
if warehouse and serial_and_batch_bundle:
|
||||
sabb = frappe.db.get_value(
|
||||
"Serial and Batch Bundle", serial_and_batch_bundle, ["posting_date", "posting_time"], as_dict=True
|
||||
)
|
||||
batch_obj = BatchNoValuation(
|
||||
sle=frappe._dict(
|
||||
{
|
||||
@@ -1738,6 +1750,8 @@ def get_valuation_rate(
|
||||
"warehouse": warehouse,
|
||||
"actual_qty": -1,
|
||||
"serial_and_batch_bundle": serial_and_batch_bundle,
|
||||
"posting_date": sabb.posting_date,
|
||||
"posting_time": sabb.posting_time,
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user