65 lines
3.0 KiB
Python
65 lines
3.0 KiB
Python
from odoo import fields, models, api
|
|
from odoo.exceptions import UserError, ValidationError
|
|
|
|
|
|
class ShelfLocationWizard(models.TransientModel):
|
|
_name = 'sf.shelf.location.wizard'
|
|
_description = '货位变更'
|
|
|
|
name = fields.Char('')
|
|
|
|
current_location_id = fields.Many2one('stock.location', string='所属库区', readonly=True)
|
|
|
|
current_shelf_id = fields.Many2one('sf.shelf', string='当前货架', readonly=True)
|
|
current_barcode = fields.Char('当前货位编码', readonly=True)
|
|
current_name = fields.Char('当前货位名称', readonly=True)
|
|
current_product_id = fields.Many2one('product.product', string='产品', readonly=True)
|
|
|
|
destination_shelf_id = fields.Many2one('sf.shelf', string='目标货架', compute='_compute_destination_name')
|
|
destination_barcode_id = fields.Many2one('sf.shelf.location', string='目标货位编码', required=True,
|
|
domain="")
|
|
destination_name = fields.Char('目标货位名称', compute='_compute_destination_name')
|
|
|
|
def return_domain(self):
|
|
val = [('location_status', '=', '空闲')]
|
|
if self.current_product_id:
|
|
val = ['|', ('location_status', '=', '空闲'), ('product_id', '=', self.current_product_id)]
|
|
if self.destination_shelf_id:
|
|
val.append(('shelf_id', '=', self.destination_shelf_id))
|
|
return "%s" % val
|
|
|
|
@api.depends('destination_barcode_id')
|
|
def _compute_destination_name(self):
|
|
if self.destination_barcode_id:
|
|
self.destination_name = self.destination_barcode_id.name
|
|
self.destination_shelf_id = self.destination_barcode_id.shelf_id.id
|
|
else:
|
|
self.destination_name = ''
|
|
self.destination_shelf_id = False
|
|
|
|
#
|
|
# @api.onchange('destination_barcode_id')
|
|
# def _onchange_destination_shelf_id(self):
|
|
# if self.destination_barcode_id:
|
|
# self.destination_shelf_id = self.destination_barcode_id.shelf_id.id
|
|
|
|
def confirm_the_change(self):
|
|
shelf_location = self.env['sf.shelf.location'].sudo().search([('barcode', '=', self.current_barcode)])
|
|
# 变更货位
|
|
if self.destination_barcode_id and shelf_location:
|
|
if self.destination_barcode_id.product_id and self.destination_barcode_id.product_id == shelf_location.current_product_id and not self.destination_barcode_id.product_sn_id:
|
|
self.destination_barcode_id.product_num += shelf_location.product_num
|
|
else:
|
|
self.destination_barcode_id.product_sn_id = shelf_location.product_sn_id.id
|
|
self.destination_barcode_id.product_id = shelf_location.product_id.id
|
|
self.destination_barcode_id.product_num = shelf_location.product_num
|
|
|
|
shelf_location.product_sn_id = False
|
|
shelf_location.product_id = False
|
|
shelf_location.product_num = 0
|
|
else:
|
|
raise ValidationError('目标货位出错,请联系管理员!')
|
|
|
|
# 关闭弹出窗口
|
|
return {'type': 'ir.actions.act_window_close'}
|