Accept Merge Request #1072: (release/release_1.5 -> develop)

Merge Request: 添加刀具按批次管理

Created By: @禹翔辉
Reviewed By: @马广威
Approved By: @马广威 
Accepted By: @马广威
URL: https://jikimo-hn.coding.net/p/jikimo_sfs/d/jikimo_sf/git/merge/1072
This commit is contained in:
马广威
2024-06-14 16:21:38 +08:00
committed by Coding
17 changed files with 753 additions and 376 deletions

View File

@@ -452,8 +452,9 @@ class ShelfLocation(models.Model):
# product_id = fields.Many2one('product.template', string='产品')
product_id = fields.Many2one('product.product', string='产品', compute='_compute_product_id', store=True)
product_sn_id = fields.Many2one('stock.lot', string='产品序列号')
product_sn_ids = fields.One2many('sf.shelf.location.lot', 'shelf_location_id', string='产品批次号')
# 产品数量
product_num = fields.Integer('数量')
product_num = fields.Integer('数量', compute='_compute_number', store=True)
@api.depends('product_num')
def _compute_product_num(self):
@@ -463,6 +464,15 @@ class ShelfLocation(models.Model):
elif record.product_num == 0:
record.location_status = '空闲'
@api.depends('product_sn_ids.qty')
def _compute_number(self):
for item in self:
if item.product_sn_ids:
qty = 0
for product_sn_id in item.product_sn_ids:
qty += product_sn_id.qty
item.product_num = qty
# 修改货位状态为禁用
def action_location_status_disable(self):
self.location_status = '禁用'
@@ -471,7 +481,7 @@ class ShelfLocation(models.Model):
def action_location_status_enable(self):
self.location_status = '空闲'
@api.depends('product_sn_id')
@api.depends('product_sn_id', 'product_sn_ids')
def _compute_product_id(self):
"""
根据产品序列号,获取产品
@@ -484,7 +494,8 @@ class ShelfLocation(models.Model):
record.sudo().product_num = 1
except Exception as e:
print('eeeeeee占用', e)
elif record.product_sn_ids:
return True
else:
try:
record.sudo().product_id = False
@@ -525,7 +536,24 @@ class ShelfLocation(models.Model):
return records
class Sf_stock_move_line(models.Model):
class SfShelfLocationLot(models.Model):
_name = 'sf.shelf.location.lot'
_description = '批次数量'
name = fields.Char('名称', related='lot_id.name')
shelf_location_id = fields.Many2one('sf.shelf.location', string="货位")
lot_id = fields.Many2one('stock.lot', string='批次号')
qty = fields.Integer('数量')
qty_num = fields.Integer('变更数量')
@api.onchange('qty_num')
def _onchange_qty_num(self):
for item in self:
if item.qty_num > item.qty:
raise ValidationError('变更数量不能比库存数量大!!!')
class SfStockMoveLine(models.Model):
_name = 'stock.move.line'
_inherit = ['stock.move.line', 'printing.utils']
@@ -825,15 +853,20 @@ class Sf_stock_move_line(models.Model):
obj = self.env['sf.shelf.location'].search([('name', '=',
self.destination_location_id.name)])
if record.lot_id:
shelf_location_obj = self.env['sf.shelf.location'].search(
[('product_sn_id', '=', record.lot_id.id)])
if shelf_location_obj:
shelf_location_obj.product_sn_id = False
if obj:
obj.product_sn_id = record.lot_id.id
else:
if obj:
obj.product_sn_id = record.lot_id.id
if record.product_id.tracking == 'serial':
shelf_location_obj = self.env['sf.shelf.location'].search(
[('product_sn_id', '=', record.lot_id.id)])
if shelf_location_obj:
shelf_location_obj.product_sn_id = False
if obj:
obj.product_sn_id = record.lot_id.id
else:
if obj:
obj.product_sn_id = record.lot_id.id
elif record.product_id.tracking == 'lot':
self.put_shelf_location(record)
if not obj.product_id:
obj.product_id = record.product_id.id
else:
if obj:
obj.product_id = record.product_id.id
@@ -853,6 +886,47 @@ class Sf_stock_move_line(models.Model):
raise ValidationError(
'%s】货位已经被占用,请重新选择!!!' % item.destination_location_id.barcode)
def put_shelf_location(self, vals):
"""
对货位的批量数据进行数量计算
"""
for record in vals:
if record.lot_id and record.product_id.tracking == 'lot':
if record.current_location_id:
location_lot = self.env['sf.shelf.location.lot'].sudo().search(
[('shelf_location_id', '=', record.current_location_id.id), ('lot_id', '=', record.lot_id.id)])
if location_lot:
location_lot.qty -= record.qty_done
if location_lot.qty == 0:
location_lot.unlink()
elif location_lot.qty < 0:
raise ValidationError('%s】货位【%s】批次的【%s】产品数量不足!' % (
record.current_location_id.barcode, record.lot_id.name, record.product_id.name))
else:
raise ValidationError('%s】货位不存在【%s】批次的【%s】产品' % (
record.current_location_id.barcode, record.lot_id.name, record.product_id.name))
if record.destination_location_id:
location_lot = self.env['sf.shelf.location.lot'].sudo().search(
[('shelf_location_id', '=', record.destination_location_id.id),
('lot_id', '=', record.lot_id.id)])
if location_lot:
location_lot.qty += record.qty_done
else:
self.env['sf.shelf.location.lot'].sudo().create({
'shelf_location_id': record.destination_location_id.id,
'lot_id': record.lot_id.id,
'qty': record.qty_done
})
if not record.destination_location_id.product_id:
record.destination_location_id.product_id = record.product_id.id
@api.model_create_multi
def create(self, vals_list):
records = super(SfStockMoveLine, self).create(vals_list)
self.put_shelf_location(records)
return records
class SfStockPicking(models.Model):
_inherit = 'stock.picking'
@@ -916,6 +990,9 @@ class SfStockPicking(models.Model):
if move and move.product_id.cutting_tool_material_id.name == '刀柄' or '托盘' in (
move.product_id.fixture_material_id.name or ''):
for item in move.move_line_nosuggest_ids:
if item.rfid:
if self.env['stock.lot'].search([('rfid', '=', item.rfid)]):
raise ValidationError('该Rfid【%s】在系统中已经存在,请重新录入!' % item.rfid)
if item.location_dest_id.name == '进货':
if not item.rfid:
raise ValidationError('你需要提供%s的Rfid' % move.product_id.name)

View File

@@ -1,7 +1,9 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_sf_shelf_location_group_sf_stock_user_group_sf_stock_user,sf.shelf.location,model_sf_shelf_location,sf_base.group_sf_stock_user,1,0,0,0
access_sf_shelf_location_lot_group_sf_stock_user_group_sf_stock_user,sf.shelf.location.lot,model_sf_shelf_location_lot,sf_base.group_sf_stock_user,1,0,0,0
access_sf_shelf_location_group_sf_stock_manager,sf.shelf.location,model_sf_shelf_location,sf_base.group_sf_stock_manager,1,1,1,0
access_sf_shelf_location_lot_group_sf_stock_manager,sf.shelf.location.lot,model_sf_shelf_location_lot,sf_base.group_sf_stock_manager,1,1,1,0
access_sf_shelf_group_sf_stock_user_group_sf_stock_user,sf.shelf.group.sf.stock.user,model_sf_shelf,sf_base.group_sf_stock_user,1,0,0,0
access_sf_shelf_group_sf_stock_manager,sf.shelf.group.sf.stock.manager,model_sf_shelf,sf_base.group_sf_stock_manager,1,1,1,0
@@ -101,6 +103,7 @@ access_stock_replenish_option_group_sf_stock_user,stock.replenishment.option,sto
access_mrp_production_group_sf_stock_user,mrp.production,mrp.model_mrp_production,sf_base.group_sf_stock_user,1,1,1,0
access_sf_shelf_location_group_plan_dispatch,sf.shelf.location,model_sf_shelf_location,sf_base.group_plan_dispatch,1,0,0,0
access_sf_shelf_location_lot_group_plan_dispatch,sf.shelf.location.lot,model_sf_shelf_location_lot,sf_base.group_plan_dispatch,1,0,0,0
access_stock_move,stock.move,stock.model_stock_move,sf_base.group_plan_dispatch,1,1,1,0
access_stock_picking_group_plan_dispatch,stock.picking,stock.model_stock_picking,sf_base.group_plan_dispatch,1,0,0,0
access_stock_lot_group_plan_dispatch,stock.lot,stock.model_stock_lot,sf_base.group_plan_dispatch,1,0,0,0
@@ -142,6 +145,9 @@ access_sf_shelf_location_wizard_group_sf_stock_manager,sf_shelf_location_wizard_
access_sf_shelf_location_group_sf_tool_user,sf.shelf.location.group_sf_tool_user,model_sf_shelf_location,sf_base.group_sf_tool_user,1,1,0,0
access_sf_shelf_group_user,sf.shelf.location.group_user,model_sf_shelf_location,base.group_user,1,1,0,0
access_sf_shelf_location_lot_group_sf_tool_user,sf.shelf.location.lot.group_sf_tool_user,model_sf_shelf_location_lot,sf_base.group_sf_tool_user,1,1,0,0
access_sf_shelf_lot_group_user,sf.shelf.location.lot.group_user,model_sf_shelf_location_lot,base.group_user,1,1,0,0
access_ir_model_group_sf_stock_user,ir_model_group_sf_stock_user,base.model_ir_model,sf_base.group_sf_stock_user,1,1,0,0
access_mrp_workorder_group_sf_stock_user,mrp_workorder_group_sf_stock_user,mrp.model_mrp_workorder,sf_base.group_sf_stock_user,1,0,0,0
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
2 access_sf_shelf_location_group_sf_stock_user_group_sf_stock_user sf.shelf.location model_sf_shelf_location sf_base.group_sf_stock_user 1 0 0 0
3 access_sf_shelf_location_group_sf_stock_manager access_sf_shelf_location_lot_group_sf_stock_user_group_sf_stock_user sf.shelf.location sf.shelf.location.lot model_sf_shelf_location model_sf_shelf_location_lot sf_base.group_sf_stock_manager sf_base.group_sf_stock_user 1 1 0 1 0 0
4 access_sf_shelf_location_group_sf_stock_manager sf.shelf.location model_sf_shelf_location sf_base.group_sf_stock_manager 1 1 1 0
5 access_sf_shelf_group_sf_stock_user_group_sf_stock_user access_sf_shelf_location_lot_group_sf_stock_manager sf.shelf.group.sf.stock.user sf.shelf.location.lot model_sf_shelf model_sf_shelf_location_lot sf_base.group_sf_stock_user sf_base.group_sf_stock_manager 1 0 1 0 1 0
6 access_sf_shelf_group_sf_stock_user_group_sf_stock_user sf.shelf.group.sf.stock.user model_sf_shelf sf_base.group_sf_stock_user 1 0 0 0
7 access_sf_shelf_group_sf_stock_manager sf.shelf.group.sf.stock.manager model_sf_shelf sf_base.group_sf_stock_manager 1 1 1 0
8 access_procurement_group procurement.group stock.model_procurement_group base.group_user 1 1 1 0
9 access_stock_warehouse_manager_group_sf_stock_user stock.warehouse.manager stock.model_stock_warehouse sf_base.group_sf_stock_user 1 1 1 0
103 access_stock_picking_group_plan_dispatch access_stock_move stock.picking stock.move stock.model_stock_picking stock.model_stock_move sf_base.group_plan_dispatch 1 0 1 0 1 0
104 access_stock_lot_group_plan_dispatch access_stock_picking_group_plan_dispatch stock.lot stock.picking stock.model_stock_lot stock.model_stock_picking sf_base.group_plan_dispatch 1 0 0 0
105 access_stock_lot_group_plan_director access_stock_lot_group_plan_dispatch stock.lot stock.model_stock_lot sf_base.group_plan_director sf_base.group_plan_dispatch 1 1 0 1 0 0
106 access_stock_lot_group_plan_director stock.lot stock.model_stock_lot sf_base.group_plan_director 1 1 1 0
107 access_stock_warehouse_orderpoint stock.warehouse.orderpoint stock.model_stock_warehouse_orderpoint sf_base.group_plan_dispatch 1 1 0 0
108 access_stock_inventory_conflict stock.inventory.conflict stock.model_stock_inventory_conflict sf_base.group_plan_dispatch 1 0 0 0
109 access_stock_inventory_warning stock.inventory.warning stock.model_stock_inventory_warning sf_base.group_plan_dispatch 1 0 0 0
145
146
147
148
149
150
151
152
153

View File

@@ -133,9 +133,11 @@
type="action"
context="{'default_name':name,
'default_current_name':name,
'default_current_product_sn_ids':product_sn_ids,
'default_lot_id':product_sn_id,
'default_current_shelf_id':shelf_id,
'default_current_location_id':location_id,
'default_current_barcode':barcode,
'default_current_barcode_id':id,
'default_current_product_id':product_id,
}"
class="btn-primary" attrs="{'invisible':[('location_status','!=','占用')]}"/>
@@ -169,8 +171,16 @@
<field name="name" readonly="1"/>
<field name="shelf_id" readonly="1"/>
<field name="location_id" readonly="1"/>
<field name="product_sn_id" options="{'no_create': True}"/>
<field name="product_id"/>
<field name="product_sn_id" options="{'no_create': True}"
attrs="{'invisible': [('product_sn_ids', '!=', [])]}"/>
<field name="product_sn_ids"
attrs="{'invisible': [('product_sn_ids', '=', [])]}">
<tree edit="1" create="0" delete="0" editable="bottom">
<field name="lot_id" readonly="1"/>
<field name="qty" readonly="1"/>
</tree>
</field>
<field name="product_num" readonly="1"/>
<field name="location_status"/>
<field name="storage_time" widget="datetime"/>

View File

@@ -8,17 +8,23 @@ class ShelfLocationWizard(models.TransientModel):
name = fields.Char('')
current_location_id = fields.Many2one('stock.location', string='所属库区', readonly=True)
lot_id = fields.Many2one('stock.lot', string="序列号", readonly=True)
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_barcode_id = fields.Many2one('sf.shelf.location', string='当前货位编码', readonly=True)
current_name = fields.Char('当前货位名称', readonly=True)
current_product_id = fields.Many2one('product.product', string='产品', readonly=True)
current_product_sn_ids = fields.Many2many('sf.shelf.location.lot', 'shelf_location_wizard', string='产品批次号',
readonly=True)
destination_location_id = fields.Many2one('stock.location', string='目标库区', compute='_compute_destination_name')
destination_shelf_id = fields.Many2one('sf.shelf', string='目标货架', compute='_compute_destination_name')
destination_barcode_id = fields.Many2one('sf.shelf.location', string='目标货位编码', required=True,
domain="")
domain="[('product_id', 'in', (False, current_product_id))]")
destination_name = fields.Char('目标货位名称', compute='_compute_destination_name')
destination_product_sn_ids = fields.Many2many('sf.shelf.location.lot', 'shelf_location_wizard', string='批次号',
domain="[('shelf_location_id', '=', current_barcode_id)]")
def return_domain(self):
val = [('location_status', '=', '空闲')]
@@ -32,9 +38,11 @@ class ShelfLocationWizard(models.TransientModel):
def _compute_destination_name(self):
if self.destination_barcode_id:
self.destination_name = self.destination_barcode_id.name
self.destination_location_id = self.destination_barcode_id.location_id.id
self.destination_shelf_id = self.destination_barcode_id.shelf_id.id
else:
self.destination_name = ''
self.destination_location_id = False
self.destination_shelf_id = False
#
@@ -43,22 +51,46 @@ class ShelfLocationWizard(models.TransientModel):
# 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.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
def create_stock_moves(self, lot_id, num):
# 创建产品货位变更的库存移动记录
stock_move_id = self.env['stock.move'].sudo().create({
'name': 'HWBG/%s' % self.id,
'product_id': self.current_product_id.id,
'location_id': self.current_location_id.id,
'location_dest_id': self.destination_location_id.id,
'product_uom_qty': num,
'state': 'done'
})
# 创建移动历史记录
stock_move_line_id = self.env['stock.move.line'].sudo().create({
'product_id': self.current_product_id.id,
'lot_id': lot_id.id,
'move_id': stock_move_id.id,
'current_location_id': self.current_barcode_id.id,
'destination_location_id': self.destination_barcode_id.id,
'install_tool_time': fields.Datetime.now(),
'qty_done': num,
'state': 'done'
})
shelf_location.product_sn_id = False
shelf_location.product_id = False
shelf_location.product_num = 0
return stock_move_id, stock_move_line_id
def confirm_the_change(self):
if self.destination_barcode_id:
if self.lot_id:
self.current_barcode_id.product_sn_id = False
self.destination_barcode_id.product_sn_id = self.lot_id.id
self.create_stock_moves(self.lot_id, 1)
elif self.current_product_sn_ids:
for current_product_sn_id in self.current_product_sn_ids:
self.create_stock_moves(current_product_sn_id.lot_id, current_product_sn_id.qty_num)
current_product_sn_id.write({
'qty_num': 0
})
else:
raise ValidationError('没有需要变更的批次/序列号!')
else:
raise ValidationError('目标货位出错,请联系管理员!')
raise ValidationError('请选择目标货位编码!')
# 关闭弹出窗口
return {'type': 'ir.actions.act_window_close'}

View File

@@ -6,27 +6,45 @@
<field name="arch" type="xml">
<form string="货位变更">
<sheet>
<group>
<group col="1">
<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>
<field name="current_barcode_id" string="编码"/>
<field name="lot_id" attrs="{'invisible': [('lot_id', '=', False)]}"/>
</group>
<field name="current_product_sn_ids"
attrs="{'invisible': [('current_product_sn_ids', '=', [])]}">
<tree edit="1" create="0" delete="0" editable="bottom">
<field name="lot_id" readonly="1"/>
<field name="qty" readonly="1"/>
</tree>
</field>
</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_location_id"/>
<field name="destination_shelf_id" string="货架" options="{'no_create': True}"/>
<field name="destination_name" string="名称"/>
<field name="current_product_id" invisible="1"/>
</group>
<group>
<field name="destination_barcode_id" string="编码" options="{'no_create': True}"
placeholder="请选择目标货位"/>
<field name="lot_id" attrs="{'invisible': [('lot_id', '=', False)]}"/>
</group>
</group>
<field name="destination_product_sn_ids"
attrs="{'invisible': [('current_product_sn_ids', '=', [])]}">
<tree edit="1" create="0" delete="1" editable="bottom">
<field name="lot_id" readonly="1"/>
<field name="qty_num"/>
</tree>
</field>
</group>
</sheet>
<footer>