Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

How to add partner to invoice template?

By
Pavel Pavlov
on 1/23/14, 6:25 PM 1,440 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

0
shashank verma
On 1/24/14, 3:52 AM

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.

0
Pavel Pavlov
On 1/24/14, 5:17 AM

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

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 1/23/14, 6:25 PM
Seen: 1440 times
Last updated: 3/16/15, 8:10 AM