Skip to content

Commit

Permalink
Price model
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn committed Jul 22, 2024
1 parent a54e4ff commit 158ccde
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 0 deletions.
1 change: 1 addition & 0 deletions config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"open_prices.products",
"open_prices.locations",
"open_prices.proofs",
"open_prices.prices",
"open_prices.www",
]

Expand Down
Empty file added open_prices/prices/admin.py
Empty file.
9 changes: 9 additions & 0 deletions open_prices/prices/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"""For raw products (fruits, vegetables, etc.), the price is either
per unit or per kilogram. This enum is used to store this information.
"""

PRICE_PER_UNIT = "UNIT"
PRICE_PER_KILOGRAM = "KILOGRAM"

PRICE_PER_LIST = [PRICE_PER_UNIT, PRICE_PER_KILOGRAM]
PRICE_PER_CHOICES = [(key, key) for key in PRICE_PER_LIST]
73 changes: 73 additions & 0 deletions open_prices/prices/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
from django.db import models
from django.utils import timezone

from open_prices.common import constants
from open_prices.locations import constants as location_constants
from open_prices.prices import constants as price_constants


class Price(models.Model):
product_code = models.CharField(blank=True, null=True)
category_tag = models.CharField(blank=True, null=True)
labels_tags = models.JSONField(blank=True, null=True)
product_name = models.CharField(blank=True, null=True)
origins_tags = models.JSONField(blank=True, null=True)
product = models.ForeignKey(
"products.Product",
on_delete=models.SET_NULL,
blank=True,
null=True,
related_name="prices",
)

price = models.DecimalField(max_digits=10, decimal_places=2, blank=True, null=True)
price_is_discounted = models.BooleanField()
price_without_discount = models.DecimalField(
max_digits=10, decimal_places=2, blank=True, null=True
)
price_per = models.CharField(
max_length=10,
constants=price_constants.PRICE_PER_CHOICES,
blank=True,
null=True,
)
currency = models.CharField(
max_length=3, choices=constants.CURRENCY_CHOICES, blank=True, null=True
)

location_osm_id = models.BigIntegerField(blank=True, null=True)
location_osm_type = models.CharField(
max_length=10,
choices=location_constants.OSM_TYPE_CHOICES,
blank=True,
null=True,
)
location = models.ForeignKey(
"locations.Location",
on_delete=models.SET_NULL,
blank=True,
null=True,
related_name="prices",
)

date = models.DateField(blank=True, null=True)

proof = models.ForeignKey(
"proofs.Proof",
on_delete=models.SET_NULL,
blank=True,
null=True,
related_name="prices",
)

owner = models.CharField(blank=True, null=True)
source = models.CharField(blank=True, null=True)

created = models.DateTimeField(default=timezone.now)
updated = models.DateTimeField(auto_now=True)

class Meta:
managed = False
db_table = "prices"
verbose_name = "Price"
verbose_name_plural = "Prices"

0 comments on commit 158ccde

Please sign in to comment.