Browse Source
[IMP] - store last_date_invoiced on contract_line
[IMP] - store last_date_invoiced on contract_line
Improve CRITERIA_ALLOWED_DICT [IMP] - code improvement [IMP] - Use last_date_invoiced to set marker in invoice description [IMP] - add migration script to init last_day_invoiced and some other improvement [FIX] - a contract line suspended should start a day after the suspension end13.0-mig-contract
sbejaoui
6 years ago
committed by
Administrator
12 changed files with 1010 additions and 519 deletions
-
2contract/__manifest__.py
-
1contract/data/__init__.py
-
281contract/data/contract_line_constraints.py
-
15contract/migrations/12.0.2.0.0/post-migration.py
-
24contract/migrations/12.0.2.0.0/pre-migration.py
-
6contract/models/abstract_contract.py
-
8contract/models/abstract_contract_line.py
-
8contract/models/contract.py
-
445contract/models/contract_line.py
-
428contract/models/contract_line_constraints.py
-
309contract/tests/test_contract.py
-
2contract/views/contract_line.xml
@ -1 +0,0 @@ |
|||
from . import contract_line_constraints |
@ -1,281 +0,0 @@ |
|||
# Copyright 2018 ACSONE SA/NV. |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
|||
|
|||
from collections import namedtuple |
|||
from odoo.fields import Date |
|||
|
|||
CRITERIA = namedtuple( |
|||
'CRITERIA', |
|||
[ |
|||
'WHEN', |
|||
'HAS_DATE_END', |
|||
'IS_AUTO_RENEW', |
|||
'HAS_SUCCESSOR', |
|||
'PREDECESSOR_HAS_SUCCESSOR', |
|||
'CANCELED', |
|||
], |
|||
) |
|||
ALLOWED = namedtuple( |
|||
'ALLOWED', |
|||
['PLAN_SUCCESSOR', 'STOP_PLAN_SUCCESSOR', 'STOP', 'CANCEL', 'UN_CANCEL'], |
|||
) |
|||
|
|||
CRITERIA_ALLOWED_DICT = { |
|||
CRITERIA( |
|||
WHEN='BEFORE', |
|||
HAS_DATE_END=True, |
|||
IS_AUTO_RENEW=True, |
|||
HAS_SUCCESSOR=False, |
|||
PREDECESSOR_HAS_SUCCESSOR=None, |
|||
CANCELED=False, |
|||
): ALLOWED( |
|||
PLAN_SUCCESSOR=False, |
|||
STOP_PLAN_SUCCESSOR=True, |
|||
STOP=True, |
|||
CANCEL=True, |
|||
UN_CANCEL=False, |
|||
), |
|||
CRITERIA( |
|||
WHEN='BEFORE', |
|||
HAS_DATE_END=True, |
|||
IS_AUTO_RENEW=False, |
|||
HAS_SUCCESSOR=True, |
|||
PREDECESSOR_HAS_SUCCESSOR=None, |
|||
CANCELED=False, |
|||
): ALLOWED( |
|||
PLAN_SUCCESSOR=False, |
|||
STOP_PLAN_SUCCESSOR=False, |
|||
STOP=True, |
|||
CANCEL=True, |
|||
UN_CANCEL=False, |
|||
), |
|||
CRITERIA( |
|||
WHEN='BEFORE', |
|||
HAS_DATE_END=True, |
|||
IS_AUTO_RENEW=False, |
|||
HAS_SUCCESSOR=False, |
|||
PREDECESSOR_HAS_SUCCESSOR=None, |
|||
CANCELED=False, |
|||
): ALLOWED( |
|||
PLAN_SUCCESSOR=True, |
|||
STOP_PLAN_SUCCESSOR=True, |
|||
STOP=True, |
|||
CANCEL=True, |
|||
UN_CANCEL=False, |
|||
), |
|||
CRITERIA( |
|||
WHEN='BEFORE', |
|||
HAS_DATE_END=False, |
|||
IS_AUTO_RENEW=False, |
|||
HAS_SUCCESSOR=False, |
|||
PREDECESSOR_HAS_SUCCESSOR=None, |
|||
CANCELED=False, |
|||
): ALLOWED( |
|||
PLAN_SUCCESSOR=False, |
|||
STOP_PLAN_SUCCESSOR=True, |
|||
STOP=True, |
|||
CANCEL=True, |
|||
UN_CANCEL=False, |
|||
), |
|||
CRITERIA( |
|||
WHEN='IN', |
|||
HAS_DATE_END=True, |
|||
IS_AUTO_RENEW=True, |
|||
HAS_SUCCESSOR=False, |
|||
PREDECESSOR_HAS_SUCCESSOR=None, |
|||
CANCELED=False, |
|||
): ALLOWED( |
|||
PLAN_SUCCESSOR=False, |
|||
STOP_PLAN_SUCCESSOR=True, |
|||
STOP=True, |
|||
CANCEL=True, |
|||
UN_CANCEL=False, |
|||
), |
|||
CRITERIA( |
|||
WHEN='IN', |
|||
HAS_DATE_END=True, |
|||
IS_AUTO_RENEW=False, |
|||
HAS_SUCCESSOR=True, |
|||
PREDECESSOR_HAS_SUCCESSOR=None, |
|||
CANCELED=False, |
|||
): ALLOWED( |
|||
PLAN_SUCCESSOR=False, |
|||
STOP_PLAN_SUCCESSOR=False, |
|||
STOP=True, |
|||
CANCEL=True, |
|||
UN_CANCEL=False, |
|||
), |
|||
CRITERIA( |
|||
WHEN='IN', |
|||
HAS_DATE_END=True, |
|||
IS_AUTO_RENEW=False, |
|||
HAS_SUCCESSOR=False, |
|||
PREDECESSOR_HAS_SUCCESSOR=None, |
|||
CANCELED=False, |
|||
): ALLOWED( |
|||
PLAN_SUCCESSOR=True, |
|||
STOP_PLAN_SUCCESSOR=True, |
|||
STOP=True, |
|||
CANCEL=True, |
|||
UN_CANCEL=False, |
|||
), |
|||
CRITERIA( |
|||
WHEN='IN', |
|||
HAS_DATE_END=False, |
|||
IS_AUTO_RENEW=False, |
|||
HAS_SUCCESSOR=False, |
|||
PREDECESSOR_HAS_SUCCESSOR=None, |
|||
CANCELED=False, |
|||
): ALLOWED( |
|||
PLAN_SUCCESSOR=False, |
|||
STOP_PLAN_SUCCESSOR=True, |
|||
STOP=True, |
|||
CANCEL=True, |
|||
UN_CANCEL=False, |
|||
), |
|||
CRITERIA( |
|||
WHEN='AFTER', |
|||
HAS_DATE_END=True, |
|||
IS_AUTO_RENEW=True, |
|||
HAS_SUCCESSOR=False, |
|||
PREDECESSOR_HAS_SUCCESSOR=None, |
|||
CANCELED=False, |
|||
): ALLOWED( |
|||
PLAN_SUCCESSOR=False, |
|||
STOP_PLAN_SUCCESSOR=False, |
|||
STOP=False, |
|||
CANCEL=False, |
|||
UN_CANCEL=False, |
|||
), |
|||
CRITERIA( |
|||
WHEN='AFTER', |
|||
HAS_DATE_END=True, |
|||
IS_AUTO_RENEW=False, |
|||
HAS_SUCCESSOR=True, |
|||
PREDECESSOR_HAS_SUCCESSOR=None, |
|||
CANCELED=False, |
|||
): ALLOWED( |
|||
PLAN_SUCCESSOR=False, |
|||
STOP_PLAN_SUCCESSOR=False, |
|||
STOP=False, |
|||
CANCEL=False, |
|||
UN_CANCEL=False, |
|||
), |
|||
CRITERIA( |
|||
WHEN='AFTER', |
|||
HAS_DATE_END=True, |
|||
IS_AUTO_RENEW=False, |
|||
HAS_SUCCESSOR=False, |
|||
PREDECESSOR_HAS_SUCCESSOR=None, |
|||
CANCELED=False, |
|||
): ALLOWED( |
|||
PLAN_SUCCESSOR=True, |
|||
STOP_PLAN_SUCCESSOR=False, |
|||
STOP=False, |
|||
CANCEL=False, |
|||
UN_CANCEL=False, |
|||
), |
|||
CRITERIA( |
|||
WHEN=None, |
|||
HAS_DATE_END=None, |
|||
IS_AUTO_RENEW=None, |
|||
HAS_SUCCESSOR=None, |
|||
PREDECESSOR_HAS_SUCCESSOR=False, |
|||
CANCELED=True, |
|||
): ALLOWED( |
|||
PLAN_SUCCESSOR=False, |
|||
STOP_PLAN_SUCCESSOR=False, |
|||
STOP=False, |
|||
CANCEL=False, |
|||
UN_CANCEL=True, |
|||
), |
|||
CRITERIA( |
|||
WHEN=None, |
|||
HAS_DATE_END=None, |
|||
IS_AUTO_RENEW=None, |
|||
HAS_SUCCESSOR=None, |
|||
PREDECESSOR_HAS_SUCCESSOR=True, |
|||
CANCELED=True, |
|||
): ALLOWED( |
|||
PLAN_SUCCESSOR=False, |
|||
STOP_PLAN_SUCCESSOR=False, |
|||
STOP=False, |
|||
CANCEL=False, |
|||
UN_CANCEL=False, |
|||
), |
|||
} |
|||
|
|||
|
|||
def compute_when(date_start, date_end): |
|||
today = Date.today() |
|||
if today < date_start: |
|||
return 'BEFORE' |
|||
if date_end and today > date_end: |
|||
return 'AFTER' |
|||
return 'IN' |
|||
|
|||
|
|||
def compute_criteria( |
|||
date_start, |
|||
date_end, |
|||
is_auto_renew, |
|||
successor_contract_line_id, |
|||
predecessor_contract_line_id, |
|||
is_canceled, |
|||
): |
|||
if is_canceled: |
|||
if ( |
|||
not predecessor_contract_line_id |
|||
or not predecessor_contract_line_id.successor_contract_line_id |
|||
): |
|||
return CRITERIA( |
|||
WHEN=None, |
|||
HAS_DATE_END=None, |
|||
IS_AUTO_RENEW=None, |
|||
HAS_SUCCESSOR=None, |
|||
PREDECESSOR_HAS_SUCCESSOR=False, |
|||
CANCELED=True, |
|||
) |
|||
else: |
|||
return CRITERIA( |
|||
WHEN=None, |
|||
HAS_DATE_END=None, |
|||
IS_AUTO_RENEW=None, |
|||
HAS_SUCCESSOR=None, |
|||
PREDECESSOR_HAS_SUCCESSOR=True, |
|||
CANCELED=True, |
|||
) |
|||
when = compute_when(date_start, date_end) |
|||
has_date_end = date_end if not date_end else True |
|||
is_auto_renew = is_auto_renew |
|||
has_successor = True if successor_contract_line_id else False |
|||
canceled = is_canceled |
|||
return CRITERIA( |
|||
WHEN=when, |
|||
HAS_DATE_END=has_date_end, |
|||
IS_AUTO_RENEW=is_auto_renew, |
|||
HAS_SUCCESSOR=has_successor, |
|||
PREDECESSOR_HAS_SUCCESSOR=None, |
|||
CANCELED=canceled, |
|||
) |
|||
|
|||
|
|||
def get_allowed( |
|||
date_start, |
|||
date_end, |
|||
is_auto_renew, |
|||
successor_contract_line_id, |
|||
predecessor_contract_line_id, |
|||
is_canceled, |
|||
): |
|||
criteria = compute_criteria( |
|||
date_start, |
|||
date_end, |
|||
is_auto_renew, |
|||
successor_contract_line_id, |
|||
predecessor_contract_line_id, |
|||
is_canceled, |
|||
) |
|||
if criteria in CRITERIA_ALLOWED_DICT: |
|||
return CRITERIA_ALLOWED_DICT[criteria] |
|||
return False |
@ -0,0 +1,24 @@ |
|||
# Copyright 2018 ACSONE SA/NV |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
|||
|
|||
import logging |
|||
|
|||
from odoo import SUPERUSER_ID, api |
|||
|
|||
_logger = logging.getLogger(__name__) |
|||
|
|||
|
|||
def migrate(cr, version): |
|||
""" |
|||
set recurring_next_date to false for finished contract |
|||
""" |
|||
_logger.info("order all contract line") |
|||
with api.Environment(cr, SUPERUSER_ID, {}) as env: |
|||
contracts = env["account.analytic.account"].search([]) |
|||
finished_contract = contracts.filtered( |
|||
lambda c: not c.create_invoice_visibility |
|||
) |
|||
cr.execute( |
|||
"UPDATE account_analytic_account set recurring_next_date=null where id in (%)" |
|||
% ','.join(finished_contract.ids) |
|||
) |
@ -0,0 +1,428 @@ |
|||
# Copyright 2018 ACSONE SA/NV. |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
|||
|
|||
import itertools |
|||
from collections import namedtuple |
|||
from odoo.fields import Date |
|||
|
|||
Criteria = namedtuple( |
|||
'Criteria', |
|||
[ |
|||
'when', # Contract line relatively to today (BEFORE, IN, AFTER) |
|||
'has_date_end', # Is date_end set on contract line (bool) |
|||
'has_last_date_invoiced', # Is last_date_invoiced set on contract line |
|||
'is_auto_renew', # Is is_auto_renew set on contract line (bool) |
|||
'has_successor', # Is contract line has_successor (bool) |
|||
'predecessor_has_successor', |
|||
# Is contract line predecessor has successor (bool) |
|||
# In almost of the cases |
|||
# contract_line.predecessor.successor == contract_line |
|||
# But at cancel action, |
|||
# contract_line.predecessor.successor == False |
|||
# This is to permit plan_successor on predecessor |
|||
# If contract_line.predecessor.successor != False |
|||
# and contract_line is canceled, we don't allow uncancel |
|||
# else we re-link contract_line and its predecessor |
|||
'canceled', # Is contract line canceled (bool) |
|||
], |
|||
) |
|||
Allowed = namedtuple( |
|||
'Allowed', |
|||
['plan_successor', 'stop_plan_successor', 'stop', 'cancel', 'uncancel'], |
|||
) |
|||
|
|||
|
|||
def _expand_none(criteria): |
|||
variations = [] |
|||
for attribute, value in criteria._asdict().items(): |
|||
if value is None: |
|||
if attribute == 'when': |
|||
variations.append(['BEFORE', 'IN', 'AFTER']) |
|||
else: |
|||
variations.append([True, False]) |
|||
else: |
|||
variations.append([value]) |
|||
return itertools.product(*variations) |
|||
|
|||
|
|||
def _add(matrix, criteria, allowed): |
|||
""" Expand None values to True/False combination """ |
|||
for c in _expand_none(criteria): |
|||
matrix[c] = allowed |
|||
|
|||
|
|||
CRITERIA_ALLOWED_DICT = { |
|||
Criteria( |
|||
when='BEFORE', |
|||
has_date_end=True, |
|||
has_last_date_invoiced=False, |
|||
is_auto_renew=True, |
|||
has_successor=False, |
|||
predecessor_has_successor=None, |
|||
canceled=False, |
|||
): Allowed( |
|||
plan_successor=False, |
|||
stop_plan_successor=True, |
|||
stop=True, |
|||
cancel=True, |
|||
uncancel=False, |
|||
), |
|||
Criteria( |
|||
when='BEFORE', |
|||
has_date_end=True, |
|||
has_last_date_invoiced=False, |
|||
is_auto_renew=False, |
|||
has_successor=True, |
|||
predecessor_has_successor=None, |
|||
canceled=False, |
|||
): Allowed( |
|||
plan_successor=False, |
|||
stop_plan_successor=False, |
|||
stop=True, |
|||
cancel=True, |
|||
uncancel=False, |
|||
), |
|||
Criteria( |
|||
when='BEFORE', |
|||
has_date_end=True, |
|||
has_last_date_invoiced=False, |
|||
is_auto_renew=False, |
|||
has_successor=False, |
|||
predecessor_has_successor=None, |
|||
canceled=False, |
|||
): Allowed( |
|||
plan_successor=True, |
|||
stop_plan_successor=True, |
|||
stop=True, |
|||
cancel=True, |
|||
uncancel=False, |
|||
), |
|||
Criteria( |
|||
when='BEFORE', |
|||
has_date_end=False, |
|||
has_last_date_invoiced=False, |
|||
is_auto_renew=False, |
|||
has_successor=False, |
|||
predecessor_has_successor=None, |
|||
canceled=False, |
|||
): Allowed( |
|||
plan_successor=False, |
|||
stop_plan_successor=True, |
|||
stop=True, |
|||
cancel=True, |
|||
uncancel=False, |
|||
), |
|||
Criteria( |
|||
when='IN', |
|||
has_date_end=True, |
|||
has_last_date_invoiced=False, |
|||
is_auto_renew=True, |
|||
has_successor=False, |
|||
predecessor_has_successor=None, |
|||
canceled=False, |
|||
): Allowed( |
|||
plan_successor=False, |
|||
stop_plan_successor=True, |
|||
stop=True, |
|||
cancel=True, |
|||
uncancel=False, |
|||
), |
|||
Criteria( |
|||
when='IN', |
|||
has_date_end=True, |
|||
has_last_date_invoiced=False, |
|||
is_auto_renew=False, |
|||
has_successor=True, |
|||
predecessor_has_successor=None, |
|||
canceled=False, |
|||
): Allowed( |
|||
plan_successor=False, |
|||
stop_plan_successor=False, |
|||
stop=True, |
|||
cancel=True, |
|||
uncancel=False, |
|||
), |
|||
Criteria( |
|||
when='IN', |
|||
has_date_end=True, |
|||
has_last_date_invoiced=False, |
|||
is_auto_renew=False, |
|||
has_successor=False, |
|||
predecessor_has_successor=None, |
|||
canceled=False, |
|||
): Allowed( |
|||
plan_successor=True, |
|||
stop_plan_successor=True, |
|||
stop=True, |
|||
cancel=True, |
|||
uncancel=False, |
|||
), |
|||
Criteria( |
|||
when='IN', |
|||
has_date_end=False, |
|||
has_last_date_invoiced=False, |
|||
is_auto_renew=False, |
|||
has_successor=False, |
|||
predecessor_has_successor=None, |
|||
canceled=False, |
|||
): Allowed( |
|||
plan_successor=False, |
|||
stop_plan_successor=True, |
|||
stop=True, |
|||
cancel=True, |
|||
uncancel=False, |
|||
), |
|||
Criteria( |
|||
when='BEFORE', |
|||
has_date_end=True, |
|||
has_last_date_invoiced=True, |
|||
is_auto_renew=True, |
|||
has_successor=False, |
|||
predecessor_has_successor=None, |
|||
canceled=False, |
|||
): Allowed( |
|||
plan_successor=False, |
|||
stop_plan_successor=True, |
|||
stop=True, |
|||
cancel=False, |
|||
uncancel=False, |
|||
), |
|||
Criteria( |
|||
when='BEFORE', |
|||
has_date_end=True, |
|||
has_last_date_invoiced=True, |
|||
is_auto_renew=False, |
|||
has_successor=True, |
|||
predecessor_has_successor=None, |
|||
canceled=False, |
|||
): Allowed( |
|||
plan_successor=False, |
|||
stop_plan_successor=False, |
|||
stop=True, |
|||
cancel=False, |
|||
uncancel=False, |
|||
), |
|||
Criteria( |
|||
when='BEFORE', |
|||
has_date_end=True, |
|||
has_last_date_invoiced=True, |
|||
is_auto_renew=False, |
|||
has_successor=False, |
|||
predecessor_has_successor=None, |
|||
canceled=False, |
|||
): Allowed( |
|||
plan_successor=True, |
|||
stop_plan_successor=True, |
|||
stop=True, |
|||
cancel=False, |
|||
uncancel=False, |
|||
), |
|||
Criteria( |
|||
when='BEFORE', |
|||
has_date_end=False, |
|||
has_last_date_invoiced=True, |
|||
is_auto_renew=False, |
|||
has_successor=False, |
|||
predecessor_has_successor=None, |
|||
canceled=False, |
|||
): Allowed( |
|||
plan_successor=False, |
|||
stop_plan_successor=True, |
|||
stop=True, |
|||
cancel=False, |
|||
uncancel=False, |
|||
), |
|||
Criteria( |
|||
when='IN', |
|||
has_date_end=True, |
|||
has_last_date_invoiced=True, |
|||
is_auto_renew=True, |
|||
has_successor=False, |
|||
predecessor_has_successor=None, |
|||
canceled=False, |
|||
): Allowed( |
|||
plan_successor=False, |
|||
stop_plan_successor=True, |
|||
stop=True, |
|||
cancel=False, |
|||
uncancel=False, |
|||
), |
|||
Criteria( |
|||
when='IN', |
|||
has_date_end=True, |
|||
has_last_date_invoiced=True, |
|||
is_auto_renew=False, |
|||
has_successor=True, |
|||
predecessor_has_successor=None, |
|||
canceled=False, |
|||
): Allowed( |
|||
plan_successor=False, |
|||
stop_plan_successor=False, |
|||
stop=True, |
|||
cancel=False, |
|||
uncancel=False, |
|||
), |
|||
Criteria( |
|||
when='IN', |
|||
has_date_end=True, |
|||
has_last_date_invoiced=True, |
|||
is_auto_renew=False, |
|||
has_successor=False, |
|||
predecessor_has_successor=None, |
|||
canceled=False, |
|||
): Allowed( |
|||
plan_successor=True, |
|||
stop_plan_successor=True, |
|||
stop=True, |
|||
cancel=False, |
|||
uncancel=False, |
|||
), |
|||
Criteria( |
|||
when='IN', |
|||
has_date_end=False, |
|||
has_last_date_invoiced=True, |
|||
is_auto_renew=False, |
|||
has_successor=False, |
|||
predecessor_has_successor=None, |
|||
canceled=False, |
|||
): Allowed( |
|||
plan_successor=False, |
|||
stop_plan_successor=True, |
|||
stop=True, |
|||
cancel=False, |
|||
uncancel=False, |
|||
), |
|||
Criteria( |
|||
when='AFTER', |
|||
has_date_end=True, |
|||
has_last_date_invoiced=None, |
|||
is_auto_renew=True, |
|||
has_successor=False, |
|||
predecessor_has_successor=None, |
|||
canceled=False, |
|||
): Allowed( |
|||
plan_successor=False, |
|||
stop_plan_successor=False, |
|||
stop=False, |
|||
cancel=False, |
|||
uncancel=False, |
|||
), |
|||
Criteria( |
|||
when='AFTER', |
|||
has_date_end=True, |
|||
has_last_date_invoiced=None, |
|||
is_auto_renew=False, |
|||
has_successor=True, |
|||
predecessor_has_successor=None, |
|||
canceled=False, |
|||
): Allowed( |
|||
plan_successor=False, |
|||
stop_plan_successor=False, |
|||
stop=False, |
|||
cancel=False, |
|||
uncancel=False, |
|||
), |
|||
Criteria( |
|||
when='AFTER', |
|||
has_date_end=True, |
|||
has_last_date_invoiced=None, |
|||
is_auto_renew=False, |
|||
has_successor=False, |
|||
predecessor_has_successor=None, |
|||
canceled=False, |
|||
): Allowed( |
|||
plan_successor=True, |
|||
stop_plan_successor=False, |
|||
stop=False, |
|||
cancel=False, |
|||
uncancel=False, |
|||
), |
|||
Criteria( |
|||
when=None, |
|||
has_date_end=None, |
|||
has_last_date_invoiced=None, |
|||
is_auto_renew=None, |
|||
has_successor=None, |
|||
predecessor_has_successor=False, |
|||
canceled=True, |
|||
): Allowed( |
|||
plan_successor=False, |
|||
stop_plan_successor=False, |
|||
stop=False, |
|||
cancel=False, |
|||
uncancel=True, |
|||
), |
|||
Criteria( |
|||
when=None, |
|||
has_date_end=None, |
|||
has_last_date_invoiced=None, |
|||
is_auto_renew=None, |
|||
has_successor=None, |
|||
predecessor_has_successor=True, |
|||
canceled=True, |
|||
): Allowed( |
|||
plan_successor=False, |
|||
stop_plan_successor=False, |
|||
stop=False, |
|||
cancel=False, |
|||
uncancel=False, |
|||
), |
|||
} |
|||
criteria_allowed_dict = {} |
|||
|
|||
for c in CRITERIA_ALLOWED_DICT: |
|||
_add(criteria_allowed_dict, c, CRITERIA_ALLOWED_DICT[c]) |
|||
|
|||
|
|||
def compute_when(date_start, date_end): |
|||
today = Date.today() |
|||
if today < date_start: |
|||
return 'BEFORE' |
|||
if date_end and today > date_end: |
|||
return 'AFTER' |
|||
return 'IN' |
|||
|
|||
|
|||
def compute_criteria( |
|||
date_start, |
|||
date_end, |
|||
has_last_date_invoiced, |
|||
is_auto_renew, |
|||
successor_contract_line_id, |
|||
predecessor_contract_line_id, |
|||
is_canceled, |
|||
): |
|||
return Criteria( |
|||
when=compute_when(date_start, date_end), |
|||
has_date_end=bool(date_end), |
|||
has_last_date_invoiced=bool(has_last_date_invoiced), |
|||
is_auto_renew=is_auto_renew, |
|||
has_successor=bool(successor_contract_line_id), |
|||
predecessor_has_successor=bool( |
|||
predecessor_contract_line_id.successor_contract_line_id |
|||
), |
|||
canceled=is_canceled, |
|||
) |
|||
|
|||
|
|||
def get_allowed( |
|||
date_start, |
|||
date_end, |
|||
has_last_date_invoiced, |
|||
is_auto_renew, |
|||
successor_contract_line_id, |
|||
predecessor_contract_line_id, |
|||
is_canceled, |
|||
): |
|||
criteria = compute_criteria( |
|||
date_start, |
|||
date_end, |
|||
has_last_date_invoiced, |
|||
is_auto_renew, |
|||
successor_contract_line_id, |
|||
predecessor_contract_line_id, |
|||
is_canceled, |
|||
) |
|||
if criteria in criteria_allowed_dict: |
|||
return criteria_allowed_dict[criteria] |
|||
return False |
Write
Preview
Loading…
Cancel
Save
Reference in new issue