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 new button in sales invoice form

By
arcull
on 1/21/16, 1:25 AM 1,247 views

Hi everyone.

I'm new to odoo 8 and would like to customize it to my needs. Not to spoil the original code, I've created new module with scaffold command. Now I would need to create a button in header of sales invoice form, which will run my customized invoice print. What I've done so far with my.xml looks like this, but it is not complete yet.

<openerp>

<data>

<record id="invoice.form.my" model="ir.ui.view">

<field name="name">account.invoice.form.my</field>

<field name="model">account.invoice</field>

<field name="inherit_id" ref="account.invoice_5"/>

<field name="arch" type="xml">

<!-- some xpath expression to add "Print2" -->

</field>

</record>

</data>

</openerp>

What would be the appropriate xpath to add button "Print2" to the form header? Should this xpath expression replace the current content of form header, or can it just add new button to it? Can you please post a short example of code.

Much thanks in advance for help, regards.

2

Akhil P Sivan

--Akhil P Sivan--
3423
| 5 3 6
Kochi, India
--Akhil P Sivan--

Interested in exploring Odoo both technically & functionality wise.

email-id : akhilpsivan01@gmail.com

Akhil P Sivan
On 1/21/16, 10:59 AM

Try like this:

<record id="invoice_form_my" model="ir.ui.view">

<field name="name">account.invoice.form.my</field>

<field name="model">account.invoice</field>

<field name="inherit_id" ref="account.invoice_form"/>

<field name="arch" type="xml">

<button name="invoice_print" position="after">

<button name="my_button" string="Print2"/>

</button>

</field>

</record>

Another way using xpath (if you want to add your button next to "Print" button ):

<record id="invoice_form_my" model="ir.ui.view">

<field name="name">account.invoice.form.my</field>

<field name="model">account.invoice</field>

<field name="inherit_id" ref="account.invoice_form"/>

<field name="arch" type="xml">

<xpath expr="/form/header/button[2][@string='Print']" position="after">

<button name="my_button" string="Print2" class="oe_highlight"/>

</xpath>

</field>

</record>

Works just great ;) Even though position="after" doesn't move my button to the end, it appears at the beginning on the left side of form header. Anyway I'm happy with this, I have my button ;) Thanks.

arcull
on 1/21/16, 11:40 AM

Arcull, please try using xpath also, which is another way to extend existing views.

Akhil P Sivan
on 1/21/16, 12:06 PM

Akhil, your suggestion with xpath version works as well, many thanks.

arcull
on 1/21/16, 1:34 PM
2

Jignesh Mehta

--Jignesh Mehta--
2081
| 6 4 8
Surat, India
--Jignesh Mehta--


Jignesh Mehta
On 1/21/16, 1:49 AM

Hello Arcull,


Here is the xpath for add button in account.invoice


<xpath expr="/form/header/button[@name='invoice-open']" position="after">

     <!-- put your button here -->

</xpath>



Hope its works for you.

Thanks,

Thanks. But I can't make it work. I guess I don't know where to position the xpath tag. I tried: account.invoice.form.my account.invoice <xpath expr="/form/header/button[@name='invoice-open']" position="after">

arcull
on 1/21/16, 11:45 AM
1
Kalpana Hemnani
On 1/21/16, 8:18 AM

Hello Arcull,

Another way of putting button is like below:

<button name="invoice_print" position="after">

<!--Add your button-->

</button>



Thanks, I'm currently using this solution.

arcull
on 1/21/16, 11:47 AM
0
arcull
On 1/21/16, 11:37 AM

Thank you guys, you are awesome ;) I was banging my head against the wall for 2 days with this, it's when you know you are very close to solution, but from another point of view, still far away...And the solution is always simple when you know it ;) Thanks again.


PS: the solution with xpath, still doesn't work, but I guess it is my fault positioning the xpath tag. I tried like this:


<openerp>

<data>

<record id="invoice_form_my" model="ir.ui.view">

<field name="name">account.invoice.form.my</field>

<field name="model">account.invoice</field>

<field name="inherit_id" ref="account.invoice_form"/>

<field name="arch" type="xml">

<xpath expr="/form/header/button[@name='invoice-open']" position="after">

<button name="my_button" string="Print3"/>

</xpath>

</field>

</record>

</data>

</openerp>

---------------------------------------------------------------------------------------------------------

I can't put second answer so I'll use this one...

Can you please suggest, how can I refernce function in my model when hitting my new print button. Then "print_invoice_my" refers to account.invoice model, while it should to "my" model in my addon. Therefore I get an error when trying to run, it says it can not find  "print_invoice_my" in account.invoice.Here is my xml:

<openerp>

<data>

<record id="invoice_form_my" model="ir.ui.view">

<field name="name">account.invoice.form.my</field>

<field name="model">account.invoice</field>

<field name="inherit_id" ref="account.invoice_form"/>

<field name="arch" type="xml">

<button name="invoice_print" position="after">

<button type="object" name="print_invoice_my" string="my Invoice"/>

</button>

</field>

</record>

</data>

</openerp>

Much thanks again, Arcull

maybe someone knows the answer, thanks

arcull
on 1/21/16, 4:59 PM

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/21/16, 1:25 AM
Seen: 1247 times
Last updated: 1/21/16, 11:47 AM