Skip to content

Commit c9b6151

Browse files
committed
[FIX] crm_date_deadline_required: fix usability issue on Kanban quick create
1 parent 6a3ee73 commit c9b6151

5 files changed

Lines changed: 42 additions & 25 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import models
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import crm_lead
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from odoo import _, api, models
2+
from odoo.exceptions import ValidationError
3+
4+
5+
class CrmLead(models.Model):
6+
_inherit = "crm.lead"
7+
8+
@api.constrains("date_deadline", "type")
9+
def _check_date_deadline_required(self):
10+
for record in self:
11+
if record.type == "opportunity" and not record.date_deadline:
12+
raise ValidationError(
13+
_("The expected closing date is required for opportunities.")
14+
)
15+
16+
@api.model_create_multi
17+
def create(self, vals_list):
18+
for vals in vals_list:
19+
if vals.get("type") == "opportunity" and not vals.get("date_deadline"):
20+
raise ValidationError(
21+
_("The expected closing date is required for opportunities.")
22+
)
23+
return super().create(vals_list)
Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
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
45
from odoo.tests import Form
56
from 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()

crm_date_deadline_required/views/crm_lead_view.xml

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,4 @@
1414
</xpath>
1515
</field>
1616
</record>
17-
<record id="quick_create_opportunity_form_inherit" model="ir.ui.view">
18-
<field name="name">Date deadline required quick create form</field>
19-
<field name="model">crm.lead</field>
20-
<field name="inherit_id" ref="crm.quick_create_opportunity_form" />
21-
<field name="arch" type="xml">
22-
<xpath expr="//field[@name='phone']" position="after">
23-
<field
24-
name="date_deadline"
25-
attrs="{'required': [('type', '=', 'opportunity')]}"
26-
/>
27-
</xpath>
28-
</field>
29-
</record>
3017
</odoo>

0 commit comments

Comments
 (0)