如何在openERP 7中添加一个函数 - sale.order继承?

时间:2013-10-24 02:54:54

标签: python function openerp

我收到错误 ERROR openerp.netsvc: 'sale.order' object has no attribute 'test_onchange_months'

我已关注How add a function in openERP 7?,但这不起作用。

我的代码

class test_salesOrder(osv.osv):
    _name = 'sale.order'
    _inherit = 'sale.order'

    _columns = {
        'test_years_from': fields.many2one('test.year', 'Years From'),
        'test_years_to': fields.many2one('test.year', 'Years From'),
        'test_months_from': fields.integer('Months From'),
        'test_months_to': fields.integer('Months To'),
        'test_months': fields.integer('Months'),
        'test_dummy': fields.char('TEST Dummy - CHAR', size=64, required=False),
    }

    def test_onchange_months(self, cr, uid, ids, test_months, context=None):
        test_product_uom_qty = test_months
        res = {}

        if context is None:
            context = {}

        if test_product_uom_qty: 
            for order in self.browse(cr, uid, ids, context=context):
                for line in order.order_line:
                    res[line.id] = {'product_uom_qty' : 0}
                    res[line.id]['product_uom_qty'] = test_product_uom_qty

        return res

    def test_onchange_months_from(self, cr, uid, ids, test_months_from, test_months_to, context=None):
        v = {}
        v['test_months'] = test_months_to - test_months_from
        return {'value': v}

    def test_onchange_months_to(self, cr, uid, ids, test_months_from, test_months_to, context=None):
        v = {}
        v['test_months'] = test_months_to - test_months_from
        return {'value': v}

test_salesOrder()

1 个答案:

答案 0 :(得分:-1)

试试这个,

替换_name = "sale.order.test"