From 5a3b49c33bff5112c4994f88c5a076a015aaab11 Mon Sep 17 00:00:00 2001 From: sniedzielski <52816247+sniedzielski@users.noreply.github.com> Date: Wed, 13 Mar 2024 12:52:48 +0100 Subject: [PATCH 1/2] CM-775: changeg labels from fixed batch to fixed amount (#19) --- calcrule_social_protection/config.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/calcrule_social_protection/config.py b/calcrule_social_protection/config.py index e6b2c5b..f423342 100644 --- a/calcrule_social_protection/config.py +++ b/calcrule_social_protection/config.py @@ -6,8 +6,8 @@ "type": "number", "name": "fixed_batch", "label": { - "en": "Fixed batch", - "fr": "Fixed batch" + "en": "Fixed amount", + "fr": "Lot fixe" }, "rights": { "read": "157101", @@ -24,7 +24,7 @@ "name": "limit_per_single_transaction", "label": { "en": "Limit Per Single Transaction", - "fr": "Limit Per Single Transaction" + "fr": "Limite par transaction unique" }, "rights": { "read": "157101", From d3a1c2580185bf719a60a8477dbd7813028d21e4 Mon Sep 17 00:00:00 2001 From: Jan Date: Wed, 20 Mar 2024 14:52:12 +0100 Subject: [PATCH 2/2] CM-742: payment cycle adjustments (#20) Co-authored-by: Jan --- calcrule_social_protection/calculation_rule.py | 2 +- .../converters/builder/builder_to_benefit.py | 9 ++++----- .../converters/builder/builder_to_bill.py | 11 +++++------ .../strategies/benefit_package_base_strategy.py | 13 +++++++------ 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/calcrule_social_protection/calculation_rule.py b/calcrule_social_protection/calculation_rule.py index 24a75e6..5900809 100644 --- a/calcrule_social_protection/calculation_rule.py +++ b/calcrule_social_protection/calculation_rule.py @@ -56,7 +56,7 @@ def calculate_if_active_for_object(cls, payment_plan, **kwargs): return cls.calculate(payment_plan, **kwargs) @classmethod - def active_for_object(cls, payment_plan): + def active_for_object(cls, payment_plan, **kwargs): return cls.check_calculation(payment_plan) @classmethod diff --git a/calcrule_social_protection/converters/builder/builder_to_benefit.py b/calcrule_social_protection/converters/builder/builder_to_benefit.py index 30bdb58..283ac30 100644 --- a/calcrule_social_protection/converters/builder/builder_to_benefit.py +++ b/calcrule_social_protection/converters/builder/builder_to_benefit.py @@ -7,12 +7,12 @@ class BuilderToBenefitConverter: TYPE = None @classmethod - def to_benefit_obj(cls, entity, amount, payment_plan): + def to_benefit_obj(cls, entity, amount, payment_plan, payment_cycle): benefit = {} cls._build_individual(benefit, entity) cls._build_code(benefit) cls._build_amount(benefit, amount) - cls._build_date_dates(benefit, payment_plan) + cls._build_date_dates(benefit, payment_plan, payment_cycle) cls._build_type(benefit) cls._build_status(benefit) return benefit @@ -36,9 +36,8 @@ def _build_amount(cls, benefit, amount): benefit["amount"] = amount @classmethod - def _build_date_dates(cls, benefit, payment_plan): - from core import datetime, datetimedelta - benefit["date_due"] = f"{datetime.date.today() + datetimedelta(days=30)}" + def _build_date_dates(cls, benefit, payment_plan, payment_cycle): + benefit["date_due"] = f"{payment_cycle.end_date}" benefit["date_valid_from"] = f"{ payment_plan.benefit_plan.date_valid_from}" benefit["date_valid_to"] = f"{payment_plan.benefit_plan.date_valid_to}" diff --git a/calcrule_social_protection/converters/builder/builder_to_bill.py b/calcrule_social_protection/converters/builder/builder_to_bill.py index 2439e0a..5a531dd 100644 --- a/calcrule_social_protection/converters/builder/builder_to_bill.py +++ b/calcrule_social_protection/converters/builder/builder_to_bill.py @@ -9,14 +9,14 @@ class BuilderToBillConverter: TYPE = None @classmethod - def to_bill_obj(cls, payment_plan, entity, amount, end_date): + def to_bill_obj(cls, payment_plan, entity, amount, end_date, payment_cycle): bill = {} cls._build_subject(bill, entity) cls._build_thirdparty(bill, payment_plan) cls._build_code(bill) cls._build_price(bill, amount) cls._build_terms(bill, payment_plan, entity, end_date) - cls._build_date_dates(bill, payment_plan) + cls._build_date_dates(bill, payment_plan, payment_cycle) cls._build_currency(bill) cls._build_status(bill) return bill @@ -46,10 +46,9 @@ def _build_price(cls, bill, amount): bill["amount_net"] = amount @classmethod - def _build_date_dates(cls, bill, payment_plan): - from core import datetime, datetimedelta - bill["date_due"] = f"{datetime.date.today() + datetimedelta(days=30)}" - bill["date_bill"] = f"{datetime.date.today()}" + def _build_date_dates(cls, bill, payment_plan, payment_cycle): + bill["date_due"] = f"{payment_cycle.end_date}" + bill["date_bill"] = f"{payment_cycle.start_date}" bill["date_valid_from"] = f"{ payment_plan.benefit_plan.date_valid_from}" bill["date_valid_to"] = f"{payment_plan.benefit_plan.date_valid_to}" diff --git a/calcrule_social_protection/strategies/benefit_package_base_strategy.py b/calcrule_social_protection/strategies/benefit_package_base_strategy.py index f22cbed..d1d19e9 100644 --- a/calcrule_social_protection/strategies/benefit_package_base_strategy.py +++ b/calcrule_social_protection/strategies/benefit_package_base_strategy.py @@ -94,12 +94,13 @@ def convert(cls, payment_plan, **kwargs): converter = kwargs.get('converter') converter_item = kwargs.get('converter_item') converter_benefit = kwargs.get('converter_benefit') + payment_cycle = kwargs.get('payment_cycle') convert_results = cls._convert_entity_to_bill( - converter, converter_item, payment_plan, entity, amount, end_date + converter, converter_item, payment_plan, entity, amount, end_date, payment_cycle ) convert_results['user'] = kwargs.get('user', None) convert_results_benefit = cls._convert_entity_to_benefit( - converter_benefit, payment_plan, entity, amount + converter_benefit, payment_plan, entity, amount, payment_cycle ) user = convert_results['user'] if not cls.is_exceed_limit: @@ -139,10 +140,10 @@ def create_and_save_business_entities( @classmethod def _convert_entity_to_bill( - cls, converter, converter_item, payment_plan, entity, amount, end_date + cls, converter, converter_item, payment_plan, entity, amount, end_date, payment_cycle ): bill = converter.to_bill_obj( - payment_plan, entity, amount, end_date + payment_plan, entity, amount, end_date, payment_cycle ) bill_line_items = [ converter_item.to_bill_item_obj(payment_plan, entity, amount) @@ -155,9 +156,9 @@ def _convert_entity_to_bill( @classmethod def _convert_entity_to_benefit( - cls, converter_benefit, payment_plan, entity, amount + cls, converter_benefit, payment_plan, entity, amount, payment_cycle ): - benefit = converter_benefit.to_benefit_obj(entity, amount, payment_plan) + benefit = converter_benefit.to_benefit_obj(entity, amount, payment_plan, payment_cycle) return { 'benefit_data': benefit, 'type_conversion': 'beneficiary - benefit'