From 3815f07c33d9c84230304d53a735d8f580f3288e Mon Sep 17 00:00:00 2001 From: barredterra <14891507+barredterra@users.noreply.github.com> Date: Tue, 23 Jan 2024 13:11:06 +0100 Subject: [PATCH 1/3] refactor(Sales Invoice): set account for mode of payment --- .../accounts/doctype/pos_invoice/pos_invoice.py | 7 ------- .../doctype/sales_invoice/sales_invoice.py | 17 +++++++---------- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/erpnext/accounts/doctype/pos_invoice/pos_invoice.py b/erpnext/accounts/doctype/pos_invoice/pos_invoice.py index e542d3cc63..9b0b3ecfab 100644 --- a/erpnext/accounts/doctype/pos_invoice/pos_invoice.py +++ b/erpnext/accounts/doctype/pos_invoice/pos_invoice.py @@ -11,7 +11,6 @@ from erpnext.accounts.doctype.loyalty_program.loyalty_program import validate_lo from erpnext.accounts.doctype.payment_request.payment_request import make_payment_request from erpnext.accounts.doctype.sales_invoice.sales_invoice import ( SalesInvoice, - get_bank_cash_account, get_mode_of_payment_info, update_multi_mode_option, ) @@ -208,7 +207,6 @@ class POSInvoice(SalesInvoice): self.validate_stock_availablility() self.validate_return_items_qty() self.set_status() - self.set_account_for_mode_of_payment() self.validate_pos() self.validate_payment_amount() self.validate_loyalty_transaction() @@ -643,11 +641,6 @@ class POSInvoice(SalesInvoice): update_multi_mode_option(self, pos_profile) self.paid_amount = 0 - def set_account_for_mode_of_payment(self): - for pay in self.payments: - if not pay.account: - pay.account = get_bank_cash_account(pay.mode_of_payment, self.company).get("account") - @frappe.whitelist() def create_payment_request(self): for pay in self.payments: diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index cc19650c38..c381b8a910 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -421,7 +421,8 @@ class SalesInvoice(SellingController): self.calculate_taxes_and_totals() def before_save(self): - set_account_for_mode_of_payment(self) + self.set_account_for_mode_of_payment() + self.set_paid_amount() def on_submit(self): self.validate_pos_paid_amount() @@ -712,9 +713,6 @@ class SalesInvoice(SellingController): ): data.sales_invoice = sales_invoice - def on_update(self): - self.set_paid_amount() - def on_update_after_submit(self): if hasattr(self, "repost_required"): fields_to_check = [ @@ -745,6 +743,11 @@ class SalesInvoice(SellingController): self.paid_amount = paid_amount self.base_paid_amount = base_paid_amount + def set_account_for_mode_of_payment(self): + for payment in self.payments: + if not payment.account: + payment.account = get_bank_cash_account(payment.mode_of_payment, self.company).get("account") + def validate_time_sheets_are_submitted(self): for data in self.timesheets: if data.time_sheet: @@ -2113,12 +2116,6 @@ def make_sales_return(source_name, target_doc=None): return make_return_doc("Sales Invoice", source_name, target_doc) -def set_account_for_mode_of_payment(self): - for data in self.payments: - if not data.account: - data.account = get_bank_cash_account(data.mode_of_payment, self.company).get("account") - - def get_inter_company_details(doc, doctype): if doctype in ["Sales Invoice", "Sales Order", "Delivery Note"]: parties = frappe.db.get_all( From 99b839d2b6ed78a62677d264c9cd90a95ed0c45c Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Fri, 26 Jan 2024 10:46:44 +0530 Subject: [PATCH 2/3] chore: failing ci tests --- .../accounts/doctype/purchase_invoice/purchase_invoice.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json index f85fc878ab..a48f5ea16e 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json @@ -1253,6 +1253,7 @@ "fieldtype": "Select", "in_standard_filter": 1, "label": "Status", + "no_copy": 1, "options": "\nDraft\nReturn\nDebit Note Issued\nSubmitted\nPaid\nPartly Paid\nUnpaid\nOverdue\nCancelled\nInternal Transfer", "print_hide": 1 }, @@ -1612,7 +1613,7 @@ "idx": 204, "is_submittable": 1, "links": [], - "modified": "2023-11-29 15:35:44.697496", + "modified": "2024-01-26 10:46:00.469053", "modified_by": "Administrator", "module": "Accounts", "name": "Purchase Invoice", From dbd4dae3d9b45dce8f6767cf7018822e1ab5d5e3 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Fri, 26 Jan 2024 18:42:29 +0530 Subject: [PATCH 3/3] test: Internal transfer using purchase receipt --- .../delivery_note/test_delivery_note.py | 4 +-- .../purchase_receipt/test_purchase_receipt.py | 27 ++++++++++++++++--- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/erpnext/stock/doctype/delivery_note/test_delivery_note.py b/erpnext/stock/doctype/delivery_note/test_delivery_note.py index 3fdda2cc49..0f12f38195 100644 --- a/erpnext/stock/doctype/delivery_note/test_delivery_note.py +++ b/erpnext/stock/doctype/delivery_note/test_delivery_note.py @@ -1597,8 +1597,8 @@ def create_delivery_note(**args): { "item_code": args.item or args.item_code or "_Test Item", "warehouse": args.warehouse or "_Test Warehouse - _TC", - "qty": args.qty if args.get("qty") is not None else 1, - "rate": args.rate if args.get("rate") is not None else 100, + "qty": args.get("qty", 1), + "rate": args.get("rate", 100), "conversion_factor": 1.0, "serial_and_batch_bundle": bundle_id, "allow_zero_valuation_rate": args.allow_zero_valuation_rate or 1, diff --git a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py index 57ba5bb0a5..6f72684ae5 100644 --- a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py @@ -21,9 +21,7 @@ from erpnext.stock.doctype.serial_and_batch_bundle.test_serial_and_batch_bundle get_serial_nos_from_bundle, make_serial_batch_bundle, ) -from erpnext.stock.doctype.serial_no.serial_no import get_serial_nos from erpnext.stock.doctype.warehouse.test_warehouse import create_warehouse -from erpnext.stock.stock_ledger import SerialNoExistsInFutureTransaction class TestPurchaseReceipt(FrappeTestCase): @@ -735,7 +733,6 @@ class TestPurchaseReceipt(FrappeTestCase): po.cancel() def test_serial_no_against_purchase_receipt(self): - from erpnext.stock.doctype.serial_no.serial_no import get_serial_nos item_code = "Test Manual Created Serial No" if not frappe.db.exists("Item", item_code): @@ -1020,6 +1017,11 @@ class TestPurchaseReceipt(FrappeTestCase): def test_stock_transfer_from_purchase_receipt_with_valuation(self): from erpnext.stock.doctype.delivery_note.delivery_note import make_inter_company_purchase_receipt from erpnext.stock.doctype.delivery_note.test_delivery_note import create_delivery_note + from erpnext.stock.doctype.stock_reconciliation.test_stock_reconciliation import ( + create_stock_reconciliation, + ) + from erpnext.stock.get_item_details import get_valuation_rate + from erpnext.stock.utils import get_stock_balance prepare_data_for_internal_transfer() @@ -1034,6 +1036,22 @@ class TestPurchaseReceipt(FrappeTestCase): company="_Test Company with perpetual inventory", ) + if ( + get_valuation_rate( + pr1.items[0].item_code, "_Test Company with perpetual inventory", warehouse="Stores - TCP1" + ) + != 50 + ): + balance = get_stock_balance(item_code=pr1.items[0].item_code, warehouse="Stores - TCP1") + create_stock_reconciliation( + item_code=pr1.items[0].item_code, + company="_Test Company with perpetual inventory", + warehouse="Stores - TCP1", + qty=balance, + rate=50, + do_not_save=True, + ) + customer = "_Test Internal Customer 2" company = "_Test Company with perpetual inventory" @@ -1071,7 +1089,8 @@ class TestPurchaseReceipt(FrappeTestCase): sl_entries = get_sl_entries("Purchase Receipt", pr.name) expected_gle = [ - ["Stock In Hand - TCP1", 272.5, 0.0], + ["Stock In Hand - TCP1", 250.0, 0.0], + ["Cost of Goods Sold - TCP1", 22.5, 0.0], ["_Test Account Stock In Hand - TCP1", 0.0, 250.0], ["_Test Account Shipping Charges - TCP1", 0.0, 22.5], ]