从另一个模型 odoo13 读取字段值

reading a field value from another model odoo13

我想在这里做的是创建一个新的字段维度,从 [stock.move] 模型中的字段获取值这种方法不起作用我不知道为什么而且它不是从 python 文件中获取任何错误 xml 文件

中 xpath 标记的唯一错误

this is models.py file

xx_Custom_Invoice(models.Model):
    _inherit = 'account.move'
    dimension = fields.Char(String="XxX", compute='get_data')

    def get_data(self):
       stock_move = self.env['stock.move']
       for move in self:
          picking = stock_move.picking_id
          if move.id != picking.account_move_ids:
              continue
          for line in move:
              line.update({
                'dimension': line.dimension,
              })  

here is the views.xml

 <record id="xx_account_move_view_inherit" model="ir.ui.view" >
<field name="name">account.move.view.inherit</field>
<field name="model">account.move</field>
<field name="inherit_id" ref="account.view_move_form"/>
<field name="arch" type="xml">
    <xpath expr="/form/sheet/notebook/page/field[@name='invoice_line_ids']/tree/field[@name='product_id']" position="after">
        <field name="dimension"/>
    </xpath>
  </field>
 </record>

这里有一个问题:

       stock_move = self.env['stock.move']
       for move in self:

stock_move这里是一个空记录集,所以for循环中不会发生迭代。 您可能使用 search() 来获取您要操作的记录:

       stock_move = self.env['stock.move'].search(<DOMAIN>)
       for move in self: