11# Copyright 2025 Moduon Team S.L.
22# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl-3.0)
33
4+ from odoo .exceptions import ValidationError
45from odoo .tests import Form
56from odoo .tests .common import TransactionCase
67
@@ -11,30 +12,34 @@ def setUpClass(cls):
1112 super ().setUpClass ()
1213
1314 def test_crm_date_deadline_required_opportunity (self ):
14- """Check date_deadline required in opportunity in default form"""
15+ """Check date_deadline is required in opportunity default form. """
1516 opportunity_form = Form (
1617 self .env ["crm.lead" ].with_context (default_type = "opportunity" )
1718 )
1819 opportunity_form .name = "Test Opportunity"
20+ # The Form object raises AssertionError for XML required fields
21+ # before the server-side ValidationError can be triggered.
1922 with self .assertRaises (AssertionError ):
2023 opportunity_form .save ()
2124 opportunity_form .date_deadline = "2025-01-01"
2225 opportunity_form .save ()
2326
2427 def test_crm_date_deadline_required_opportunity_quick_create (self ):
25- """Check date_deadline required in opportunity in quick create form"""
26- opportunity_quick_create_form = Form (
27- self .env ["crm.lead" ].with_context (default_type = "opportunity" ),
28- "crm.quick_create_opportunity_form" ,
29- )
30- opportunity_quick_create_form .name = "Test Opportunity Quick Create"
31- with self .assertRaises (AssertionError ):
32- opportunity_quick_create_form .save ()
33- opportunity_quick_create_form .date_deadline = "2025-01-01"
34- opportunity_quick_create_form .save ()
28+ """Check date_deadline is required via server validation for quick create."""
29+ # We test the server constraint directly because the field
30+ # was removed from the quick create view to fix the OWL UI bug.
31+ with self .assertRaises (ValidationError ):
32+ self .env ["crm.lead" ].with_context (default_type = "opportunity" ).create (
33+ {
34+ "name" : "Test Opportunity Quick Create" ,
35+ "type" : "opportunity" ,
36+ # We omit date_deadline to trigger the Python ValidationError
37+ }
38+ )
3539
3640 def test_crm_date_deadline_required_lead (self ):
37- """Check date_deadline not required in lead in default form """
41+ """Check date_deadline is not required for lead types. """
3842 lead_form = Form (self .env ["crm.lead" ].with_context (default_type = "lead" ))
3943 lead_form .name = "Test Lead"
44+ # Should save without errors as it's not an opportunity
4045 lead_form .save ()
0 commit comments