Skip to content

Commit

Permalink
New Proof.ready_for_price_tag_validation boolean field. With specific…
Browse files Browse the repository at this point in the history
… rule
  • Loading branch information
raphodn committed Dec 26, 2024
1 parent 6438f6a commit 40dbf92
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 0 deletions.
5 changes: 5 additions & 0 deletions open_prices/proofs/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
(PRICE_TAG_EXTRACTION_TYPE, PRICE_TAG_EXTRACTION_TYPE)
]

PROOF_READY_FOR_PRICE_TAG_VALIDATION_SOURCES = [
"/proofs/add/single",
"/proofs/add/multiple",
]


class PriceTagStatus(enum.IntEnum):
deleted = 0
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 5.1.4 on 2024-12-26 16:37

from django.db import migrations, models


def init_ready_for_price_tag_validation(apps, schema_editor):
Proof = apps.get_model("proofs", "Proof")
Proof.objects.filter(type="PRICE_TAG", source__contains="/proofs/add/").update(
ready_for_price_tag_validation=True
)


class Migration(migrations.Migration):
dependencies = [
("proofs", "0008_alter_proofprediction_type_pricetagprediction"),
]

operations = [
migrations.AddField(
model_name="proof",
name="ready_for_price_tag_validation",
field=models.BooleanField(default=False),
),
migrations.RunPython(init_ready_for_price_tag_validation),
]
14 changes: 14 additions & 0 deletions open_prices/proofs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ class Proof(models.Model):
null=True,
)

ready_for_price_tag_validation = models.BooleanField(default=False)

price_count = models.PositiveIntegerField(default=0, blank=True, null=True)

owner = models.CharField(blank=True, null=True)
Expand Down Expand Up @@ -230,9 +232,21 @@ def set_location(self):
)
self.location = location

def set_ready_for_price_tag_validation(self):
if (
self.type == proof_constants.TYPE_PRICE_TAG
and self.source
and any(
source in self.source
for source in proof_constants.PROOF_READY_FOR_PRICE_TAG_VALIDATION_SOURCES
)
):
self.ready_for_price_tag_validation = True

def save(self, *args, **kwargs):
self.full_clean()
self.set_location()
self.set_ready_for_price_tag_validation()
super().save(*args, **kwargs)

@property
Expand Down
7 changes: 7 additions & 0 deletions open_prices/proofs/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,13 @@ def test_proof_receipt_fields(self):
type=proof_constants.TYPE_PRICE_TAG,
)

def test_proof_ready_for_price_tag_validation_field(self):
proof = ProofFactory(type=proof_constants.TYPE_PRICE_TAG, source="/proofs/add/")
self.assertFalse(proof.ready_for_price_tag_validation)
proof.source = "/proofs/add/multiple"
proof.save()
self.assertTrue(proof.ready_for_price_tag_validation)


class ProofQuerySetTest(TestCase):
@classmethod
Expand Down

0 comments on commit 40dbf92

Please sign in to comment.