添加功能

This commit is contained in:
李鹏宇
2025-09-09 19:16:56 +08:00
parent caf68b8835
commit bba015378e
@@ -7,17 +7,68 @@ class InheritStockPickingType(models.Model):
_inherit = 'stock.picking.type'
def update_type(self):
# 获取选中的库存调拨类型记录
picking_ids = self.env["stock.picking.type"].browse(
self._context.get('active_ids', [self._context.get('active_id')] if self._context.get('active_id') else []))
for picking in picking_ids:
# if picking.name == "内部调拨":
# picking.unlink()
# continue
if picking.name == "接收":
picking.name = "入库"
if picking.name == "交货单":
picking.name = "出库"
# # 获取选中的库存调拨类型记录
# picking_ids = self.env["stock.picking.type"].browse(
# self._context.get('active_ids', [self._context.get('active_id')] if self._context.get('active_id') else []))
# for picking in picking_ids:
# # if picking.name == "内部调拨":
# # picking.unlink()
# # continue
# if picking.name == "接收":
# picking.name = "入库"
# if picking.name == "交货单":
# picking.name = "出库"
# 定义目标公司名称
target_companies = ['集团本部', '天河粮储', '天河物管']
excluded_depts = ['党群部', '管理员','集团本部', '天河粮储', '天河物管']
# 查找对应的公司记录
companies = self.env['res.company'].search([('name', 'in', target_companies)])
if not companies:
return False
for company in companies:
departments = self.env['hr.department'].search([
('company_id', '=', company.id),
('child_ids', '=', False),
('name', 'not in', excluded_depts)
])
if departments:
print(f"公司 [{company.name}] 的末级部门列表:")
for dept in departments:
print(f"- {dept.name}")
if not departments:
continue # 没有末级部门则跳过
# 遍历每个末级部门
for loop_idx, dept in enumerate(departments, start=1):
warehouse_name = f"{company.name}-{dept.name}"
warehouse_code = f"{dept.name}{loop_idx}"
warehouse = self.env['stock.warehouse'].search([
('name', '=', warehouse_name),
('company_id', '=', company.id)
], limit=1)
if not warehouse:
warehouse = self.env['stock.warehouse'].create({
'name': warehouse_name,
'code': warehouse_code,
'company_id': company.id,
})
self.env["stock.picking.type"].create({
'name': '领用',
'code': 'outgoing',
'sequence_code': 'otg',
'company_id': company.id,
'warehouse_id': warehouse.id,
})
self.env["stock.picking.type"].create({
'name': '借用',
'code': 'outgoing',
'sequence_code': 'otg',
'company_id': company.id,
'warehouse_id': warehouse.id,
# 其他必要字段可根据实际需求添加
})
# if picking.warehouse_id and picking.warehouse_id.name:
# name_prefix = picking.warehouse_id.name[:4]