From 228f10bf30b0c9e304927b5a877cc0730a66ab7c Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Thu, 12 Aug 2021 15:39:07 +0530 Subject: [PATCH 01/16] fix: Account currency validation for first transaction (cherry picked from commit 80c85dd17cf0c0fdcf07d2e0c2151b2852a0c611) # Conflicts: # erpnext/controllers/accounts_controller.py --- erpnext/controllers/accounts_controller.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index 7d41c84acfc..d821915a4cf 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -44,6 +44,12 @@ from erpnext.controllers.print_settings import ( set_print_templates_for_taxes, ) from erpnext.controllers.sales_and_purchase_return import validate_return +<<<<<<< HEAD +======= +from erpnext.accounts.party import get_party_account_currency, validate_party_frozen_disabled, get_party_gle_currency +from erpnext.accounts.doctype.pricing_rule.utils import (apply_pricing_rule_on_transaction, + apply_pricing_rule_for_free_items, get_applied_pricing_rules) +>>>>>>> 80c85dd17c (fix: Account currency validation for first transaction) from erpnext.exceptions import InvalidCurrency from erpnext.setup.utils import get_exchange_rate from erpnext.stock.doctype.packed_item.packed_item import make_packing_list @@ -169,6 +175,7 @@ class AccountsController(TransactionBase): self.validate_party() self.validate_currency() + self.validate_party_account_currency() if self.doctype in ["Purchase Invoice", "Sales Invoice"]: pos_check_field = "is_pos" if self.doctype == "Sales Invoice" else "is_paid" @@ -1445,6 +1452,19 @@ class AccountsController(TransactionBase): # at quotation / sales order level and we shouldn't stop someone # from creating a sales invoice if sales order is already created + def validate_party_account_currency(self): + if self.doctype not in ('Sales Invoice', 'Purchase Invoice'): + return + + party_type, party = self.get_party() + party_gle_currency = get_party_gle_currency(party_type, party, self.company) + party_account = self.get('debit_to') if self.doctype == 'Sales Invoice' else self.get('credit_to') + party_account_currency = get_account_currency(party_account) + + if not party_gle_currency and (party_account_currency != self.currency): + frappe.throw(_("Party Account {0} currency and document currency should be same").format(frappe.bold(party_account))) + + def delink_advance_entries(self, linked_doc_name): total_allocated_amount = 0 for adv in self.advances: From 7f853b1f0febad2a33548558f2f0556801c0196f Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Sun, 15 Aug 2021 21:18:13 +0530 Subject: [PATCH 02/16] fix: Add party account validation for journal entry (cherry picked from commit f00620a3ca8d507dc947b82abdb5a90c6759bde5) --- .../accounts/doctype/journal_entry/journal_entry.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py index 8660c18bf95..ba0b1416d7e 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.py +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py @@ -51,6 +51,7 @@ class JournalEntry(AccountsController): self.validate_party() self.validate_entries_for_advance() self.validate_multi_currency() + self.validate_party_account_currency() self.set_amounts_in_company_currency() self.validate_debit_credit_amount() @@ -655,6 +656,18 @@ class JournalEntry(AccountsController): self.set_exchange_rate() + def validate_party_account_currency(self): + for d in self.get("accounts"): + if self.party_type not in ('Customer', 'Supplier'): + continue + + party_gle_currency = get_party_gle_currency(self.party_type, self.party, self.company) + party_account_currency = get_account_currency(d.account) + + if not party_gle_currency and (party_account_currency != self.currency): + frappe.throw(_("Row {0}: Party Account {1} currency and document currency should be same").format( + frappe.bold(d.idx), frappe.bold(d.account))) + def set_amounts_in_company_currency(self): for d in self.get("accounts"): d.debit_in_account_currency = flt( From 09a42a122f0a446d73942d9b8a69149721379e42 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Sun, 15 Aug 2021 21:19:18 +0530 Subject: [PATCH 03/16] fix: Healthcare module accounting test cases (cherry picked from commit bcaf4752952f4aa7819c057ce61c8bd2ef69df78) # Conflicts: # erpnext/healthcare/doctype/lab_test/test_lab_test.py --- erpnext/healthcare/doctype/lab_test/test_lab_test.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/erpnext/healthcare/doctype/lab_test/test_lab_test.py b/erpnext/healthcare/doctype/lab_test/test_lab_test.py index 06c02d1ea07..754ee94c396 100644 --- a/erpnext/healthcare/doctype/lab_test/test_lab_test.py +++ b/erpnext/healthcare/doctype/lab_test/test_lab_test.py @@ -163,8 +163,14 @@ def create_sales_invoice(): sales_invoice.patient = patient sales_invoice.customer = frappe.db.get_value("Patient", patient, "customer") sales_invoice.due_date = getdate() +<<<<<<< HEAD sales_invoice.company = "_Test Company" sales_invoice.debit_to = get_receivable_account("_Test Company") +======= + sales_invoice.company = '_Test Company' + sales_invoice.currency = 'INR' + sales_invoice.debit_to = get_receivable_account('_Test Company') +>>>>>>> bcaf475295 (fix: Healthcare module accounting test cases) tests = [insulin_resistance_template, blood_test_template] for entry in tests: From 9d43a90eb08ddbcb80a7b488b9696762058e69cc Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Mon, 16 Aug 2021 10:40:26 +0530 Subject: [PATCH 04/16] Revert "fix: Add party account validation for journal entry" This reverts commit f00620a3ca8d507dc947b82abdb5a90c6759bde5. (cherry picked from commit 0a618817dc76e7da00e8ae16521bf554b5fd9704) --- .../accounts/doctype/journal_entry/journal_entry.py | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py index ba0b1416d7e..8660c18bf95 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.py +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py @@ -51,7 +51,6 @@ class JournalEntry(AccountsController): self.validate_party() self.validate_entries_for_advance() self.validate_multi_currency() - self.validate_party_account_currency() self.set_amounts_in_company_currency() self.validate_debit_credit_amount() @@ -656,18 +655,6 @@ class JournalEntry(AccountsController): self.set_exchange_rate() - def validate_party_account_currency(self): - for d in self.get("accounts"): - if self.party_type not in ('Customer', 'Supplier'): - continue - - party_gle_currency = get_party_gle_currency(self.party_type, self.party, self.company) - party_account_currency = get_account_currency(d.account) - - if not party_gle_currency and (party_account_currency != self.currency): - frappe.throw(_("Row {0}: Party Account {1} currency and document currency should be same").format( - frappe.bold(d.idx), frappe.bold(d.account))) - def set_amounts_in_company_currency(self): for d in self.get("accounts"): d.debit_in_account_currency = flt( From 8f969fbd666a9db6c934afbb50958e41b4039159 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Sat, 21 Aug 2021 23:05:48 +0530 Subject: [PATCH 05/16] test: Update test cases for currency change validation (cherry picked from commit 60915e874d9f466618b313be65023a62591d0f97) # Conflicts: # erpnext/accounts/doctype/period_closing_voucher/test_period_closing_voucher.py # erpnext/healthcare/doctype/patient_appointment/patient_appointment.py # erpnext/healthcare/doctype/therapy_plan/therapy_plan.py # erpnext/non_profit/doctype/membership/membership.py --- .../test_period_closing_voucher.py | 8 +++++++ erpnext/controllers/accounts_controller.py | 3 +++ .../patient_appointment.py | 12 ++++++++++ .../doctype/therapy_plan/therapy_plan.py | 11 ++++++++++ .../doctype/membership/membership.py | 22 +++++++++++++++++++ .../doctype/membership/test_membership.py | 2 +- 6 files changed, 57 insertions(+), 1 deletion(-) diff --git a/erpnext/accounts/doctype/period_closing_voucher/test_period_closing_voucher.py b/erpnext/accounts/doctype/period_closing_voucher/test_period_closing_voucher.py index 8e0e62d5f8c..a61f32c3d1e 100644 --- a/erpnext/accounts/doctype/period_closing_voucher/test_period_closing_voucher.py +++ b/erpnext/accounts/doctype/period_closing_voucher/test_period_closing_voucher.py @@ -78,6 +78,10 @@ class TestPeriodClosingVoucher(unittest.TestCase): expense_account="Cost of Goods Sold - TPC", rate=400, debit_to="Debtors - TPC", +<<<<<<< HEAD +======= + currency="USD" +>>>>>>> 60915e874d (test: Update test cases for currency change validation) ) create_sales_invoice( company=company, @@ -86,6 +90,10 @@ class TestPeriodClosingVoucher(unittest.TestCase): expense_account="Cost of Goods Sold - TPC", rate=200, debit_to="Debtors - TPC", +<<<<<<< HEAD +======= + currency="USD" +>>>>>>> 60915e874d (test: Update test cases for currency change validation) ) pcv = self.make_period_closing_voucher(submit=False) diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index d821915a4cf..60ff067a91f 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -1456,6 +1456,9 @@ class AccountsController(TransactionBase): if self.doctype not in ('Sales Invoice', 'Purchase Invoice'): return + if self.is_opening == 'Yes': + return + party_type, party = self.get_party() party_gle_currency = get_party_gle_currency(party_type, party, self.company) party_account = self.get('debit_to') if self.doctype == 'Sales Invoice' else self.get('credit_to') diff --git a/erpnext/healthcare/doctype/patient_appointment/patient_appointment.py b/erpnext/healthcare/doctype/patient_appointment/patient_appointment.py index b6e30060437..131767797db 100755 --- a/erpnext/healthcare/doctype/patient_appointment/patient_appointment.py +++ b/erpnext/healthcare/doctype/patient_appointment/patient_appointment.py @@ -22,6 +22,7 @@ from erpnext.healthcare.utils import ( manage_fee_validity, ) from erpnext.hr.doctype.employee.employee import is_holiday +<<<<<<< HEAD class MaximumCapacityError(frappe.ValidationError): @@ -31,6 +32,11 @@ class MaximumCapacityError(frappe.ValidationError): class OverlapError(frappe.ValidationError): pass +======= +from erpnext.healthcare.doctype.healthcare_settings.healthcare_settings import get_receivable_account, get_income_account +from erpnext.healthcare.utils import check_fee_validity, get_service_item_and_practitioner_charge, manage_fee_validity +from erpnext import get_company_currency +>>>>>>> 60915e874d (test: Update test cases for currency change validation) class PatientAppointment(Document): def validate(self): @@ -251,7 +257,13 @@ def invoice_appointment(appointment_doc): def create_sales_invoice(appointment_doc): sales_invoice = frappe.new_doc("Sales Invoice") sales_invoice.patient = appointment_doc.patient +<<<<<<< HEAD sales_invoice.customer = frappe.get_value("Patient", appointment_doc.patient, "customer") +======= + sales_invoice.customer = frappe.get_value('Patient', appointment_doc.patient, 'customer') + sales_invoice.currency = frappe.get_value('Customer', sales_invoice.customer, 'default_currency') \ + or get_company_currency(appointment_doc.currency) +>>>>>>> 60915e874d (test: Update test cases for currency change validation) sales_invoice.appointment = appointment_doc.name sales_invoice.due_date = getdate() sales_invoice.company = appointment_doc.company diff --git a/erpnext/healthcare/doctype/therapy_plan/therapy_plan.py b/erpnext/healthcare/doctype/therapy_plan/therapy_plan.py index 44f0a9785c4..b82894c366b 100644 --- a/erpnext/healthcare/doctype/therapy_plan/therapy_plan.py +++ b/erpnext/healthcare/doctype/therapy_plan/therapy_plan.py @@ -4,8 +4,13 @@ import frappe from frappe.model.document import Document +<<<<<<< HEAD from frappe.utils import flt +======= +from frappe.utils import flt, today +from erpnext import get_company_currency +>>>>>>> 60915e874d (test: Update test cases for currency change validation) class TherapyPlan(Document): def validate(self): @@ -71,7 +76,13 @@ def make_sales_invoice(reference_name, patient, company, therapy_plan_template): si = frappe.new_doc("Sales Invoice") si.company = company si.patient = patient +<<<<<<< HEAD si.customer = frappe.db.get_value("Patient", patient, "customer") +======= + si.customer = frappe.db.get_value('Patient', patient, 'customer') + si.currency = frappe.get_value('Customer', si.customer, 'default_currency') \ + or get_company_currency(si.company) +>>>>>>> 60915e874d (test: Update test cases for currency change validation) item = frappe.db.get_value("Therapy Plan Template", therapy_plan_template, "linked_item") price_list, price_list_currency = frappe.db.get_values( diff --git a/erpnext/non_profit/doctype/membership/membership.py b/erpnext/non_profit/doctype/membership/membership.py index 835e2db8519..c420a2879b7 100644 --- a/erpnext/non_profit/doctype/membership/membership.py +++ b/erpnext/non_profit/doctype/membership/membership.py @@ -13,8 +13,12 @@ from frappe.model.document import Document from frappe.utils import add_days, add_months, add_years, get_link_to_form, getdate, nowdate import erpnext +<<<<<<< HEAD from erpnext.non_profit.doctype.member.member import create_member +======= +from erpnext import get_company_currency +>>>>>>> 60915e874d (test: Update test cases for currency change validation) class Membership(Document): def validate(self): @@ -198,6 +202,7 @@ class Membership(Document): def make_invoice(membership, member, plan, settings): +<<<<<<< HEAD invoice = frappe.get_doc( { "doctype": "Sales Invoice", @@ -209,6 +214,23 @@ def make_invoice(membership, member, plan, settings): "items": [{"item_code": plan.linked_item, "rate": membership.amount, "qty": 1}], } ) +======= + invoice = frappe.get_doc({ + "doctype": "Sales Invoice", + "customer": member.customer, + "debit_to": settings.membership_debit_account, + "currency": membership.currency or get_company_currency(settings.company), + "company": settings.company, + "is_pos": 0, + "items": [ + { + "item_code": plan.linked_item, + "rate": membership.amount, + "qty": 1 + } + ] + }) +>>>>>>> 60915e874d (test: Update test cases for currency change validation) invoice.set_missing_values() invoice.insert() invoice.submit() diff --git a/erpnext/non_profit/doctype/membership/test_membership.py b/erpnext/non_profit/doctype/membership/test_membership.py index aef34a69606..d73c2bed5f4 100644 --- a/erpnext/non_profit/doctype/membership/test_membership.py +++ b/erpnext/non_profit/doctype/membership/test_membership.py @@ -94,7 +94,7 @@ def make_membership(member, payload={}): "member": member, "membership_status": "Current", "membership_type": "_rzpy_test_milythm", - "currency": "INR", + "currency": "USD", "paid": 1, "from_date": nowdate(), "amount": 100, From e28f6b7d312e9a06346700a9f9627a21c06d64d9 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Sun, 22 Aug 2021 18:05:24 +0530 Subject: [PATCH 06/16] test: fix property name (cherry picked from commit c10a22529c8b612ca31d2221700e45184426753d) # Conflicts: # erpnext/healthcare/doctype/patient_appointment/patient_appointment.py --- .../doctype/patient_appointment/patient_appointment.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/erpnext/healthcare/doctype/patient_appointment/patient_appointment.py b/erpnext/healthcare/doctype/patient_appointment/patient_appointment.py index 131767797db..713e5b3501e 100755 --- a/erpnext/healthcare/doctype/patient_appointment/patient_appointment.py +++ b/erpnext/healthcare/doctype/patient_appointment/patient_appointment.py @@ -262,8 +262,12 @@ def create_sales_invoice(appointment_doc): ======= sales_invoice.customer = frappe.get_value('Patient', appointment_doc.patient, 'customer') sales_invoice.currency = frappe.get_value('Customer', sales_invoice.customer, 'default_currency') \ +<<<<<<< HEAD or get_company_currency(appointment_doc.currency) >>>>>>> 60915e874d (test: Update test cases for currency change validation) +======= + or get_company_currency(appointment_doc.company) +>>>>>>> c10a22529c (test: fix property name) sales_invoice.appointment = appointment_doc.name sales_invoice.due_date = getdate() sales_invoice.company = appointment_doc.company From 4727482737e96aeefa04aa4b22ab3afd78b20ca2 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Sun, 22 Aug 2021 23:48:23 +0530 Subject: [PATCH 07/16] test: Set default currency for patient (cherry picked from commit 30876a105ca9ebb7f51741068b50385ca5a915c5) # Conflicts: # erpnext/healthcare/doctype/patient_appointment/test_patient_appointment.py --- .../test_patient_appointment.py | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/erpnext/healthcare/doctype/patient_appointment/test_patient_appointment.py b/erpnext/healthcare/doctype/patient_appointment/test_patient_appointment.py index 048547a9322..274f1afdaae 100644 --- a/erpnext/healthcare/doctype/patient_appointment/test_patient_appointment.py +++ b/erpnext/healthcare/doctype/patient_appointment/test_patient_appointment.py @@ -235,6 +235,7 @@ class TestPatientAppointment(unittest.TestCase): ) ip_record1 = frappe.get_doc("Inpatient Record", ip_record.name) mark_invoiced_inpatient_occupancy(ip_record1) +<<<<<<< HEAD discharge_patient(ip_record1, now_datetime()) def test_payment_should_be_mandatory_for_new_patient_appointment(self): @@ -415,6 +416,44 @@ def create_practitioner(id=0, medical_department=None): return practitioner.name +======= + discharge_patient(ip_record1) + + +def create_healthcare_docs(): + patient = create_patient() + practitioner = frappe.db.exists('Healthcare Practitioner', '_Test Healthcare Practitioner') + medical_department = frappe.db.exists('Medical Department', '_Test Medical Department') + + if not medical_department: + medical_department = frappe.new_doc('Medical Department') + medical_department.department = '_Test Medical Department' + medical_department.save(ignore_permissions=True) + medical_department = medical_department.name + + if not practitioner: + practitioner = frappe.new_doc('Healthcare Practitioner') + practitioner.first_name = '_Test Healthcare Practitioner' + practitioner.gender = 'Female' + practitioner.department = medical_department + practitioner.op_consulting_charge = 500 + practitioner.inpatient_visit_charge = 500 + practitioner.save(ignore_permissions=True) + practitioner = practitioner.name + + return patient, medical_department, practitioner + +def create_patient(): + patient = frappe.db.exists('Patient', '_Test Patient') + if not patient: + patient = frappe.new_doc('Patient') + patient.first_name = '_Test Patient' + patient.sex = 'Female' + patient.default_currency = 'INR' + patient.save(ignore_permissions=True) + patient = patient.name + return patient +>>>>>>> 30876a105c (test: Set default currency for patient) def create_encounter(appointment): if appointment: From d10c2e50bee2256b43039d7d09b53dc01e72160d Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Thu, 26 Aug 2021 17:13:36 +0530 Subject: [PATCH 08/16] fix: Party account validation in JV (cherry picked from commit 417d6abcf48668d053b413dae577f7c775c08416) # Conflicts: # erpnext/accounts/doctype/journal_entry/journal_entry.py --- .../doctype/journal_entry/journal_entry.py | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py index 8660c18bf95..a7c52dd24d0 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.py +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py @@ -26,6 +26,13 @@ from erpnext.accounts.utils import ( ) from erpnext.controllers.accounts_controller import AccountsController from erpnext.hr.doctype.expense_claim.expense_claim import update_reimbursed_amount +<<<<<<< HEAD +======= +from erpnext.accounts.doctype.invoice_discounting.invoice_discounting \ + import get_party_account_based_on_invoice_discounting +from erpnext.accounts.deferred_revenue import get_deferred_booking_accounts +from erpnext.accounts.party import get_party_gle_currency +>>>>>>> 417d6abcf4 (fix: Party account validation in JV) class StockAccountInvalidTransaction(frappe.ValidationError): @@ -49,6 +56,7 @@ class JournalEntry(AccountsController): self.clearance_date = None self.validate_party() + self.validate_party_account_currency() self.validate_entries_for_advance() self.validate_multi_currency() self.set_amounts_in_company_currency() @@ -327,11 +335,25 @@ class JournalEntry(AccountsController): account_type = frappe.db.get_value("Account", d.account, "account_type") if account_type in ["Receivable", "Payable"]: if not (d.party_type and d.party): +<<<<<<< HEAD frappe.throw( _("Row {0}: Party Type and Party is required for Receivable / Payable account {1}").format( d.idx, d.account ) ) +======= + frappe.throw(_("Row {0}: Party Type and Party is required for Receivable / Payable account {1}").format(d.idx, d.account)) + + def validate_party_account_currency(self): + for d in self.get("accounts"): + if d.party_type in ('Customer', 'Supplier'): + party_gle_currency = get_party_gle_currency(d.party_type, d.party, self.company) + party_account_currency = get_account_currency(d.account) + party_currency = frappe.db.get_value(d.party_type, d.party, 'default_currency') + + if not party_gle_currency and (party_account_currency != party_currency): + frappe.throw(_("Party Account {0} currency and default party currency should be same").format(frappe.bold(d.account))) +>>>>>>> 417d6abcf4 (fix: Party account validation in JV) def check_credit_limit(self): customers = list( From 4ca6cdca7621e40093abe43d016124798ede25ea Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Sun, 15 May 2022 21:10:52 +0530 Subject: [PATCH 09/16] fix: Remove validation from Journal Entry (cherry picked from commit 5b8726405d54c2a0601d379dbc78482e19858cda) # Conflicts: # erpnext/accounts/doctype/journal_entry/journal_entry.py --- erpnext/accounts/doctype/journal_entry/journal_entry.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py index a7c52dd24d0..7bd978561ba 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.py +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py @@ -56,7 +56,6 @@ class JournalEntry(AccountsController): self.clearance_date = None self.validate_party() - self.validate_party_account_currency() self.validate_entries_for_advance() self.validate_multi_currency() self.set_amounts_in_company_currency() @@ -341,6 +340,7 @@ class JournalEntry(AccountsController): d.idx, d.account ) ) +<<<<<<< HEAD ======= frappe.throw(_("Row {0}: Party Type and Party is required for Receivable / Payable account {1}").format(d.idx, d.account)) @@ -354,6 +354,8 @@ class JournalEntry(AccountsController): if not party_gle_currency and (party_account_currency != party_currency): frappe.throw(_("Party Account {0} currency and default party currency should be same").format(frappe.bold(d.account))) >>>>>>> 417d6abcf4 (fix: Party account validation in JV) +======= +>>>>>>> 5b8726405d (fix: Remove validation from Journal Entry) def check_credit_limit(self): customers = list( From 0628785c646a221b66277f8fb22c1e9dddfefbfc Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Mon, 16 May 2022 10:52:58 +0530 Subject: [PATCH 10/16] test: Update test cases (cherry picked from commit 65232edfd5634cb270a20cab076d2ad3cc644e28) # Conflicts: # erpnext/accounts/doctype/period_closing_voucher/test_period_closing_voucher.py # erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py --- .../test_period_closing_voucher.py | 15 +++++++- .../doctype/pricing_rule/test_pricing_rule.py | 35 +++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/erpnext/accounts/doctype/period_closing_voucher/test_period_closing_voucher.py b/erpnext/accounts/doctype/period_closing_voucher/test_period_closing_voucher.py index a61f32c3d1e..8a8e186a826 100644 --- a/erpnext/accounts/doctype/period_closing_voucher/test_period_closing_voucher.py +++ b/erpnext/accounts/doctype/period_closing_voucher/test_period_closing_voucher.py @@ -79,9 +79,14 @@ class TestPeriodClosingVoucher(unittest.TestCase): rate=400, debit_to="Debtors - TPC", <<<<<<< HEAD +<<<<<<< HEAD ======= currency="USD" >>>>>>> 60915e874d (test: Update test cases for currency change validation) +======= + currency="USD", + customer="_Test Customer USD", +>>>>>>> 65232edfd5 (test: Update test cases) ) create_sales_invoice( company=company, @@ -91,9 +96,14 @@ class TestPeriodClosingVoucher(unittest.TestCase): rate=200, debit_to="Debtors - TPC", <<<<<<< HEAD +<<<<<<< HEAD ======= currency="USD" >>>>>>> 60915e874d (test: Update test cases for currency change validation) +======= + currency="USD", + customer="_Test Customer USD", +>>>>>>> 65232edfd5 (test: Update test cases) ) pcv = self.make_period_closing_voucher(submit=False) @@ -127,14 +137,17 @@ class TestPeriodClosingVoucher(unittest.TestCase): surplus_account = create_account() cost_center = create_cost_center("Test Cost Center 1") - create_sales_invoice( + si = create_sales_invoice( company=company, income_account="Sales - TPC", expense_account="Cost of Goods Sold - TPC", cost_center=cost_center, rate=400, debit_to="Debtors - TPC", + currency="USD", + customer="_Test Customer USD", ) + jv = make_journal_entry( account1="Cash - TPC", account2="Sales - TPC", diff --git a/erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py b/erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py index 4b81a7d6a23..709f0a52eec 100644 --- a/erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py +++ b/erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py @@ -768,6 +768,41 @@ class TestPricingRule(unittest.TestCase): frappe.get_doc("Item Price", {"item_code": "Water Flask"}).delete() item.delete() +<<<<<<< HEAD +======= + def test_multiple_pricing_rules_with_min_qty(self): + make_pricing_rule( + discount_percentage=20, + selling=1, + priority=1, + min_qty=4, + apply_multiple_pricing_rules=1, + title="_Test Pricing Rule with Min Qty - 1", + ) + make_pricing_rule( + discount_percentage=10, + selling=1, + priority=2, + min_qty=4, + apply_multiple_pricing_rules=1, + title="_Test Pricing Rule with Min Qty - 2", + ) + + si = create_sales_invoice(do_not_submit=True, customer="_Test Customer 1", qty=1) + item = si.items[0] + item.stock_qty = 1 + si.save() + self.assertFalse(item.discount_percentage) + item.qty = 5 + item.stock_qty = 5 + si.save() + self.assertEqual(item.discount_percentage, 30) + si.delete() + + frappe.delete_doc_if_exists("Pricing Rule", "_Test Pricing Rule with Min Qty - 1") + frappe.delete_doc_if_exists("Pricing Rule", "_Test Pricing Rule with Min Qty - 2") + +>>>>>>> 65232edfd5 (test: Update test cases) test_dependencies = ["Campaign"] From 761669c7ca73448ba5306816f9b412a0b6cbd425 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Wed, 25 May 2022 15:42:47 +0530 Subject: [PATCH 11/16] chore: Update test case (cherry picked from commit bc3473770947ed5796a8e7d6fa718b2a55f326eb) # Conflicts: # erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py --- erpnext/accounts/party.py | 15 ++++++ .../purchase_receipt/test_purchase_receipt.py | 52 +++++++++++++++++++ 2 files changed, 67 insertions(+) diff --git a/erpnext/accounts/party.py b/erpnext/accounts/party.py index b76ce29b505..177624ca032 100644 --- a/erpnext/accounts/party.py +++ b/erpnext/accounts/party.py @@ -898,3 +898,18 @@ def get_default_contact(doctype, name): return None else: return None + + +def add_party_account(party_type, party, company, account): + doc = frappe.get_doc(party_type, party) + account_exists = False + for d in doc.get("accounts"): + if d.account == account: + account_exists = True + + if not account_exists: + accounts = {"company": company, "account": account} + + doc.append("accounts", accounts) + + doc.save() diff --git a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py index 65c30de0978..441bfc1b63c 100644 --- a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py @@ -1295,6 +1295,58 @@ class TestPurchaseReceipt(FrappeTestCase): self.assertEqual(pr.status, "To Bill") self.assertAlmostEqual(pr.per_billed, 50.0, places=2) +<<<<<<< HEAD +======= + def test_purchase_receipt_with_exchange_rate_difference(self): + from erpnext.accounts.doctype.purchase_invoice.purchase_invoice import ( + make_purchase_receipt as create_purchase_receipt, + ) + from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import ( + make_purchase_invoice as create_purchase_invoice, + ) + from erpnext.accounts.party import add_party_account + + add_party_account( + "Supplier", + "_Test Supplier USD", + "_Test Company with perpetual inventory", + "_Test Payable USD - TCP1", + ) + + pi = create_purchase_invoice( + company="_Test Company with perpetual inventory", + cost_center="Main - TCP1", + warehouse="Stores - TCP1", + expense_account="_Test Account Cost for Goods Sold - TCP1", + currency="USD", + conversion_rate=70, + supplier="_Test Supplier USD", + ) + + pr = create_purchase_receipt(pi.name) + pr.conversion_rate = 80 + pr.items[0].purchase_invoice = pi.name + pr.items[0].purchase_invoice_item = pi.items[0].name + + pr.save() + pr.submit() + + # Get exchnage gain and loss account + exchange_gain_loss_account = frappe.db.get_value( + "Company", pr.company, "exchange_gain_loss_account" + ) + + # fetching the latest GL Entry with exchange gain and loss account account + amount = frappe.db.get_value( + "GL Entry", {"account": exchange_gain_loss_account, "voucher_no": pr.name}, "credit" + ) + discrepancy_caused_by_exchange_rate_diff = abs( + pi.items[0].base_net_amount - pr.items[0].base_net_amount + ) + + self.assertEqual(discrepancy_caused_by_exchange_rate_diff, amount) + +>>>>>>> bc34737709 (chore: Update test case) def test_payment_terms_are_fetched_when_creating_purchase_invoice(self): from erpnext.accounts.doctype.payment_entry.test_payment_entry import ( create_payment_terms_template, From f724f6d1bbd727789b6136b5adb390323927f5f2 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Wed, 25 May 2022 19:04:20 +0530 Subject: [PATCH 12/16] chore: Resolve conflicts --- .../doctype/journal_entry/journal_entry.py | 30 +-- .../test_period_closing_voucher.py | 15 +- .../doctype/pricing_rule/test_pricing_rule.py | 35 --- erpnext/controllers/accounts_controller.py | 22 +- .../patient_appointment.py | 22 +- .../test_patient_appointment.py | 209 ++---------------- .../doctype/therapy_plan/therapy_plan.py | 14 +- .../doctype/membership/membership.py | 25 +-- .../purchase_receipt/test_purchase_receipt.py | 52 ----- 9 files changed, 48 insertions(+), 376 deletions(-) diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py index 7bd978561ba..cc6e6137a13 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.py +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py @@ -17,7 +17,7 @@ from erpnext.accounts.doctype.invoice_discounting.invoice_discounting import ( from erpnext.accounts.doctype.tax_withholding_category.tax_withholding_category import ( get_party_tax_withholding_details, ) -from erpnext.accounts.party import get_party_account +from erpnext.accounts.party import get_party_account, get_party_gle_currency from erpnext.accounts.utils import ( get_account_currency, get_balance_on, @@ -26,13 +26,6 @@ from erpnext.accounts.utils import ( ) from erpnext.controllers.accounts_controller import AccountsController from erpnext.hr.doctype.expense_claim.expense_claim import update_reimbursed_amount -<<<<<<< HEAD -======= -from erpnext.accounts.doctype.invoice_discounting.invoice_discounting \ - import get_party_account_based_on_invoice_discounting -from erpnext.accounts.deferred_revenue import get_deferred_booking_accounts -from erpnext.accounts.party import get_party_gle_currency ->>>>>>> 417d6abcf4 (fix: Party account validation in JV) class StockAccountInvalidTransaction(frappe.ValidationError): @@ -334,28 +327,25 @@ class JournalEntry(AccountsController): account_type = frappe.db.get_value("Account", d.account, "account_type") if account_type in ["Receivable", "Payable"]: if not (d.party_type and d.party): -<<<<<<< HEAD frappe.throw( _("Row {0}: Party Type and Party is required for Receivable / Payable account {1}").format( d.idx, d.account ) ) -<<<<<<< HEAD -======= - frappe.throw(_("Row {0}: Party Type and Party is required for Receivable / Payable account {1}").format(d.idx, d.account)) - + def validate_party_account_currency(self): for d in self.get("accounts"): - if d.party_type in ('Customer', 'Supplier'): + if d.party_type in ("Customer", "Supplier"): party_gle_currency = get_party_gle_currency(d.party_type, d.party, self.company) party_account_currency = get_account_currency(d.account) - party_currency = frappe.db.get_value(d.party_type, d.party, 'default_currency') - + party_currency = frappe.db.get_value(d.party_type, d.party, "default_currency") + if not party_gle_currency and (party_account_currency != party_currency): - frappe.throw(_("Party Account {0} currency and default party currency should be same").format(frappe.bold(d.account))) ->>>>>>> 417d6abcf4 (fix: Party account validation in JV) -======= ->>>>>>> 5b8726405d (fix: Remove validation from Journal Entry) + frappe.throw( + _("Party Account {0} currency and default party currency should be same").format( + frappe.bold(d.account) + ) + ) def check_credit_limit(self): customers = list( diff --git a/erpnext/accounts/doctype/period_closing_voucher/test_period_closing_voucher.py b/erpnext/accounts/doctype/period_closing_voucher/test_period_closing_voucher.py index 8a8e186a826..a944a373832 100644 --- a/erpnext/accounts/doctype/period_closing_voucher/test_period_closing_voucher.py +++ b/erpnext/accounts/doctype/period_closing_voucher/test_period_closing_voucher.py @@ -78,16 +78,10 @@ class TestPeriodClosingVoucher(unittest.TestCase): expense_account="Cost of Goods Sold - TPC", rate=400, debit_to="Debtors - TPC", -<<<<<<< HEAD -<<<<<<< HEAD -======= - currency="USD" ->>>>>>> 60915e874d (test: Update test cases for currency change validation) -======= currency="USD", customer="_Test Customer USD", ->>>>>>> 65232edfd5 (test: Update test cases) ) + create_sales_invoice( company=company, cost_center=cost_center2, @@ -95,15 +89,8 @@ class TestPeriodClosingVoucher(unittest.TestCase): expense_account="Cost of Goods Sold - TPC", rate=200, debit_to="Debtors - TPC", -<<<<<<< HEAD -<<<<<<< HEAD -======= - currency="USD" ->>>>>>> 60915e874d (test: Update test cases for currency change validation) -======= currency="USD", customer="_Test Customer USD", ->>>>>>> 65232edfd5 (test: Update test cases) ) pcv = self.make_period_closing_voucher(submit=False) diff --git a/erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py b/erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py index 709f0a52eec..4b81a7d6a23 100644 --- a/erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py +++ b/erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py @@ -768,41 +768,6 @@ class TestPricingRule(unittest.TestCase): frappe.get_doc("Item Price", {"item_code": "Water Flask"}).delete() item.delete() -<<<<<<< HEAD -======= - def test_multiple_pricing_rules_with_min_qty(self): - make_pricing_rule( - discount_percentage=20, - selling=1, - priority=1, - min_qty=4, - apply_multiple_pricing_rules=1, - title="_Test Pricing Rule with Min Qty - 1", - ) - make_pricing_rule( - discount_percentage=10, - selling=1, - priority=2, - min_qty=4, - apply_multiple_pricing_rules=1, - title="_Test Pricing Rule with Min Qty - 2", - ) - - si = create_sales_invoice(do_not_submit=True, customer="_Test Customer 1", qty=1) - item = si.items[0] - item.stock_qty = 1 - si.save() - self.assertFalse(item.discount_percentage) - item.qty = 5 - item.stock_qty = 5 - si.save() - self.assertEqual(item.discount_percentage, 30) - si.delete() - - frappe.delete_doc_if_exists("Pricing Rule", "_Test Pricing Rule with Min Qty - 1") - frappe.delete_doc_if_exists("Pricing Rule", "_Test Pricing Rule with Min Qty - 2") - ->>>>>>> 65232edfd5 (test: Update test cases) test_dependencies = ["Campaign"] diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index 60ff067a91f..01586b3de1c 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -35,6 +35,7 @@ from erpnext.accounts.doctype.pricing_rule.utils import ( from erpnext.accounts.party import ( get_party_account, get_party_account_currency, + get_party_gle_currency, validate_party_frozen_disabled, ) from erpnext.accounts.utils import get_account_currency, get_fiscal_years, validate_fiscal_year @@ -44,12 +45,6 @@ from erpnext.controllers.print_settings import ( set_print_templates_for_taxes, ) from erpnext.controllers.sales_and_purchase_return import validate_return -<<<<<<< HEAD -======= -from erpnext.accounts.party import get_party_account_currency, validate_party_frozen_disabled, get_party_gle_currency -from erpnext.accounts.doctype.pricing_rule.utils import (apply_pricing_rule_on_transaction, - apply_pricing_rule_for_free_items, get_applied_pricing_rules) ->>>>>>> 80c85dd17c (fix: Account currency validation for first transaction) from erpnext.exceptions import InvalidCurrency from erpnext.setup.utils import get_exchange_rate from erpnext.stock.doctype.packed_item.packed_item import make_packing_list @@ -1453,20 +1448,25 @@ class AccountsController(TransactionBase): # from creating a sales invoice if sales order is already created def validate_party_account_currency(self): - if self.doctype not in ('Sales Invoice', 'Purchase Invoice'): + if self.doctype not in ("Sales Invoice", "Purchase Invoice"): return - if self.is_opening == 'Yes': + if self.is_opening == "Yes": return party_type, party = self.get_party() party_gle_currency = get_party_gle_currency(party_type, party, self.company) - party_account = self.get('debit_to') if self.doctype == 'Sales Invoice' else self.get('credit_to') + party_account = ( + self.get("debit_to") if self.doctype == "Sales Invoice" else self.get("credit_to") + ) party_account_currency = get_account_currency(party_account) if not party_gle_currency and (party_account_currency != self.currency): - frappe.throw(_("Party Account {0} currency and document currency should be same").format(frappe.bold(party_account))) - + frappe.throw( + _("Party Account {0} currency and document currency should be same").format( + frappe.bold(party_account) + ) + ) def delink_advance_entries(self, linked_doc_name): total_allocated_amount = 0 diff --git a/erpnext/healthcare/doctype/patient_appointment/patient_appointment.py b/erpnext/healthcare/doctype/patient_appointment/patient_appointment.py index 713e5b3501e..db61e0d9c55 100755 --- a/erpnext/healthcare/doctype/patient_appointment/patient_appointment.py +++ b/erpnext/healthcare/doctype/patient_appointment/patient_appointment.py @@ -12,6 +12,7 @@ from frappe.model.document import Document from frappe.model.mapper import get_mapped_doc from frappe.utils import flt, get_link_to_form, get_time, getdate +from erpnext import get_company_currency from erpnext.healthcare.doctype.healthcare_settings.healthcare_settings import ( get_income_account, get_receivable_account, @@ -22,7 +23,6 @@ from erpnext.healthcare.utils import ( manage_fee_validity, ) from erpnext.hr.doctype.employee.employee import is_holiday -<<<<<<< HEAD class MaximumCapacityError(frappe.ValidationError): @@ -32,11 +32,6 @@ class MaximumCapacityError(frappe.ValidationError): class OverlapError(frappe.ValidationError): pass -======= -from erpnext.healthcare.doctype.healthcare_settings.healthcare_settings import get_receivable_account, get_income_account -from erpnext.healthcare.utils import check_fee_validity, get_service_item_and_practitioner_charge, manage_fee_validity -from erpnext import get_company_currency ->>>>>>> 60915e874d (test: Update test cases for currency change validation) class PatientAppointment(Document): def validate(self): @@ -257,17 +252,12 @@ def invoice_appointment(appointment_doc): def create_sales_invoice(appointment_doc): sales_invoice = frappe.new_doc("Sales Invoice") sales_invoice.patient = appointment_doc.patient -<<<<<<< HEAD + sales_invoice.customer = frappe.get_value("Patient", appointment_doc.patient, "customer") -======= - sales_invoice.customer = frappe.get_value('Patient', appointment_doc.patient, 'customer') - sales_invoice.currency = frappe.get_value('Customer', sales_invoice.customer, 'default_currency') \ -<<<<<<< HEAD - or get_company_currency(appointment_doc.currency) ->>>>>>> 60915e874d (test: Update test cases for currency change validation) -======= - or get_company_currency(appointment_doc.company) ->>>>>>> c10a22529c (test: fix property name) + sales_invoice.currency = frappe.get_value( + "Customer", sales_invoice.customer, "default_currency" + ) or get_company_currency(appointment_doc.currency) + sales_invoice.appointment = appointment_doc.name sales_invoice.due_date = getdate() sales_invoice.company = appointment_doc.company diff --git a/erpnext/healthcare/doctype/patient_appointment/test_patient_appointment.py b/erpnext/healthcare/doctype/patient_appointment/test_patient_appointment.py index 274f1afdaae..21c481dac42 100644 --- a/erpnext/healthcare/doctype/patient_appointment/test_patient_appointment.py +++ b/erpnext/healthcare/doctype/patient_appointment/test_patient_appointment.py @@ -235,206 +235,24 @@ class TestPatientAppointment(unittest.TestCase): ) ip_record1 = frappe.get_doc("Inpatient Record", ip_record.name) mark_invoiced_inpatient_occupancy(ip_record1) -<<<<<<< HEAD - discharge_patient(ip_record1, now_datetime()) - - def test_payment_should_be_mandatory_for_new_patient_appointment(self): - frappe.db.set_value("Healthcare Settings", None, "enable_free_follow_ups", 1) - frappe.db.set_value("Healthcare Settings", None, "automate_appointment_invoicing", 1) - frappe.db.set_value("Healthcare Settings", None, "max_visits", 3) - frappe.db.set_value("Healthcare Settings", None, "valid_days", 30) - - patient = create_patient() - assert check_is_new_patient(patient) - payment_required = check_payment_fields_reqd(patient) - assert payment_required is True - - def test_sales_invoice_should_be_generated_for_new_patient_appointment(self): - patient, practitioner = create_healthcare_docs() - frappe.db.set_value("Healthcare Settings", None, "automate_appointment_invoicing", 1) - invoice_count = frappe.db.count("Sales Invoice") - - assert check_is_new_patient(patient) - create_appointment(patient, practitioner, nowdate()) - new_invoice_count = frappe.db.count("Sales Invoice") - - assert new_invoice_count == invoice_count + 1 - - def test_overlap_appointment(self): - from erpnext.healthcare.doctype.patient_appointment.patient_appointment import OverlapError - - patient, practitioner = create_healthcare_docs(id=1) - patient_1, practitioner_1 = create_healthcare_docs(id=2) - service_unit = create_service_unit(id=0) - service_unit_1 = create_service_unit(id=1) - appointment = create_appointment( - patient, practitioner, nowdate(), service_unit=service_unit - ) # valid - - # patient and practitioner cannot have overlapping appointments - appointment = create_appointment( - patient, practitioner, nowdate(), service_unit=service_unit, save=0 - ) - self.assertRaises(OverlapError, appointment.save) - appointment = create_appointment( - patient, practitioner, nowdate(), service_unit=service_unit_1, save=0 - ) # diff service unit - self.assertRaises(OverlapError, appointment.save) - appointment = create_appointment( - patient, practitioner, nowdate(), save=0 - ) # with no service unit link - self.assertRaises(OverlapError, appointment.save) - - # patient cannot have overlapping appointments with other practitioners - appointment = create_appointment( - patient, practitioner_1, nowdate(), service_unit=service_unit, save=0 - ) - self.assertRaises(OverlapError, appointment.save) - appointment = create_appointment( - patient, practitioner_1, nowdate(), service_unit=service_unit_1, save=0 - ) - self.assertRaises(OverlapError, appointment.save) - appointment = create_appointment(patient, practitioner_1, nowdate(), save=0) - self.assertRaises(OverlapError, appointment.save) - - # practitioner cannot have overlapping appointments with other patients - appointment = create_appointment( - patient_1, practitioner, nowdate(), service_unit=service_unit, save=0 - ) - self.assertRaises(OverlapError, appointment.save) - appointment = create_appointment( - patient_1, practitioner, nowdate(), service_unit=service_unit_1, save=0 - ) - self.assertRaises(OverlapError, appointment.save) - appointment = create_appointment(patient_1, practitioner, nowdate(), save=0) - self.assertRaises(OverlapError, appointment.save) - - def test_service_unit_capacity(self): - from erpnext.healthcare.doctype.patient_appointment.patient_appointment import ( - MaximumCapacityError, - OverlapError, - ) - - practitioner = create_practitioner() - capacity = 3 - overlap_service_unit_type = create_service_unit_type( - id=10, allow_appointments=1, overlap_appointments=1 - ) - overlap_service_unit = create_service_unit( - id=100, service_unit_type=overlap_service_unit_type, service_unit_capacity=capacity - ) - - for i in range(0, capacity): - patient = create_patient(id=i) - create_appointment(patient, practitioner, nowdate(), service_unit=overlap_service_unit) # valid - appointment = create_appointment( - patient, practitioner, nowdate(), service_unit=overlap_service_unit, save=0 - ) # overlap - self.assertRaises(OverlapError, appointment.save) - - patient = create_patient(id=capacity) - appointment = create_appointment( - patient, practitioner, nowdate(), service_unit=overlap_service_unit, save=0 - ) - self.assertRaises(MaximumCapacityError, appointment.save) - - def test_patient_appointment_should_consider_permissions_while_fetching_appointments(self): - patient, practitioner = create_healthcare_docs() - create_appointment(patient, practitioner, nowdate()) - - patient, new_practitioner = create_healthcare_docs(id=2) - create_appointment(patient, new_practitioner, nowdate()) - - roles = [{"doctype": "Has Role", "role": "Physician"}] - user = create_user(roles=roles) - new_practitioner = frappe.get_doc("Healthcare Practitioner", new_practitioner) - new_practitioner.user_id = user.email - new_practitioner.save() - - frappe.set_user(user.name) - appointments = frappe.get_list("Patient Appointment") - assert len(appointments) == 1 - - frappe.set_user("Administrator") - appointments = frappe.get_list("Patient Appointment") - assert len(appointments) == 2 - - -def create_healthcare_docs(id=0): - patient = create_patient(id) - practitioner = create_practitioner(id) - - return patient, practitioner - - -def create_patient( - id=0, patient_name=None, email=None, mobile=None, customer=None, create_user=False -): - if frappe.db.exists("Patient", {"firstname": f"_Test Patient {str(id)}"}): - patient = frappe.db.get_value("Patient", {"first_name": f"_Test Patient {str(id)}"}, ["name"]) - return patient - - patient = frappe.new_doc("Patient") - patient.first_name = patient_name if patient_name else f"_Test Patient {str(id)}" - patient.sex = "Female" - patient.mobile = mobile - patient.email = email - patient.customer = customer - patient.invite_user = create_user - patient.save(ignore_permissions=True) - - return patient.name - - -def create_medical_department(id=0): - if frappe.db.exists("Medical Department", f"_Test Medical Department {str(id)}"): - return f"_Test Medical Department {str(id)}" - - medical_department = frappe.new_doc("Medical Department") - medical_department.department = f"_Test Medical Department {str(id)}" - medical_department.save(ignore_permissions=True) - - return medical_department.name - - -def create_practitioner(id=0, medical_department=None): - if frappe.db.exists( - "Healthcare Practitioner", {"firstname": f"_Test Healthcare Practitioner {str(id)}"} - ): - practitioner = frappe.db.get_value( - "Healthcare Practitioner", {"firstname": f"_Test Healthcare Practitioner {str(id)}"}, ["name"] - ) - return practitioner - - practitioner = frappe.new_doc("Healthcare Practitioner") - practitioner.first_name = f"_Test Healthcare Practitioner {str(id)}" - practitioner.gender = "Female" - practitioner.department = medical_department or create_medical_department(id) - practitioner.op_consulting_charge = 500 - practitioner.inpatient_visit_charge = 500 - practitioner.save(ignore_permissions=True) - - return practitioner.name - -======= discharge_patient(ip_record1) def create_healthcare_docs(): patient = create_patient() - practitioner = frappe.db.exists('Healthcare Practitioner', '_Test Healthcare Practitioner') - medical_department = frappe.db.exists('Medical Department', '_Test Medical Department') + practitioner = frappe.db.exists("Healthcare Practitioner", "_Test Healthcare Practitioner") + medical_department = frappe.db.exists("Medical Department", "_Test Medical Department") if not medical_department: - medical_department = frappe.new_doc('Medical Department') - medical_department.department = '_Test Medical Department' + medical_department = frappe.new_doc("Medical Department") + medical_department.department = "_Test Medical Department" medical_department.save(ignore_permissions=True) medical_department = medical_department.name if not practitioner: - practitioner = frappe.new_doc('Healthcare Practitioner') - practitioner.first_name = '_Test Healthcare Practitioner' - practitioner.gender = 'Female' + practitioner = frappe.new_doc("Healthcare Practitioner") + practitioner.first_name = "_Test Healthcare Practitioner" + practitioner.gender = "Female" practitioner.department = medical_department practitioner.op_consulting_charge = 500 practitioner.inpatient_visit_charge = 500 @@ -443,17 +261,18 @@ def create_healthcare_docs(): return patient, medical_department, practitioner + def create_patient(): - patient = frappe.db.exists('Patient', '_Test Patient') + patient = frappe.db.exists("Patient", "_Test Patient") if not patient: - patient = frappe.new_doc('Patient') - patient.first_name = '_Test Patient' - patient.sex = 'Female' - patient.default_currency = 'INR' + patient = frappe.new_doc("Patient") + patient.first_name = "_Test Patient" + patient.sex = "Female" + patient.default_currency = "INR" patient.save(ignore_permissions=True) patient = patient.name return patient ->>>>>>> 30876a105c (test: Set default currency for patient) + def create_encounter(appointment): if appointment: diff --git a/erpnext/healthcare/doctype/therapy_plan/therapy_plan.py b/erpnext/healthcare/doctype/therapy_plan/therapy_plan.py index b82894c366b..6cb2a24e6af 100644 --- a/erpnext/healthcare/doctype/therapy_plan/therapy_plan.py +++ b/erpnext/healthcare/doctype/therapy_plan/therapy_plan.py @@ -4,13 +4,10 @@ import frappe from frappe.model.document import Document -<<<<<<< HEAD from frappe.utils import flt -======= -from frappe.utils import flt, today from erpnext import get_company_currency ->>>>>>> 60915e874d (test: Update test cases for currency change validation) + class TherapyPlan(Document): def validate(self): @@ -76,13 +73,10 @@ def make_sales_invoice(reference_name, patient, company, therapy_plan_template): si = frappe.new_doc("Sales Invoice") si.company = company si.patient = patient -<<<<<<< HEAD si.customer = frappe.db.get_value("Patient", patient, "customer") -======= - si.customer = frappe.db.get_value('Patient', patient, 'customer') - si.currency = frappe.get_value('Customer', si.customer, 'default_currency') \ - or get_company_currency(si.company) ->>>>>>> 60915e874d (test: Update test cases for currency change validation) + si.currency = frappe.get_value( + "Customer", si.customer, "default_currency" + ) or get_company_currency(si.company) item = frappe.db.get_value("Therapy Plan Template", therapy_plan_template, "linked_item") price_list, price_list_currency = frappe.db.get_values( diff --git a/erpnext/non_profit/doctype/membership/membership.py b/erpnext/non_profit/doctype/membership/membership.py index c420a2879b7..7f7abd06594 100644 --- a/erpnext/non_profit/doctype/membership/membership.py +++ b/erpnext/non_profit/doctype/membership/membership.py @@ -13,12 +13,9 @@ from frappe.model.document import Document from frappe.utils import add_days, add_months, add_years, get_link_to_form, getdate, nowdate import erpnext -<<<<<<< HEAD +from erpnext import get_company_currency from erpnext.non_profit.doctype.member.member import create_member -======= -from erpnext import get_company_currency ->>>>>>> 60915e874d (test: Update test cases for currency change validation) class Membership(Document): def validate(self): @@ -202,35 +199,17 @@ class Membership(Document): def make_invoice(membership, member, plan, settings): -<<<<<<< HEAD invoice = frappe.get_doc( { "doctype": "Sales Invoice", "customer": member.customer, "debit_to": settings.membership_debit_account, - "currency": membership.currency, + "currency": membership.currency or get_company_currency(settings.company), "company": settings.company, "is_pos": 0, "items": [{"item_code": plan.linked_item, "rate": membership.amount, "qty": 1}], } ) -======= - invoice = frappe.get_doc({ - "doctype": "Sales Invoice", - "customer": member.customer, - "debit_to": settings.membership_debit_account, - "currency": membership.currency or get_company_currency(settings.company), - "company": settings.company, - "is_pos": 0, - "items": [ - { - "item_code": plan.linked_item, - "rate": membership.amount, - "qty": 1 - } - ] - }) ->>>>>>> 60915e874d (test: Update test cases for currency change validation) invoice.set_missing_values() invoice.insert() invoice.submit() diff --git a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py index 441bfc1b63c..65c30de0978 100644 --- a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py @@ -1295,58 +1295,6 @@ class TestPurchaseReceipt(FrappeTestCase): self.assertEqual(pr.status, "To Bill") self.assertAlmostEqual(pr.per_billed, 50.0, places=2) -<<<<<<< HEAD -======= - def test_purchase_receipt_with_exchange_rate_difference(self): - from erpnext.accounts.doctype.purchase_invoice.purchase_invoice import ( - make_purchase_receipt as create_purchase_receipt, - ) - from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import ( - make_purchase_invoice as create_purchase_invoice, - ) - from erpnext.accounts.party import add_party_account - - add_party_account( - "Supplier", - "_Test Supplier USD", - "_Test Company with perpetual inventory", - "_Test Payable USD - TCP1", - ) - - pi = create_purchase_invoice( - company="_Test Company with perpetual inventory", - cost_center="Main - TCP1", - warehouse="Stores - TCP1", - expense_account="_Test Account Cost for Goods Sold - TCP1", - currency="USD", - conversion_rate=70, - supplier="_Test Supplier USD", - ) - - pr = create_purchase_receipt(pi.name) - pr.conversion_rate = 80 - pr.items[0].purchase_invoice = pi.name - pr.items[0].purchase_invoice_item = pi.items[0].name - - pr.save() - pr.submit() - - # Get exchnage gain and loss account - exchange_gain_loss_account = frappe.db.get_value( - "Company", pr.company, "exchange_gain_loss_account" - ) - - # fetching the latest GL Entry with exchange gain and loss account account - amount = frappe.db.get_value( - "GL Entry", {"account": exchange_gain_loss_account, "voucher_no": pr.name}, "credit" - ) - discrepancy_caused_by_exchange_rate_diff = abs( - pi.items[0].base_net_amount - pr.items[0].base_net_amount - ) - - self.assertEqual(discrepancy_caused_by_exchange_rate_diff, amount) - ->>>>>>> bc34737709 (chore: Update test case) def test_payment_terms_are_fetched_when_creating_purchase_invoice(self): from erpnext.accounts.doctype.payment_entry.test_payment_entry import ( create_payment_terms_template, From 3fab8a22133e963a06892a415feb1f8168e795a1 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Wed, 25 May 2022 19:20:09 +0530 Subject: [PATCH 13/16] chore: Remove unintended changes --- .../doctype/journal_entry/journal_entry.py | 16 +- .../doctype/lab_test/test_lab_test.py | 6 - .../patient_appointment.py | 6 - .../test_patient_appointment.py | 206 +++++++++++++++--- .../doctype/therapy_plan/therapy_plan.py | 5 - 5 files changed, 175 insertions(+), 64 deletions(-) diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py index cc6e6137a13..8660c18bf95 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.py +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py @@ -17,7 +17,7 @@ from erpnext.accounts.doctype.invoice_discounting.invoice_discounting import ( from erpnext.accounts.doctype.tax_withholding_category.tax_withholding_category import ( get_party_tax_withholding_details, ) -from erpnext.accounts.party import get_party_account, get_party_gle_currency +from erpnext.accounts.party import get_party_account from erpnext.accounts.utils import ( get_account_currency, get_balance_on, @@ -333,20 +333,6 @@ class JournalEntry(AccountsController): ) ) - def validate_party_account_currency(self): - for d in self.get("accounts"): - if d.party_type in ("Customer", "Supplier"): - party_gle_currency = get_party_gle_currency(d.party_type, d.party, self.company) - party_account_currency = get_account_currency(d.account) - party_currency = frappe.db.get_value(d.party_type, d.party, "default_currency") - - if not party_gle_currency and (party_account_currency != party_currency): - frappe.throw( - _("Party Account {0} currency and default party currency should be same").format( - frappe.bold(d.account) - ) - ) - def check_credit_limit(self): customers = list( set( diff --git a/erpnext/healthcare/doctype/lab_test/test_lab_test.py b/erpnext/healthcare/doctype/lab_test/test_lab_test.py index 754ee94c396..06c02d1ea07 100644 --- a/erpnext/healthcare/doctype/lab_test/test_lab_test.py +++ b/erpnext/healthcare/doctype/lab_test/test_lab_test.py @@ -163,14 +163,8 @@ def create_sales_invoice(): sales_invoice.patient = patient sales_invoice.customer = frappe.db.get_value("Patient", patient, "customer") sales_invoice.due_date = getdate() -<<<<<<< HEAD sales_invoice.company = "_Test Company" sales_invoice.debit_to = get_receivable_account("_Test Company") -======= - sales_invoice.company = '_Test Company' - sales_invoice.currency = 'INR' - sales_invoice.debit_to = get_receivable_account('_Test Company') ->>>>>>> bcaf475295 (fix: Healthcare module accounting test cases) tests = [insulin_resistance_template, blood_test_template] for entry in tests: diff --git a/erpnext/healthcare/doctype/patient_appointment/patient_appointment.py b/erpnext/healthcare/doctype/patient_appointment/patient_appointment.py index db61e0d9c55..b6e30060437 100755 --- a/erpnext/healthcare/doctype/patient_appointment/patient_appointment.py +++ b/erpnext/healthcare/doctype/patient_appointment/patient_appointment.py @@ -12,7 +12,6 @@ from frappe.model.document import Document from frappe.model.mapper import get_mapped_doc from frappe.utils import flt, get_link_to_form, get_time, getdate -from erpnext import get_company_currency from erpnext.healthcare.doctype.healthcare_settings.healthcare_settings import ( get_income_account, get_receivable_account, @@ -252,12 +251,7 @@ def invoice_appointment(appointment_doc): def create_sales_invoice(appointment_doc): sales_invoice = frappe.new_doc("Sales Invoice") sales_invoice.patient = appointment_doc.patient - sales_invoice.customer = frappe.get_value("Patient", appointment_doc.patient, "customer") - sales_invoice.currency = frappe.get_value( - "Customer", sales_invoice.customer, "default_currency" - ) or get_company_currency(appointment_doc.currency) - sales_invoice.appointment = appointment_doc.name sales_invoice.due_date = getdate() sales_invoice.company = appointment_doc.company diff --git a/erpnext/healthcare/doctype/patient_appointment/test_patient_appointment.py b/erpnext/healthcare/doctype/patient_appointment/test_patient_appointment.py index 21c481dac42..048547a9322 100644 --- a/erpnext/healthcare/doctype/patient_appointment/test_patient_appointment.py +++ b/erpnext/healthcare/doctype/patient_appointment/test_patient_appointment.py @@ -235,43 +235,185 @@ class TestPatientAppointment(unittest.TestCase): ) ip_record1 = frappe.get_doc("Inpatient Record", ip_record.name) mark_invoiced_inpatient_occupancy(ip_record1) - discharge_patient(ip_record1) + discharge_patient(ip_record1, now_datetime()) + + def test_payment_should_be_mandatory_for_new_patient_appointment(self): + frappe.db.set_value("Healthcare Settings", None, "enable_free_follow_ups", 1) + frappe.db.set_value("Healthcare Settings", None, "automate_appointment_invoicing", 1) + frappe.db.set_value("Healthcare Settings", None, "max_visits", 3) + frappe.db.set_value("Healthcare Settings", None, "valid_days", 30) + + patient = create_patient() + assert check_is_new_patient(patient) + payment_required = check_payment_fields_reqd(patient) + assert payment_required is True + + def test_sales_invoice_should_be_generated_for_new_patient_appointment(self): + patient, practitioner = create_healthcare_docs() + frappe.db.set_value("Healthcare Settings", None, "automate_appointment_invoicing", 1) + invoice_count = frappe.db.count("Sales Invoice") + + assert check_is_new_patient(patient) + create_appointment(patient, practitioner, nowdate()) + new_invoice_count = frappe.db.count("Sales Invoice") + + assert new_invoice_count == invoice_count + 1 + + def test_overlap_appointment(self): + from erpnext.healthcare.doctype.patient_appointment.patient_appointment import OverlapError + + patient, practitioner = create_healthcare_docs(id=1) + patient_1, practitioner_1 = create_healthcare_docs(id=2) + service_unit = create_service_unit(id=0) + service_unit_1 = create_service_unit(id=1) + appointment = create_appointment( + patient, practitioner, nowdate(), service_unit=service_unit + ) # valid + + # patient and practitioner cannot have overlapping appointments + appointment = create_appointment( + patient, practitioner, nowdate(), service_unit=service_unit, save=0 + ) + self.assertRaises(OverlapError, appointment.save) + appointment = create_appointment( + patient, practitioner, nowdate(), service_unit=service_unit_1, save=0 + ) # diff service unit + self.assertRaises(OverlapError, appointment.save) + appointment = create_appointment( + patient, practitioner, nowdate(), save=0 + ) # with no service unit link + self.assertRaises(OverlapError, appointment.save) + + # patient cannot have overlapping appointments with other practitioners + appointment = create_appointment( + patient, practitioner_1, nowdate(), service_unit=service_unit, save=0 + ) + self.assertRaises(OverlapError, appointment.save) + appointment = create_appointment( + patient, practitioner_1, nowdate(), service_unit=service_unit_1, save=0 + ) + self.assertRaises(OverlapError, appointment.save) + appointment = create_appointment(patient, practitioner_1, nowdate(), save=0) + self.assertRaises(OverlapError, appointment.save) + + # practitioner cannot have overlapping appointments with other patients + appointment = create_appointment( + patient_1, practitioner, nowdate(), service_unit=service_unit, save=0 + ) + self.assertRaises(OverlapError, appointment.save) + appointment = create_appointment( + patient_1, practitioner, nowdate(), service_unit=service_unit_1, save=0 + ) + self.assertRaises(OverlapError, appointment.save) + appointment = create_appointment(patient_1, practitioner, nowdate(), save=0) + self.assertRaises(OverlapError, appointment.save) + + def test_service_unit_capacity(self): + from erpnext.healthcare.doctype.patient_appointment.patient_appointment import ( + MaximumCapacityError, + OverlapError, + ) + + practitioner = create_practitioner() + capacity = 3 + overlap_service_unit_type = create_service_unit_type( + id=10, allow_appointments=1, overlap_appointments=1 + ) + overlap_service_unit = create_service_unit( + id=100, service_unit_type=overlap_service_unit_type, service_unit_capacity=capacity + ) + + for i in range(0, capacity): + patient = create_patient(id=i) + create_appointment(patient, practitioner, nowdate(), service_unit=overlap_service_unit) # valid + appointment = create_appointment( + patient, practitioner, nowdate(), service_unit=overlap_service_unit, save=0 + ) # overlap + self.assertRaises(OverlapError, appointment.save) + + patient = create_patient(id=capacity) + appointment = create_appointment( + patient, practitioner, nowdate(), service_unit=overlap_service_unit, save=0 + ) + self.assertRaises(MaximumCapacityError, appointment.save) + + def test_patient_appointment_should_consider_permissions_while_fetching_appointments(self): + patient, practitioner = create_healthcare_docs() + create_appointment(patient, practitioner, nowdate()) + + patient, new_practitioner = create_healthcare_docs(id=2) + create_appointment(patient, new_practitioner, nowdate()) + + roles = [{"doctype": "Has Role", "role": "Physician"}] + user = create_user(roles=roles) + new_practitioner = frappe.get_doc("Healthcare Practitioner", new_practitioner) + new_practitioner.user_id = user.email + new_practitioner.save() + + frappe.set_user(user.name) + appointments = frappe.get_list("Patient Appointment") + assert len(appointments) == 1 + + frappe.set_user("Administrator") + appointments = frappe.get_list("Patient Appointment") + assert len(appointments) == 2 -def create_healthcare_docs(): - patient = create_patient() - practitioner = frappe.db.exists("Healthcare Practitioner", "_Test Healthcare Practitioner") - medical_department = frappe.db.exists("Medical Department", "_Test Medical Department") +def create_healthcare_docs(id=0): + patient = create_patient(id) + practitioner = create_practitioner(id) - if not medical_department: - medical_department = frappe.new_doc("Medical Department") - medical_department.department = "_Test Medical Department" - medical_department.save(ignore_permissions=True) - medical_department = medical_department.name - - if not practitioner: - practitioner = frappe.new_doc("Healthcare Practitioner") - practitioner.first_name = "_Test Healthcare Practitioner" - practitioner.gender = "Female" - practitioner.department = medical_department - practitioner.op_consulting_charge = 500 - practitioner.inpatient_visit_charge = 500 - practitioner.save(ignore_permissions=True) - practitioner = practitioner.name - - return patient, medical_department, practitioner + return patient, practitioner -def create_patient(): - patient = frappe.db.exists("Patient", "_Test Patient") - if not patient: - patient = frappe.new_doc("Patient") - patient.first_name = "_Test Patient" - patient.sex = "Female" - patient.default_currency = "INR" - patient.save(ignore_permissions=True) - patient = patient.name - return patient +def create_patient( + id=0, patient_name=None, email=None, mobile=None, customer=None, create_user=False +): + if frappe.db.exists("Patient", {"firstname": f"_Test Patient {str(id)}"}): + patient = frappe.db.get_value("Patient", {"first_name": f"_Test Patient {str(id)}"}, ["name"]) + return patient + + patient = frappe.new_doc("Patient") + patient.first_name = patient_name if patient_name else f"_Test Patient {str(id)}" + patient.sex = "Female" + patient.mobile = mobile + patient.email = email + patient.customer = customer + patient.invite_user = create_user + patient.save(ignore_permissions=True) + + return patient.name + + +def create_medical_department(id=0): + if frappe.db.exists("Medical Department", f"_Test Medical Department {str(id)}"): + return f"_Test Medical Department {str(id)}" + + medical_department = frappe.new_doc("Medical Department") + medical_department.department = f"_Test Medical Department {str(id)}" + medical_department.save(ignore_permissions=True) + + return medical_department.name + + +def create_practitioner(id=0, medical_department=None): + if frappe.db.exists( + "Healthcare Practitioner", {"firstname": f"_Test Healthcare Practitioner {str(id)}"} + ): + practitioner = frappe.db.get_value( + "Healthcare Practitioner", {"firstname": f"_Test Healthcare Practitioner {str(id)}"}, ["name"] + ) + return practitioner + + practitioner = frappe.new_doc("Healthcare Practitioner") + practitioner.first_name = f"_Test Healthcare Practitioner {str(id)}" + practitioner.gender = "Female" + practitioner.department = medical_department or create_medical_department(id) + practitioner.op_consulting_charge = 500 + practitioner.inpatient_visit_charge = 500 + practitioner.save(ignore_permissions=True) + + return practitioner.name def create_encounter(appointment): diff --git a/erpnext/healthcare/doctype/therapy_plan/therapy_plan.py b/erpnext/healthcare/doctype/therapy_plan/therapy_plan.py index 6cb2a24e6af..44f0a9785c4 100644 --- a/erpnext/healthcare/doctype/therapy_plan/therapy_plan.py +++ b/erpnext/healthcare/doctype/therapy_plan/therapy_plan.py @@ -6,8 +6,6 @@ import frappe from frappe.model.document import Document from frappe.utils import flt -from erpnext import get_company_currency - class TherapyPlan(Document): def validate(self): @@ -74,9 +72,6 @@ def make_sales_invoice(reference_name, patient, company, therapy_plan_template): si.company = company si.patient = patient si.customer = frappe.db.get_value("Patient", patient, "customer") - si.currency = frappe.get_value( - "Customer", si.customer, "default_currency" - ) or get_company_currency(si.company) item = frappe.db.get_value("Therapy Plan Template", therapy_plan_template, "linked_item") price_list, price_list_currency = frappe.db.get_values( From 14422eaf59e24d2d1b6dbcd3dfd9825f1adea2fd Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Wed, 25 May 2022 20:06:31 +0530 Subject: [PATCH 14/16] chore: Update test cases --- erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py | 2 +- erpnext/healthcare/doctype/lab_test/test_lab_test.py | 1 + .../doctype/patient_appointment/patient_appointment.py | 4 ++++ erpnext/healthcare/doctype/therapy_plan/therapy_plan.py | 5 +++++ 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py b/erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py index 4b81a7d6a23..5701402811e 100644 --- a/erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py +++ b/erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py @@ -712,7 +712,7 @@ class TestPricingRule(unittest.TestCase): title="_Test Pricing Rule with Min Qty - 2", ) - si = create_sales_invoice(do_not_submit=True, customer="_Test Customer 1", qty=1, currency="USD") + si = create_sales_invoice(do_not_submit=True, customer="_Test Customer 1", qty=1) item = si.items[0] item.stock_qty = 1 si.save() diff --git a/erpnext/healthcare/doctype/lab_test/test_lab_test.py b/erpnext/healthcare/doctype/lab_test/test_lab_test.py index 06c02d1ea07..c08820f36be 100644 --- a/erpnext/healthcare/doctype/lab_test/test_lab_test.py +++ b/erpnext/healthcare/doctype/lab_test/test_lab_test.py @@ -164,6 +164,7 @@ def create_sales_invoice(): sales_invoice.customer = frappe.db.get_value("Patient", patient, "customer") sales_invoice.due_date = getdate() sales_invoice.company = "_Test Company" + sales_invoice.currency = "INR" sales_invoice.debit_to = get_receivable_account("_Test Company") tests = [insulin_resistance_template, blood_test_template] diff --git a/erpnext/healthcare/doctype/patient_appointment/patient_appointment.py b/erpnext/healthcare/doctype/patient_appointment/patient_appointment.py index b6e30060437..34aa8650e19 100755 --- a/erpnext/healthcare/doctype/patient_appointment/patient_appointment.py +++ b/erpnext/healthcare/doctype/patient_appointment/patient_appointment.py @@ -12,6 +12,7 @@ from frappe.model.document import Document from frappe.model.mapper import get_mapped_doc from frappe.utils import flt, get_link_to_form, get_time, getdate +from erpnext import get_company_currency from erpnext.healthcare.doctype.healthcare_settings.healthcare_settings import ( get_income_account, get_receivable_account, @@ -252,6 +253,9 @@ def create_sales_invoice(appointment_doc): sales_invoice = frappe.new_doc("Sales Invoice") sales_invoice.patient = appointment_doc.patient sales_invoice.customer = frappe.get_value("Patient", appointment_doc.patient, "customer") + sales_invoice.currency = frappe.get_value( + "Customer", sales_invoice.customer, "default_currency" + ) or get_company_currency(appointment_doc.currency) sales_invoice.appointment = appointment_doc.name sales_invoice.due_date = getdate() sales_invoice.company = appointment_doc.company diff --git a/erpnext/healthcare/doctype/therapy_plan/therapy_plan.py b/erpnext/healthcare/doctype/therapy_plan/therapy_plan.py index 44f0a9785c4..6cb2a24e6af 100644 --- a/erpnext/healthcare/doctype/therapy_plan/therapy_plan.py +++ b/erpnext/healthcare/doctype/therapy_plan/therapy_plan.py @@ -6,6 +6,8 @@ import frappe from frappe.model.document import Document from frappe.utils import flt +from erpnext import get_company_currency + class TherapyPlan(Document): def validate(self): @@ -72,6 +74,9 @@ def make_sales_invoice(reference_name, patient, company, therapy_plan_template): si.company = company si.patient = patient si.customer = frappe.db.get_value("Patient", patient, "customer") + si.currency = frappe.get_value( + "Customer", si.customer, "default_currency" + ) or get_company_currency(si.company) item = frappe.db.get_value("Therapy Plan Template", therapy_plan_template, "linked_item") price_list, price_list_currency = frappe.db.get_values( From 3d51d125bfeac08d47c5bb61193e7874ad7fdc9e Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Wed, 25 May 2022 23:52:40 +0530 Subject: [PATCH 15/16] chore: Update test case --- .../doctype/patient_appointment/patient_appointment.py | 3 ++- .../doctype/patient_appointment/test_patient_appointment.py | 1 + erpnext/projects/doctype/timesheet/test_timesheet.py | 4 +++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/erpnext/healthcare/doctype/patient_appointment/patient_appointment.py b/erpnext/healthcare/doctype/patient_appointment/patient_appointment.py index 34aa8650e19..0d98fff04ff 100755 --- a/erpnext/healthcare/doctype/patient_appointment/patient_appointment.py +++ b/erpnext/healthcare/doctype/patient_appointment/patient_appointment.py @@ -255,7 +255,8 @@ def create_sales_invoice(appointment_doc): sales_invoice.customer = frappe.get_value("Patient", appointment_doc.patient, "customer") sales_invoice.currency = frappe.get_value( "Customer", sales_invoice.customer, "default_currency" - ) or get_company_currency(appointment_doc.currency) + ) or get_company_currency(appointment_doc.company) + sales_invoice.appointment = appointment_doc.name sales_invoice.due_date = getdate() sales_invoice.company = appointment_doc.company diff --git a/erpnext/healthcare/doctype/patient_appointment/test_patient_appointment.py b/erpnext/healthcare/doctype/patient_appointment/test_patient_appointment.py index 048547a9322..05e6b9cfe0d 100644 --- a/erpnext/healthcare/doctype/patient_appointment/test_patient_appointment.py +++ b/erpnext/healthcare/doctype/patient_appointment/test_patient_appointment.py @@ -379,6 +379,7 @@ def create_patient( patient.mobile = mobile patient.email = email patient.customer = customer + patient.default_currency = "INR" patient.invite_user = create_user patient.save(ignore_permissions=True) diff --git a/erpnext/projects/doctype/timesheet/test_timesheet.py b/erpnext/projects/doctype/timesheet/test_timesheet.py index 57bfd5b6074..7298c037a70 100644 --- a/erpnext/projects/doctype/timesheet/test_timesheet.py +++ b/erpnext/projects/doctype/timesheet/test_timesheet.py @@ -84,7 +84,9 @@ class TestTimesheet(unittest.TestCase): emp = make_employee("test_employee_6@salary.com") timesheet = make_timesheet(emp, simulate=True, is_billable=1) - sales_invoice = make_sales_invoice(timesheet.name, "_Test Item", "_Test Customer") + sales_invoice = make_sales_invoice( + timesheet.name, "_Test Item", "_Test Customer", currency="INR" + ) sales_invoice.due_date = nowdate() sales_invoice.submit() timesheet = frappe.get_doc("Timesheet", timesheet.name) From 7df829f9cc9c73a068d1c4f7940a2c74242c7705 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Thu, 26 May 2022 09:03:18 +0530 Subject: [PATCH 16/16] chore: Update test case --- .../erpnext_integrations/connectors/shopify_connection.py | 6 ++++++ .../doctype/shopify_settings/test_shopify_settings.py | 1 + 2 files changed, 7 insertions(+) diff --git a/erpnext/erpnext_integrations/connectors/shopify_connection.py b/erpnext/erpnext_integrations/connectors/shopify_connection.py index 4579a274ffa..f28afbcd83a 100644 --- a/erpnext/erpnext_integrations/connectors/shopify_connection.py +++ b/erpnext/erpnext_integrations/connectors/shopify_connection.py @@ -4,6 +4,7 @@ import frappe from frappe import _ from frappe.utils import cint, cstr, flt, get_datetime, get_request_session, getdate, nowdate +from erpnext import get_company_currency from erpnext.erpnext_integrations.doctype.shopify_log.shopify_log import ( dump_request_data, make_shopify_log, @@ -143,6 +144,10 @@ def create_sales_order(shopify_order, shopify_settings, company=None): "taxes": get_order_taxes(shopify_order, shopify_settings), "apply_discount_on": "Grand Total", "discount_amount": get_discounted_amount(shopify_order), + "currency": frappe.get_value( + "Customer", customer or shopify_settings.default_customer, "default_currency" + ) + or get_company_currency(shopify_settings.company), } ) @@ -178,6 +183,7 @@ def create_sales_invoice(shopify_order, shopify_settings, so, old_order_sync=Fal si.set_posting_time = 1 si.posting_date = posting_date si.due_date = posting_date + si.currency = so.currency si.naming_series = shopify_settings.sales_invoice_series or "SI-Shopify-" si.flags.ignore_mandatory = True set_cost_center(si.items, shopify_settings.cost_center) diff --git a/erpnext/erpnext_integrations/doctype/shopify_settings/test_shopify_settings.py b/erpnext/erpnext_integrations/doctype/shopify_settings/test_shopify_settings.py index 7cc45d2115f..47d6d438b06 100644 --- a/erpnext/erpnext_integrations/doctype/shopify_settings/test_shopify_settings.py +++ b/erpnext/erpnext_integrations/doctype/shopify_settings/test_shopify_settings.py @@ -58,6 +58,7 @@ class ShopifySettings(unittest.TestCase): "warehouse": "_Test Warehouse - _TC", "cash_bank_account": "Cash - _TC", "account": "Cash - _TC", + "company": "_Test Company", "customer_group": "_Test Customer Group", "cost_center": "Main - _TC", "taxes": [{"shopify_tax": "International Shipping", "tax_account": "Legal Expenses - _TC"}],