Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
4 Risposte
15079 Visualizzazioni

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.

Avatar
Abbandona
Risposta migliore

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>

Avatar
Abbandona
Autore

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, please try using xpath also, which is another way to extend existing views.

Autore

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

how can i make it runnable or how can i perform some function on click of this button

how can i make it runnable or how can i perform some function on click of this button????

i have tried this :

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

<field name="name">hr.payslip.form</field>

<field name="model">hr.payslip</field>

<field name="type">form</field>

<field name="inherit_id" ref="hr_payroll.view_hr_payslip_form"/>

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

<xpath expr="//header" position="inside">

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

</xpath>

</field>

</record>

models.py

class custom_hr_payslip(models.Model):

_name = 'custom.hr.payslip'

_inherit = 'hr.payslip'

@api.one

def my_button(self):

print("##########################################")

Risposta migliore

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,

Avatar
Abbandona
Autore

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">

Risposta migliore

Hello Arcull,

Another way of putting button is like below:

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

<!--Add your button-->

</button>



Avatar
Abbandona
Autore

Thanks, I'm currently using this solution.

Autore Risposta migliore

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

Avatar
Abbandona
Autore

maybe someone knows the answer, thanks

Post correlati Risposte Visualizzazioni Attività
0
ago 23
1839
1
dic 22
5117
0
set 17
3272
0
mar 15
4015
0
mar 15
3865