Merge branch 'black' into 'master'

black

See merge request engineering/make-post-sell/make_post_sell!12
This commit is contained in:
Russell Ballestrini 2024-06-20 19:50:07 +00:00
commit 8cc3aff705
9 changed files with 42 additions and 24 deletions

View file

@ -1,5 +1,6 @@
def dollars_to_cents(dollars):
return int(float(dollars) * 100)
def cents_to_dollars(cents):
return int(cents) / 100.0

View file

@ -4,7 +4,7 @@ from sqlalchemy import Column, BigInteger, Boolean, Integer, UnicodeText, Unicod
from .meta import Base, RBase, UUIDType, foreign_key, now_timestamp, get_object_by_id
from sqlalchemy.orm import relationship, backref
from sqlalchemy.orm import relationship
from .coupon_redemption import CouponRedemption
@ -225,7 +225,11 @@ class Invoice(RBase, Base):
def human_created_timestamp(self):
"""Return the created timestamp in a human-readable format."""
from datetime import datetime
return datetime.fromtimestamp(self.created_timestamp / 1000).strftime('%Y-%m-%d %H:%M:%S')
return datetime.fromtimestamp(self.created_timestamp / 1000).strftime(
"%Y-%m-%d %H:%M:%S"
)
def get_invoice_by_id(dbsession, invoice_id):
"""Try to get Invoice object by id or return None."""

View file

@ -1,5 +1,3 @@
import uuid
from sqlalchemy import Column, Unicode
from .meta import Base, RBase, UUIDType
@ -7,5 +5,6 @@ from .meta import Base, RBase, UUIDType
class Market(RBase, Base):
"""This class represents a Market place."""
id = Column(UUIDType, primary_key=True, index=True)
name = Column(Unicode(64), unique=True, nullable=False)

View file

@ -4,6 +4,7 @@ from .meta import Base, RBase, UUIDType, now_timestamp, foreign_key, get_object_
from sqlalchemy.orm import relationship
from ..lib.currency import cents_to_dollars, dollars_to_cents
class ShopLocation(RBase, Base):
"""This class represents a physical location of a shop."""
@ -47,7 +48,11 @@ class ShopLocation(RBase, Base):
@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
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):
@ -55,7 +60,11 @@ class ShopLocation(RBase, Base):
@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
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):
@ -63,7 +72,11 @@ class ShopLocation(RBase, Base):
@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
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):

View file

@ -40,16 +40,17 @@ class StripeUserShop(RBase, Base):
@property
def stripe_customer_default_source(self):
if self.stripe_customer:
if self.stripe_customer.default_source:
return self.stripe_customer.sources.retrieve(
self.stripe_customer.default_source
)
if self.stripe_customer and self.stripe_customer.default_source:
return self.stripe_customer.sources.retrieve(
self.stripe_customer.default_source
)
return None
@property
def stripe_cards(self):
return self.shop.stripe.Customer.list_payment_methods(self.stripe_customer, type="card")["data"]
return self.shop.stripe.Customer.list_payment_methods(
self.stripe_customer, type="card"
)["data"]
@property
def stripe_card_ids(self):
@ -75,6 +76,4 @@ def get_all_stripe_customer_objects(dbsession):
Return all Stripe customer objects.
created timestamp (newest first).
"""
return [
i.stripe_customer for i in dbsession.query(StripeUserShop).all()
]
return [i.stripe_customer for i in dbsession.query(StripeUserShop).all()]

View file

@ -12,13 +12,11 @@ class UserAddress(RBase, Base):
id = Column(UUIDType, primary_key=True, index=True)
user_id = Column(UUIDType, foreign_key("User", "id"), nullable=True)
#shop_id = Column(UUIDType, foreign_key("Shop", "id"), nullable=True)
data = Column(UnicodeText)
created_timestamp = Column(BigInteger, nullable=False)
user = relationship(argument="User", uselist=False, lazy="joined")
#shop = relationship(argument="Shop", uselist=False, lazy="joined")
def __init__(self, data):
self.created_timestamp = now_timestamp()

View file

@ -1,6 +1,6 @@
import uuid
from sqlalchemy import Column, Boolean, BigInteger
from sqlalchemy import Column, BigInteger
from .meta import Base, RBase, UUIDType, foreign_key, now_timestamp
@ -19,7 +19,8 @@ class UserProduct(RBase, Base):
created_timestamp = Column(BigInteger, nullable=False)
user = relationship(
argument="User", backref=backref("user_products", cascade="all, delete-orphan"),
argument="User",
backref=backref("user_products", cascade="all, delete-orphan"),
)
product = relationship(

View file

@ -8,10 +8,11 @@ from sqlalchemy.orm import relationship, backref
role_id_to_name = {
0: "owner", # root.
1: "editor", # virtual assistant.
2: "member", # viewer.
1: "editor", # virtual assistant.
2: "member", # viewer.
}
class UserShop(RBase, Base):
"""
Many shops to many users.

View file

@ -7,6 +7,7 @@ from . import (
get_referer_or_home,
)
@view_config(route_name="view_invoice", renderer="invoice.j2")
@user_required()
def view_invoice(request):
@ -19,11 +20,12 @@ def view_invoice(request):
# Check if the user is the owner of the invoice or a shop editor
if request.user != invoice.user and not request.user.can_edit_shop(invoice.shop):
request.session.flash(("You do not have permission to view this invoice.", "error"))
request.session.flash(
("You do not have permission to view this invoice.", "error")
)
return HTTPFound(get_referer_or_home(request))
return {
"invoice": invoice,
"line_items": invoice.line_items.all(),
}