Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
6431 Lượt xem

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)
       (...)

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi Vincent,


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

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 12 17
7628
1
thg 9 15
5085
3
thg 8 15
9232
1
thg 7 15
8632
1
thg 3 15
5801