문제

I have a inherited module for "purchase". If I add a new method in purchase.py, I am able to use it in my view (form). However if i add it in inherited module. I am not able to use it in form view.

Is there a way to add my new method in inherited module?

Thanks in advance.

도움이 되었습니까?

해결책

Basically what you have to do for your code to work in inherited module is use:

_inherit = 'purchase.order'

And then call your function from the updated xml view. For example check code like that:

class account_asset_asset(osv.osv):

    _inherit = 'account.asset.asset'

    def _check_value(self, cr, uid, ids, context=None):
        for asset in self.browse(cr, uid, ids, context=context):
            if asset.purchase_value < 0.0:
                return False
        return True

    _constraints = [
        (_check_value, 'Asset value must be greater than 0!', ['purchase_value']),
    ]

That will check if the purchase_value of an asset is greater than 0 and return False if not, so that user will not be able to save his record. What is more, you can easily override the function used in inherited model so that it works the way you want it to work.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top