It appears that you might have an indentation problem within the else:
statement of calc_total_price function.


On Sun, Apr 6, 2014 at 12:57 AM, Anthony Smith
<[email protected]>wrote:

> thanks now  but getting the following error
>
> File "/home/tony/Documents/stockapp/stock/models.py" in save
>   128.         self.total_price = self.calc_total_price()
> File "/home/tony/Documents/stockapp/stock/models.py" in calc_total_price
>   124. amount_price = (self.estimated_total_weight * self.sale_kg)
>
> have attached the code if you have time if not dont worry
>
>     def calc_estimated_total_weight(self):
>     amount = 0
>     if self.sale_head <= 0:
> amount = (self.number * self.estimated_weight_hd)
> return amount
>      def save(self):
> self.estimated_total_weight = self.calc_estimated_total_weight()
> super(SaleNote, self).save()
>
>     def calc_total_price(self):
>     amount_price = 0
>     if self.sale_head > 0:
>            amount_price = (self.number * self.sale_head)
>            return amount_price
> else:
>  amount_price = (self.estimated_total_weight * self.sale_kg)
> return amount_price
>
>     def save(self):
>         self.total_price = self.calc_total_price()
>         super(SaleNote, self).save()
>
>  def __unicode__(self):
>             return self.buyer
>
> cheers
>
> anthony
>
>
> On Sun, Apr 6, 2014 at 3:20 PM, Jay Lozier <[email protected]> wrote:
>
>>
>> On 04/05/2014 11:08 PM, Anthony Smith wrote:
>>
>>> Hi
>>>
>>>
>>>
>>> I have a small project and I have been unable to get the following
>>> statement to work. Any help would great.User inputs can either
>>> self_sale_head which is a $ value,if a $ value is not add a
>>> self.estimated_weight_hd is used to get the total weight, the code below
>>> should return a estimated_weight_total which can be used for the total sale
>>> price. All works when I add the estimated_weight_total manually. I am lost
>>> as why.
>>>
>>> |def  calc_estimated_weight_total(self):
>>>      if  self.sale_head<=  0:
>>>          amount=  (self.number*  self.estimated_weight_hd)
>>>          return  amount
>>>
>>> def  save(self):
>>>      self.estimated_total_weight=  self.calc_estimated_weight_total()
>>>      super(SaleNote,  self).save()|
>>>
>>>
>>>
>>>  Anthony,
>>
>> In your first function, when the if condition evaluates to False it not
>> return anything.
>>
>> A possible version is:
>>
>> def calc_estimated_weight_total(self):
>>     if self.sale_head <= 0:
>>         amount = self.number * self.estimated_weight_hd
>>     else:
>>         amount = 0  # (or your default value or other code to calculate
>> amount)
>>     return amount
>>
>> Another version
>>
>> def calc_estimated_weight_total(self):
>>     amount = 0
>>     if self.sale_head <= 0:
>>         amount = self.number * self.estimated_weight_hd
>>     return amount
>>
>> Both versions will return a value not matter whether the test condition
>> evaluates to True or False. The second version assumes the default value is
>> 0
>>
>>
>> --
>> Jay Lozier
>> [email protected]
>>
>> --
>> You received this message because you are subscribed to a topic in the
>> Google Groups "Django users" group.
>> To unsubscribe from this topic, visit https://groups.google.com/d/
>> topic/django-users/irveWPRuvCY/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to
>> [email protected].
>>
>> To post to this group, send email to [email protected].
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit https://groups.google.com/d/
>> msgid/django-users/5340E423.2070700%40gmail.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CACJNqTXNbBvLnJAJZ%3DOiDt4npqwvfgHeU4YDX1KZ6Ajp02WRyg%40mail.gmail.com<https://groups.google.com/d/msgid/django-users/CACJNqTXNbBvLnJAJZ%3DOiDt4npqwvfgHeU4YDX1KZ6Ajp02WRyg%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Keith Edmiston
(512)970-7222

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAP_gv7KOdQ%2BDkE7wbEtUQ_nHYaBrv3OzN2pqDr4rAxxukOckPA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to