Skip to Content
Menu
This question has been flagged
3 Replies
1819 Views

I made a button to change status in form view.

in xml

<record id="eric_product_attribute_form_view" model="ir.ui.view">
<field name="model">product.attribute</field>
<field name="view_type">form</field>
<field name="mode">primary</field>
<field name="arch" type="xml">
<header>
<button name="change_attribute_status" states="confirmed" string="Confirm" type="object" class="btn-primary" attrs="{'invisible': [('state', '!=', 'saved')]}"/>
       </header>
    </field>
</record>


  1. and Action

class ProductAttribute(models.Model):
_name = "product.attribute"
_inherit = "product.attribute"

state = fields.Char("Status")

@api.multi
def change_attribute_status(self):
_logger.info("====================================456========================================")
But I cannot get any log

Please help

Avatar
Discard

Your xml code is wrong.

Its not necessary to add _name="same.name" for inheriting models

Best Answer

you have to inheri the form view too 

add <field name=”inherit_id” ref=”module_name.id_of view”/>

then use xpath to add a button

here is a simple example to inherit sale order form view :

<record model=”ir.ui.view” id=”sale_order_custom_field”>
    <field name=”name”>sale.order.form</field>
    <field name=”model”>sale.order</field>
    <field name=”inherit_id” ref=”sale.view_order_form”/>
    <field name=”arch” type=”xml”>
        <xpath expr=”//field[@name='partner_id']” position=”after”>
            <field name=”your_field”/>
        </xpath>
</field>
</record>

Avatar
Discard
Best Answer

To change state you can use self.write({'field name':'value'}) in this function.

Avatar
Discard
Related Posts Replies Views Activity
0
Apr 17
4330
2
Mar 19
2251
1
Mar 15
2883
0
Dec 24
6
0
Nov 24
6