Skip to content
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

Send revenue to jsecommerce #590

Merged
merged 7 commits into from
Oct 5, 2018

Conversation

ArtemijRodionov
Copy link
Contributor

Closes #589

Copy link
Contributor

@duker33 duker33 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • revenue vs purchase
  • position quantity in puchase calc

Tag as caTag,
TagQuerySet as caTagQuerySet,
)
from catalog import models as ca_models
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's call it catalog_models. We have not so many places to work with shortcut instead of full and clear word

class ProductQuerySet(ca_models.ProductQuerySet):

def calculate_revenue(self):
return self.aggregate(total_revenue=models.Sum('purchase_price'))['total_revenue']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • it's not revenue, it's purchase price. Revenue is cart.price - cart.purchase_price
  • QS getter methods have no verbs: count, raw, first and so on
  • so, i suggest name total_purchase_price

order = Order.objects.all().prefetch_related('positions')

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
positions = context['order'].positions.all()
total_revenue = Product.objects.filter(
id__in=[p.product_id for p in positions]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should use position quantity in this calculation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops

Copy link
Contributor

@duker33 duker33 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thoughts about revenue calculation good location

print(position['price'], position['purchase_price'])
print(position['quantity'])
import sys
sys.stdout.flush()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

forgot some prints

import sys
sys.stdout.flush()
price_diff = position['price'] - position['purchase_price']
self.revenue += price_diff * position['quantity']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

several thoughts about revenue field:

  • it's not clear to calc revenue field in set_positions method
  • it's not clear to keep revenue in DB. Because every order will have a state when this revenue was either set or not
  • Cart is more good place to cal revenue: it focused only on positions and it's prices. Order = cart + credentials

So, i suggest to create Cart's revenue or total_revenue property: it already has total_price and total_quantity props

Copy link
Contributor Author

@ArtemijRodionov ArtemijRodionov Oct 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not clear to calc revenue field in set_positions method

From set_positions docs: Save cart's state into Order instance.. May be it is not the best name for this method, but it falls into the semantic bounds

it's not clear to keep revenue in DB

We have to calculate a revenue from a cart and save it to db, because when we process a successful order, we will clear the cart, although we still need this revenue in next steps

Cart is more good place to cal revenue

We can calculate a revenue in the cart, but we still have to save it in an order.

I will move a calculation of revenue to Cart.revenue

P.S.: We would put a revenue to a session, but it seems, that this order's field may be helpful in some other cases too. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@artemiy312

We would put a revenue to a session

in this case Cart.clear method will clear the whole session instead of one revenue field.
It can be confusing state between real order sessions.


As of other points: you are right here. Seems set_positions is the best place to save revenue in our arch.
But semantically it's still not the best place in the world because of semantical binding between Cart.revenue and Cart.set_positions().
It's the problem in our arch:

  • now we suggest that Cart.positions == CartSession (contains all it's data). It's not true
  • we should create separated CartSession and models.Cart classes
  • they should have methods CartSession.as_model and models.Cart.as_session
  • after cart_session.clear() call a binded cart_model should preserve it's state

Create pdd task with the link on this comment plz. We can continue discussion in it's comments if it's needed

@ArtemijRodionov ArtemijRodionov merged commit d540802 into master Oct 5, 2018
@ArtemijRodionov ArtemijRodionov deleted the 589-income-calculation-jsecommere branch October 5, 2018 09:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants