This question has been flagged
2 Replies
5177 Views

Hello,

I’m struggling to add some data that I need to my Invoice report…
In Delivery Slip(Tech name: stock.picking.list.out) I get the Invoice
Address from [[ display_address(picking.partner_invoice_id.parent_id) ]]
and Delivery Address from [[ display_address(picking.partner_shipping_id) ]]

I’d like to use same information in my Invoice(Tech name: account.invoice) template,
but the invoice object does not contain the Invoice and Delivery addresses. It has only
display_address(o.partner_id), which is not the one that I need for my invoice document.

I found a nice mapping table in the database “sale_order_invoice_rel” and managed to
build a SQL query that does what I need, but I can’t figure out how to perform the same thing
in the invoice report, when I modify it with Open Office. My query is

SELECT 
  account_invoice.id,
  sale_order.partner_id, 
  sale_order.partner_invoice_id, 
  sale_order.partner_shipping_id

FROM 
  public.sale_order_invoice_rel, 
  public.sale_order, 
  public.account_invoice
WHERE 
  sale_order_invoice_rel.order_id = sale_order.id AND
  account_invoice.id = sale_order_invoice_rel.invoice_id;

and it returns what I need… for example:
“id ;partner_id; partner_invoice_id; partner_shipping_id
1;5;6;7”

Question is how do I get those IDs in the Invoice template via RML tags or where can I extend a python method, that is being used to provide to the template this o object that contains the invoice data…
I found invoice_print method in account.account_invoice, that according to the comment should be ”This function prints the invoice and mark it as sent, so that we can see more easily the next step of the workflow”, but not sure how to extend it – it doesn’t return this o object, so that I could extend it…

If you’ve done something similar please tell me how it worked for you.
Can I somehow modify the report or extend the python code and which method?

Best Regards,
Pavel Pavlov

Avatar
Discard
Best Answer

Hello pavel

py file

class account_invoice(report_sxw.rml_parse):

def __init__(self, cr, uid, name, context):
    super(account_invoice, self).__init__(cr, uid, name, context=context)
    self.localcontext.update({
       'my_new_detail':_my_new_detail
    })


 def _my_new_detail(self,ids):


    return obj_browse

rml file

para style="terp_default_2">[[repeatIn( _my_new_detail(picking), 'my_detail')]]</para>

<blocktable colwidths="410.0" style="Header_Order_Reference_Tbl" &gt;<="" p="">

 <tr>

    <td>
      <para style="terp_default_1cm_above_space">[my_detail.fieldname ]]</para>
    </td>

  </tr>

Hope this might help you.

Avatar
Discard
Author Best Answer

Hello,

shashank verma, thank you for sharing your idea! I believe what you wrote will work, thou I haven't tried it, because after banging my head in this almost whole night I found a smoother solution!

class account_invoice(osv.osv):
_inherit = 'account.invoice'
_columns = {
'zSO': fields.many2many('sale.order', 'sale_order_invoice_rel', 'invoice_id', 'order_id', 'Invoices', readonly=True, help="List of Sales Orders related to this Invoice"),              
}

Then in the Invoice report I do [[ display_address(o.zSOid[0].partner_shipping_id) ]] and it works! The benefit of using this approach instead of the other one above is that this way no native SQL shall be used and you go thru the openERP framework to get to the DB layer.

Both solutions will work, but please mark this one as answer. thank you!

Regards, Pavel Pavlov

Avatar
Discard