Skip to content

Commit

Permalink
Merge pull request #120 from mkumar-02/G2P-1088
Browse files Browse the repository at this point in the history
G2P-1088 Added a condition check on active_cycle of create entitlement button.
  • Loading branch information
shibu-narayanan authored Oct 16, 2023
2 parents c3209f2 + 268f1a1 commit 340d7e7
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions g2p_program_assessment/wizard/create_entitlement_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from datetime import datetime

from odoo import _, api, fields, models
from odoo.exceptions import ValidationError
from odoo.exceptions import UserError, ValidationError

_logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -48,9 +48,18 @@ def open_entitlement_form_wizard(self, beneficiary):
valid_from = datetime.utcnow()
valid_until = valid_from + (active_cycle.end_date - active_cycle.start_date)
else:
active_cycle = program.cycle_ids.filtered(
lambda x: x.state == "draft"
).sorted("start_date", reverse=True)[0]
active_cycle = (
program.cycle_ids.filtered(lambda x: x.state == "draft").sorted(
"start_date", reverse=True
)[0]
if program.cycle_ids.filtered(lambda x: x.state == "draft")
else None
)
if not active_cycle:
raise UserError(
_("No cycle is present for program: %s. Create a new cycle.")
% program.name
)
valid_from = active_cycle.start_date
valid_until = active_cycle.end_date

Expand Down

0 comments on commit 340d7e7

Please sign in to comment.