Can anyone help me out with discount coupons in Django? - python

Currently I am working on a E-Commerce Website, I Need to Implement these Offers on add to cart as the Products are being added, the Price should be discounted according to the Offer Provided.
The Offers are as follows:
Offer 1- Buy one get one free,
Offer 2- 50% off on more than 2000 buy,
Offer 3- 30% off on selecting more than 2 products to add to the cart.
I have made the E commerce website everything is fine but just don't know how to use the Offer logic and though tried multiple things but nothing worked as it should.
The offer must automatically work on cart as soon as the products are added and before payment gateway the discount should work and get deducted.

idk how are your models and what's exactly your problem but let's say price_all is a field in your cart model and count is how many products of one type are in cart.
for Offer 1 easily you can divide price(this is not price_all this field belongs to your product) into 2.or you can just double the count and I think the second way is better.
for Offer 2 you can add an if to check if price_all is more than 2000 or not.
for offer 3 you can check if the count is more than 2 or not easily.
you can check all of this in save() function of your model or you can make a presave signal for that.if you don't know how just read the docs.

Related

How to model an financial accounting system in Django?

The Django application I'm developing for a taxi company has following modules,
Trips
Customers (who buy products)
Vehicles
Drivers
Each trip is constituted by selecting a customer, a vehicle and a driver along with a few other parameters.
I will be recording every single trip, and the revenue generated because of it.
I also would like to assign this revenue generated to the individual customer who took the vehicle, and to the vehicle which was used in the trip. Since I would like to have a deeper understanding of the customer's spending and the revenue generated by vehicles.
I need to have an Accounts Receivables and a Received statement for each trip.
Is there a standard way to achieve this? I believe a similar approach is used in typical e-commerce systems. Any and every help is appreciated.
Edit 1
I believe I can record all the transactions in this way. Since a trip already contains vehicles and customers, probably I can derive the respective transactions to them.

Mutually exclusive many-to-many relationship in Django models

I'm trying to create a simple model to keep track of discount coupons in Django 1.10 (with Postgres 9.5 as underlying database) and I was wondering if there's a way to make sure that a coupon instance (id, perhaps is a more accurate term?) doesn't appear in two M2M relationships at the same time.
I'm sure everyone is familiar with how discount coupons work but, just in case, let me explain my use case:
Some coupons would be always applied. For instance: "Free delivery in your first purchase", or "10% off Pepsi for the rest of your life"... things like that.
Some other coupons would be applied through a code (a simple string, really) that the user would have to input somewhere (like "Get a 5% off with the code "5-OFF" "... yeah, I'll probably have to work on the obfuscation of the codes :-D )
The user could say "No, I don't want to apply this coupon to this order, I'll use it later". For instance: if the user can use a one-time 5% off coupon, but wants to keep it for a large purchase. Let's say the customer knows he's going to make a large purchase in the upcoming future, and right now he's doing a small one. He might wanna keep the 5% off for the later (bigger) purchase.
To keep track of those things, I have a model like this:
class CouponTracker(models.Model):
# Coupons that require a code to be activated:
extra_applied_coupons = ManyToManyField('Coupon', related_name='+')
# Coupons that the user could have applied and specifically
# said no (such as 5% off if the purchase is small, and wants
# to use it later):
vetoed_coupons = ManyToManyField('Coupon', related_name='+')
So, the question is:
How can I enforce (at a database level, through a constraint) that a coupon does not appear at the same time in extra_applied_coupons and vetoed_coupons?
Thank you in advance!
Why don't you combine 2 extra_applied_coupons and vetoed_coupons and have 1 more fields (for example, type) to determine coupon's group. Then problem will be simpler, just ensure unique in 1 ManyToMany relationship
class CouponTracker(models.Model):
coupons = ManyToManyField('Coupon', related_name='+')
type = models.IntegerField(default=0)
type can be 0 for extra_applied_coupons and 1 for vetoed_coupons.
If you want to add more relationship attribute, you can check https://docs.djangoproject.com/en/1.11/topics/db/models/#extra-fields-on-many-to-many-relationships
Since ManyToMany relations creating a seperate table, AFAIK there cannot make an UNIQUE constraint across tables. So there is no direct way to add contraint on db level. Check this . Either you have to do on application layer or some hackish way like this

How to buy a product using a various payments methods in python?

I have a project that am working in and it almost done except one problem that i can't make or in fact i don't know how to make it done .
The client told me that he want to connect a various payments methods to his site , so lets consider that you are a user and you want to buy a product , inside your panel as a user there is a various banks or methods to buy this product, lets say:
Qiwi wallet
Webmoney
Visa Card
Master Card
Yandex money
you can choose anyone of these to buy it .
Another thing is to show your balance inside the panel so to know whether you have enough money to pay or not, also he want that the user could charge money into his balance if he didn't have enough money.
There is a service called Stripe, which provide stuffs like that, but i 'am not really sure if it would help in any way, all i know about it is, you can make any payments using Master card or Visa card that's all .
Simply the issue is to know how to, pay with various payments methods, balance status and charge balance.
The project is written in python using Flask framework .
Please Please Please , bagging you all, how to make that work, or in a different way from where to start ?, which process should i follow ?, any help really truly would be tons appreciated .
Stripe actually provides quite a number of payment methods but not all of the ones you've listed, so Stripe can definitely help, but you're going to have to implement multiple payment flows here - one for the methods that Stripe can handle, and one for each of the others - as part of your application.
With regards to the Stripe stuff, I'd suggest you have a read through the documentation to learn about getting started there.

Manually update ratings in recomender system

I developed a recommender system using Matrix Factorization in Python. The ratings are in the range [1-5]. It works very well. This system is made for client advisors rather than clients themselves. Hence, the system recommends some products to the client advisor and then this one decides which products he's gonna recommend to his client.
In my application I want to have 2 additional buttons: relevant, irrelevant. Thus, for each recommendation the client advisor would press the button irrelevant if the recommendation is not good but its rating is high and he would press the button relevant if the recommendation is good but its rating is low.
The problem is that I can't figure how to update the ratings when one of the buttons is pressed. Please give me some idea about how to handle that feature. I insist on having only two buttons (relevant and irrelevant), the client advisor can't modify the rating himself.
Thank you very much.
Based on your comment above, I would manipulate the Number of times they purchased the product field. You need to basically transform the Number of times they purchased the product field into an implicit rating field. I would maybe scale the product rating system to 1-5. If they press the don't like the product button, the rating is a 1, if they press the like the product button, they get a 5. If they have bought the product frequently, it's a 5, otherwise it starts at a 3 on the first purchase and scales up to a 4 then 5, based on your data. If they have never bought the product AND have never rated the product, it's a null value, so won't contribute to ratings.

Provide discount to preferred customer with Satchmo?

I am new to Satchmo -- picked it up because I needed payment processing for site subscriptions and physical product.
My site will have two classes of users: paid subscribers and free users. Both can order a
physical product. Paid subscribers get an automatic discount on all orders.
I don't see a configuration for this in the admin. (Discount looks like it would apply to all users. If I'm missing something here, let me know.)
So what's the best place to automatically override the price depending on the user class? The displayed price should show up, say, 10% less for subscribers everywhere in the site, not just at the checkout.
Thanks.
Checkout the tiered pricing module

Categories