2012/6/8 Cédric Krier <[email protected]>

> On 07/06/12 08:02 -0700, oscar_andres_col wrote:
> > Hello, Developers
> >
> > I am making a module with a Report about products in location for to
> > see something this in report:
> >
> > location: MyLocation
> >
> >   product      quantity
> > product A          5
> > product B          3
> > product C          10
> >
> >
> > I get the view with path >Inventory &
> > Stock>Locations>MyLocation>Wizard (date_end)>Products (MyLocation),
> >
> > but I can't get data of this view because this data is computed with a
> > context, so then the report .odt show this:
> >
> >   product      quantity
> > product A          0
> > product B          0
> > product C          0
> >
> > I need get the context in my class report something like:
> >
> > context = {'stock_date_end': datetime.date(2012, 6, 7), 'locations':
> > [4], ... }
> >
> > But I can't  get context, I tried this but did'nt work:
> >
> > class StockProductReport(Report):
> >     _name = 'product.product'
> >
> >     def __init__(self):
> >         super(StockProductReport, self).__init__()
> >
> >     def parse(self, report, objects, datas, localcontext=None):
> >         location_obj = Pool().get('stock.location')
> >         uom_obj = Pool().get('product.uom')
> >
> >         localcontext['stock_date_end'] =
> > Transaction().context.get('stock_date_end'):
> >         localcontext['locations'] =
> > Transaction().context.get('locations'):
> >
> >         with Transaction().set_context(localcontext):
> >             for obj in objects:
> >                  <<to do something>>
> >
> >         return super(StockProductReport, self).parse(report,
> >                 objects, datas, localcontext)
> >
> > StockProductReport()
>
> You must setup the context via a wizard.
> You can find an example in
> http://hg.tryton.org/modules/account/file/5a1c2d24c1af/account.py#l1155
>
> --
> Cédric Krier
>
> B2CK SPRL
> Rue de Rotterdam, 4
> 4000 Liège
> Belgium
> Tel: +32 472 54 46 59
> Email/Jabber: [email protected]
> Website: http://www.b2ck.com/
>

@cedk,

I solved with other easy way. Now this works:

class StockProductReport(CompanyReport):
    _name = 'product.product'

    def parse(self, report, objects, datas, localcontext=None):
        user_obj = Pool().get('res.user')
        location_obj = Pool().get('stock.location')
        uom_obj = Pool().get('product.uom')
        sum_total = 0

        localcontext['locations'] = Transaction().context.get('locations')
        localcontext['stock_date_end'] =
Transaction().context.get('stock_date_end')

        with Transaction().set_context(localcontext):
            for obj in objects:
                sum_total += obj.cost_value

        datas['sum_total'] = sum_total

        locations = location_obj.browse(localcontext['locations'])
        for location in locations:
            datas['locations'] = location.rec_name

        user = user_obj.browse(Transaction().user)
        localcontext['company'] = user.company

        datas['create_user'] = user.name
        datas['stock_date_end'] = localcontext['stock_date_end']

        return super(StockProductReport, self).parse(report,
                objects, datas, localcontext)

StockProductReport()

--------------------------------------------------------

How can I solved?

With a litlle patch in the tryton client 2.4:

See this file,

.../tryton/gui/window/form.py

line 504
-        Action._exec_action(action, data, {})
+       Action._exec_action(action, data, self.context)

It is the similar to method founded in same file "sig_save_as(self,
widget=None)" for to make exports where the self.context is fixed.
I think that the fixed this context for the reports is as important as in
exports.

If you are agree, I can to start creating a new feature, and codereview


Oscar Alvarez

-- 
[email protected] mailing list

Reply via email to