From a1037a54e8e7e8f9a0b43cc068b4b57a3f1e4fa2 Mon Sep 17 00:00:00 2001 From: Russell Ballestrini Date: Sat, 8 Jun 2024 11:45:39 -0400 Subject: [PATCH] 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 --- make_post_sell/models/shop_location.py | 44 +++++++++++++++++- ...bd6d96915_shop_location_rates_and_hours.py | 46 +++++++++++++++++++ 2 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 make_post_sell/scripts/alembic/versions/ddfbd6d96915_shop_location_rates_and_hours.py diff --git a/make_post_sell/models/shop_location.py b/make_post_sell/models/shop_location.py index ecc1b64..528a49b 100644 --- a/make_post_sell/models/shop_location.py +++ b/make_post_sell/models/shop_location.py @@ -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) diff --git a/make_post_sell/scripts/alembic/versions/ddfbd6d96915_shop_location_rates_and_hours.py b/make_post_sell/scripts/alembic/versions/ddfbd6d96915_shop_location_rates_and_hours.py new file mode 100644 index 0000000..d7627d7 --- /dev/null +++ b/make_post_sell/scripts/alembic/versions/ddfbd6d96915_shop_location_rates_and_hours.py @@ -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 ###