Chirag Kalal
Chirag Kalal

Reputation: 708

Could not get Retail Price in django oscar

I have created one parent product taj mahal tea in which I have created its child product taj mahal tea 1 kg variant and gave price(excl_tax) and Retail Price which you can see in this image.

enter image description here

But when I am trying to access price object I could not get a retail price attribute in it. here is my sample code:

from oscar.core.loading import get_class, get_model
from oscar.apps.partner.strategy import Selector

Product = get_model('catalogue', 'Product')
product = Product.objects.filter(id=11).first()
strategy = Selector().strategy()

info = strategy.fetch_for_product(product)
print(info.price)

Output:

FixedPrice({'currency': 'INR', 'excl_tax': Decimal('400.00'), 'tax': Decimal('0.00')})

Here is my testing code and its output:

>>> strategy = Selector().strategy()
>>> info = strategy.fetch_for_product(product)
>>> info
PurchaseInfo(price=FixedPrice({'currency': 'INR', 'excl_tax': Decimal('400.00'), 'tax': Decimal('0.00')}), availability=<oscar.apps.partner.availability.StockRequired object at 0x7f2db2324e80>, stockrecord=<StockRecord: Partner: Aapnik, product: Taj mahal 1 kg (xyz)>)
>>> info.price
FixedPrice({'currency': 'INR', 'excl_tax': Decimal('400.00'), 'tax': Decimal('0.00')})

Any help will be greatly appericiated.

Upvotes: 1

Views: 553

Answers (1)

solarissmoke
solarissmoke

Reputation: 31474

This is expected, if somewhat confusing behaviour. The retail price field on the stock record isn't used anywhere in Oscar's core - it is just there as a data field and is in fact deprecated in Oscar 1.6.

The default strategy (which I guess is what you are using) only uses price excl. tax, which is what you are seeing.

If you want to use the retail price you will need to provide your own strategy class that does this. Bear in mind that this field is deprecated though, and will be removed from Oscar core in future.

On a separate note, the code you have posted should actually fail with an exception, because of this line:

product = Product.objects.filter(id=11)

product is this case will not be a Product object, but a queryset, which is not a valid argument to Strategy.fetch_for_product().

You probably want to do Product.objects.get(id=11) instead.

Upvotes: 3

Related Questions