Skip to content

Commit

Permalink
Merge pull request #37247 from frappe/version-14-hotfix
Browse files Browse the repository at this point in the history
chore: release v14
  • Loading branch information
deepeshgarg007 authored Sep 27, 2023
2 parents 2713925 + 1dc58b3 commit e752027
Show file tree
Hide file tree
Showing 37 changed files with 692 additions and 125 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def on_submit(self):
def on_cancel(self):
self.validate_future_closing_vouchers()
self.db_set("gle_processing_status", "In Progress")
self.ignore_linked_doctypes = ("GL Entry", "Stock Ledger Entry")
self.ignore_linked_doctypes = ("GL Entry", "Stock Ledger Entry", "Payment Ledger Entry")
gle_count = frappe.db.count(
"GL Entry",
{"voucher_type": "Period Closing Voucher", "voucher_no": self.name, "is_cancelled": 0},
Expand Down
2 changes: 1 addition & 1 deletion erpnext/accounts/doctype/pos_invoice/pos_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ def set_pos_fields(self, for_validate=False):
selling_price_list = (
customer_price_list or customer_group_price_list or profile.get("selling_price_list")
)
if customer_currency != profile.get("currency"):
if customer_currency and customer_currency != profile.get("currency"):
self.set("currency", customer_currency)

else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def get_report_pdf(doc, consolidated=True):
filters = get_common_filters(doc)

if doc.report == "General Ledger":
filters.update(get_gl_filters(doc, entry, tax_id, presentation_currency))
col, res = get_soa(filters)
for x in [0, -2, -1]:
res[x]["account"] = res[x]["account"].replace("'", "")
Expand Down Expand Up @@ -142,7 +143,8 @@ def get_gl_filters(doc, entry, tax_id, presentation_currency):
def get_ar_filters(doc, entry):
return {
"report_date": doc.posting_date if doc.posting_date else None,
"customer": entry.customer,
"party_type": "Customer",
"party": entry.customer,
"customer_name": entry.customer_name if entry.customer_name else None,
"payment_terms_template": doc.payment_terms_template if doc.payment_terms_template else None,
"sales_partner": doc.sales_partner if doc.sales_partner else None,
Expand Down
32 changes: 28 additions & 4 deletions erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -1801,6 +1801,10 @@ def test_outstanding_amount_after_advance_jv_cancellation(self):
)

def test_outstanding_amount_after_advance_payment_entry_cancellation(self):
"""Test impact of advance PE submission/cancellation on SI and SO."""
from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order

sales_order = make_sales_order(item_code="138-CMS Shoe", qty=1, price_list_rate=500)
pe = frappe.get_doc(
{
"doctype": "Payment Entry",
Expand All @@ -1820,17 +1824,33 @@ def test_outstanding_amount_after_advance_payment_entry_cancellation(self):
"paid_to": "_Test Cash - _TC",
}
)
pe.append(
"references",
{
"reference_doctype": "Sales Order",
"reference_name": sales_order.name,
"total_amount": sales_order.grand_total,
"outstanding_amount": sales_order.grand_total,
"allocated_amount": 300,
},
)
pe.insert()
pe.submit()

sales_order.reload()
self.assertEqual(sales_order.advance_paid, 300)

si = frappe.copy_doc(test_records[0])
si.items[0].sales_order = sales_order.name
si.items[0].so_detail = sales_order.get("items")[0].name
si.is_pos = 0
si.append(
"advances",
{
"doctype": "Sales Invoice Advance",
"reference_type": "Payment Entry",
"reference_name": pe.name,
"reference_row": pe.references[0].name,
"advance_amount": 300,
"allocated_amount": 300,
"remarks": pe.remarks,
Expand All @@ -1839,19 +1859,23 @@ def test_outstanding_amount_after_advance_payment_entry_cancellation(self):
si.insert()
si.submit()

si.load_from_db()
si.reload()
pe.reload()
sales_order.reload()

# Check if SO is unlinked/replaced by SI in PE & if SO advance paid is 0
self.assertEqual(pe.references[0].reference_name, si.name)
self.assertEqual(sales_order.advance_paid, 0.0)

# check outstanding after advance allocation
self.assertEqual(
flt(si.outstanding_amount),
flt(si.rounded_total - si.total_advance, si.precision("outstanding_amount")),
)

# added to avoid Document has been modified exception
pe = frappe.get_doc("Payment Entry", pe.name)
pe.cancel()
si.reload()

si.load_from_db()
# check outstanding after advance cancellation
self.assertEqual(
flt(si.outstanding_amount),
Expand Down
3 changes: 0 additions & 3 deletions erpnext/accounts/report/accounts_payable/accounts_payable.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,8 @@ frappe.query_reports["Accounts Payable"] = {
},
on_change: () => {
frappe.query_report.set_filter_value('party', "");
let party_type = frappe.query_report.get_filter_value('party_type');
frappe.query_report.toggle_filter_display('supplier_group', frappe.query_report.get_filter_value('party_type') !== "Supplier");

}

},
{
"fieldname":"party",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,27 @@ frappe.query_reports["Accounts Payable Summary"] = {
}
},
{
"fieldname":"supplier",
"label": __("Supplier"),
"fieldname": "party_type",
"label": __("Party Type"),
"fieldtype": "Link",
"options": "Supplier"
"options": "Party Type",
get_query: () => {
return {
filters: {
'account_type': 'Payable'
}
};
},
on_change: () => {
frappe.query_report.set_filter_value('party', "");
frappe.query_report.toggle_filter_display('supplier_group', frappe.query_report.get_filter_value('party_type') !== "Supplier");
}
},
{
"fieldname":"party",
"label": __("Party"),
"fieldtype": "Dynamic Link",
"options": "party_type",
},
{
"fieldname":"payment_terms_template",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ frappe.query_reports["Accounts Receivable"] = {
},
on_change: () => {
frappe.query_report.set_filter_value('party', "");
let party_type = frappe.query_report.get_filter_value('party_type');
frappe.query_report.toggle_filter_display('customer_group', frappe.query_report.get_filter_value('party_type') !== "Customer");

}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,28 @@ frappe.query_reports["Accounts Receivable Summary"] = {
}
},
{
"fieldname":"customer",
"label": __("Customer"),
"fieldname": "party_type",
"label": __("Party Type"),
"fieldtype": "Link",
"options": "Customer"
"options": "Party Type",
"Default": "Customer",
get_query: () => {
return {
filters: {
'account_type': 'Receivable'
}
};
},
on_change: () => {
frappe.query_report.set_filter_value('party', "");
frappe.query_report.toggle_filter_display('customer_group', frappe.query_report.get_filter_value('party_type') !== "Customer");
}
},
{
"fieldname":"party",
"label": __("Party"),
"fieldtype": "Dynamic Link",
"options": "party_type",
},
{
"fieldname":"customer_group",
Expand Down
6 changes: 6 additions & 0 deletions erpnext/accounts/report/trial_balance/trial_balance.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ frappe.require("assets/erpnext/js/financial_statements.js", function() {
"label": __("Include Default Book Entries"),
"fieldtype": "Check",
"default": 1
},
{
"fieldname": "show_net_values",
"label": __("Show net values in opening and closing columns"),
"fieldtype": "Check",
"default": 1
}
],
"formatter": erpnext.financial_statements.formatter,
Expand Down
11 changes: 7 additions & 4 deletions erpnext/accounts/report/trial_balance/trial_balance.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ def get_data(filters):
ignore_opening_entries=True,
)

calculate_values(accounts, gl_entries_by_account, opening_balances)
calculate_values(
accounts, gl_entries_by_account, opening_balances, filters.get("show_net_values")
)
accumulate_values_into_parents(accounts, accounts_by_name)

data = prepare_data(accounts, filters, parent_children_map, company_currency)
Expand Down Expand Up @@ -310,7 +312,7 @@ def get_opening_balance(
return gle


def calculate_values(accounts, gl_entries_by_account, opening_balances):
def calculate_values(accounts, gl_entries_by_account, opening_balances, show_net_values):
init = {
"opening_debit": 0.0,
"opening_credit": 0.0,
Expand All @@ -335,7 +337,8 @@ def calculate_values(accounts, gl_entries_by_account, opening_balances):
d["closing_debit"] = d["opening_debit"] + d["debit"]
d["closing_credit"] = d["opening_credit"] + d["credit"]

prepare_opening_closing(d)
if show_net_values:
prepare_opening_closing(d)


def calculate_total_row(accounts, company_currency):
Expand Down Expand Up @@ -375,7 +378,7 @@ def prepare_data(accounts, filters, parent_children_map, company_currency):

for d in accounts:
# Prepare opening closing for group account
if parent_children_map.get(d.account):
if parent_children_map.get(d.account) and filters.get("show_net_values"):
prepare_opening_closing(d)

has_value = False
Expand Down
11 changes: 11 additions & 0 deletions erpnext/accounts/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,10 @@ def update_reference_in_journal_entry(d, journal_entry, do_not_save=False):
"""
jv_detail = journal_entry.get("accounts", {"name": d["voucher_detail_no"]})[0]

# Update Advance Paid in SO/PO since they might be getting unlinked
if jv_detail.get("reference_type") in ("Sales Order", "Purchase Order"):
frappe.get_doc(jv_detail.reference_type, jv_detail.reference_name).set_total_advance_paid()

if flt(d["unadjusted_amount"]) - flt(d["allocated_amount"]) != 0:
# adjust the unreconciled balance
amount_in_account_currency = flt(d["unadjusted_amount"]) - flt(d["allocated_amount"])
Expand Down Expand Up @@ -625,6 +629,13 @@ def update_reference_in_payment_entry(

if d.voucher_detail_no:
existing_row = payment_entry.get("references", {"name": d["voucher_detail_no"]})[0]

# Update Advance Paid in SO/PO since they are getting unlinked
if existing_row.get("reference_doctype") in ("Sales Order", "Purchase Order"):
frappe.get_doc(
existing_row.reference_doctype, existing_row.reference_name
).set_total_advance_paid()

original_row = existing_row.as_dict().copy()
existing_row.update(reference_details)

Expand Down
2 changes: 1 addition & 1 deletion erpnext/controllers/subcontracting_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ def make_sl_entries_for_supplier_warehouse(self, sl_entries):
{
"item_code": item.rm_item_code,
"warehouse": self.supplier_warehouse,
"actual_qty": -1 * flt(item.consumed_qty),
"actual_qty": -1 * flt(item.consumed_qty, item.precision("consumed_qty")),
"dependant_sle_voucher_detail_no": item.reference_name,
},
)
Expand Down
6 changes: 3 additions & 3 deletions erpnext/e_commerce/doctype/website_item/test_website_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ def test_website_item_stock_when_out_of_stock(self):
# check if stock details are fetched and item not in stock with warehouse set
data = get_product_info_for_website(item_code, skip_quotation_creation=True)
self.assertFalse(bool(data.product_info["in_stock"]))
self.assertEqual(data.product_info["stock_qty"][0][0], 0)
self.assertEqual(data.product_info["stock_qty"], 0)

# disable show stock availability
setup_e_commerce_settings({"show_stock_availability": 0})
Expand Down Expand Up @@ -355,7 +355,7 @@ def test_website_item_stock_when_in_stock(self):
# check if stock details are fetched and item is in stock with warehouse set
data = get_product_info_for_website(item_code, skip_quotation_creation=True)
self.assertTrue(bool(data.product_info["in_stock"]))
self.assertEqual(data.product_info["stock_qty"][0][0], 2)
self.assertEqual(data.product_info["stock_qty"], 2)

# unset warehouse
frappe.db.set_value("Website Item", {"item_code": item_code}, "website_warehouse", "")
Expand All @@ -364,7 +364,7 @@ def test_website_item_stock_when_in_stock(self):
# (even though it has stock in some warehouse)
data = get_product_info_for_website(item_code, skip_quotation_creation=True)
self.assertFalse(bool(data.product_info["in_stock"]))
self.assertFalse(bool(data.product_info["stock_qty"]))
self.assertFalse(data.product_info["stock_qty"])

# disable show stock availability
setup_e_commerce_settings({"show_stock_availability": 0})
Expand Down
6 changes: 0 additions & 6 deletions erpnext/e_commerce/doctype/website_item/website_item.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@ frappe.ui.form.on('Website Item', {
onload: (frm) => {
// should never check Private
frm.fields_dict["website_image"].df.is_private = 0;

frm.set_query("website_warehouse", () => {
return {
filters: {"is_group": 0}
};
});
},

refresh: (frm) => {
Expand Down
4 changes: 2 additions & 2 deletions erpnext/e_commerce/doctype/website_item/website_item.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
"fieldtype": "Column Break"
},
{
"description": "Show Stock availability based on this warehouse.",
"description": "Show Stock availability based on this warehouse. If the parent warehouse is selected, then the system will display the consolidated available quantity of all child warehouses.",
"fieldname": "website_warehouse",
"fieldtype": "Link",
"ignore_user_permissions": 1,
Expand Down Expand Up @@ -348,7 +348,7 @@
"index_web_pages_for_search": 1,
"links": [],
"make_attachments_public": 1,
"modified": "2022-09-30 04:01:52.090732",
"modified": "2023-09-12 14:19:22.822689",
"modified_by": "Administrator",
"module": "E-commerce",
"name": "Website Item",
Expand Down
10 changes: 5 additions & 5 deletions erpnext/e_commerce/product_data_engine/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@ def get_price_discount_info(self, item, price_object, discount_list):
)

def get_stock_availability(self, item):
from erpnext.templates.pages.wishlist import (
get_stock_availability as get_stock_availability_from_template,
)

"""Modify item object and add stock details."""
item.in_stock = False
warehouse = item.get("website_warehouse")
Expand All @@ -274,11 +278,7 @@ def get_stock_availability(self, item):
else:
item.in_stock = True
elif warehouse:
# stock item and has warehouse
actual_qty = frappe.db.get_value(
"Bin", {"item_code": item.item_code, "warehouse": item.get("website_warehouse")}, "actual_qty"
)
item.in_stock = bool(flt(actual_qty))
item.in_stock = get_stock_availability_from_template(item.item_code, warehouse)

def get_cart_items(self):
customer = get_customer(silent=True)
Expand Down
Loading

0 comments on commit e752027

Please sign in to comment.