diff --git a/jobs/payment-jobs/requirements.txt b/jobs/payment-jobs/requirements.txt index 0ae8073dc..5a3c3157b 100644 --- a/jobs/payment-jobs/requirements.txt +++ b/jobs/payment-jobs/requirements.txt @@ -1,5 +1,5 @@ -e git+https://github.com/bcgov/sbc-common-components.git@a643801c373063dfa44a2f7213d9122d3ad03851#egg=sbc_common_components&subdirectory=python --e git+https://github.com/bcgov/sbc-pay.git@e952ae4da28387fce8f7e706d47be56ff6858135#egg=pay_api&subdirectory=pay-api +-e git+https://github.com/seeker25/sbc-pay.git@aafc77ad4b1e0681f44580e14a4f559936c5d96e#egg=pay_api&subdirectory=pay-api Flask-Caching==2.0.2 Flask-Migrate==2.7.0 Flask-Moment==1.0.5 diff --git a/jobs/payment-jobs/tasks/ap_task.py b/jobs/payment-jobs/tasks/ap_task.py index 92ba25ca0..ed4f5e278 100644 --- a/jobs/payment-jobs/tasks/ap_task.py +++ b/jobs/payment-jobs/tasks/ap_task.py @@ -90,8 +90,7 @@ def _create_routing_slip_refund_file(cls): # pylint:disable=too-many-locals, to current_app.logger.info(f'Creating refund for {rs.number}, Amount {rs.refund_amount}.') refund: RefundModel = RefundModel.find_by_routing_slip_id(rs.id) ap_content = f'{ap_content}{cls.get_ap_header(rs.refund_amount, rs.number, datetime.now())}' - ap_line = APLine(total=rs.refund_amount, invoice_number=rs.number, line_number=1, - invoice_date=datetime.now()) + ap_line = APLine(total=rs.refund_amount, invoice_number=rs.number, line_number=1) ap_content = f'{ap_content}{cls.get_ap_invoice_line(ap_line)}' ap_content = f'{ap_content}{cls.get_ap_address(refund.details, rs.number)}' total_line_count += 3 diff --git a/jobs/payment-jobs/tasks/common/cgi_ap.py b/jobs/payment-jobs/tasks/common/cgi_ap.py index 6551d2d2a..8f7311c52 100644 --- a/jobs/payment-jobs/tasks/common/cgi_ap.py +++ b/jobs/payment-jobs/tasks/common/cgi_ap.py @@ -48,13 +48,14 @@ def get_ap_header(cls, total, invoice_number, invoice_date): invoice_type = 'ST' remit_code = f"{current_app.config.get('CGI_AP_REMITTANCE_CODE'):<4}" currency = 'CAD' - invoice_date = cls._get_invoice_date(invoice_date) + effective_date = cls._get_date(datetime.now()) + invoice_date = cls._get_date(invoice_date) oracle_invoice_batch_name = cls._get_oracle_invoice_batch_name(invoice_number) disbursement_method = 'CHQ' if cls.ap_type == EjvFileType.REFUND else 'EFT' term = f'{cls.EMPTY:<50}' if cls.ap_type == EjvFileType.REFUND else f'Immediate{cls.EMPTY:<41}' ap_header = f'{cls._feeder_number()}APIH{cls.DELIMITER}{cls._supplier_number()}{cls._supplier_location()}' \ f'{invoice_number:<50}{cls._po_number()}{invoice_type}{invoice_date}GEN {disbursement_method} N' \ - f'{remit_code}{cls.format_amount(total)}{currency}{invoice_date}' \ + f'{remit_code}{cls.format_amount(total)}{currency}{effective_date}' \ f'{term}{cls.EMPTY:<60}{cls.EMPTY:<8}{cls.EMPTY:<8}' \ f'{oracle_invoice_batch_name:<30}{cls.EMPTY:<9}Y{cls.EMPTY:<110}{cls.DELIMITER}{os.linesep}' return ap_header @@ -65,12 +66,12 @@ def get_ap_invoice_line(cls, ap_line: APLine): commit_line_number = f'{cls.EMPTY:<4}' # Pad Zeros to four digits. EG. 0001 line_number = f'{ap_line.line_number:04}' - invoice_date = cls._get_invoice_date(ap_line.invoice_date) + effective_date = cls._get_date(datetime.now()) line_code = cls._get_line_code(ap_line) ap_line = \ f'{cls._feeder_number()}APIL{cls.DELIMITER}{cls._supplier_number()}{cls._supplier_location()}' \ f'{ap_line.invoice_number:<50}{line_number}{commit_line_number}{cls.format_amount(ap_line.total)}' \ - f'{line_code}{cls._distribution(ap_line.distribution)}{cls.EMPTY:<55}{invoice_date}{cls.EMPTY:<10}' \ + f'{line_code}{cls._distribution(ap_line.distribution)}{cls.EMPTY:<55}{effective_date}{cls.EMPTY:<10}' \ f'{cls.EMPTY:<15}{cls.EMPTY:<15}{cls.EMPTY:<15}{cls.EMPTY:<15}{cls.EMPTY:<20}{cls.EMPTY:<4}' \ f'{cls.EMPTY:<30}{cls.EMPTY:<25}{cls.EMPTY:<30}{cls.EMPTY:<8}{cls.EMPTY:<1}{cls._dist_vendor()}' \ f'{cls.EMPTY:<110}{cls.DELIMITER}{os.linesep}' @@ -151,9 +152,9 @@ def _po_number(cls): return f'{cls.EMPTY:<20}' @classmethod - def _get_invoice_date(cls, invoice_date): - """Return invoice date.""" - return invoice_date.strftime('%Y%m%d') + def _get_date(cls, date): + """Return date.""" + return date.strftime('%Y%m%d') @classmethod def _distribution(cls, distribution_code: str = None): diff --git a/jobs/payment-jobs/tasks/common/dataclasses.py b/jobs/payment-jobs/tasks/common/dataclasses.py index 3804eecf8..b5bdda484 100644 --- a/jobs/payment-jobs/tasks/common/dataclasses.py +++ b/jobs/payment-jobs/tasks/common/dataclasses.py @@ -13,7 +13,6 @@ # limitations under the License. """Common dataclasses for tasks, dataclasses allow for cleaner code with autocompletion in vscode.""" from dataclasses import dataclass -from datetime import datetime from typing import List, Optional from dataclass_wizard import JSONWizard from pay_api.models import Invoice as InvoiceModel @@ -45,7 +44,6 @@ class APLine: total: float invoice_number: str line_number: int - invoice_date: Optional[datetime] = None is_reversal: Optional[bool] = None distribution: Optional[str] = None @@ -54,7 +52,7 @@ def from_invoice_and_line_item(cls, invoice: InvoiceModel, line_item: LineItemMo distribution: str): """Build dataclass object from invoice.""" # Note the invoice_date should be the payment_date in the future. - return cls(total=line_item.total, invoice_number=invoice.id, invoice_date=invoice.created_on, + return cls(total=line_item.total, invoice_number=invoice.id, line_number=line_number, is_reversal=invoice.invoice_status_code in [InvoiceStatus.REFUNDED.value, InvoiceStatus.REFUND_REQUESTED.value], diff --git a/jobs/payment-jobs/tasks/statement_task.py b/jobs/payment-jobs/tasks/statement_task.py index 9e117372d..aa1605204 100644 --- a/jobs/payment-jobs/tasks/statement_task.py +++ b/jobs/payment-jobs/tasks/statement_task.py @@ -13,7 +13,7 @@ # limitations under the License. """Service to manage PAYBC services.""" -from datetime import datetime +from datetime import datetime, timedelta from dateutil.parser import parse from flask import current_app @@ -41,11 +41,10 @@ def generate_statements(cls, date_override=None): 1. Get all payment accounts and it's active statement settings. """ target_time = get_local_time(datetime.now()) if date_override is None \ - else datetime.strptime(date_override, '%Y-%m-%d') + else datetime.strptime(date_override, '%Y-%m-%d') + timedelta(days=1) cls.skip_notify = date_override is not None if date_override: - current_app.logger.debug(f'Generating statements for: {date_override} using date override,' - ' this generates for the previous day/week/month.') + current_app.logger.debug(f'Generating statements for: {date_override} using date override.') # If today is sunday - generate all weekly statements for pervious week # If today is month beginning - generate all monthly statements for previous month # For every day generate all daily statements for previous day @@ -98,7 +97,7 @@ def _generate_monthly_statements(cls, target_time: datetime): statement_settings = StatementSettingsModel.find_accounts_settings_by_frequency(previous_day, StatementFrequency.MONTHLY) current_app.logger.debug(f'Found {len(statement_settings)} accounts to generate MONTHLY statements') - last_month, last_month_year = get_previous_month_and_year() + last_month, last_month_year = get_previous_month_and_year(target_time) search_filter = { 'monthFilter': { 'month': last_month, diff --git a/pay-api/src/pay_api/utils/util.py b/pay-api/src/pay_api/utils/util.py index d1bad8259..8ed4c4739 100755 --- a/pay-api/src/pay_api/utils/util.py +++ b/pay-api/src/pay_api/utils/util.py @@ -94,9 +94,9 @@ def get_first_and_last_dates_of_month(month: int, year: int): return start_date, end_date -def get_previous_month_and_year(): +def get_previous_month_and_year(target_date=datetime.now()): """Return last month and year.""" - last_month = datetime.now().replace(day=1) - timedelta(days=1) + last_month = target_date.replace(day=1) - timedelta(days=1) return last_month.month, last_month.year