将自定义字段值从销售订单行复制到 odoo 中的 stock.move
copying custom field value from sale order line to stock.move in odoo
将销售订单行中的值复制到库存移动中,两行中仅显示第二行值。代码:
[在此处输入图片描述][1]
from odoo import models, fields, api
class StockMove(models.Model):
@api.multi
def get_data(self):
data = self.env['sale.order.line'].search([])
print("Get Data Function")
for rec in data:
print(rec.x_serialnumber)
for record in self:
record.x_serialnumber = rec.x_serialnumber
_inherit = 'stock.move'
x_serialnumber = fields.Text(string="Serial Number", compute='get_data')"
销售订单行显示如下:
序列号:两行
112233
445566
但股票走势:
序列号:两行
445566
445566
奥朗赛布
更新您的代码:
@api.multi
def get_data(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)
for line in sale_order.order_line:
if line.product_id.id != move.product_id.id:
continue
move.update({
'x_serialnumber': line.x_serialnumber,
})
将销售订单行中的值复制到库存移动中,两行中仅显示第二行值。代码: [在此处输入图片描述][1]
from odoo import models, fields, api
class StockMove(models.Model):
@api.multi
def get_data(self):
data = self.env['sale.order.line'].search([])
print("Get Data Function")
for rec in data:
print(rec.x_serialnumber)
for record in self:
record.x_serialnumber = rec.x_serialnumber
_inherit = 'stock.move'
x_serialnumber = fields.Text(string="Serial Number", compute='get_data')"
销售订单行显示如下:
序列号:两行
112233
445566
但股票走势:
序列号:两行
445566
445566
奥朗赛布
更新您的代码:
@api.multi
def get_data(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)
for line in sale_order.order_line:
if line.product_id.id != move.product_id.id:
continue
move.update({
'x_serialnumber': line.x_serialnumber,
})