"""Logic for updating payment_group_payment_account action state.""" from abacus_common_logic.connectors.database import db from owsresponse import response from abacus_state.constants.error import ERROR_RECORD_DOES_NOT_EXIST from abacus_state.exceptions import OwsAbacusStateApiException from abacus_state.models.abacus_state import AbacusState from abacus_state.schemas.abacus_state import AbacusStateDetailSchema def bulk_update_payment_group_payment_account_states(parent_table_name, params): """Update payment_group_payment_account's action_status method by parent_table_name and parent_table_id.""" updated_account_states = list() for param in params: payment_group_account_params = param parent_table_id = payment_group_account_params.get('parent_table_id') payment_group_payment_account = AbacusState.get_action_status_list( parent_table_name, parent_table_id ) if not payment_group_payment_account: db.session.rollback() raise OwsAbacusStateApiException( ERROR_RECORD_DOES_NOT_EXIST.format( parent_table_id=parent_table_id, parent_table_name=parent_table_name ) ) payment_group_payment_account[0].update_attributes( **payment_group_account_params ) updated_account_states.append(payment_group_payment_account[0]) if updated_account_states: AbacusState.commit_changes() return response.Response( message=AbacusStateDetailSchema(many=True).dump(updated_account_states), status=200, ) def update_payment_group_payment_account_state(abacus_state, **params): """Update payment_group_payment_account state.""" abacus_state.update_attributes(**params) AbacusState.commit_changes() return response.Response( message=AbacusStateDetailSchema().dump(abacus_state), status=200 )