Siirry sisältöön
Menu
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Tämä kysymys on merkitty
4 Vastaukset
15021 Näkymät

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
Hylkää
Paras vastaus

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
Hylkää
Tekijä

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.

Tekijä

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("##########################################")

Paras vastaus

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
Hylkää
Tekijä

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

Paras vastaus

Hello Arcull,

Another way of putting button is like below:

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

<!--Add your button-->

</button>



Avatar
Hylkää
Tekijä

Thanks, I'm currently using this solution.

Tekijä Paras vastaus

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
Hylkää
Tekijä

maybe someone knows the answer, thanks

Aiheeseen liittyviä artikkeleita Vastaukset Näkymät Toimenpide
0
elok. 23
1779
1
jouluk. 22
5074
0
syysk. 17
3203
0
maalisk. 15
3945
0
maalisk. 15
3841