How to display data from other model on report (but without ID related) - OpenERP

StackOverflow https://stackoverflow.com/questions/22802006

  •  25-06-2023
  •  | 
  •  

سؤال

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._______]]
هل كانت مفيدة؟

المحلول

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top