def _delete_commit(self, model_object) -> None: """ Commit model object delete """ db.session.delete(model_object) commit_with_error_handling(db) return None
def _post_commit(self, model_object) -> 'RPC response': """ Save the new model object """ db.session.add(model_object) commit_with_error_handling(db) return self.__serialize(model_object)
def _post_commit(self, item) -> 'RPC response': """ Save the new object """ db.session.add(item) commit_with_error_handling(db) return self._serializer(item).data
def _delete_commit(self, item) -> None: """ Commit item delete """ db.session.delete(item) commit_with_error_handling(db) return None
def _apply_quantity_changes(self, nested_model_objects: list, insufficient_quantity_error_message: str, quantity_field_of_object: str = 'quantity', multiplier_for_sign: int = 1): """ Pre-check and apply quantity changes """ insufficient_quantities = [] for nested_model_object in nested_model_objects: quantity = getattr(nested_model_object, quantity_field_of_object) if quantity is None: setattr(nested_model_object, quantity_field_of_object, 0.0) continue quantity_diff = multiplier_for_sign * quantity if nested_model_object.item.quantity + quantity_diff < 0: insufficient_quantities.append(nested_model_object) continue nested_model_object.item.quantity += quantity_diff if insufficient_quantities: db.session.rollback() abort(422, message='{}: {}'.format( insufficient_quantity_error_message, ', '.join([ '{name!r}: {current} - {decrease}'.format( name=model_item.item.name, current=model_item.item.quantity, decrease=-multiplier_for_sign * getattr(model_item, quantity_field_of_object)) for model_item in insufficient_quantities ]))) commit_with_error_handling(db)
def _put_commit(self, model_object) -> 'RPC response': """ Save change model object """ commit_with_error_handling(db) return self.__serialize(model_object)
def _put_commit(self, item) -> 'RPC response': """ Save change object """ commit_with_error_handling(db) return self._serializer(item).data