mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-15 11:09:17 +00:00
fix: use shipping_address_name for address validation in sales invoice (#46473)
* fix: validate address and contact related to party * fix: solve unboundlocal error * refactor: improve variable scope * refactor: translatable strings * fix: use shipping_address_name for address validation in sales invoice * test: add new unit test for address and contact validation * chore: to avoid keyerror --------- Co-authored-by: ruthra kumar <ruthra@erpnext.com>
This commit is contained in:
@@ -2179,3 +2179,59 @@ class TestAccountsController(IntegrationTestCase):
|
||||
si_1 = create_sales_invoice(do_not_submit=True)
|
||||
si_1.items[0].project = project.name
|
||||
self.assertRaises(frappe.ValidationError, si_1.save)
|
||||
|
||||
def test_party_billing_and_shipping_address(self):
|
||||
from erpnext.crm.doctype.prospect.test_prospect import make_address
|
||||
|
||||
customer_billing = make_address(address_title="Customer")
|
||||
customer_billing.append("links", {"link_doctype": "Customer", "link_name": "_Test Customer"})
|
||||
customer_billing.save()
|
||||
supplier_billing = make_address(address_title="Supplier", address_line1="2", city="Ahmedabad")
|
||||
supplier_billing.append("links", {"link_doctype": "Supplier", "link_name": "_Test Supplier"})
|
||||
supplier_billing.save()
|
||||
|
||||
customer_shipping = make_address(
|
||||
address_title="Customer", address_type="Shipping", address_line1="10"
|
||||
)
|
||||
customer_shipping.append("links", {"link_doctype": "Customer", "link_name": "_Test Customer"})
|
||||
customer_shipping.save()
|
||||
supplier_shipping = make_address(
|
||||
address_title="Supplier", address_type="Shipping", address_line1="20", city="Ahmedabad"
|
||||
)
|
||||
supplier_shipping.append("links", {"link_doctype": "Supplier", "link_name": "_Test Supplier"})
|
||||
supplier_shipping.save()
|
||||
|
||||
si = create_sales_invoice(do_not_save=True)
|
||||
si.customer_address = supplier_billing.name
|
||||
self.assertRaises(frappe.ValidationError, si.save)
|
||||
si.customer_address = customer_billing.name
|
||||
si.save()
|
||||
|
||||
si.shipping_address_name = supplier_shipping.name
|
||||
self.assertRaises(frappe.ValidationError, si.save)
|
||||
si.shipping_address_name = customer_shipping.name
|
||||
si.reload()
|
||||
si.save()
|
||||
|
||||
pi = make_purchase_invoice(do_not_save=True)
|
||||
pi.supplier_address = customer_shipping.name
|
||||
self.assertRaises(frappe.ValidationError, pi.save)
|
||||
pi.supplier_address = supplier_shipping.name
|
||||
pi.save()
|
||||
|
||||
def test_party_contact(self):
|
||||
from frappe.contacts.doctype.contact.test_contact import create_contact
|
||||
|
||||
customer_contact = create_contact(name="Customer", salutation="Mr", save=False)
|
||||
customer_contact.append("links", {"link_doctype": "Customer", "link_name": "_Test Customer"})
|
||||
customer_contact.save()
|
||||
|
||||
supplier_contact = create_contact(name="Supplier", salutation="Mr", save=False)
|
||||
supplier_contact.append("links", {"link_doctype": "Supplier", "link_name": "_Test Supplier"})
|
||||
supplier_contact.save()
|
||||
|
||||
si = create_sales_invoice(do_not_save=True)
|
||||
si.contact_person = supplier_contact.name
|
||||
self.assertRaises(frappe.ValidationError, si.save)
|
||||
si.contact_person = customer_contact.name
|
||||
si.save()
|
||||
|
||||
Reference in New Issue
Block a user