1

I create report on account.invoice module and i try to display some data form sale.order but in account.invoice table have no order_id (id related) what should i do if i want to show some data form sale.order on account.invoice report but without id related to sale.order?

So, if account.invoice have order_id (id related) i can use

[[o.order_id._____]]

Can someone please give me some advice ??

Here is my code

class order(report_sxw.rml_parse):
    def __init__(self, cr, uid, name, context=None):
        super(order,self).__init__(cr, uid, name, context=context)
        so_origin = self.pool.get('account.invoice').browse(cr, uid, uid)
        so_obj = self.pool.get('sale.order').browse(cr, uid, so_origin.id)
        self.localcontext.update({
                'order_id': so_obj.id
        })

and in the rml file

[[repeatIn(objects,'o')]]
[[o.order_id._______]]
iSS.f
  • 77
  • 2
  • 8

1 Answers1

2

just write a method which sets a sale order browse_record, so you can use it the normal way.

class invoice_parser(report_sxw.rml_parse):
    def __init__(self, cr, uid, name, context=None):
        super(invoice_parser,self).__init__(cr, uid, name, context=context)
        self.order = False

        def setOrder(invoice_id):
            self.order = False
            so_obj = self.pool.get('sale.order')
            so_list = so_obj.search(cr, uid, [('invoice_ids.id','=',invoice_id)], context=context)
            # big question: what should be done with more than one sale order found
            # easiest solution: return True only when one was found
            if len(so_list) == 1:
                self.order = so_obj.browse(cr, uid, so_list[0], context)
                return True
            else:
                return False

        def getOrder():
            return self.order

        self.localcontext.update({
                'setOrder': setOrder,
                'getOrder': getOrder,
        })

now you can use:

[[ setOrder(o.id) and getOrder().name or ' ']]

or whatever you want to do.

CZoellner
  • 13,553
  • 3
  • 25
  • 38
  • i try '[[ setOrder(o.id) and Order.name]]' that your advice but nothing display on report i also try '[[setOrder(o.id)]]' it's display "True" what should do – iSS.f Apr 02 '14 at 07:59
  • the True means, that a sale order was found, but when nothing was displayed for Order.name then there couldn't be a name on the order. Try Order.id instead, every sale order has an id. – CZoellner Apr 02 '14 at 08:15
  • i already debug self.order and i can see the id of sale order but when i use [[ Order.id ]] and nothing display again :'( – iSS.f Apr 02 '14 at 08:26
  • first i coded it on the fly, but now i tested it. i will edit my answer. problem was the localcontext with self.order. – CZoellner Apr 02 '14 at 08:31