将字段自定义从采购订单行复制到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,
# })

然而,我发现自己被困在了从购买到股票移动的其他领域

您可以使用链接到purchase.order.linestock.move上的purchase_line_id字段

代码-股票移动中的PoL参考

如果您继承股票。移动,则将您的模型名称更改为class StockMove(models.Model):而不是class StockMoveLine(models.Model):

请尝试使用@api。这取决于的计算函数。

最新更新