我正在扩展stock.picking以修改用作location_dest_id
的默认值。
标准定义是:
location_dest_id = fields.Many2one(¬
'stock.location', "Destination Location Zone",¬
default=lambda self: self.env['stock.picking.type'].browse(self._context.get('default_picking_type_id')).default_location_dest_id,¬
readonly=True, required=True,¬
states={'draft': [('readonly', False)]})¬
其中基本上使用了picking_type中定义的默认位置。
我扩展了模型,因此picking_type
中有一个名为force_destination
的新字段。我想根据这个条件在stock.picking上设置目的地。
伪代码:
location_dest_id = fields.Many2one(¬
....
default=
if self.env['stock.picking.type'].browse(self._context.get('default_picking_type_id')).force_destination:
default=1
else:
default=lambda self: self.env['stock.picking.type'].browse(self._context.get('default_picking_type_id')).default_location_dest_id
....
答案 0 :(得分:2)
您只需要定义一个默认函数:
tournameLb.Text = Session["tourName"].ToString();
我希望这对你有所帮助。
答案 1 :(得分:2)
使用默认方法(default
)计算默认位置:
location_dest_id = fields.Many2one('stock.location',
string="Destination Location Zone",
default=lambda self: self._get_default_location(),
readonly=True,
required=True,
states={'draft': [('readonly', False)]})
@api.model
def _get_default_name(self):
picking_type = self.env['stock.picking.type'].browse(self._context.get('default_picking_type_id'))
return picking.force_destination and 1 or picking.default_location_dest_id