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.

1

error: AttributeError: 'sale.order' object has no attribute '_ids'

By
MrTwo
on 1/29/15, 3:22 AM 5,737 views

I'm trying to Put button inside header to do certain tasks depends on boolean field,
but when try to print the value inside this field this error appears
"AttributeError: 'sale.order' object has no attribute '_ids'"
How can I fix this
my code


class sale_order(models.Model):
    _inherit = 'sale.order'

    category = fields.Boolean(string="Category", default=False)

     def apply_test(self, cr, uid, ids, context=None):
        print "Hello World" 
        print self.category # error


<record model="ir.ui.view" id="view_order_form_inh_promotion">
            <field name="name">sale.order.form.inh.promotion</field>
            <field name="model">sale.order</field>
            <field name="inherit_id" ref="sale.view_order_form"/>
            <field name="arch" type="xml">
                <button name="invoice_recreate" position="after">
                    <button name="apply_test" string="Test" type="object"/>
                </button>
</record>

2

Yannick Vaucher

--Yannick Vaucher--
1699
| 5 7 9
Lausanne, Switzerland
--Yannick Vaucher--
Yannick Vaucher
On 4/29/15, 3:46 AM

You are trying to use self as in new API 8.0


if you want to access to `self.category` that way, you must be in a new API method.

Somithing like:


    @api.multi

    def apply_test(self):

        print self.category


Otherwise if you are in a prior version of Odoo, you must do a browse first.


    sale_order = self.browse(cr, uid, ids[0], context=context)

    print sale_order.category

why here you used api.multi decorator

Odoo
on 5/3/16, 1:43 AM

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/29/15, 3:22 AM
Seen: 5737 times
Last updated: 5/3/16, 1:41 AM