Compare commits

...

3 Commits

Author SHA1 Message Date
Smit Vora
5e3b2c1a84 test: test voucher subtype for sales invoice
(cherry picked from commit ad6cc352f1)

# Conflicts:
#	erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py
2024-11-08 04:50:48 +00:00
ljain112
203718a90b fix: patch
(cherry picked from commit d76cc21086)

# Conflicts:
#	erpnext/patches.txt
#	erpnext/patches/v14_0/update_sub_voucher_type_in_gl_entries.py
2024-11-08 04:50:48 +00:00
ljain112
1022acc299 fix: improved the conditions for determining voucher subtypes
(cherry picked from commit 00eee16190)

# Conflicts:
#	erpnext/controllers/accounts_controller.py
2024-11-08 04:50:47 +00:00
4 changed files with 137 additions and 0 deletions

View File

@@ -3761,6 +3761,7 @@ class TestSalesInvoice(FrappeTestCase):
self.assertEqual(jv[0], si.grand_total)
<<<<<<< HEAD
def check_gl_entries(doc, voucher_no, expected_gle, posting_date):
gl_entries = frappe.db.sql(
"""select account, debit, credit, posting_date
@@ -3770,6 +3771,36 @@ def check_gl_entries(doc, voucher_no, expected_gle, posting_date):
order by posting_date asc, account asc""",
(voucher_no, posting_date),
as_dict=1,
=======
def test_gl_voucher_subtype(self):
si = create_sales_invoice()
gl_entries = frappe.get_all(
"GL Entry",
filters={"voucher_type": "Sales Invoice", "voucher_no": si.name},
pluck="voucher_subtype",
)
self.assertTrue(all([x == "Sales Invoice" for x in gl_entries]))
si = create_sales_invoice(is_return=1, qty=-1)
gl_entries = frappe.get_all(
"GL Entry",
filters={"voucher_type": "Sales Invoice", "voucher_no": si.name},
pluck="voucher_subtype",
)
self.assertTrue(all([x == "Credit Note" for x in gl_entries]))
def set_advance_flag(company, flag, default_account):
frappe.db.set_value(
"Company",
company,
{
"book_advance_payments_in_separate_party_account": flag,
"default_advance_received_account": default_account,
},
>>>>>>> ad6cc352f1 (test: test voucher subtype for sales invoice)
)
for i, gle in enumerate(gl_entries):

View File

@@ -981,6 +981,36 @@ class AccountsController(TransactionBase):
return gl_dict
<<<<<<< HEAD
=======
def get_voucher_subtype(self):
voucher_subtypes = {
"Journal Entry": "voucher_type",
"Payment Entry": "payment_type",
"Stock Entry": "stock_entry_type",
"Asset Capitalization": "entry_type",
}
if self.doctype in voucher_subtypes:
return self.get(voucher_subtypes[self.doctype])
elif self.doctype == "Purchase Receipt" and self.is_return:
return "Purchase Return"
elif self.doctype == "Delivery Note" and self.is_return:
return "Sales Return"
elif self.doctype == "Sales Invoice" and self.is_return:
return "Credit Note"
elif self.doctype == "Sales Invoice" and self.is_debit_note:
return "Debit Note"
elif self.doctype == "Purchase Invoice" and self.is_return:
return "Debit Note"
return self.doctype
def get_value_in_transaction_currency(self, account_currency, gl_dict, field):
if account_currency == self.get("currency"):
return gl_dict.get(field + "_in_account_currency")
else:
return flt(gl_dict.get(field, 0) / self.get("conversion_rate", 1))
>>>>>>> 00eee16190 (fix: improved the conditions for determining voucher subtypes)
def validate_zero_qty_for_return_invoices_with_stock(self):
rows = []
for item in self.items:

View File

@@ -366,4 +366,23 @@ execute:frappe.db.set_single_value('E Commerce Settings', 'show_actual_qty', 1)
erpnext.patches.v14_0.delete_orphaned_asset_movement_item_records
erpnext.patches.v14_0.remove_cancelled_asset_capitalization_from_asset
erpnext.patches.v14_0.enable_set_priority_for_pricing_rules #1
<<<<<<< HEAD
erpnext.patches.v14_0.update_currency_exchange_settings_for_frankfurter
=======
erpnext.patches.v15_0.rename_number_of_depreciations_booked_to_opening_booked_depreciations
erpnext.patches.v15_0.add_default_operations
erpnext.patches.v15_0.enable_old_serial_batch_fields
erpnext.patches.v15_0.update_warehouse_field_in_asset_repair_consumed_item_doctype
erpnext.patches.v15_0.update_asset_repair_field_in_stock_entry
erpnext.patches.v15_0.update_total_number_of_booked_depreciations
erpnext.patches.v15_0.do_not_use_batchwise_valuation
erpnext.patches.v15_0.update_invoice_remarks
erpnext.patches.v14_0.update_reports_with_range
erpnext.patches.v15_0.drop_index_posting_datetime_from_sle
erpnext.patches.v15_0.add_disassembly_order_stock_entry_type #1
erpnext.patches.v15_0.set_standard_stock_entry_type
erpnext.patches.v15_0.set_difference_amount_in_asset_value_adjustment
erpnext.patches.v15_0.link_purchase_item_to_asset_doc
erpnext.patches.v15_0.migrate_to_utm_analytics
erpnext.patches.v15_0.update_sub_voucher_type_in_gl_entries
>>>>>>> d76cc21086 (fix: patch)

View File

@@ -0,0 +1,57 @@
import frappe
def execute():
update_purchase_invoices()
update_sales_invoices()
update_sales_debit_notes()
def update_purchase_invoices():
invoices = frappe.get_all(
"Purchase Invoice",
filters={"docstatus": 1, "is_return": 0},
pluck="name",
)
if not invoices:
return
update_gl_entry(doctype="Purchase Invoice", invoices=invoices, value="Purchase Invoice")
def update_sales_invoices():
invoices = frappe.get_all(
"Sales Invoice",
filters={"docstatus": 1, "is_return": 0, "is_debit_note": 0},
pluck="name",
)
if not invoices:
return
update_gl_entry(doctype="Sales Invoice", invoices=invoices, value="Sales Invoice")
def update_sales_debit_notes():
invoices = frappe.get_all(
"Sales Invoice",
filters={"docstatus": 1, "is_debit_note": 1},
pluck="name",
)
if not invoices:
return
update_gl_entry(doctype="Sales Invoice", invoices=invoices, value="Debit Note")
def update_gl_entry(doctype, invoices, value):
gl_entry = frappe.qb.DocType("GL Entry")
(
frappe.qb.update(gl_entry)
.set("voucher_subtype", value)
.where(gl_entry.voucher_subtype.isnotnull())
.where(gl_entry.voucher_no.isin(invoices))
.where(gl_entry.voucher_type == doctype)
.run()
)