도움말

0

make one part of one2many filed readonly?

Avatar
mitra safari

hello odoo community

I have one2many filed(line_ids) in purchase requisition form that contains product name, product category,... and I want make product category readonly 

I try to use attr in XML code but it does not save product category value 

my python code:

in purchase.requisition

'line_ids' : fields.one2many('purchase.requisition.line','requisition_id','Products to Purchase',states={'done': [('readonly', True)]}),

in  purchase.requisition.line  

_columns = {
'product_id': fields.many2one('product.product', 'Product' ),
'product_uom_id': fields.many2one('product.uom', 'Product UoM'),
'product_qty': fields.float('Quantity', digits_compute=dp.get_precision('Product UoM')),
'requisition_id' : fields.many2one('purchase.requisition','Purchase Requisition', ondelete='cascade'),
'company_id': fields.related('requisition_id','company_id',type='many2one',relation='res.company',string='Company', store=True, readonly=True),
'categ' : fields.many2one('product.category', 'categ' ,store=True),
}

my XML code:

<field name="line_ids" colspan="4" nolabel="1">
    <tree string="Products" editable="bottom">
        <field name="product_id" on_change="onchange_product_id(product_id,product_uom_id)"/>
        <field name="categ" attrs="{'readonly':[('product_id','!=',False)]}"/>
        <field name="product_qty"/>
        <field name="product_uom_id"/>
    </tree>

openerp v6.1

아바타
작성취소
1 답변
0
Avatar
mitra safari
최고의 답변

I solve my problem with rewrite creat and write functions  like below :

in purchase.requisition.line  

_columns = {
'product_id': fields.many2one('product.product', 'Product' ),
'product_uom_id': fields.many2one('product.uom', 'Product UoM'),
'product_qty': fields.float('Quantity', digits_compute=dp.get_precision('Product UoM')),
'requisition_id' : fields.many2one('purchase.requisition','Purchase Requisition', ondelete='cascade'),
'company_id': fields.related('requisition_id','company_id',type='many2one',relation='res.company',string='Company', store=True, readonly=True),
'categ' : fields.many2one('product.category', 'categ' ,store=True,readonly=True),
}

def write(self, cr, uid, ids, vals, context=None):
if vals.get('product_id'):
a= self.pool.get('product.product').browse(cr, uid, vals['product_id']).categ_id.id
vals.update({'categ': a})
return super(purchase_requisition_line, self).write(cr, uid, ids, vals, context=context)

def create(self, cr, uid, vals, context=None):
if vals.get('product_id'):
a= self.pool.get('product.product').browse(cr, uid, vals['product_id']).categ_id.id
vals.update({'categ': a})
return super(purchase_requisition_line, self).create(cr, uid, vals, context=context)

아바타
작성취소