-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Settlement report #184
Settlement report #184
Changes from 8 commits
b67d4f2
cb988fd
206d0bc
a917fa2
9c2348a
ce5faed
374b917
4820a42
d708182
91f8f54
50ecd3c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from .razorpay import * | ||
from .razorpay_status import * |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from baseframe import __ | ||
from coaster.utils import LabeledEnum | ||
|
||
__all__ = ['RAZORPAY_PAYMENT_STATUS'] | ||
|
||
class RAZORPAY_PAYMENT_STATUS(LabeledEnum): | ||
""" | ||
Reflects payment statuses as specified in | ||
https://docs.razorpay.com/docs/return-objects | ||
""" | ||
CREATED = (0, __("Created")) | ||
AUTHORIZED = (1, __("Authorized")) | ||
CAPTURED = (2, __("Captured")) | ||
#: Only fully refunded payments. | ||
REFUNDED = (3, __("Refunded")) | ||
FAILED = (4, __("Failed")) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ class LINE_ITEM_STATUS(LabeledEnum): | |
#: A line item can be made void by the system to invalidate | ||
#: a line item. Eg: a discount no longer applicable on a line item as a result of a cancellation | ||
VOID = (3, __("Void")) | ||
|
||
TRANSACTION = {CONFIRMED, VOID, CANCELLED} | ||
|
||
LineItemTuple = namedtuple('LineItemTuple', ['item_id', 'id', 'base_amount', 'discount_policy_id', 'discount_coupon_id', 'discounted_amount', 'final_amount']) | ||
|
||
|
@@ -66,7 +66,8 @@ class LineItem(BaseMixin, db.Model): | |
""" | ||
__tablename__ = 'line_item' | ||
__uuid_primary_key__ = True | ||
__table_args__ = (db.UniqueConstraint('customer_order_id', 'line_item_seq'),) | ||
__table_args__ = (db.UniqueConstraint('customer_order_id', 'line_item_seq'), | ||
db.UniqueConstraint('previous_id')) | ||
|
||
# line_item_seq is the relative number of the line item per order. | ||
line_item_seq = db.Column(db.Integer, nullable=False) | ||
|
@@ -78,6 +79,12 @@ class LineItem(BaseMixin, db.Model): | |
item_id = db.Column(None, db.ForeignKey('item.id'), nullable=False, index=True, unique=False) | ||
item = db.relationship(Item, backref=db.backref('line_items', cascade='all, delete-orphan')) | ||
|
||
previous_id = db.Column(None, db.ForeignKey('line_item.id'), nullable=True, index=True, unique=True) | ||
previous = db.relationship('LineItem', | ||
primaryjoin=('line_item.c.id==line_item.c.previous_id'), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Brackets not required. It's confusing as it appears as a tuple until you notice it ends with |
||
backref=db.backref('revision', uselist=False), | ||
remote_side='LineItem.id') | ||
|
||
discount_policy_id = db.Column(None, db.ForeignKey('discount_policy.id'), nullable=True, index=True, unique=False) | ||
discount_policy = db.relationship('DiscountPolicy', backref=db.backref('line_items')) | ||
|
||
|
@@ -325,6 +332,11 @@ def get_confirmed_line_items(self): | |
Order.get_confirmed_line_items = property(get_confirmed_line_items) | ||
|
||
|
||
def initial_line_items(self): | ||
return LineItem.query.filter(LineItem.order == self, LineItem.previous == None, LineItem.status.in_(LINE_ITEM_STATUS.TRANSACTION)) | ||
Order.initial_line_items = property(initial_line_items) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Both this and the other function could be lazy relationships with elaborate |
||
|
||
|
||
def get_from_item(cls, item, qty, coupon_codes=[]): | ||
""" | ||
Returns a list of (discount_policy, discount_coupon) tuples | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,9 +5,9 @@ | |
from decimal import Decimal | ||
from coaster.utils import LabeledEnum, isoweek_datetime | ||
from isoweek import Week | ||
from baseframe import __ | ||
from baseframe import __, localize_timezone | ||
from boxoffice.models import db, BaseMixin, Order, ORDER_STATUS, MarkdownColumn, ItemCollection | ||
from ..extapi import RAZORPAY_PAYMENT_STATUS | ||
from ..extapi.razorpay_status import RAZORPAY_PAYMENT_STATUS | ||
|
||
__all__ = ['OnlinePayment', 'PaymentTransaction', 'CURRENCY', 'CURRENCY_SYMBOL', 'TRANSACTION_TYPE'] | ||
|
||
|
@@ -35,7 +35,7 @@ class OnlinePayment(BaseMixin, db.Model): | |
order = db.relationship(Order, backref=db.backref('online_payments', cascade='all, delete-orphan')) | ||
|
||
# Payment id issued by the payment gateway | ||
pg_paymentid = db.Column(db.Unicode(80), nullable=False) | ||
pg_paymentid = db.Column(db.Unicode(80), nullable=False, unique=True) | ||
# Payment status issued by the payment gateway | ||
pg_payment_status = db.Column(db.Integer, nullable=False) | ||
confirmed_at = db.Column(db.DateTime, nullable=True) | ||
|
@@ -74,6 +74,8 @@ class PaymentTransaction(BaseMixin, db.Model): | |
internal_note = db.Column(db.Unicode(250), nullable=True) | ||
refund_description = db.Column(db.Unicode(250), nullable=True) | ||
note_to_user = MarkdownColumn('note_to_user', nullable=True) | ||
# Refund id issued by the payment gateway | ||
pg_refundid = db.Column(db.Unicode(80), nullable=True, unique=True) | ||
|
||
|
||
def get_refund_transactions(self): | ||
|
@@ -167,3 +169,5 @@ def calculate_weekly_refunds(item_collection_ids, user_tz, year): | |
ordered_week_refunds[int(week_refund.sales_week)] = week_refund.sum | ||
|
||
return ordered_week_refunds | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extra blank lines |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,6 +54,9 @@ class Organization(ProfileBase, db.Model): | |
# logo (image url), refund_policy (html), ticket_faq (html), website (url) | ||
details = db.Column(JsonDict, nullable=False, server_default='{}') | ||
contact_email = db.Column(db.Unicode(254), nullable=False) | ||
# Merchant account involves settlements and hence can access | ||
# settlement reports | ||
merchant = db.Column(db.Boolean, nullable=False, default=False) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What sort of organization accounts would we have that are not merchant accounts? |
||
|
||
def permissions(self, user, inherited=None): | ||
perms = super(Organization, self).permissions(user, inherited) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want the timezone object, it's
app.config['tz']
. Our convention is to usetimezone
andTIMEZONE
for the string andtz
for the object.