mirror of
https://github.com/frappe/erpnext.git
synced 2024-06-03 02:41:03 +00:00
Compare commits
10 Commits
755ab67c12
...
828aacd4fe
Author | SHA1 | Date | |
---|---|---|---|
|
828aacd4fe | ||
|
e22b0fd6e1 | ||
|
be1fce2da6 | ||
|
30aa4e031d | ||
|
214b38f7c8 | ||
|
cafa2f52e5 | ||
|
8ac11ae88d | ||
|
000c1b49dc | ||
|
070e2d4d26 | ||
|
fa942661cb |
|
@ -20,6 +20,7 @@
|
|||
"party",
|
||||
"party_name",
|
||||
"book_advance_payments_in_separate_party_account",
|
||||
"reconcile_on_advance_payment_date",
|
||||
"column_break_11",
|
||||
"bank_account",
|
||||
"party_bank_account",
|
||||
|
@ -751,6 +752,7 @@
|
|||
"fieldtype": "Check",
|
||||
"hidden": 1,
|
||||
"label": "Book Advance Payments in Separate Party Account",
|
||||
"no_copy": 1,
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
|
@ -766,6 +768,16 @@
|
|||
"label": "In Words",
|
||||
"print_hide": 1,
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
"fetch_from": "company.reconcile_on_advance_payment_date",
|
||||
"fieldname": "reconcile_on_advance_payment_date",
|
||||
"fieldtype": "Check",
|
||||
"hidden": 1,
|
||||
"label": "Reconcile on Advance Payment Date",
|
||||
"no_copy": 1,
|
||||
"read_only": 1
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
|
@ -779,7 +791,7 @@
|
|||
"table_fieldname": "payment_entries"
|
||||
}
|
||||
],
|
||||
"modified": "2024-04-11 11:25:07.366347",
|
||||
"modified": "2024-05-17 10:21:11.199445",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Payment Entry",
|
||||
|
|
|
@ -1344,13 +1344,16 @@ class PaymentEntry(AccountsController):
|
|||
"voucher_detail_no": invoice.name,
|
||||
}
|
||||
|
||||
date_field = "posting_date"
|
||||
if invoice.reference_doctype in ["Sales Order", "Purchase Order"]:
|
||||
date_field = "transaction_date"
|
||||
posting_date = frappe.db.get_value(invoice.reference_doctype, invoice.reference_name, date_field)
|
||||
|
||||
if getdate(posting_date) < getdate(self.posting_date):
|
||||
if self.reconcile_on_advance_payment_date:
|
||||
posting_date = self.posting_date
|
||||
else:
|
||||
date_field = "posting_date"
|
||||
if invoice.reference_doctype in ["Sales Order", "Purchase Order"]:
|
||||
date_field = "transaction_date"
|
||||
posting_date = frappe.db.get_value(invoice.reference_doctype, invoice.reference_name, date_field)
|
||||
|
||||
if getdate(posting_date) < getdate(self.posting_date):
|
||||
posting_date = self.posting_date
|
||||
|
||||
dr_or_cr, account = self.get_dr_and_account_for_advances(invoice)
|
||||
args_dict["account"] = account
|
||||
|
|
|
@ -1525,6 +1525,55 @@ class TestPaymentReconciliation(FrappeTestCase):
|
|||
]
|
||||
self.assertEqual(pl_entries, expected_ple)
|
||||
|
||||
def test_advance_payment_reconciliation_date(self):
|
||||
frappe.db.set_value(
|
||||
"Company",
|
||||
self.company,
|
||||
{
|
||||
"book_advance_payments_in_separate_party_account": 1,
|
||||
"default_advance_paid_account": self.advance_payable_account,
|
||||
"reconcile_on_advance_payment_date": 1,
|
||||
},
|
||||
)
|
||||
|
||||
self.supplier = "_Test Supplier"
|
||||
amount = 1500
|
||||
|
||||
pe = self.create_payment_entry(amount=amount)
|
||||
pe.posting_date = add_days(nowdate(), -1)
|
||||
pe.party_type = "Supplier"
|
||||
pe.party = self.supplier
|
||||
pe.payment_type = "Pay"
|
||||
pe.paid_from = self.cash
|
||||
pe.paid_to = self.advance_payable_account
|
||||
pe.save().submit()
|
||||
|
||||
pi = self.create_purchase_invoice(qty=10, rate=100)
|
||||
self.assertNotEqual(pe.posting_date, pi.posting_date)
|
||||
|
||||
pr = self.create_payment_reconciliation(party_is_customer=False)
|
||||
pr.default_advance_account = self.advance_payable_account
|
||||
pr.from_payment_date = pe.posting_date
|
||||
pr.get_unreconciled_entries()
|
||||
self.assertEqual(len(pr.invoices), 1)
|
||||
self.assertEqual(len(pr.payments), 1)
|
||||
invoices = [invoice.as_dict() for invoice in pr.invoices]
|
||||
payments = [payment.as_dict() for payment in pr.payments]
|
||||
pr.allocate_entries(frappe._dict({"invoices": invoices, "payments": payments}))
|
||||
pr.reconcile()
|
||||
|
||||
# Assert Ledger Entries
|
||||
gl_entries = frappe.db.get_all(
|
||||
"GL Entry",
|
||||
filters={"voucher_no": pe.name, "is_cancelled": 0, "posting_date": pe.posting_date},
|
||||
)
|
||||
self.assertEqual(len(gl_entries), 4)
|
||||
pl_entries = frappe.db.get_all(
|
||||
"Payment Ledger Entry",
|
||||
filters={"voucher_no": pe.name, "delinked": 0, "posting_date": pe.posting_date},
|
||||
)
|
||||
self.assertEqual(len(pl_entries), 3)
|
||||
|
||||
|
||||
def make_customer(customer_name, currency=None):
|
||||
if not frappe.db.exists("Customer", customer_name):
|
||||
|
|
|
@ -164,9 +164,10 @@ def prepare_data(
|
|||
rows = {}
|
||||
|
||||
target_qty_amt_field = "target_qty" if filters.get("target_on") == "Quantity" else "target_amount"
|
||||
|
||||
qty_or_amount_field = "stock_qty" if filters.get("target_on") == "Quantity" else "base_net_amount"
|
||||
|
||||
item_group_parent_child_map = get_item_group_parent_child_map()
|
||||
|
||||
for d in sales_users_data:
|
||||
key = (d.parent, d.item_group)
|
||||
dist_data = get_periodwise_distribution_data(d.distribution_id, period_list, filters.get("period"))
|
||||
|
@ -191,7 +192,11 @@ def prepare_data(
|
|||
r.get(sales_field) == d.parent
|
||||
and period.from_date <= r.get(date_field)
|
||||
and r.get(date_field) <= period.to_date
|
||||
and (not sales_user_wise_item_groups.get(d.parent) or r.item_group == d.item_group)
|
||||
and (
|
||||
not sales_user_wise_item_groups.get(d.parent)
|
||||
or r.item_group == d.item_group
|
||||
or r.item_group in item_group_parent_child_map.get(d.item_group, [])
|
||||
)
|
||||
):
|
||||
details[p_key] += r.get(qty_or_amount_field, 0)
|
||||
details[variance_key] = details.get(p_key) - details.get(target_key)
|
||||
|
@ -204,6 +209,25 @@ def prepare_data(
|
|||
return rows
|
||||
|
||||
|
||||
def get_item_group_parent_child_map():
|
||||
"""
|
||||
Returns a dict of all item group parents and leaf children associated with them.
|
||||
"""
|
||||
|
||||
item_groups = frappe.get_all(
|
||||
"Item Group", fields=["name", "parent_item_group"], order_by="lft desc, rgt desc"
|
||||
)
|
||||
item_group_parent_child_map = {}
|
||||
|
||||
for item_group in item_groups:
|
||||
children = item_group_parent_child_map.get(item_group.name, [])
|
||||
if not children:
|
||||
children = [item_group.name]
|
||||
item_group_parent_child_map.setdefault(item_group.parent_item_group, []).extend(children)
|
||||
|
||||
return item_group_parent_child_map
|
||||
|
||||
|
||||
def get_actual_data(filters, sales_users_or_territory_data, date_field, sales_field):
|
||||
fiscal_year = get_fiscal_year(fiscal_year=filters.get("fiscal_year"), as_dict=1)
|
||||
|
||||
|
|
|
@ -67,6 +67,7 @@
|
|||
"default_finance_book",
|
||||
"advance_payments_section",
|
||||
"book_advance_payments_in_separate_party_account",
|
||||
"reconcile_on_advance_payment_date",
|
||||
"column_break_fwcf",
|
||||
"default_advance_received_account",
|
||||
"default_advance_paid_account",
|
||||
|
@ -763,6 +764,14 @@
|
|||
"fieldtype": "Tab Break",
|
||||
"label": "Dashboard",
|
||||
"show_dashboard": 1
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
"depends_on": "eval: doc.book_advance_payments_in_separate_party_account",
|
||||
"description": "If <b>Enabled</b> - Reconciliation happens on the <b>Advance Payment posting date</b><br>\nIf <b>Disabled</b> - Reconciliation happens on oldest of 2 Dates: <b>Invoice Date</b> or the <b>Advance Payment posting date</b><br>\n",
|
||||
"fieldname": "reconcile_on_advance_payment_date",
|
||||
"fieldtype": "Check",
|
||||
"label": "Reconcile on Advance Payment Date"
|
||||
}
|
||||
],
|
||||
"icon": "fa fa-building",
|
||||
|
@ -770,7 +779,7 @@
|
|||
"image_field": "company_logo",
|
||||
"is_tree": 1,
|
||||
"links": [],
|
||||
"modified": "2024-04-23 12:38:33.173938",
|
||||
"modified": "2024-05-16 12:39:54.694232",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Setup",
|
||||
"name": "Company",
|
||||
|
|
|
@ -85,6 +85,7 @@ class Company(NestedSet):
|
|||
parent_company: DF.Link | None
|
||||
payment_terms: DF.Link | None
|
||||
phone_no: DF.Data | None
|
||||
reconcile_on_advance_payment_date: DF.Check
|
||||
registration_details: DF.Code | None
|
||||
rgt: DF.Int
|
||||
round_off_account: DF.Link | None
|
||||
|
|
|
@ -17,15 +17,11 @@ class DeprecatedSerialNoValuation:
|
|||
if not serial_nos:
|
||||
return
|
||||
|
||||
actual_qty = flt(self.sle.actual_qty)
|
||||
|
||||
stock_value_change = 0
|
||||
if actual_qty < 0:
|
||||
if not self.sle.is_cancelled:
|
||||
outgoing_value = self.get_incoming_value_for_serial_nos(serial_nos)
|
||||
stock_value_change = -1 * outgoing_value
|
||||
if not self.sle.is_cancelled:
|
||||
stock_value_change = self.get_incoming_value_for_serial_nos(serial_nos)
|
||||
|
||||
self.stock_value_change += stock_value_change
|
||||
self.stock_value_change += flt(stock_value_change)
|
||||
|
||||
def get_filterd_serial_nos(self):
|
||||
serial_nos = []
|
||||
|
@ -139,7 +135,14 @@ class DeprecatedBatchNoValuation:
|
|||
if not self.non_batchwise_balance_qty:
|
||||
continue
|
||||
|
||||
self.batch_avg_rate[batch_no] = self.non_batchwise_balance_value / self.non_batchwise_balance_qty
|
||||
if self.non_batchwise_balance_value == 0:
|
||||
self.batch_avg_rate[batch_no] = 0.0
|
||||
self.stock_value_differece[batch_no] = 0.0
|
||||
else:
|
||||
self.batch_avg_rate[batch_no] = (
|
||||
self.non_batchwise_balance_value / self.non_batchwise_balance_qty
|
||||
)
|
||||
self.stock_value_differece[batch_no] = self.non_batchwise_balance_value
|
||||
|
||||
stock_value_change = self.batch_avg_rate[batch_no] * ledger.qty
|
||||
self.stock_value_change += stock_value_change
|
||||
|
|
|
@ -1724,6 +1724,132 @@ class TestDeliveryNote(FrappeTestCase):
|
|||
if row.serial_no:
|
||||
self.assertEqual(row.serial_no, serial_no)
|
||||
|
||||
def test_delivery_note_legacy_serial_no_valuation(self):
|
||||
from erpnext.stock.doctype.delivery_note.delivery_note import make_sales_return
|
||||
from erpnext.stock.doctype.serial_no.serial_no import get_serial_nos
|
||||
|
||||
frappe.flags.ignore_serial_batch_bundle_validation = True
|
||||
sn_item = "Old Serial NO Item Valuation Test - 2"
|
||||
make_item(
|
||||
sn_item,
|
||||
{
|
||||
"has_serial_no": 1,
|
||||
"serial_no_series": "SN-SOVOSN-.####",
|
||||
"is_stock_item": 1,
|
||||
},
|
||||
)
|
||||
|
||||
serial_nos = [
|
||||
"SN-SOVOSN-1234",
|
||||
"SN-SOVOSN-2234",
|
||||
]
|
||||
|
||||
for sn in serial_nos:
|
||||
if not frappe.db.exists("Serial No", sn):
|
||||
sn_doc = frappe.get_doc(
|
||||
{
|
||||
"doctype": "Serial No",
|
||||
"item_code": sn_item,
|
||||
"serial_no": sn,
|
||||
}
|
||||
)
|
||||
sn_doc.insert()
|
||||
|
||||
warehouse = "_Test Warehouse - _TC"
|
||||
company = frappe.db.get_value("Warehouse", warehouse, "company")
|
||||
se_doc = make_stock_entry(
|
||||
item_code=sn_item,
|
||||
company=company,
|
||||
target="_Test Warehouse - _TC",
|
||||
qty=2,
|
||||
basic_rate=150,
|
||||
do_not_submit=1,
|
||||
use_serial_batch_fields=0,
|
||||
)
|
||||
se_doc.submit()
|
||||
|
||||
se_doc.items[0].db_set("serial_no", "\n".join(serial_nos))
|
||||
|
||||
sle_data = frappe.get_all(
|
||||
"Stock Ledger Entry",
|
||||
filters={"voucher_no": se_doc.name, "voucher_type": "Stock Entry"},
|
||||
)[0]
|
||||
|
||||
sle_doc = frappe.get_doc("Stock Ledger Entry", sle_data.name)
|
||||
self.assertFalse(sle_doc.serial_no)
|
||||
sle_doc.db_set("serial_no", "\n".join(serial_nos))
|
||||
sle_doc.reload()
|
||||
self.assertTrue(sle_doc.serial_no)
|
||||
self.assertFalse(sle_doc.is_cancelled)
|
||||
|
||||
for sn in serial_nos:
|
||||
sn_doc = frappe.get_doc("Serial No", sn)
|
||||
sn_doc.db_set(
|
||||
{
|
||||
"status": "Active",
|
||||
"warehouse": warehouse,
|
||||
}
|
||||
)
|
||||
|
||||
self.assertEqual(sorted(get_serial_nos(se_doc.items[0].serial_no)), sorted(serial_nos))
|
||||
frappe.flags.ignore_serial_batch_bundle_validation = False
|
||||
|
||||
se_doc = make_stock_entry(
|
||||
item_code=sn_item,
|
||||
company=company,
|
||||
target="_Test Warehouse - _TC",
|
||||
qty=2,
|
||||
basic_rate=200,
|
||||
)
|
||||
|
||||
serial_nos.extend(get_serial_nos_from_bundle(se_doc.items[0].serial_and_batch_bundle))
|
||||
|
||||
dn = create_delivery_note(
|
||||
item_code=sn_item,
|
||||
qty=3,
|
||||
rate=500,
|
||||
warehouse=warehouse,
|
||||
company=company,
|
||||
expense_account="Cost of Goods Sold - _TC",
|
||||
cost_center="Main - _TC",
|
||||
use_serial_batch_fields=1,
|
||||
serial_no="\n".join(serial_nos[0:3]),
|
||||
)
|
||||
|
||||
dn.reload()
|
||||
|
||||
sle_data = frappe.get_all(
|
||||
"Stock Ledger Entry",
|
||||
filters={"voucher_no": dn.name, "voucher_type": "Delivery Note"},
|
||||
fields=["stock_value_difference", "actual_qty"],
|
||||
)[0]
|
||||
|
||||
self.assertEqual(sle_data.actual_qty, 3 * -1)
|
||||
self.assertEqual(sle_data.stock_value_difference, 500.0 * -1)
|
||||
|
||||
dn = create_delivery_note(
|
||||
item_code=sn_item,
|
||||
qty=1,
|
||||
rate=500,
|
||||
warehouse=warehouse,
|
||||
company=company,
|
||||
expense_account="Cost of Goods Sold - _TC",
|
||||
cost_center="Main - _TC",
|
||||
use_serial_batch_fields=1,
|
||||
serial_no=serial_nos[-1],
|
||||
)
|
||||
|
||||
dn.reload()
|
||||
|
||||
sle_data = frappe.get_all(
|
||||
"Stock Ledger Entry",
|
||||
filters={"voucher_no": dn.name, "voucher_type": "Delivery Note"},
|
||||
fields=["stock_value_difference", "actual_qty"],
|
||||
)[0]
|
||||
|
||||
self.assertEqual(sle_data.actual_qty, 1 * -1)
|
||||
self.assertEqual(sle_data.stock_value_difference, 200.0 * -1)
|
||||
|
||||
|
||||
def create_delivery_note(**args):
|
||||
dn = frappe.new_doc("Delivery Note")
|
||||
|
|
|
@ -92,12 +92,12 @@ class StockLedgerEntry(Document):
|
|||
self.block_transactions_against_group_warehouse()
|
||||
self.validate_with_last_transaction_posting_time()
|
||||
self.validate_inventory_dimension_negative_stock()
|
||||
self.set_posting_datetime()
|
||||
|
||||
def set_posting_datetime(self):
|
||||
from erpnext.stock.utils import get_combine_datetime
|
||||
|
||||
self.posting_datetime = get_combine_datetime(self.posting_date, self.posting_time)
|
||||
self.db_set("posting_datetime", self.posting_datetime)
|
||||
|
||||
def validate_inventory_dimension_negative_stock(self):
|
||||
if self.is_cancelled:
|
||||
|
@ -169,7 +169,6 @@ class StockLedgerEntry(Document):
|
|||
return inv_dimension_dict
|
||||
|
||||
def on_submit(self):
|
||||
self.set_posting_datetime()
|
||||
self.check_stock_frozen_date()
|
||||
|
||||
# Added to handle few test cases where serial_and_batch_bundles are not required
|
||||
|
|
|
@ -553,7 +553,7 @@ class BatchNoValuation(DeprecatedBatchNoValuation):
|
|||
self.set_stock_value_difference()
|
||||
|
||||
def get_batch_no_ledgers(self) -> list[dict]:
|
||||
if not self.batches:
|
||||
if not self.batchwise_valuation_batches:
|
||||
return []
|
||||
|
||||
parent = frappe.qb.DocType("Serial and Batch Bundle")
|
||||
|
@ -575,7 +575,7 @@ class BatchNoValuation(DeprecatedBatchNoValuation):
|
|||
Sum(child.qty).as_("qty"),
|
||||
)
|
||||
.where(
|
||||
(child.batch_no.isin(self.batches))
|
||||
(child.batch_no.isin(self.batchwise_valuation_batches))
|
||||
& (parent.warehouse == self.sle.warehouse)
|
||||
& (parent.item_code == self.sle.item_code)
|
||||
& (parent.docstatus == 1)
|
||||
|
|
Loading…
Reference in New Issue
Block a user