Pregunta

class marcos_artwork(osv.osv):
    def _check_appraisal_price(self, cr, uid, ids, context=None):
        record = self.pool.get('appraisal_price')
        if record<0:
            return False
        return True

    """artwork class"""
    _name = 'marcos.artwork'
    _columns = {
        'name': fields.char('Artwork',size=32,required=True),
        'description': fields.char('Description',size=200),
        'appraisal_price': fields.integer('Appraisal price' ),
        'createArtWork': fields.integer('Year of creation'),
        'award': fields.boolean('Award'),
        'barcode': fields.integer('Barcode'),
        'commission': fields.integer('Commission',size=10),
        'author_ids': fields.many2one('marcos.author', 'Author'),
        'typeartwork_ids': fields.many2one('marcos.artwork_type', 'Artwork Type'),
        'owner_ids': fields.many2one('marcos.owner','Owner'),
        'style_ids': fields.many2one('marcos.style','Style'),
        'lots_ids': fields.many2many('marcos.lots','artworks_lots_form_rel','id_artwork','id_lot','Artworks'),
    }
    _defaults = {
        'award': lambda *a: False,
    }

    _sql_constraints = [
        ('name_uniqe', 'unique(name)', 'only equals name!'),
        ('barcode_uniqe', 'unique(barcode)', 'only equals barcode!')
    ]

    _constraints = [(_check_appraisal_price, 'Error: Length must be Positive', ['appraisal_price'])]

marcos_artwork()

When I want to install the module, I get shown this error:

-cannot concatenate 'str' and 'function' object...

My function is for checking that the appraisal price is positive.

Can anybody help me?

¿Fue útil?

Solución

your price checking won't work this way. the big problem here is the line

record = self.pool.get('appraisal_price')

that's not correct. self.pool.get will get you instances of your "business models" like your 'marcos.artwork' but you want some field values to check.

in this case you don't even need self.pool.get, because you're already on this model and can use self instead.

so here is the code you need (you will find so many examples in the addons):

def _check_appraisal_price(self, cr, uid, ids, context=None):
    for artwork in self.browse(cr, uid, ids, context):
        if artwork.appraisal_price < 0:
            return False
    return True

Otros consejos

I don't know this specific framework. but I guess from the code It's some kind of "orm" style class. mapping some behavior to a db/table of some sort. Really hard to tell without the full stacktrace but I believe that the error is that your are passing the __check_appraisal_price function as reference and not the result of the function - that would be something like _check_appraisal_price(arg,arg2, etc)

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top