Skip to content

Commit

Permalink
Merge pull request #95 from shivamg9/15.0-develop
Browse files Browse the repository at this point in the history
G2P-1275: Implemented date_collected field to disallow future dates
  • Loading branch information
shibu-narayanan authored Nov 3, 2023
2 parents 3974366 + 7478eff commit 77cf208
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions g2p_registry_base/models/phone_number.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import logging
import re

from odoo import _, api, fields, models
from odoo import _, api, exceptions, fields, models

from odoo.addons.phone_validation.tools import phone_validation

Expand All @@ -24,11 +24,21 @@ class G2PPhoneNumber(models.Model):
)
phone_no = fields.Char("Phone Number", required=True)
phone_sanitized = fields.Char(compute="_compute_phone_sanitized", store=True)
date_collected = fields.Date(default=fields.Date.today)
date_collected = fields.Date(
default=fields.Date.today,
)
disabled = fields.Datetime("Date Disabled")
disabled_by = fields.Many2one("res.users")
country_id = fields.Many2one("res.country", "Country")

@api.onchange("date_collected")
def _check_date_collected(self):
for record in self:
if record.date_collected and record.date_collected > fields.Date.today():
raise exceptions.ValidationError(
_("Date collected cannot be in the future.")
)

@api.depends("phone_no", "country_id")
def _compute_phone_sanitized(self):
for rec in self:
Expand Down

0 comments on commit 77cf208

Please sign in to comment.