首页 > 解决方案 > 将字段自定义从采购订单行复制到odoo中的库存移动

问题描述

我正在使用 odoo 13。我在采购订单行中有一个自定义字段权重。我想将此字段的值复制到库存移动中的自定义字段。我知道要将字段的值从销售订单转移到库存移动,我可以通过以下方式进行。

class StockMoveLine(models.Model):
    _inherit = 'stock.move'

    weight = fields.Float(
        compute='_compute_weight' )
    

    def _compute_weight(self):

        for move in self:
            if not (move.picking_id and move.picking_id.group_id):
                continue
            picking = move.picking_id
            sale_order = self.env['sale.order'].sudo().search([
                ('procurement_group_id', '=', picking.group_id.id)], limit=1)
            # print(picking)
            
            if sale_order:
                for line in sale_order.order_line:
                    if line.product_id.id != move.product_id.id:
                        continue
                    move.update({
                        'weight': line.weight,
                    })
                continue
            else:
                # move.update({
                #         'weight': move.weight,
                # })

但是,我发现自己陷入了从购买到库存转移的其他领域

标签: odoostockodoo-13

解决方案


您可以使用链接到的purchase_line_id字段stock.movepurchase.order.line

代码 -库存移动中的 PoL 参考


推荐阅读