This question has been flagged
2 Replies
5349 Views

Can someone explain why fields_view_get is not being triggered ? Even in debug. I'm using v9

class AdjustmentLines(models.Model):
    
    _name = 'load.valuation.adjustment.lines'
    _description = 'Stock Valuation Adjustment Lines'
    name = fields.Char('Description', compute='_compute_name', store=True)
    cost_id = fields.Many2one('load.load', 'Landed Cost', ondelete='cascade', required=True)
    cost_line_id = fields.Many2one('load.landed.cost.lines', 'Cost Line', readonly=True)
    move_id = fields.Many2one('stock.move', 'Stock Move', readonly=True)
    product_id = fields.Many2one('product.product', 'Product', required=True)
    quantity = fields.Float('Quantity', default=1.0, digits=dp.get_precision('Product Unit of Measure'), required=True)
    weight = fields.Float('Weight', default=1.0, digits=dp.get_precision('Product Unit of Measure'))
    test = fields.Char(string='Test', default='aaa')
    volume = fields.Float('Volume', default=1.0, digits=dp.get_precision('Product Unit of Measure'))
    former_cost = fields.Float('Former Cost', digits=dp.get_precision('Product Price'))
    former_cost_per_unit = fields.Float('Former Cost(Per Unit)', compute='_compute_former_cost_per_unit', digits=0, store=True)
    additional_landed_cost = fields.Float('Additional Landed Cost', digits=dp.get_precision('Product Price'))
    final_cost = fields.Float('Final Cost', compute='_compute_final_cost', digits=0, store=True)
 
    def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
        #override of fields_view_get in order to replace the name field to product template
        if context is None:
            context={}
            res = super(AdjustmentLines, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=submenu)
       (...)

Avatar
Discard
Author Best Answer

Finally the reason why it wasn't being displayed was that the field that I wanted to change was a Many2one and when I placed the code in the parent entity it worked.


<pre data-original-code="def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False): #override of fields_view_get in order to replace the name field to product template if context is None: context={} res = super(AdjustmentLines, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=submenu) doc = etree.XML(res['arch']) for node in doc.xpath(&quot;//label[@string='Test']&quot;): node.set('string','Salut') res['arch'] = etree.tostring(doc) return res " data-snippet-id="ext.d4721cecd57564839eec96a58e5383de" data-snippet-saved="false" data-codota-status="done">def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
    #override of fields_view_get in order to replace the name field to product template
    if context is None:
        context={}
        res = super(AdjustmentLines, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=submenu)
     
        doc = etree.XML(res['arch'])
        for node in doc.xpath("//label[@string='Test']"):
            node.set('string','Salut')
    
        res['arch'] = etree.tostring(doc)
        return res

Avatar
Discard
Best Answer

Hi Vincent,


fields_view_get method will be called when view of object load.valuation.adjustment.lines will be rendered on the screen

Avatar
Discard