1

I'm wondering what I'm doing wrong here. I'm trying to access an object that I have in another object.

So for res.partner I made a custom module that gives an extra field named xx_manager.

Now in sale.order I want to check if the field is empty or not, so I thought I'd just have to do this:

    def action_button_confirm(self, cr, uid, ids, context=None):
    partner = self.pool.get('res.partner')
    if not partner.xx_manager:
        raise osv.except_osv(_('Warning!'), _('No account manager has been set'))
    return super(sale_order, self).create(cr, uid, ids, context=context)

What am I doing wrong?

Thanks in advance

EDIT:

The error that I'm getting:

AttributeError: 'res.partner' object has no attribute 'xx_manager'

My custom module for res.partner:

class res_partner(osv.osv):
_inherit="res.partner"

_columns = {
    'xx_manager': fields.many2one('res.users', string='Account Manager'),
}
2
  • So, are you getting an error message, or what? Commented Jan 28, 2015 at 14:52
  • @Kevin Yes, I've included it in the post, sorry for the missing information Commented Jan 28, 2015 at 14:58

1 Answer 1

1

Yeah because you forget to browse the current record. So browse the current record and take partner id from it and than check partner condition as you want.

try with this code

def action_button_confirm(self, cr, uid, ids, context=None):
    partner = self.browse(cr, uid, ids[0], context=context)
    if partner.partner_id and not partner.partner_id.xx_manager:
        raise osv.except_osv(_('Warning!'), _('No account manager has been set'))
    return super(sale_order, self).action_button_confirm(cr, uid, ids, context=context)
Sign up to request clarification or add additional context in comments.

7 Comments

But this code assumes your working in the class where the method is right? Cause I need to method to be in sale.order and I'm getting the xx_manager from res.partner
yeah you can do that, in sale.order you have partner_id, it has relationship with res.partner so take partner_id form it and check the condition on of it.
If I do so I get the following error: AttributeError: 'list' object has no attribute 'get'
The method def_action_button is in the sales.order class
flow is wrong, try with create method don't do on that method. i will update create method so you will get better idea.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.