If statement issue driving me nuts

2014-04-05 Thread Anthony Smith
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()
-- 
https://mail.python.org/mailman/listinfo/python-list


Learner looking for assistance

2014-04-14 Thread Anthony Smith
Hi All

I am probably doing something wrong but don't know what 
Any help would great 

Code below 

the calc_total does not return a estimated_total_weight

if add the estimated_total_weight the rest of the code works 

I am at a lose as to why ?

def calc_total(self):
amount = 0
if self.estimated_weight_hd > 0:
amount = self.number * self.estimated_weight_hd
return amount

def save(self):
self.estimated_total_weight = self.calc_total()
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:
if self.estimated_total_weight > 0:
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()

thanks 

anthony 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Learner looking for assistance

2014-04-14 Thread Anthony Smith
On Monday, 14 April 2014 17:43:41 UTC+10, Anthony Smith  wrote:
> Hi All
> 
> 
> 
> I am probably doing something wrong but don't know what 
> 
> Any help would great 
> 
> 
> 
> Code below 
> 
> 
> 
> the calc_total does not return a estimated_total_weight
> 
> 
> 
> if add the estimated_total_weight the rest of the code works 
> 
> 
> 
> I am at a lose as to why ?
> 
> 
> 
> def calc_total(self):
> 
>   amount = 0
> 
>   if self.estimated_weight_hd > 0:
> 
> amount = self.number * self.estimated_weight_hd
> 
>   return amount
> 
>   
> 
>   def save(self):
> 
>   self.estimated_total_weight = self.calc_total()
> 
>   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:
> 
> if self.estimated_total_weight > 0:
> 
> 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()
> 
> 
> 
> thanks 
> 
> 
> 
> anthony

Thanks Ben this involves django as well forgot to mention in ear
lier post Maybe it a django issue rather code. Thats why I posted it here first.

thanks 

cheers
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Learner looking for assistance

2014-04-15 Thread Anthony Smith
On Monday, 14 April 2014 17:43:41 UTC+10, Anthony Smith  wrote:
> Hi All
> 
> 
> 
> I am probably doing something wrong but don't know what 
> 
> Any help would great 
> 
> 
> 
> Code below 
> 
> 
> 
> the calc_total does not return a estimated_total_weight
> 
> 
> 
> if add the estimated_total_weight the rest of the code works 
> 
> 
> 
> I am at a lose as to why ?
> 
> 
> 
> def calc_total(self):
> 
>   amount = 0
> 
>   if self.estimated_weight_hd > 0:
> 
> amount = self.number * self.estimated_weight_hd
> 
>   return amount
> 
>   
> 
>   def save(self):
> 
>   self.estimated_total_weight = self.calc_total()
> 
>   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:
> 
> if self.estimated_total_weight > 0:
> 
> 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()
> 
> 
> 
> thanks 
> 
> 
> 
> anthony

Hi 

To see what I am trying go to yambuk.no-ip.org:8000/admin

this will allow hands on what I am what the program does 

username python password test
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Learner looking for assistance

2014-04-15 Thread Anthony Smith
On Tuesday, 15 April 2014 18:29:27 UTC+10, Steven D'Aprano  wrote:
> On Mon, 14 Apr 2014 00:43:41 -0700, Anthony Smith wrote:
> 
> 
> 
> 
> 
> > the calc_total does not return a estimated_total_weight
> 
> 
> 
> That's because you don't tell it to. Your calc_total method multiplies by 
> 
> estimated_weight_hd which is not the same as estimated_total_weight.
> 
> 
> 
> > 
> 
> > if add the estimated_total_weight the rest of the code works
> 
> > I am at a lose as to why ?
> 
> 
> 
> What does "works" mean in this context? What is the code supposed to do, 
> 
> and what does it do instead?
> 
> 
> 
> Because you have only given us a tiny snippet of code, we have no way of 
> 
> running it. Please read this page here:
> 
> 
> 
> http://www.sscce.org/
> 
> 
> 
> 
> 
> and try to prepare a short, working (in the sense that it runs and 
> 
> demonstrates the problem) example.
> 
> 
> 
>  
> 
> > def calc_total(self):
> 
> > amount = 0
> 
> > if self.estimated_weight_hd > 0:
> 
> > amount = self.number * self.estimated_weight_hd
> 
> > return amount
> 
> 
> 
> This only adds the weight to amount if it is positive. If it is negative, 
> 
> nothing happens. Is that deliberate? Also, I see you have mixed spaces 
> 
> and tabs. Please use one, or the other, but never use both. Mixing spaces 
> 
> and tabs will give you no end of headaches.
> 
> 
> 
> 
> 
> > def save(self):
> 
> > self.estimated_total_weight = self.calc_total()
> 
> > super(SaleNote, self).save()
> 
> 
> 
> This appears to be indented *inside* the calc_total method, but after the 
> 
> return statement, it is dead code and will never be executed. Or perhaps 
> 
> not -- because you have mixed spaces and tabs, it is very difficult to 
> 
> tell.
> 
> 
> 
> 
> 
> > def calc_total_price(self):
> 
> > amount_price = 0
> 
> > if self.sale_head > 0:
> 
> > amount_price = self.number * self.sale_head
> 
> > return amount_price
> 
> > else:
> 
> > if self.estimated_total_weight > 0:
> 
> > amount_price = self.estimated_total_weight *
> 
> > self.sale_kg
> 
> > return amount_price
> 
> 
> 
> Without knowing what your code is supposed to do, we cannot tell how it 
> 
> is broken. What is self.sale_head? Under what circumstances is is 
> 
> negative?
> 
> 
> 
> 
> 
> 
> 
> -- 
> 
> Steven

Sale head is a positive 
if sale head is used the first function is not required 

but if it is not used the first function is used 

then the last function is used to calculate the total price 
-- 
https://mail.python.org/mailman/listinfo/python-list