From 961b4f8e2df39afe8a9b795689eb2a99a0db3c87 Mon Sep 17 00:00:00 2001
From: mgw <1392924357@qq.com>
Date: Tue, 9 Apr 2024 15:21:47 +0800
Subject: [PATCH 1/2] =?UTF-8?q?=E5=BA=93=E5=AD=98=E9=9C=80=E6=B1=82?=
=?UTF-8?q?=E4=BF=AE=E6=94=B91?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
sf_warehouse/models/model.py | 57 +++++++++++++------
.../views/change_stock_move_views.xml | 16 ++++--
sf_warehouse/views/shelf_location.xml | 1 +
3 files changed, 52 insertions(+), 22 deletions(-)
diff --git a/sf_warehouse/models/model.py b/sf_warehouse/models/model.py
index 347fd658..63a02e0d 100644
--- a/sf_warehouse/models/model.py
+++ b/sf_warehouse/models/model.py
@@ -310,7 +310,7 @@ class SfShelf(models.Model):
class ShelfLocation(models.Model):
_name = 'sf.shelf.location'
_description = '货位'
- _order = 'create_date desc'
+ _order = 'id asc, create_date asc'
# current_location_id = fields.Many2one('sf.shelf.location', string='当前位置')
# # 目的位置
@@ -363,8 +363,10 @@ class ShelfLocation(models.Model):
('禁用', '禁用')
], string='货位状态', default='空闲', readonly=True)
# product_id = fields.Many2one('product.template', string='产品')
- product_id = fields.Many2one('product.product', string='产品', readonly=True)
+ product_id = fields.Many2one('product.product', string='产品', compute='_compute_product_id', store=True)
product_sn_id = fields.Many2one('stock.lot', string='产品序列号')
+ # 产品数量
+ product_num = fields.Integer('数量')
# 修改货位状态为禁用
def action_location_status_disable(self):
@@ -381,12 +383,20 @@ class ShelfLocation(models.Model):
"""
for record in self:
if record.product_sn_id:
- record.sudo().product_id = record.product_sn_id.product_id
- record.sudo().location_status = '占用'
+ try:
+ record.sudo().product_id = record.product_sn_id.product_id
+ record.sudo().location_status = '占用'
+ record.sudo().product_num = 1
+ except Exception as e:
+ print('eeeeeee占用', e)
else:
- record.product_id = False
- # record.location_status = '空闲'
+ try:
+ record.sudo().product_id = False
+ record.sudo().location_status = '空闲'
+ record.sudo().product_num = 0
+ except Exception as e:
+ print('eeeeeee空闲', e)
# 调取获取货位信息接口
def get_sf_shelf_location_info(self):
@@ -423,6 +433,8 @@ class Sf_stock_move_line(models.Model):
location_dest_id_value = fields.Integer(compute='_compute_location_dest_id_value', store=True)
# lot_qr_code = fields.Binary(string='二维码', compute='_compute_lot_qr_code', store=True)
lot_qr_code = fields.Binary(string='二维码', compute='_compute_lot_qr_code', store=True)
+ current_product_id = fields.Integer(compute='_compute_location_dest_id_value', store=True)
+ there_is_no_sn = fields.Boolean('是否有序列号', default=False)
def action_revert_inventory(self):
# 检查用户是否有执行操作的权限
@@ -692,6 +704,7 @@ class Sf_stock_move_line(models.Model):
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
+ record.current_product_id = record.product_id.id if record.product_id else False
destination_location_id = fields.Many2one(
'sf.shelf.location', string='目标货位')
@@ -699,23 +712,31 @@ class Sf_stock_move_line(models.Model):
@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
+ 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
+ # 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:
- pass
+ obj = self.env['sf.shelf.location'].search([('name', '=',
+ self.destination_location_id.name)])
+ if obj:
+ obj.product_sn_id = record.lot_id.id
else:
obj = self.env['sf.shelf.location'].search([('name', '=',
self.destination_location_id.name)])
if obj:
- obj.product_sn_id = record.lot_id.id
+ obj.product_id = record.product_id.id
+ obj.location_status = '占用'
+ obj.product_num = record.reserved_uom_qty
class SfStockPicking(models.Model):
diff --git a/sf_warehouse/views/change_stock_move_views.xml b/sf_warehouse/views/change_stock_move_views.xml
index cc4213c6..c9db5059 100644
--- a/sf_warehouse/views/change_stock_move_views.xml
+++ b/sf_warehouse/views/change_stock_move_views.xml
@@ -10,10 +10,18 @@
-
+
+
+
+
+
+
+
+
+
+
diff --git a/sf_warehouse/views/shelf_location.xml b/sf_warehouse/views/shelf_location.xml
index 49fdf42e..9cd4446a 100644
--- a/sf_warehouse/views/shelf_location.xml
+++ b/sf_warehouse/views/shelf_location.xml
@@ -149,6 +149,7 @@
+
From 310a2de34f5e8a8fb2abfca022c0aa27be6b2c01 Mon Sep 17 00:00:00 2001
From: mgw <1392924357@qq.com>
Date: Tue, 9 Apr 2024 20:14:44 +0800
Subject: [PATCH 2/2] =?UTF-8?q?=E5=BC=80=E5=AE=8C=E5=BA=93=E5=AD=98?=
=?UTF-8?q?=E5=A4=84=E6=96=B0=E5=A2=9E=E9=9C=80=E6=B1=82=E5=9F=BA=E6=9C=AC?=
=?UTF-8?q?=E5=AE=8C=E6=88=90?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
sf_warehouse/models/model.py | 27 +++++++++++++++++++--------
1 file changed, 19 insertions(+), 8 deletions(-)
diff --git a/sf_warehouse/models/model.py b/sf_warehouse/models/model.py
index 63a02e0d..1e1d8328 100644
--- a/sf_warehouse/models/model.py
+++ b/sf_warehouse/models/model.py
@@ -132,7 +132,7 @@ class SfLocation(models.Model):
for record in self:
if record.product_sn_id:
record.product_id = record.product_sn_id.product_id
- record.location_status = '占用'
+ # record.location_status = '占用'
else:
record.product_id = False
# record.location_status = '空闲'
@@ -361,13 +361,21 @@ class ShelfLocation(models.Model):
('空闲', '空闲'),
('占用', '占用'),
('禁用', '禁用')
- ], string='货位状态', default='空闲', readonly=True)
+ ], string='货位状态', default='空闲', compute='_compute_product_num', store=True)
# 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_num = fields.Integer('数量')
+ @api.depends('product_num')
+ def _compute_product_num(self):
+ for record in self:
+ if record.product_num > 0:
+ record.location_status = '占用'
+ elif record.product_num == 0:
+ record.location_status = '空闲'
+
# 修改货位状态为禁用
def action_location_status_disable(self):
self.location_status = '禁用'
@@ -385,7 +393,7 @@ class ShelfLocation(models.Model):
if record.product_sn_id:
try:
record.sudo().product_id = record.product_sn_id.product_id
- record.sudo().location_status = '占用'
+ # record.sudo().location_status = '占用'
record.sudo().product_num = 1
except Exception as e:
print('eeeeeee占用', e)
@@ -393,7 +401,7 @@ class ShelfLocation(models.Model):
else:
try:
record.sudo().product_id = False
- record.sudo().location_status = '空闲'
+ # record.sudo().location_status = '空闲'
record.sudo().product_num = 0
except Exception as e:
print('eeeeeee空闲', e)
@@ -735,8 +743,8 @@ class Sf_stock_move_line(models.Model):
self.destination_location_id.name)])
if obj:
obj.product_id = record.product_id.id
- obj.location_status = '占用'
- obj.product_num = record.reserved_uom_qty
+ # obj.location_status = '占用'
+ obj.product_num += record.reserved_uom_qty
class SfStockPicking(models.Model):
@@ -761,8 +769,11 @@ class SfStockPicking(models.Model):
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.location_status = '空闲'
+ if line.current_location_id.product_sn_id:
+ line.current_location_id.product_sn_id = False
+ # line.current_location_id.location_status = '空闲'
+ line.current_location_id.product_num = 0
+
return res
# def print_all_barcode(self):