The first 2 saves are overly complex:
def save(self):
if self.unit_price and not self.price_discount == '0':
adjust = float(self.price_discount / 100.0)
val_result = str(adjust)
discount = Decimal(self.unit_price - (Decimal(val_result) *
self.unit_price))
self.product_id.product_selling_price = discount
self.product_id.save()
super(ProductSellingPrice, self).save()
else:
self.product_id.product_selling_price = self.unit_price
self.product_id.save()
super(ProductSellingPrice, self).save()
There is no need for an if here, the math works out, so you just lose
the if and do the computations every time. I would still move the
code to something like:
self.product_id.product_selling_price = adjust_price(self.unit_price)
which of course would just be written as self.adjust_selling_price()
The last one looks like a complicated business rule in the first
place, not sure how you fix it, other than to refactor that code out
of save into an adjust_pricing() so that the save logic is
reasonable. This does just move the glob that is the discounting to
somewhere else, but it makes it easier to follow the save logic while
it is happening.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---