Thanks guys, Signals I think is beyond me for the time being but Mark I think I see what you're saying... you mean define an 'adjust_price' method outside of save and call that when necessary? Cleaning up the code would help me get through the rest of it!
The last save method is indeed a complicated one, It's there to check whether the admin has specified an all-encompasing price override that can either be a percentage vale, a price or a new product discount value. On Feb 24, 2:49 pm, Mark Jones <mark0...@gmail.com> wrote: > 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 django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---