Exemplo n.º 1
0
    def process_annotation(
        self,
        insight: ProductInsight,
        data: Optional[Dict] = None,
        auth: Optional[OFFAuthentication] = None,
    ) -> AnnotationResult:
        product = get_product(insight.barcode, ["quantity"])

        if product is None:
            return MISSING_PRODUCT_RESULT

        quantity: Optional[str] = product.get("quantity") or None

        if quantity is not None:
            return ALREADY_ANNOTATED_RESULT

        update_quantity(
            insight.barcode,
            insight.value,
            insight_id=insight.id,
            server_domain=insight.server_domain,
            auth=auth,
        )

        return UPDATED_ANNOTATION_RESULT
Exemplo n.º 2
0
    def update_product(self, insight: ProductInsight) -> AnnotationResult:
        product = get_product(insight.barcode, ['quantity'])

        if product is None:
            return MISSING_PRODUCT_RESULT

        quantity: Optional[str] = product.get('quantity') or None

        if quantity is not None:
            return ALREADY_ANNOTATED_RESULT

        weight = insight.data['text']
        update_quantity(insight.barcode, weight)

        return UPDATED_ANNOTATION_RESULT