1、货位看板模型添加货位变更弹窗模块及其功能按钮,实现产品在同库区的内部货位移动;
This commit is contained in:
1
sf_warehouse/wizard/__init__.py
Normal file
1
sf_warehouse/wizard/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import wizard
|
||||
64
sf_warehouse/wizard/wizard.py
Normal file
64
sf_warehouse/wizard/wizard.py
Normal file
@@ -0,0 +1,64 @@
|
||||
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'}
|
||||
49
sf_warehouse/wizard/wizard_view.xml
Normal file
49
sf_warehouse/wizard/wizard_view.xml
Normal file
@@ -0,0 +1,49 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<odoo>
|
||||
<record id="sf_shelf_location_wizard_form" model="ir.ui.view">
|
||||
<field name="name">货位变更</field>
|
||||
<field name="model">sf.shelf.location.wizard</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="货位变更">
|
||||
<sheet>
|
||||
<group>
|
||||
<group string="初始货位">
|
||||
<group>
|
||||
<field name="current_location_id"/>
|
||||
<field name="current_shelf_id" string="货架"/>
|
||||
<field name="current_barcode" string="编码"/>
|
||||
<field name="current_name" string="名称"/>
|
||||
</group>
|
||||
</group>
|
||||
<group string="目标货位">
|
||||
<group>
|
||||
<field name="current_location_id"/>
|
||||
<field name="destination_shelf_id" string="货架" options="{'no_create': True}"
|
||||
placeholder="请选择目标货架"/>
|
||||
<field name="destination_barcode_id" string="编码" options="{'no_create': True}"
|
||||
placeholder="请选择目标货位"
|
||||
domain="['|', ('location_status', '=', '空闲'), ('product_id', '=', current_product_id)]"/>
|
||||
<field name="destination_name" string="名称"/>
|
||||
<field name="current_product_id" invisible="1"/>
|
||||
</group>
|
||||
</group>
|
||||
</group>
|
||||
</sheet>
|
||||
<footer>
|
||||
<button string="确定" name="confirm_the_change" type="object" class="btn-primary"
|
||||
confirm="是否确认变更货位"/>
|
||||
<button string="取消" class="btn-secondary" special="cancel"/>
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="sf_shelf_location_wizard_act" model="ir.actions.act_window">
|
||||
<field name="name">货位变更</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">sf.shelf.location.wizard</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="view_id" ref="sf_shelf_location_wizard_form"/>
|
||||
<field name="target">new</field>
|
||||
</record>
|
||||
</odoo>
|
||||
Reference in New Issue
Block a user