more fields for shop_location

modified:   make_post_sell/models/shop_location.py
	new file:   make_post_sell/scripts/alembic/versions/ddfbd6d96915_shop_location_rates_and_hours.py
This commit is contained in:
Russell Ballestrini 2024-06-08 11:45:39 -04:00
parent 47be09817f
commit a1037a54e8
2 changed files with 88 additions and 2 deletions

View file

@ -1,7 +1,8 @@
import uuid
from sqlalchemy import Column, Unicode, BigInteger
from sqlalchemy import Column, Unicode, BigInteger, Boolean, Integer
from .meta import Base, RBase, UUIDType, now_timestamp, foreign_key
from sqlalchemy.orm import relationship
from sqlalchemy.orm import relationship, backref
from ..lib.currency import cents_to_dollars, dollars_to_cents
class ShopLocation(RBase, Base):
"""This class represents a physical location of a shop."""
@ -16,6 +17,21 @@ class ShopLocation(RBase, Base):
postal_code = Column(Unicode(16), nullable=False)
created_timestamp = Column(BigInteger, nullable=False)
# Delivery options
local_pickup = Column(Boolean, default=False, nullable=False)
local_delivery = Column(Boolean, default=False, nullable=False)
local_shipping = Column(Boolean, default=False, nullable=False)
international_shipping = Column(Boolean, default=False, nullable=False)
# Delivery rates in cents
local_delivery_rate_in_cents = Column(BigInteger, nullable=True)
local_shipping_rate_in_cents = Column(BigInteger, nullable=True)
international_shipping_rate_in_cents = Column(BigInteger, nullable=True)
# Operating hours
days_open = Column(Unicode(64), nullable=True) # e.g., "Mon-Fri"
hours_open = Column(Unicode(64), nullable=True) # e.g., "9am-5pm"
shop = relationship("Shop", uselist=False)
def __init__(self, shop, name, address, city, state, country, postal_code):
@ -28,3 +44,27 @@ class ShopLocation(RBase, Base):
self.country = country
self.postal_code = postal_code
self.created_timestamp = now_timestamp()
@property
def local_delivery_rate(self):
return cents_to_dollars(self.local_delivery_rate_in_cents) if self.local_delivery_rate_in_cents else None
@local_delivery_rate.setter
def local_delivery_rate(self, value):
self.local_delivery_rate_in_cents = dollars_to_cents(value)
@property
def local_shipping_rate(self):
return cents_to_dollars(self.local_shipping_rate_in_cents) if self.local_shipping_rate_in_cents else None
@local_shipping_rate.setter
def local_shipping_rate(self, value):
self.local_shipping_rate_in_cents = dollars_to_cents(value)
@property
def international_shipping_rate(self):
return cents_to_dollars(self.international_shipping_rate_in_cents) if self.international_shipping_rate_in_cents else None
@international_shipping_rate.setter
def international_shipping_rate(self, value):
self.international_shipping_rate_in_cents = dollars_to_cents(value)

View file

@ -0,0 +1,46 @@
"""shop_location rates and hours
Revision ID: ddfbd6d96915
Revises: cc6211ec360e
Create Date: 2024-06-08 11:38:38.812584
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'ddfbd6d96915'
down_revision = 'cc6211ec360e'
branch_labels = None
depends_on = None
from make_post_sell.models.meta import UUIDType
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('mps_shop_location', sa.Column('local_pickup', sa.Boolean(), nullable=False, server_default=sa.false()))
op.add_column('mps_shop_location', sa.Column('local_delivery', sa.Boolean(), nullable=False, server_default=sa.false()))
op.add_column('mps_shop_location', sa.Column('local_shipping', sa.Boolean(), nullable=False, server_default=sa.false()))
op.add_column('mps_shop_location', sa.Column('international_shipping', sa.Boolean(), nullable=False, server_default=sa.false()))
op.add_column('mps_shop_location', sa.Column('local_delivery_rate_in_cents', sa.BigInteger(), nullable=True))
op.add_column('mps_shop_location', sa.Column('local_shipping_rate_in_cents', sa.BigInteger(), nullable=True))
op.add_column('mps_shop_location', sa.Column('international_shipping_rate_in_cents', sa.BigInteger(), nullable=True))
op.add_column('mps_shop_location', sa.Column('days_open', sa.Unicode(length=64), nullable=True))
op.add_column('mps_shop_location', sa.Column('hours_open', sa.Unicode(length=64), nullable=True))
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('mps_shop_location', 'hours_open')
op.drop_column('mps_shop_location', 'days_open')
op.drop_column('mps_shop_location', 'international_shipping_rate_in_cents')
op.drop_column('mps_shop_location', 'local_shipping_rate_in_cents')
op.drop_column('mps_shop_location', 'local_delivery_rate_in_cents')
op.drop_column('mps_shop_location', 'international_shipping')
op.drop_column('mps_shop_location', 'local_shipping')
op.drop_column('mps_shop_location', 'local_delivery')
op.drop_column('mps_shop_location', 'local_pickup')
# ### end Alembic commands ###