Skip to content

Commit

Permalink
Merge pull request #245 from Abhishek-Wagh/15.0-develop
Browse files Browse the repository at this point in the history
for bug G2P-2165, G2P-2147
  • Loading branch information
shibu-narayanan authored Jun 13, 2024
2 parents 961428b + 5955b67 commit 96af613
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
15 changes: 10 additions & 5 deletions g2p_programs/models/cycle_membership.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,17 @@ def unlink(self):
)

for record in draft_records:
beneficiary = record.cycle_id.entitlement_ids.filtered(
entitlement = record.cycle_id.entitlement_ids.filtered(
lambda x: x.partner_id.id == record.partner_id.id
)
if record.cycle_id.state == "approved" or beneficiary and beneficiary.state == "approved":
raise ValidationError(
_("Beneficiaries can only be deleted when both the cycle and entitlement are unapproved.")
)
if entitlement:
if entitlement.state == "approved":
raise ValidationError(
_(
"Beneficiaries can only be deleted when both the cycle and"
"entitlement are unapproved."
)
)
entitlement.unlink()

return super().unlink()
8 changes: 8 additions & 0 deletions g2p_programs/models/entitlement.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ def _generate_code(self):
),
]

@api.constrains("valid_from", "valid_until")
def _check_valid_dates(self):
for record in self:
if record.valid_until and record.valid_from and record.valid_until < record.valid_from:
raise ValidationError(
_('The "Valid Until" date cannot be earlier than the "Valid From" date.')
)

def fields_view_get(self, view_id=None, view_type="list", toolbar=False, submenu=False):
res = super(G2PEntitlement, self).fields_view_get(
view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu
Expand Down

0 comments on commit 96af613

Please sign in to comment.