Re: [tryton] Get product stock with proteus at specific date

119 views
Skip to first unread message

Cédric Krier

unread,
Aug 21, 2012, 2:57:23 AM8/21/12
to try...@googlegroups.com
On 19/08/12 10:34 -0700, TPH wrote:
> Hello
>
> How can I get stock for product with proteus at a specific date? I think
> its something with context but I don't know how to use it. I would be very
> nice to have a little example. thx

You can read it from the field quantity on product if you put in the
context:

- stock_date_end: default to today
- locations: a list of location ids

--
Cédric Krier

B2CK SPRL
Rue de Rotterdam, 4
4000 Liège
Belgium
Tel: +32 472 54 46 59
Email/Jabber: cedric...@b2ck.com
Website: http://www.b2ck.com/

Truckparts Hamburg COM

unread,
Aug 21, 2012, 5:18:18 AM8/21/12
to try...@googlegroups.com



> You can read it from the field quantity on product if you put in the
> context:
>
> - stock_date_end: default to today
> - locations: a list of location ids
>

Thank you. Why is this not working?:

stockdate = datetime.date(2012,1,1)
config._context['stock_date_end'] = stockdate
stock_2012_01_01 = product.quantity

It always shows the stock of today, but I need stock from 2012/01/01.

Robin Baumgartner

unread,
Aug 21, 2012, 5:54:02 AM8/21/12
to try...@googlegroups.com
----- Ursprüngliche Mail -----
> Thank you. Why is this not working?:
>
> stockdate = datetime.date(2012,1,1)
> config._context['stock_date_end'] = stockdate
> stock_2012_01_01 = product.quantity
>
> It always shows the stock of today, but I need stock from 2012/01/01.

It should be something like that (untested):

stockdate = datetime.date(2012, 1, 1)
with Transaction().set_context(stock_date_end=stockdate):
stock_2012_01_01 = product.quantity

Truckparts Hamburg COM

unread,
Aug 21, 2012, 9:22:39 AM8/21/12
to try...@googlegroups.com

> It should be something like that (untested):
>
> stockdate = datetime.date(2012, 1, 1)
> with Transaction().set_context(stock_date_end=stockdate):
> stock_2012_01_01 = product.quantity

I tried this in different variants but can't get it work.

Cédric Krier

unread,
Aug 21, 2012, 9:34:32 AM8/21/12
to try...@googlegroups.com
Normally something like this should work:

config.context['stock_date_end'] = stockdate
product = Product(<id>)
product.quantity

You must set the context before instanciating the record otherwise you
can not know if it was not yet read before.

Truckparts Hamburg COM

unread,
Aug 21, 2012, 9:59:08 AM8/21/12
to try...@googlegroups.com

> You must set the context before instanciating the record otherwise you
> can not know if it was not yet read before.

That was the problem.

Thank you very much.


Jesús Martín Jiménez

unread,
Jan 27, 2016, 5:07:53 AM1/27/16
to tryton
Hi


El martes, 21 de agosto de 2012, 15:34:32 (UTC+2), Cédric Krier escribió:
On 21/08/12 15:22 +0200, Truckparts Hamburg COM wrote:
>
> > It should be something like that (untested):
> >
> > stockdate = datetime.date(2012, 1, 1)
> > with Transaction().set_context(stock_date_end=stockdate):
> >     stock_2012_01_01 = product.quantity
>
> I tried this in different variants but can't get it work.

Normally something like this should work:

    config.context['stock_date_end'] = stockdate
    product = Product(<id>)
    product.quantity

I'm trying to set the active_ids param to the context with proteus this way

>>> Invoice = Model.get('account.invoice')
>>> d = datetime(year=2015, month=12, day=1)
>>> invoices = Invoice.find([('create_date', '>=', d)])
>>> config.set_context({'active_ids': [i.id for i in invoices]})

in order to execute a method of a wizard that takes values from the context of the transaction, but the transaction context that arrives to the method has the None value on the active_ids param.

I've tried these too:

>>> config.context['active_ids'] = [i.id for i in invoices]
>>> config._context['active_ids'] = [i.id for i in invoices]

But nothing works properly. I've tested with proteus 3.4.2 and 3.8.1

Could someone tell me what am i doing wrong?

Thank you very much.

Raimon Esteve

unread,
Jan 27, 2016, 5:17:47 AM1/27/16
to try...@googlegroups.com
2016-01-27 11:07 GMT+01:00 Jesús Martín Jiménez <jma...@zikzakmedia.com>:
> Hi
>
> El martes, 21 de agosto de 2012, 15:34:32 (UTC+2), Cédric Krier escribió:
>>
>> On 21/08/12 15:22 +0200, Truckparts Hamburg COM wrote:
>> >
>> > > It should be something like that (untested):
>> > >
>> > > stockdate = datetime.date(2012, 1, 1)
>> > > with Transaction().set_context(stock_date_end=stockdate):
>> > > stock_2012_01_01 = product.quantity
>> >
>> > I tried this in different variants but can't get it work.
>>
>> Normally something like this should work:
>>
>> config.context['stock_date_end'] = stockdate
>> product = Product(<id>)
>> product.quantity
>
>
> I'm trying to set the active_ids param to the context with proteus this way
>
>>>> Invoice = Model.get('account.invoice')
>>>> d = datetime(year=2015, month=12, day=1)
>>>> invoices = Invoice.find([('create_date', '>=', d)])
>>>> config.set_context({'active_ids': [i.id for i in invoices]})
>
> in order to execute a method of a wizard that takes values from the context
> of the transaction, but the transaction context that arrives to the method
> has the None value on the active_ids param.
>
> I've tried these too:
>
>>>> config.context['active_ids'] = [i.id for i in invoices]
>>>> config._context['active_ids'] = [i.id for i in invoices]

I think is not necessary add active_ids in context.

An example to call a wizard with some records:

http://hg.tryton.org/modules/account/file/355d38d4a518/tests/scenario_account_reconciliation.rst#l96

Regards

> But nothing works properly. I've tested with proteus 3.4.2 and 3.8.1
>
> Could someone tell me what am i doing wrong?
>
> Thank you very much.
>
>>
>> You must set the context before instanciating the record otherwise you
>> can not know if it was not yet read before.
>>
>> --
>> Cédric Krier
>>
>> B2CK SPRL
>> Rue de Rotterdam, 4
>> 4000 Liège
>> Belgium
>> Tel: +32 472 54 46 59
>> Email/Jabber: cedric...@b2ck.com
>> Website: http://www.b2ck.com/
>
> --
> You received this message because you are subscribed to the Google Groups
> "tryton" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/tryton/c9837995-d4e4-4ded-a663-cb1b52299fde%40googlegroups.com.



--
Si us plau, NO adjunti arxius a les seves respostes. Li preguem que
integri el text al cos del missatge. Pot respondre usant NetEtiquete
que li ajudarà a seguir la conversa.
http://es.wikipedia.org/wiki/Netiquette

Por favor, NO adjunte archivos a sus respuestas. Le rogamos que
integre el texto en el cuerpo del mensaje. Puede responder usando
NetEtiquete que le ayudará a seguir la
conversación.http://es.wikipedia.org/wiki/Netiquette

Please, DO NOT send attachment files with your answers, just copy and
paste only the text you need to send into the body of your mails.
Repply using NetEtiquete. http://en.wikipedia.org/wiki/Netiquette

Jesús Martín Jiménez

unread,
Jan 27, 2016, 5:35:19 AM1/27/16
to tryton

Thanks, this way works properly.
 
Reply all
Reply to author
Forward
0 new messages