def complete_filing(business, filing, draft) -> Tuple[dict, int]: """Complete the filing, either to COLIN or by getting an invoice. Used for encapsulation of common functionality used in Filing and Business endpoints. """ # if filing is from COLIN, place on queue and return if jwt.validate_roles([COLIN_SVC_ROLE]): err_msg, err_code = ListFilingResource._process_colin_filing( business.identifier, filing, business) return jsonify(err_msg), err_code # create invoice if not draft: filing_types = ListFilingResource._get_filing_types( filing.filing_json) err_msg, err_code = ListFilingResource._create_invoice( business, filing, filing_types, jwt) if err_code: reply = filing.json reply['errors'] = [ err_msg, ] return jsonify(reply), err_code ListFilingResource._set_effective_date(business, filing) return None, None
def patch(filing_id): """Patch the colin_event_id for a filing.""" # check authorization if not jwt.validate_roles([COLIN_SVC_ROLE]): return jsonify({ 'message': 'You are not authorized to update the colin id' }), HTTPStatus.UNAUTHORIZED json_input = request.get_json() if not json_input: return None, None, {'message': f'No filing json data in body of patch for {filing_id}.'}, \ HTTPStatus.BAD_REQUEST colin_id = json_input['colinId'] filing = Filing.find_by_id(filing_id) if not filing: return { 'message': f'{filing_id} no filings found' }, HTTPStatus.NOT_FOUND try: filing.colin_event_id = colin_id filing.save() except BusinessException as err: return None, None, {'message': err.error}, err.status_code return jsonify(filing.json), HTTPStatus.ACCEPTED
def patch(filing_id): """Patch the colin_event_id for a filing.""" # check authorization try: if not jwt.validate_roles([COLIN_SVC_ROLE]): return jsonify({'message': 'You are not authorized to update the colin id'}), HTTPStatus.UNAUTHORIZED json_input = request.get_json() if not json_input: return None, None, {'message': f'No filing json data in body of patch for {filing_id}.'}, \ HTTPStatus.BAD_REQUEST colin_ids = json_input['colinIds'] filing = Filing.find_by_id(filing_id) if not filing: return {'message': f'{filing_id} no filings found'}, HTTPStatus.NOT_FOUND for colin_id in colin_ids: try: colin_event_id_obj = ColinEventId() colin_event_id_obj.colin_event_id = colin_id filing.colin_event_ids.append(colin_event_id_obj) filing.save() except BusinessException as err: current_app.logger.Error(f'Error adding colin event id {colin_id} to filing with id {filing_id}') return None, None, {'message': err.error}, err.status_code return jsonify(filing.json), HTTPStatus.ACCEPTED except Exception as err: current_app.logger.Error(f'Error patching colin event id for filing with id {filing_id}') raise err
def put(identifier, filing_id): # pylint: disable=too-many-return-statements """Modify an incomplete filing for the business.""" # basic checks err_msg, err_code = ListFilingResource._put_basic_checks(identifier, filing_id, request) if err_msg: return jsonify({'errors': [err_msg, ]}), err_code json_input = request.get_json() # check authorization if not authorized(identifier, jwt, action=['edit']): return jsonify({'message': f'You are not authorized to submit a filing for {identifier}.'}), \ HTTPStatus.UNAUTHORIZED draft = (request.args.get('draft', None).lower() == 'true') \ if request.args.get('draft', None) else False only_validate = (request.args.get('only_validate', None).lower() == 'true') \ if request.args.get('only_validate', None) else False # validate filing if not draft: business = Business.find_by_identifier(identifier) err = validate(business, json_input) # err_msg, err_code = ListFilingResource._validate_filing_json(request) if err or only_validate: if err: json_input['errors'] = err.msg return jsonify(json_input), err.code return jsonify(json_input), HTTPStatus.OK # save filing, if it's draft only then bail user = User.get_or_create_user_by_jwt(g.jwt_oidc_token_info) business, filing, err_msg, err_code = ListFilingResource._save_filing(request, identifier, user, filing_id) if err_msg or draft: reply = filing.json if filing else json_input reply['errors'] = [err_msg, ] return jsonify(reply), err_code or \ (HTTPStatus.CREATED if (request.method == 'POST') else HTTPStatus.ACCEPTED) # if filing is from COLIN, place on queue and return if jwt.validate_roles([COLIN_SVC_ROLE]): err_msg, err_code = ListFilingResource._process_colin_filing(identifier, json_input) return jsonify(err_msg), err_code # create invoice ?? if not draft: filing_types = ListFilingResource._get_filing_types(filing.filing_json) err_msg, err_code = ListFilingResource._create_invoice(business, filing, filing_types, jwt) if err_code: reply = filing.json reply['errors'] = [err_msg, ] return jsonify(reply), err_code # all done return jsonify(filing.json),\ (HTTPStatus.CREATED if (request.method == 'POST') else HTTPStatus.ACCEPTED)
def get(): """Return all identifiers with no tax_id set that are supposed to have a tax_id. Excludes COOPS because they do not ge a tax id/business number. """ if not jwt.validate_roles([COLIN_SVC_ROLE]): return jsonify({ 'message': 'You are not authorized to update the colin id' }), HTTPStatus.UNAUTHORIZED identifiers = [] bussinesses_no_taxid = Business.get_all_by_no_tax_id() for business in bussinesses_no_taxid: identifiers.append(business.identifier) return jsonify({'identifiers': identifiers}), HTTPStatus.OK
def post(colin_id): """Add a row to the colin_last_update table.""" try: # check authorization if not jwt.validate_roles([COLIN_SVC_ROLE]): return jsonify({'message': 'You are not authorized to update this table'}), HTTPStatus.UNAUTHORIZED db.session.execute( f""" insert into colin_last_update (last_update, last_event_id) values (current_timestamp, {colin_id}) """ ) db.session.commit() return ColinLastUpdate.get() except Exception as err: # pylint: disable=broad-except current_app.logger.error(f'Error updating colin_last_update table in legal db: {err}') return {f'message: failed to update colin_last_update.', 500}
def post(): """Set tax ids for businesses for given identifiers.""" if not jwt.validate_roles([COLIN_SVC_ROLE]): return jsonify({ 'message': 'You are not authorized to update the colin id' }), HTTPStatus.UNAUTHORIZED json_input = request.get_json() if not json_input: return ({ 'message': 'No identifiers in body of post.' }, HTTPStatus.BAD_REQUEST) for identifier in json_input.keys(): # json input is a dict -> identifier: tax id business = Business.find_by_identifier(identifier) business.tax_id = json_input[identifier] business.save() return jsonify({'message': 'Successfully updated tax ids.'}), HTTPStatus.CREATED