Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/frappe/erpnext into fina…
Browse files Browse the repository at this point in the history
…nce-book-filter
  • Loading branch information
khushi8112 committed Sep 13, 2024
2 parents 3a34eec + ce34bb9 commit a7a0499
Show file tree
Hide file tree
Showing 10 changed files with 519 additions and 361 deletions.
73 changes: 73 additions & 0 deletions erpnext/accounts/doctype/payment_entry/test_payment_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -1791,6 +1791,79 @@ def test_opening_flag_for_advance_as_liability(self):
# 'Is Opening' should always be 'No' for normal advance payments
self.assertEqual(gl_with_opening_set, [])

@change_settings("Accounts Settings", {"delete_linked_ledger_entries": 1})
def test_delete_linked_exchange_gain_loss_journal(self):
from erpnext.accounts.doctype.account.test_account import create_account
from erpnext.accounts.doctype.opening_invoice_creation_tool.test_opening_invoice_creation_tool import (
make_customer,
)

debtors = create_account(
account_name="Debtors USD",
parent_account="Accounts Receivable - _TC",
company="_Test Company",
account_currency="USD",
account_type="Receivable",
)

# create a customer
customer = make_customer(customer="_Test Party USD")
cust_doc = frappe.get_doc("Customer", customer)
cust_doc.default_currency = "USD"
test_account_details = {
"company": "_Test Company",
"account": debtors,
}
cust_doc.append("accounts", test_account_details)
cust_doc.save()

# create a sales invoice
si = create_sales_invoice(
customer=customer,
currency="USD",
conversion_rate=83.970000000,
debit_to=debtors,
do_not_save=1,
)
si.party_account_currency = "USD"
si.save()
si.submit()

# create a payment entry for the invoice
pe = get_payment_entry("Sales Invoice", si.name)
pe.reference_no = "1"
pe.reference_date = frappe.utils.nowdate()
pe.paid_amount = 100
pe.source_exchange_rate = 90
pe.append(
"deductions",
{
"account": "_Test Exchange Gain/Loss - _TC",
"cost_center": "_Test Cost Center - _TC",
"amount": 2710,
},
)
pe.save()
pe.submit()

# check creation of journal entry
jv = frappe.get_all(
"Journal Entry Account",
{"reference_type": pe.doctype, "reference_name": pe.name, "docstatus": 1},
pluck="parent",
)
self.assertTrue(jv)

# check cancellation of payment entry and journal entry
pe.cancel()
self.assertTrue(pe.docstatus == 2)
self.assertTrue(frappe.db.get_value("Journal Entry", {"name": jv[0]}, "docstatus") == 2)

# check deletion of payment entry and journal entry
pe.delete()
self.assertRaises(frappe.DoesNotExistError, frappe.get_doc, pe.doctype, pe.name)
self.assertRaises(frappe.DoesNotExistError, frappe.get_doc, "Journal Entry", jv[0])


def create_payment_entry(**args):
payment_entry = frappe.new_doc("Payment Entry")
Expand Down
3 changes: 2 additions & 1 deletion erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import unittest

import frappe
from frappe.tests.utils import FrappeTestCase, change_settings

from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import make_purchase_invoice
from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice
Expand All @@ -14,7 +15,7 @@
from erpnext.stock.get_item_details import get_item_details


class TestPricingRule(unittest.TestCase):
class TestPricingRule(FrappeTestCase):
def setUp(self):
delete_existing_pricing_rules()
setup_pricing_rule_data()
Expand Down
98 changes: 66 additions & 32 deletions erpnext/accounts/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -769,40 +769,74 @@ def cancel_exchange_gain_loss_journal(
Cancel Exchange Gain/Loss for Sales/Purchase Invoice, if they have any.
"""
if parent_doc.doctype in ["Sales Invoice", "Purchase Invoice", "Payment Entry", "Journal Entry"]:
journals = frappe.db.get_all(
"Journal Entry Account",
filters={
"reference_type": parent_doc.doctype,
"reference_name": parent_doc.name,
"docstatus": 1,
},
fields=["parent"],
as_list=1,
gain_loss_journals = get_linked_exchange_gain_loss_journal(
referenced_dt=parent_doc.doctype, referenced_dn=parent_doc.name, je_docstatus=1
)

if journals:
gain_loss_journals = frappe.db.get_all(
"Journal Entry",
filters={
"name": ["in", [x[0] for x in journals]],
"voucher_type": "Exchange Gain Or Loss",
"docstatus": 1,
},
as_list=1,
)
for doc in gain_loss_journals:
gain_loss_je = frappe.get_doc("Journal Entry", doc[0])
if referenced_dt and referenced_dn:
references = [(x.reference_type, x.reference_name) for x in gain_loss_je.accounts]
if (
len(references) == 2
and (referenced_dt, referenced_dn) in references
and (parent_doc.doctype, parent_doc.name) in references
):
# only cancel JE generated against parent_doc and referenced_dn
gain_loss_je.cancel()
else:
for doc in gain_loss_journals:
gain_loss_je = frappe.get_doc("Journal Entry", doc)
if referenced_dt and referenced_dn:
references = [(x.reference_type, x.reference_name) for x in gain_loss_je.accounts]
if (
len(references) == 2
and (referenced_dt, referenced_dn) in references
and (parent_doc.doctype, parent_doc.name) in references
):
# only cancel JE generated against parent_doc and referenced_dn
gain_loss_je.cancel()
else:
gain_loss_je.cancel()


def delete_exchange_gain_loss_journal(
parent_doc: dict | object, referenced_dt: str | None = None, referenced_dn: str | None = None
) -> None:
"""
Delete Exchange Gain/Loss for Sales/Purchase Invoice, if they have any.
"""
if parent_doc.doctype in ["Sales Invoice", "Purchase Invoice", "Payment Entry", "Journal Entry"]:
gain_loss_journals = get_linked_exchange_gain_loss_journal(
referenced_dt=parent_doc.doctype, referenced_dn=parent_doc.name, je_docstatus=2
)
for doc in gain_loss_journals:
gain_loss_je = frappe.get_doc("Journal Entry", doc)
if referenced_dt and referenced_dn:
references = [(x.reference_type, x.reference_name) for x in gain_loss_je.accounts]
if (
len(references) == 2
and (referenced_dt, referenced_dn) in references
and (parent_doc.doctype, parent_doc.name) in references
):
# only delete JE generated against parent_doc and referenced_dn
gain_loss_je.delete()
else:
gain_loss_je.delete()


def get_linked_exchange_gain_loss_journal(referenced_dt: str, referenced_dn: str, je_docstatus: int) -> list:
"""
Get all the linked exchange gain/loss journal entries for a given document.
"""
gain_loss_journals = []
if journals := frappe.db.get_all(
"Journal Entry Account",
{
"reference_type": referenced_dt,
"reference_name": referenced_dn,
"docstatus": je_docstatus,
},
pluck="parent",
):
gain_loss_journals = frappe.db.get_all(
"Journal Entry",
{
"name": ["in", journals],
"voucher_type": "Exchange Gain Or Loss",
"is_system_generated": 1,
"docstatus": je_docstatus,
},
pluck="name",
)
return gain_loss_journals


def cancel_common_party_journal(self):
Expand Down
5 changes: 5 additions & 0 deletions erpnext/controllers/accounts_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,12 +346,17 @@ def _remove_references_in_repost_doctypes(self):
repost_doc.save(ignore_permissions=True)

def on_trash(self):
from erpnext.accounts.utils import delete_exchange_gain_loss_journal

self._remove_references_in_repost_doctypes()
self._remove_references_in_unreconcile()
self.remove_serial_and_batch_bundle()

# delete sl and gl entries on deletion of transaction
if frappe.db.get_single_value("Accounts Settings", "delete_linked_ledger_entries"):
# delete linked exchange gain/loss journal
delete_exchange_gain_loss_journal(self)

ple = frappe.qb.DocType("Payment Ledger Entry")
frappe.qb.from_(ple).delete().where(
(ple.voucher_type == self.doctype) & (ple.voucher_no == self.name)
Expand Down
32 changes: 16 additions & 16 deletions erpnext/locale/fa.po
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ msgstr ""
"Project-Id-Version: frappe\n"
"Report-Msgid-Bugs-To: info@erpnext.com\n"
"POT-Creation-Date: 2024-09-01 09:35+0000\n"
"PO-Revision-Date: 2024-09-07 18:35\n"
"PO-Revision-Date: 2024-09-10 18:59\n"
"Last-Translator: info@erpnext.com\n"
"Language-Team: Persian\n"
"MIME-Version: 1.0\n"
Expand Down Expand Up @@ -715,7 +715,7 @@ msgstr ""
#. Header text in the Stock Workspace
#: selling/workspace/selling/selling.json stock/workspace/stock/stock.json
msgid "<span class=\"h4\"><b>Quick Access</b></span>"
msgstr ""
msgstr "<span class=\"h4\"><b>دسترسی سریع</b></span>"

#. Header text in the Assets Workspace
#. Header text in the Quality Workspace
Expand Down Expand Up @@ -748,7 +748,7 @@ msgstr ""
#. Header text in the Settings Workspace
#: setup/workspace/settings/settings.json
msgid "<span class=\"h4\"><b>Settings</b></span>"
msgstr ""
msgstr "<span class=\"h4\"><b>تنظیمات</b></span>"

#. Header text in the Accounting Workspace
#. Header text in the Payables Workspace
Expand All @@ -757,7 +757,7 @@ msgstr ""
#: accounts/workspace/payables/payables.json
#: accounts/workspace/receivables/receivables.json
msgid "<span class=\"h4\"><b>Shortcuts</b></span>"
msgstr ""
msgstr "<span class=\"h4\"><b>میانبرها</b></span>"

#. Header text in the Settings Workspace
#: setup/workspace/settings/settings.json
Expand Down Expand Up @@ -785,7 +785,7 @@ msgstr ""
#: quality_management/workspace/quality/quality.json
#: setup/workspace/home/home.json support/workspace/support/support.json
msgid "<span class=\"h4\"><b>Your Shortcuts</b></span>"
msgstr ""
msgstr "<span class=\"h4\"><b>میانبرهای شما</b></span>"

#. Content of the 'html_19' (HTML) field in DocType 'Inventory Dimension'
#: stock/doctype/inventory_dimension/inventory_dimension.json
Expand Down Expand Up @@ -1020,7 +1020,7 @@ msgstr "در بالا"
#: accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.html:99
#: accounts/doctype/process_statement_of_accounts/process_statement_of_accounts_accounts_receivable.html:351
msgid "Above 120 Days"
msgstr ""
msgstr "بالای 120 روز"

#. Name of a role
#: setup/doctype/department/department.json
Expand Down Expand Up @@ -3632,7 +3632,7 @@ msgstr "گروهی از آیتم‌ها را در یک آیتم دیگر جمع

#: setup/setup_wizard/data/industry_type.txt:4
msgid "Agriculture"
msgstr ""
msgstr "کشاورزی"

#. Name of a role
#: assets/doctype/location/location.json
Expand All @@ -3646,7 +3646,7 @@ msgstr "کاربر کشاورزی"

#: setup/setup_wizard/data/industry_type.txt:5
msgid "Airline"
msgstr ""
msgstr "شرکت هواپیمایی"

#. Label of the algorithm (Select) field in DocType 'Bisect Accounting
#. Statements'
Expand Down Expand Up @@ -4914,7 +4914,7 @@ msgstr "قابل اجرا در حساب"
#. Label of the to_designation (Link) field in DocType 'Authorization Rule'
#: setup/doctype/authorization_rule/authorization_rule.json
msgid "Applicable To (Designation)"
msgstr "قابل اجرا برای (تعیین)"
msgstr "قابل اجرا برای (نقش سازمانی)"

#. Label of the to_emp (Link) field in DocType 'Authorization Rule'
#: setup/doctype/authorization_rule/authorization_rule.json
Expand Down Expand Up @@ -5158,7 +5158,7 @@ msgstr "درخواست برای سند"
#. Label of a Link in the CRM Workspace
#: crm/doctype/appointment/appointment.json crm/workspace/crm/crm.json
msgid "Appointment"
msgstr "وقت ملاقات"
msgstr "قرار ملاقات"

#. Name of a DocType
#: crm/doctype/appointment_booking_settings/appointment_booking_settings.json
Expand Down Expand Up @@ -7930,7 +7930,7 @@ msgstr "Biot"

#: setup/setup_wizard/data/industry_type.txt:9
msgid "Biotechnology"
msgstr ""
msgstr "بیوتکنولوژی"

#. Name of a DocType
#: accounts/doctype/bisect_accounting_statements/bisect_accounting_statements.json
Expand Down Expand Up @@ -8048,7 +8048,7 @@ msgstr "آبی"
#. Accounts'
#: accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.json
msgid "Body"
msgstr "بدن"
msgstr "بدنه"

#. Label of the body_text (Text Editor) field in DocType 'Dunning'
#. Label of the body_text (Text Editor) field in DocType 'Dunning Letter Text'
Expand Down Expand Up @@ -9756,7 +9756,7 @@ msgstr "سفارش پرداخت / ارسال سفارش / سفارش جدید"

#: setup/setup_wizard/data/industry_type.txt:12
msgid "Chemical"
msgstr ""
msgstr "شیمیایی"

#. Option for the 'Salary Mode' (Select) field in DocType 'Employee'
#: setup/doctype/employee/employee.json
Expand Down Expand Up @@ -19255,7 +19255,7 @@ msgstr "لاگ درون‌بُرد برون‌بُرد"

#: setup/setup_wizard/operations/install_fixtures.py:286
msgid "External"
msgstr ""
msgstr "بیرونی"

#. Label of the external_work_history (Table) field in DocType 'Employee'
#: setup/doctype/employee/employee.json
Expand Down Expand Up @@ -51167,7 +51167,7 @@ msgstr " شناسه مالیاتی:"

#: accounts/doctype/process_statement_of_accounts/process_statement_of_accounts_accounts_receivable.html:32
msgid "Tax Id: {0}"
msgstr ""
msgstr "شناسه مالیاتی: {0}"

#. Label of a Card Break in the Accounting Workspace
#: accounts/workspace/accounting/accounting.json
Expand Down Expand Up @@ -53861,7 +53861,7 @@ msgstr "تعداد کل پیش بینی شده"

#: buying/report/item_wise_purchase_history/item_wise_purchase_history.py:272
msgid "Total Purchase Amount"
msgstr ""
msgstr "کل مبلغ خرید"

#. Label of the total_purchase_cost (Currency) field in DocType 'Project'
#: projects/doctype/project/project.json
Expand Down
4 changes: 2 additions & 2 deletions erpnext/locale/sv.po
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ msgstr ""
"Project-Id-Version: frappe\n"
"Report-Msgid-Bugs-To: info@erpnext.com\n"
"POT-Creation-Date: 2024-09-01 09:35+0000\n"
"PO-Revision-Date: 2024-09-07 18:35\n"
"PO-Revision-Date: 2024-09-10 18:59\n"
"Last-Translator: info@erpnext.com\n"
"Language-Team: Swedish\n"
"MIME-Version: 1.0\n"
Expand Down Expand Up @@ -28131,7 +28131,7 @@ msgstr "Maskin"

#: public/js/plant_floor_visual/visual_plant.js:70
msgid "Machine Type"
msgstr "Naskin Typ"
msgstr "Maskin Typ"

#. Option for the 'Stop Reason' (Select) field in DocType 'Downtime Entry'
#: manufacturing/doctype/downtime_entry/downtime_entry.json
Expand Down
Loading

0 comments on commit a7a0499

Please sign in to comment.