diff --git a/sf_warehouse/models/model.py b/sf_warehouse/models/model.py index 02c52392..14db4f8d 100644 --- a/sf_warehouse/models/model.py +++ b/sf_warehouse/models/model.py @@ -223,9 +223,82 @@ class SfLocation(models.Model): # return area_type_barcode + self.channel + self.direction + '-' + self.barcode + '-' + i_str + '-' + j_str +class SfShelf(models.Model): + _name = 'sf.shelf' + _description = '货架' + _order = 'name' + + name = fields.Char('货架名称', required=True, size=20) + barcode = fields.Char('编码', copy=False, size=15, required=True) + # 货位 + location_ids = fields.One2many('sf.shelf.location', 'shelf_id', string='货位') + + check_state = fields.Selection([ + ('enable', '启用'), + ('close', '关闭') + ], string='审核状态', default='close') + + def action_check(self): + self.check_state = 'enable' + + # 绑定库区 + shelf_location_id = fields.Many2one('stock.location', string='所属库区') + + # 货架独有字段:通道、方向、货架高度(m)、货架层数、层数容量 + channel = fields.Char(string='通道', required=True, size=10) + direction = fields.Selection([ + ('R', 'R'), + ('L', 'L') + ], string='方向', required=True) + shelf_height = fields.Float(string='货架高度(m)') + shelf_layer = fields.Integer(string='货架层数') + layer_capacity = fields.Integer(string='层数容量') + + @api.onchange('shelf_location_id') + def _onchange_shelf_location_id(self): + """ + 根据货架的所属库区修改货位的所属库区 + """ + if self.name: + all_location = self.env['sf.shelf.location'].search([('name', 'ilike', self.name)]) + for record in self: + for location in all_location: + location.location_id = record.shelf_location_id.id + + def create_location(self): + """ + 当仓库类型为货架时,自动生成其下面的货位,数量为货架层数*层数容量 + """ + area_obj = self.env['sf.shelf.location'] + for i in range(self.shelf_layer): + for j in range(self.layer_capacity): + location_name = self.name + '-' + str(i + 1) + '层' + '-' + str(j + 1) + '位置' + # 检查是否已经有同名的位置存在 + existing_location = area_obj.search([('name', '=', location_name)]) + if not existing_location: + area_obj.create({ + 'name': location_name, + 'location_id': self.shelf_location_id.id, + 'barcode': self.generate_barcode(i, j), + 'location_status': '空闲', + 'shelf_id': self.id + }) + + def generate_barcode(self, i, j): + """ + 生成货位条码 + """ + # 这里是你生成barcode的代码 + # area_type_barcode = self.location_id.barcode + area_type_barcode = self.barcode + i_str = str(i + 1).zfill(3) # 确保是两位数,如果不足两位,左侧补0 + j_str = str(j + 1).zfill(3) # 确保是两位数,如果不足两位,左侧补0 + return area_type_barcode + self.channel + self.direction + '-' + self.barcode + '-' + i_str + '-' + j_str + + class ShelfLocation(models.Model): _name = 'sf.shelf.location' - _description = '货架货位' + _description = '货位' _order = 'name' # current_location_id = fields.Many2one('sf.shelf.location', string='当前位置') @@ -245,8 +318,10 @@ class ShelfLocation(models.Model): if record.location_status == '禁用': record.storage_time = False - name = fields.Char('名称', required=True, size=20) - barcode = fields.Char('编码', copy=False, size=15) + name = fields.Char('货位名称', required=True, size=20) + barcode = fields.Char('货位编码', copy=False, size=15) + # 货架 + shelf_id = fields.Many2one('sf.shelf', string='货架') check_state = fields.Selection([ ('enable', '启用'), @@ -256,27 +331,18 @@ class ShelfLocation(models.Model): def action_check(self): self.check_state = 'enable' - # 仓库类别(selection:库区、库位、货位) - location_type = fields.Selection([ - ('货架', '货架'), - ('货位', '货位') - ], string='存储类型') + # # 仓库类别(selection:库区、库位、货位) + # location_type = fields.Selection([ + # ('货架', '货架'), + # ('货位', '货位') + # ], string='存储类型') # 绑定库区 - shelf_location_id = fields.Many2one('stock.location', string='所属库区', domain=[('location_type', '=', '库区')]) - location_id = fields.Many2one('stock.location', string='所属库区', domain=[('location_type', '=', '库区')]) + # shelf_location_id = fields.Many2one('stock.location', string='所属库区', domain=[('location_type', '=', '库区')]) + location_id = fields.Many2one('stock.location', string='所属库区') # 产品类别 (关联:product.category) # product_type = fields.Many2many('product.category', string='产品类别') # picking_product_type = fields.Many2many('stock.picking', string='调拨产品类别', related='location_dest_id.product_type') - # 货架独有字段:通道、方向、货架高度(m)、货架层数、层数容量 - channel = fields.Char(string='通道') - direction = fields.Selection([ - ('R', 'R'), - ('L', 'L') - ], string='方向') - shelf_height = fields.Float(string='货架高度(m)') - shelf_layer = fields.Integer(string='货架层数') - layer_capacity = fields.Integer(string='层数容量') # 货位独有字段:货位状态、产品(关联产品对象)、产品序列号(关联产品序列号对象) location_status = fields.Selection([ @@ -288,9 +354,6 @@ class ShelfLocation(models.Model): product_id = fields.Many2one('product.product', string='产品', compute='_compute_product_id', readonly=True) product_sn_id = fields.Many2one('stock.lot', string='产品序列号') - hide_shelf = fields.Boolean(compute='_compute_hide_what', string='隐藏货架') - hide_location = fields.Boolean(compute='_compute_hide_what', string='隐藏货位') - # 修改货位状态为禁用 def action_location_status_disable(self): self.location_status = '禁用' @@ -299,17 +362,6 @@ class ShelfLocation(models.Model): def action_location_status_enable(self): self.location_status = '空闲' - @api.onchange('shelf_location_id') - def _onchange_shelf_location_id(self): - """ - 根据货架的所属库区修改货位的所属库区 - """ - if self.name: - all_location = self.env['sf.shelf.location'].search([('name', 'ilike', self.name)]) - for record in self: - for location in all_location: - location.location_id = record.shelf_location_id.id - @api.depends('product_sn_id') def _compute_product_id(self): """ @@ -321,53 +373,7 @@ class ShelfLocation(models.Model): record.sudo().location_status = '占用' else: record.product_id = False - # record.location_status = '空闲' - - @api.depends('location_type') - def _compute_hide_what(self): - """ - 根据仓库类别,隐藏不需要的字段 - :return: - """ - for record in self: - record.sudo().hide_shelf = False - record.sudo().hide_location = False - if record.location_type and record.location_type == '货架': - record.sudo().hide_shelf = True - elif record.location_type and record.location_type == '货位': - record.sudo().hide_location = True - else: - pass - - def create_location(self): - """ - 当仓库类型为货架时,自动生成其下面的货位,数量为货架层数*层数容量 - """ - if self.location_type == '货架': - for i in range(self.shelf_layer): - for j in range(self.layer_capacity): - location_name = self.name + '-' + str(i + 1) + '层' + '-' + str(j + 1) + '位置' - # 检查是否已经有同名的位置存在 - existing_location = self.search([('name', '=', location_name)]) - if not existing_location: - self.create({ - 'name': location_name, - 'location_id': self.shelf_location_id.id, - 'location_type': '货位', - 'barcode': self.generate_barcode(i, j), - 'location_status': '空闲', - }) - - def generate_barcode(self, i, j): - """ - 生成货位条码 - """ - # 这里是你生成barcode的代码 - # area_type_barcode = self.location_id.barcode - area_type_barcode = self.barcode - i_str = str(i + 1).zfill(3) # 确保是两位数,如果不足两位,左侧补0 - j_str = str(j + 1).zfill(3) # 确保是两位数,如果不足两位,左侧补0 - return area_type_barcode + self.channel + self.direction + '-' + self.barcode + '-' + i_str + '-' + j_str + record.location_status = '空闲' class Sf_stock_move_line(models.Model): diff --git a/sf_warehouse/security/ir.model.access.csv b/sf_warehouse/security/ir.model.access.csv index f66fbbd6..1fa8570f 100644 --- a/sf_warehouse/security/ir.model.access.csv +++ b/sf_warehouse/security/ir.model.access.csv @@ -1,7 +1,9 @@ id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink -access_sf_shelf_location,sf.shelf.location,model_sf_shelf_location,sf_warehouse.group_sf_stock_user,1,0,0,0 -access_sf_shelf_location,sf.shelf.location,model_sf_shelf_location,sf_warehouse.group_sf_stock_manager,1,1,1,0 +access_sf_shelf_location_group_sf_stock_user,sf.shelf.location,model_sf_shelf_location,sf_warehouse.group_sf_stock_user,1,0,0,0 +access_sf_shelf_location_group_sf_stock_manager,sf.shelf.location,model_sf_shelf_location,sf_warehouse.group_sf_stock_manager,1,1,1,0 +access_sf_shelf_group_sf_stock_user,sf.shelf.group.sf.stock.user,model_sf_shelf,sf_warehouse.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_warehouse.group_sf_stock_manager,1,1,1,0 access_procurement_group,procurement.group,stock.model_procurement_group,base.group_user,1,1,1,0 access_stock_warehouse_manager,stock.warehouse.manager,stock.model_stock_warehouse,sf_warehouse.group_sf_stock_user,1,1,1,0 diff --git a/sf_warehouse/views/change_stock_move_views.xml b/sf_warehouse/views/change_stock_move_views.xml index 40294a20..e7d63d67 100644 --- a/sf_warehouse/views/change_stock_move_views.xml +++ b/sf_warehouse/views/change_stock_move_views.xml @@ -11,7 +11,6 @@ diff --git a/sf_warehouse/views/shelf_location.xml b/sf_warehouse/views/shelf_location.xml index ad72f2c3..ef5747e2 100644 --- a/sf_warehouse/views/shelf_location.xml +++ b/sf_warehouse/views/shelf_location.xml @@ -1,14 +1,77 @@ + + + Sf Shelf + sf.shelf + +
+
+
+ + + + + + + + + + + + + + + + + + + +
+
+
+ + + Sf Shelf tree + sf.shelf + + + + + + + + + + + + 货架 + ir.actions.act_window + sf.shelf + tree,form + + + + + + + Shelf Location tree sf.shelf.location - - - + + + @@ -56,20 +119,10 @@
-
@@ -91,31 +144,13 @@
- - - - - - - - - - - - - - - - - - + + + + + + +
@@ -134,13 +169,13 @@ #{record.location_status.raw_value == '空闲' ? 'kanban_color_1' : ''} #{record.location_status.raw_value == '占用' ? 'kanban_color_2' : ''} #{record.location_status.raw_value == '禁用' ? 'kanban_color_3' : ''}"> - +
- +
@@ -151,31 +186,31 @@ - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + +
@@ -186,10 +221,12 @@ shelf.location.search sf.shelf.location - + @@ -197,11 +234,11 @@
- 货架货位 + 货位看板 ir.actions.act_window sf.shelf.location kanban,form - [('location_type', '=', '货位'),('check_state','=','enable')] + @@ -223,7 +260,7 @@ groups="sf_warehouse.group_sf_stock_user"/> - 货架货位 + 货位 ir.actions.act_window sf.shelf.location tree,form @@ -246,8 +283,8 @@ -