跳至内容
菜单
此问题已终结
4 回复
15063 查看

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.

形象
丢弃
最佳答案

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

编写者

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

最佳答案

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

最佳答案

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.

编写者 最佳答案

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

相关帖文 回复 查看 活动
0
8月 23
1816
1
12月 22
5105
0
9月 17
3262
0
3月 15
3990
0
3月 15
3859