Skip to Content
Menu
This question has been flagged
1 Reply
2781 Views

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

Avatar
Discard
Author Best Answer

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)

Avatar
Discard
Related Posts Replies Views Activity
1
Oct 24
251
2
Apr 23
7213
2
Sep 22
7898
2
Apr 22
2464
9
Jul 21
60648