This question has been flagged
3 Replies
4540 Views

I would like to know how could I get all picking references related to a given source origin sales order.

So basically I would like to retrieve in python a list of picking OUT orders (WH/OUT/...) that has a given sales order as origin (for example "SO-015" reference).

So far I am trying to include in a parser the following code:

def _get_related_picking(self, value):
if value:
stock_picking_pool = self.pool.get('stock.picking')
stock_picking_ids = stock_picking_pool.search(self.cr, self.uid, [('origin', '=', value)])
if stock_picking_ids:
return stock_picking_ids
else
return ""

Then I register the funcion with self.localcontext.update and call it from the XML report using

<span t-esc="get_related_picking(l.origin)"/>

But I got the following error:

QWebException: ""'NoneType' object is not callable" while evaluating
'get_related_picking(l.origin)'" while evaluating
"translate_doc(doc_id, doc_model, 'partner_id.lang', 'custom_reports.invoice_custom_document')"

Avatar
Discard

can you post the wrapper class and report class ..

Best Answer

Try like this,

def _get_related_picking(self, value):
if value:
stock_picking_pool = self.pool.get('stock.picking')
stock_picking_ids = stock_picking_pool.search(self.cr, self.uid, [('origin', '=', value)])
ref = ""
if stock_picking_ids:

for pid in stock_picking_ids:
p_rec = stock_picking_pool.browse(self.cr, self.uid, [pid])
ref = ref + str(p_rec.name) + ","

return ref

Avatar
Discard
Author

Thanks Akhil it works, you made my day

Author Best Answer

It works. I had a bad time trying to get it working because I forgot to restart the server.

Instead of a ',' I would like a carriage return, and I would like to avoid that for the last item. I am trying to fix that now. 

I include the whole parser just in case someone is interested:

from openerp.report import report_sxw
from openerp.osv import osv
from openerp import api

class invoice_parser(report_sxw.rml_parse):

def __init__(self, cr, uid, name, context):
super(invoice_parser, self).__init__(cr, uid, name, context=context)
self.localcontext.update(
'get_related_picking': self._get_related_picking,
}

    def _get_related_picking(self, value):
    if value:
    stock_picking_pool = self.pool.get('stock.picking')
 stock_picking_ids = stock_picking_pool.search(self.cr, self.uid, [('origin', '=', value)]) ref = "" if stock_picking_ids: for pid in stock_picking_ids: p_rec = stock_picking_pool.browse(self.cr, self.uid, [pid]) ref = ref + str(p_rec.name) + "," return ref

class report_custom_invoice_parser(osv.AbstractModel):
_name = 'report.custom_reports.invoice_custom'
_inherit = 'report.abstract_report'
_template = 'custom_reports.invoice_custom'
_wrapped_report_class = invoice_parser

Avatar
Discard