diff --git a/yuthon_stock/models/inherit_stock_picking.py b/yuthon_stock/models/inherit_stock_picking.py
index d25969e31..c89c2099a 100644
--- a/yuthon_stock/models/inherit_stock_picking.py
+++ b/yuthon_stock/models/inherit_stock_picking.py
@@ -173,9 +173,73 @@ class StockPicking(models.Model):
record._compute_json_display()
return True
+ def action_update_name_by_products(self):
+ """批量更新入库单名称(根据产品生成)"""
+ updated_count = 0
+ for picking in self:
+ # 只处理入库单
+ if picking.picking_type_code == 'incoming' and picking.move_ids_without_package:
+ product_names = picking.move_ids_without_package.mapped('product_id.name')
+ if product_names:
+ products_str = '/'.join(product_names)
+ # 添加入库单ID确保唯一性
+ new_name = f"{products_str}的入库单-{picking.id}"
+ picking.write({'name': new_name})
+ updated_count += 1
+
+ # 返回提示消息
+ return {
+ 'type': 'ir.actions.client',
+ 'tag': 'display_notification',
+ 'params': {
+ 'title': '更新完成',
+ 'message': f'已成功更新 {updated_count} 条入库单的名称',
+ 'type': 'success',
+ 'sticky': False,
+ }
+ }
+
def action_acceptance(self):
"""验收按钮"""
self.ensure_one()
self.acceptance_date = fields.Datetime.now()
self.receipt_status = 'certification' # 状态变为证明
- return True
\ No newline at end of file
+ return True
+
+ @api.model_create_multi
+ def create(self, vals_list):
+ """重写create方法,根据产品生成入库单名称"""
+ pickings = super(StockPicking, self).create(vals_list)
+
+ for picking in pickings:
+ # 只处理入库单(picking_type_code为incoming)
+ if picking.picking_type_code == 'incoming' and picking.move_ids_without_package:
+ # 获取所有产品名称
+ product_names = picking.move_ids_without_package.mapped('product_id.name')
+ if product_names:
+ # 用/连接产品名称
+ products_str = '/'.join(product_names)
+ # 生成新的name格式:产品/产品/产品的入库单-ID(确保唯一性)
+ new_name = f"{products_str}的入库单-{picking.id}"
+ # 更新name字段
+ picking.write({'name': new_name})
+
+ return pickings
+
+ def write(self, vals):
+ """重写write方法,当产品变化时更新入库单名称"""
+ result = super(StockPicking, self).write(vals)
+
+ # 如果修改了move_ids相关字段,更新name
+ if 'move_ids_without_package' in vals or 'move_ids' in vals:
+ for picking in self:
+ if picking.picking_type_code == 'incoming' and picking.move_ids_without_package:
+ product_names = picking.move_ids_without_package.mapped('product_id.name')
+ if product_names:
+ products_str = '/'.join(product_names)
+ new_name = f"{products_str}的入库单-{picking.id}"
+ # 避免递归调用,使用super().write
+ if picking.name != new_name:
+ super(StockPicking, picking).write({'name': new_name})
+
+ return result
\ No newline at end of file
diff --git a/yuthon_stock/views/inherit_stock_picking.xml b/yuthon_stock/views/inherit_stock_picking.xml
index da76036bf..0892f669d 100644
--- a/yuthon_stock/views/inherit_stock_picking.xml
+++ b/yuthon_stock/views/inherit_stock_picking.xml
@@ -9,7 +9,7 @@
- receipt_status in ['acceptance', 'certification']
+ state != 'draft' and receipt_status in ['acceptance', 'certification']
1
@@ -31,14 +31,14 @@
-
-
-
+
+
+
-
-
-
+
+
+
@@ -66,10 +66,10 @@
供应商
- receipt_status in ['acceptance', 'certification']
+ state != 'draft' and receipt_status in ['acceptance', 'certification']
- receipt_status in ['acceptance', 'certification']
+ state != 'draft' and receipt_status in ['acceptance', 'certification']
@@ -84,6 +84,11 @@
stock.picking
+
+
+
编号