Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

acquisition: add logging file to rollover cli #3801

Open
wants to merge 1 commit into
base: staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rero_ils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3482,7 +3482,7 @@ def _(x):
"console": {"class": "logging.StreamHandler", "formatter": "standard"},
"file": {
"class": "logging.handlers.RotatingFileHandler",
"filename": "logs/rollover_log",
"filename": "logs/rollover",
"backupCount": 10,
"formatter": "standard",
},
Expand Down
1 change: 1 addition & 0 deletions rero_ils/modules/acquisition/acq_order_lines/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ def status(self):
if self.order_date
else AcqOrderLineStatus.APPROVED
)

received_quantity = self.received_quantity
# not use the property to prevent an extra ES call
unreceived_quantity = self.quantity - received_quantity
Expand Down
7 changes: 6 additions & 1 deletion rero_ils/modules/acquisition/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def acquisition():
"--budget-start-date", "budget_start_date", help="The new budget start-date"
)
@click.option("--budget-end-date", "budget_end_date", help="The new budget end-date")
@click.option("--logging_file", "logging_file", help="Logging file name", default=None)
@with_appcontext
def rollover(
origin_budget_pid,
Expand All @@ -66,6 +67,7 @@ def rollover(
budget_name,
budget_start_date,
budget_end_date,
logging_file,
):
"""CLI to run rollover process between two acquisition budgets."""
# Check parameters
Expand All @@ -92,6 +94,9 @@ def rollover(

destination_budget = Budget.get_record_by_pid(dest_budget_pid)
rollover_runner = AcqRollover(
original_budget, destination_budget, is_interactive=interactive
original_budget=original_budget,
destination_budget=destination_budget,
is_interactive=interactive,
logging_file=logging_file,
)
rollover_runner.run()
13 changes: 12 additions & 1 deletion rero_ils/modules/acquisition/rollover.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import random
import string
from copy import deepcopy
from datetime import datetime

from elasticsearch_dsl import Q
from flask import current_app
Expand Down Expand Up @@ -117,6 +118,7 @@ def __init__(
original_budget,
destination_budget=None,
logging_config=None,
logging_file=None,
is_interactive=True,
propagate_errors=False,
**kwargs,
Expand All @@ -130,6 +132,8 @@ def __init__(
:param logging_config: (optional) a dictionary containing all necessary
configuration to log the rollover process result. If not specified
the configuration comes from `ROLLOVER_LOGGING_CONFIG` setting.
:param logging_file: (optional) Logging file name. If not specified
the configuration comes from `ROLLOVER_LOGGING_CONFIG` setting is used.
:param is_interactive: boolean to determine if user confirmation is
required. True by default.
:param propagate_errors: Boolean to determine if error will be
Expand All @@ -148,7 +152,14 @@ def __init__(
self.propagate_errors = propagate_errors

# Set special logging configuration for rollover process
default_config = current_app.config.get("ROLLOVER_LOGGING_CONFIG")
default_config = deepcopy(current_app.config.get("ROLLOVER_LOGGING_CONFIG"))
if logging_file:
default_config["handlers"]["file"]["filename"] = logging_file
else:
time_stamp = datetime.now().strftime("%Y%m%d_%H%M")
file_name = default_config["handlers"]["file"]["filename"]
file_name = f"{file_name}_{time_stamp}.log"
default_config["handlers"]["file"]["filename"] = file_name
logging.config.dictConfig(logging_config or default_config)
self.logger = logging.getLogger(__name__)
self.logger.info("ROLLOVER PROCESS ==================================")
Expand Down
2 changes: 2 additions & 0 deletions tests/api/acquisition/test_acquisition_rollover.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ def test_rollover_cli(client, acq_full_structure_a, org_martigny):
"2022-01-01",
"--budget-end-date",
"2022-12-31",
"--logging_file",
"logs/rollover_log",
],
)
assert result.exit_code == 0 # all works fine !
Expand Down
Loading