Thanks a lot Richard! you were right! I have put the wrong field on the
calculation! You are the best!

Thank you!

On Wed, Feb 29, 2012 at 6:25 PM, Richard Vézina <ml.richard.vez...@gmail.com
> wrote:

> You valor_do_dolar field is still a problem in the model down here...
> Since you can't or your lambda can't accès valor_do_dolar in that example.
> The field don't exist in the form so the key not exist so web2py return
> none and custo_em_dolar*none will return none I guest.
>
> try this :
>
> db.define_table('compra_produto',
>     Field('compra', 'reference compra'),
>     Field('produto','reference produto'),
>     Field('quantidade','integer'),
>     Field('custo_em_dolar','double'),
>     Field('cotacao_do_dolar','double'),
>     Field('custo_em_real', compute=lambda cr: cr['custo_em_dolar']*cr['*
> cotacao_do_dolar*']),
> )
>
> And provide input data for both field and it should works, not like you
> want it to works, but you will make sure that it could works.
>
> Also, notice that if you set a field to writable and/or readable = False,
> they will not be in the form and not provide any input data to your lambda
> so it will failed.
>
> I don't see what you do in your controller here that why I notice you
> about that. It is a common pit fall into which I run often when set new
> computed field on existing table because I kind of filter the field I show
> to user with writable and readable = False often and forget about those
> rules.
>
> :)
>
> Richard
>
>
> On Wed, Feb 29, 2012 at 4:16 PM, Tito Garrido <titogarr...@gmail.com>wrote:
>
>> Nice Catch, but I have commented the last field to apply what you
>> suggested and this also doesn't work:
>>
>> db.define_table('compra_produto',
>>     Field('compra', 'reference compra'),
>>     Field('produto','reference produto'),
>>     Field('quantidade','integer'),
>>     Field('custo_em_dolar','double'),
>>     Field('cotacao_do_dolar','double'),
>>     Field('custo_em_real', compute=lambda cr:
>> cr['custo_em_dolar']*cr['valor_do_dolar']),
>>  )
>>
>>
>> On Wed, Feb 29, 2012 at 6:06 PM, Richard Vézina <
>> ml.richard.vez...@gmail.com> wrote:
>>
>>> You can't access valor_do_dolar from custo_em_real lambda computed since
>>> it is a computed field that get computed un submit... If you want to do
>>> that you will have to make a real function that get process on submit with
>>> form.process().accepted and the argument onsuccess or onvalidation
>>>
>>> See chapter 7 with both keyword here a link for the first keyword :
>>>
>>> http://web2py.com/books/default/chapter/29/7?search=onsuccess
>>>
>>> Richard
>>>
>>> On Wed, Feb 29, 2012 at 3:51 PM, Tito Garrido <titogarr...@gmail.com>wrote:
>>>
>>>> Hi Folks,
>>>>
>>>> I am trying a simple example using sqlite:
>>>>
>>>> db.define_table('compra_produto',
>>>>     Field('compra', 'reference compra'),
>>>>     Field('produto','reference produto'),
>>>>     Field('quantidade','integer'),
>>>>     Field('custo_em_dolar','double'),
>>>>     Field('cotacao_do_dolar','double'),
>>>>     Field('custo_em_real', compute=lambda cr:
>>>> cr['custo_em_dolar']*cr['valor_do_dolar']),
>>>>     Field('valor_total', compute=lambda vt:
>>>> vt['custo_em_real']*vt['quantidade'])
>>>>
>>>> But both computed fields are always set as "None"... I am trying it
>>>> from administrative database screen...
>>>>
>>>> Am I doing anything wrong?
>>>>
>>>> --
>>>>
>>>> Linux User #387870
>>>> .........____
>>>> .... _/_õ|__|
>>>> ..º[ .-.___.-._| . . . .
>>>> .__( o)__( o).:_______
>>>>
>>>
>>>
>>
>>
>> --
>>
>> Linux User #387870
>> .........____
>> .... _/_õ|__|
>> ..º[ .-.___.-._| . . . .
>> .__( o)__( o).:_______
>>
>
>


-- 

Linux User #387870
.........____
.... _/_õ|__|
..º[ .-.___.-._| . . . .
.__( o)__( o).:_______

Reply via email to