From 2c1a101c24efd94d9eff4f15542a260a7bf0e06f Mon Sep 17 00:00:00 2001 From: mgw <1392924357@qq.com> Date: Tue, 28 Nov 2023 16:42:19 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BA=93=E5=AD=98=E8=B4=A7=E6=9E=B6=E8=B4=A7?= =?UTF-8?q?=E4=BD=8D=E4=BF=AE=E6=94=B9=E5=9F=BA=E6=9C=AC=E5=AE=8C=E6=88=90?= =?UTF-8?q?=EF=BC=8C=E6=8E=A8=E9=80=81=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_warehouse/__manifest__.py | 1 + sf_warehouse/models/model.py | 185 +++++++++++++++--- .../views/change_stock_move_views.xml | 41 ++++ sf_warehouse/views/shelf_location.xml | 183 ++++++++--------- sf_warehouse/views/view.xml | 6 +- 5 files changed, 279 insertions(+), 137 deletions(-) create mode 100644 sf_warehouse/views/change_stock_move_views.xml diff --git a/sf_warehouse/__manifest__.py b/sf_warehouse/__manifest__.py index 0f241b90..45143693 100644 --- a/sf_warehouse/__manifest__.py +++ b/sf_warehouse/__manifest__.py @@ -16,6 +16,7 @@ 'security/ir.model.access.csv', 'views/view.xml', 'views/shelf_location.xml', + 'views/change_stock_move_views.xml', ], 'demo': [ ], diff --git a/sf_warehouse/models/model.py b/sf_warehouse/models/model.py index 5e83ff1f..29b8aa2e 100644 --- a/sf_warehouse/models/model.py +++ b/sf_warehouse/models/model.py @@ -185,33 +185,29 @@ class SfLocation(models.Model): """ 当仓库类型为货架时,自动生成其下面的货位,数量为货架层数*层数容量 """ - if self.location_type == '货架': - for i in range(self.shelf_layer): - for j in range(self.layer_capacity): - self.create({ - 'name': self.name + '-' + str(i + 1) + '层' + '-' + str(j + 1) + '位置', - 'location_id': self.id, - 'location_type': '货位', - 'barcode': self.generate_barcode(i, j), - 'location_status': '空闲' - }) + pass + # if self.location_type == '货架': + # for i in range(self.shelf_layer): + # for j in range(self.layer_capacity): + # self.create({ + # 'name': self.name + '-' + str(i + 1) + '层' + '-' + str(j + 1) + '位置', + # 'location_id': self.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 - - # def generate_barcode(self, i, j): - # # 这里是你生成barcode的代码 - # area_type_barcode = self.location_id.barcode - # return area_type_barcode + self.channel + self.direction + '-' + self.barcode + '-' + str(i + 1) + '-' - # + str(j + 1) + pass + # # 这里是你生成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): @@ -227,9 +223,12 @@ class ShelfLocation(models.Model): ('货位', '货位') ], string='存储类型') # 绑定库区 + shelf_location_id = fields.Many2one('stock.location', string='所属库区', domain=[('location_type', '=', '库区')]) location_id = fields.Many2one('stock.location', string='所属库区', domain=[('location_type', '=', '库区')]) # 产品类别 (关联:product.category) - product_type = fields.Many2many('product.category', string='产品类别') + # 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([ @@ -253,6 +252,16 @@ class ShelfLocation(models.Model): hide_shelf = fields.Boolean(compute='_compute_hide_what', string='隐藏货架') hide_location = fields.Boolean(compute='_compute_hide_what', string='隐藏货位') + @api.onchange('shelf_location_id') + def _onchange_shelf_location_id(self): + """ + 根据货架的所属库区修改货位的所属库区 + """ + 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): """ @@ -264,7 +273,7 @@ class ShelfLocation(models.Model): record.location_status = '占用' else: record.product_id = False - # record.location_status = '空闲' + record.location_status = '空闲' @api.depends('location_type') def _compute_hide_what(self): @@ -292,10 +301,10 @@ class ShelfLocation(models.Model): for j in range(self.layer_capacity): self.create({ 'name': self.name + '-' + str(i + 1) + '层' + '-' + str(j + 1) + '位置', - 'location_id': self.id, + 'location_id': self.shelf_location_id.id, 'location_type': '货位', 'barcode': self.generate_barcode(i, j), - 'location_status': '空闲' + 'location_status': '空闲', }) def generate_barcode(self, i, j): @@ -309,11 +318,125 @@ class ShelfLocation(models.Model): j_str = str(j + 1).zfill(3) # 确保是两位数,如果不足两位,左侧补0 return area_type_barcode + self.channel + self.direction + '-' + self.barcode + '-' + i_str + '-' + j_str - # def generate_barcode(self, i, j): - # # 这里是你生成barcode的代码 - # area_type_barcode = self.location_id.barcode - # return area_type_barcode + self.channel + self.direction + '-' + self.barcode + '-' + str(i + 1) + '-' - # + str(j + 1) + +class Sf_stock_move_line(models.Model): + _inherit = 'stock.move.line' + + current_location_id = fields.Many2one( + 'sf.shelf.location', string='当前货位', compute='_compute_current_location_id', store=True) + # location_dest_id = fields.Many2one('stock.location', string='目标库位') + location_dest_id_product_type = fields.Many2many(related='location_dest_id.product_type') + location_dest_id_value = fields.Integer(compute='_compute_location_dest_id_value', store=True) + + # def button_test(self): + # print(self.picking_id.name) + # stock_picking = self.env['stock.picking'].search([('name', '=', self.picking_id.name)], limit=1) + # print(self.picking_id.name) + # print(aa.move_line_ids.lot_id.name) + # # 获取当前的stock.picking对象 + # current_picking = self.env['stock.picking'].search([('name', '=', self.picking_id.name)], limit=1) + # + # # 获取当前picking的第一个stock.move对象 + # current_move = current_picking.move_ids[0] if current_picking.move_ids else False + # + # # 如果存在相关的stock.move对象 + # if current_move: + # # 获取源stock.move对象 + # origin_move = current_move.move_orig_ids[0] if current_move.move_orig_ids else False + # + # # 从源stock.move对象获取源stock.picking对象 + # origin_picking = origin_move.picking_id if origin_move else False + # # 现在,origin_picking就是current_picking的上一步 + # # 获取目标stock.move对象 + # dest_move = current_move.move_dest_ids[0] if current_move.move_dest_ids else False + # + # # 从目标stock.move对象获取目标stock.picking对象 + # dest_picking = dest_move.picking_id if dest_move else False + # # 现在,dest_picking就是current_picking的下一步 + + @api.depends('location_id') + def _compute_current_location_id(self): + # for record in self: + # 获取当前的stock.picking对象 + current_picking = self.env['stock.picking'].search([('name', '=', self.picking_id.name)], limit=1) + + # 获取当前picking的第一个stock.move对象 + current_move = current_picking.move_ids[0] if current_picking.move_ids else False + + # 如果存在相关的stock.move对象 + if current_move: + # 获取源stock.move对象 + origin_move = current_move.move_orig_ids[0] if current_move.move_orig_ids else False + + # 从源stock.move对象获取源stock.picking对象 + origin_picking = origin_move.picking_id if origin_move else False + # 现在,origin_picking就是current_picking的上一步 + + # 如果前一个调拨单有目标货位,那么当前调拨单的当前货位就是前一个调拨单的目标货位 + if origin_picking: + for i in current_picking.move_line_ids: + for j in origin_picking.move_line_ids: + if j.destination_location_id: + if i.lot_id == j.lot_id: + i.current_location_id = j.destination_location_id + + # if origin_picking.move_line_ids.destination_location_id: + # aa = origin_picking.move_line_ids + # bb = origin_picking.move_line_ids.destination_location_id + # record.current_location_id = origin_picking.move_line_ids.destination_location_id + # + # # 获取目标stock.move对象 + # dest_move = current_move.move_dest_ids[0] if current_move.move_dest_ids else False + # + # # 从目标stock.move对象获取目标stock.picking对象 + # dest_picking = dest_move.picking_id if dest_move else False + # # 现在,dest_picking就是current_picking的下一步 + + # 是一张单据一张单据往下走的,所以这里的目标货位是上一张单据的当前货位,且这样去计算是可以的。 + @api.depends('location_dest_id') + def _compute_location_dest_id_value(self): + for record in self: + record.location_dest_id_value = record.location_dest_id.id if record.location_dest_id else False + + destination_location_id = fields.Many2one( + 'sf.shelf.location', string='目标货位') + + @api.onchange('destination_location_id') + def _compute_destination_location_id(self): + for record in self: + 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 + # obj = self.env['sf.shelf.location'].search([('location_id', '=', + # self.destination_location_id.id)]) + obj = self.env['sf.shelf.location'].search([('name', '=', + self.destination_location_id.name)]) + if obj: + obj.product_sn_id = record.lot_id.id + else: + pass + else: + obj = self.env['sf.shelf.location'].search([('name', '=', + self.destination_location_id.name)]) + if obj: + obj.product_sn_id = record.lot_id.id + + +class SfStockPicking(models.Model): + _inherit = 'stock.picking' + + def button_validate(self): + """ + 重写验证方法,当验证时意味着调拨单已经完成,已经移动到了目标货位,所以需要将当前货位的状态改为空闲 + """ + res = super(SfStockPicking, self).button_validate() + for line in self.move_line_ids: + if line: + if line.current_location_id: + line.current_location_id.product_sn_id = False + line.current_location_id = False + return res class SfProcurementGroup(models.Model): diff --git a/sf_warehouse/views/change_stock_move_views.xml b/sf_warehouse/views/change_stock_move_views.xml new file mode 100644 index 00000000..d0999a7b --- /dev/null +++ b/sf_warehouse/views/change_stock_move_views.xml @@ -0,0 +1,41 @@ + + + + + sf.stock.move.line.tree + stock.move.line + + + + + + + + + + + + + + + + + sf.stock.move.line.form + stock.move.line + + + + + + + + + + + + + diff --git a/sf_warehouse/views/shelf_location.xml b/sf_warehouse/views/shelf_location.xml index a7ef00d9..458db805 100644 --- a/sf_warehouse/views/shelf_location.xml +++ b/sf_warehouse/views/shelf_location.xml @@ -28,15 +28,18 @@ - + + - + - + + + @@ -44,108 +47,49 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + shelf.location.kanban + sf.shelf.location + + + + +
+ +
+
+ +
+
+ +
+ +
+
+ + | + +
+
+
- + - + - + @@ -156,17 +100,50 @@ - - - - +
+
+
+
- - - - - - + + + shelf.location.search + sf.shelf.location + + + + + + + + + 货架货位 + ir.actions.act_window + sf.shelf.location + kanban,form + [('location_type', '=', '货位')] + + + + + + + + + + + + + + + + 货架货位 diff --git a/sf_warehouse/views/view.xml b/sf_warehouse/views/view.xml index 93e55dfb..b80177bc 100644 --- a/sf_warehouse/views/view.xml +++ b/sf_warehouse/views/view.xml @@ -158,9 +158,9 @@ - + + +