From bf03ec22ff7517eacdf2f8af2905a20b437b88c7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=9D=8E=E9=B9=8F=E5=AE=87?=
<9664676+pengyuthon@user.noreply.gitee.com>
Date: Sat, 13 Dec 2025 17:30:49 +0800
Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8A=9F=E8=83=BD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
yuthon_partner/models/inherit_res_partner.py | 4 +-
yuthon_stock/models/__init__.py | 3 +-
yuthon_stock/models/inherit_stock_location.py | 40 +++++++++++++++++++
yuthon_stock/models/inherit_stock_picking.py | 9 +++++
yuthon_stock/views/inherit_stock_picking.xml | 9 ++++-
5 files changed, 60 insertions(+), 5 deletions(-)
create mode 100644 yuthon_stock/models/inherit_stock_location.py
diff --git a/yuthon_partner/models/inherit_res_partner.py b/yuthon_partner/models/inherit_res_partner.py
index 237526ec8..f77b7a5b7 100644
--- a/yuthon_partner/models/inherit_res_partner.py
+++ b/yuthon_partner/models/inherit_res_partner.py
@@ -11,6 +11,4 @@ class InheritResPartner(models.Model):
partner_ids = self.env["res.partner"].browse(
self._context.get('active_ids', self._context.get('active_id')))
for partner in partner_ids:
- employee = self.env['hr.employee'].search([('name', '=', partner.display_name)])
- if employee:
- partner.is_employee = True
\ No newline at end of file
+ partner.is_employee = True
\ No newline at end of file
diff --git a/yuthon_stock/models/__init__.py b/yuthon_stock/models/__init__.py
index bb15a2da1..b756e8246 100644
--- a/yuthon_stock/models/__init__.py
+++ b/yuthon_stock/models/__init__.py
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
from . import inherit_stock_picking
-from . import Inherit_stock_picking_type
\ No newline at end of file
+from . import Inherit_stock_picking_type
+from . import inherit_stock_location
\ No newline at end of file
diff --git a/yuthon_stock/models/inherit_stock_location.py b/yuthon_stock/models/inherit_stock_location.py
new file mode 100644
index 000000000..0b80ffe10
--- /dev/null
+++ b/yuthon_stock/models/inherit_stock_location.py
@@ -0,0 +1,40 @@
+# -*- coding: utf-8 -*-
+from odoo import api, fields, models
+import json
+
+
+class InheritStockLocation(models.Model):
+ _inherit = 'stock.location'
+
+ def update_stock(self):
+ department_obj = self.env['hr.department']
+ root_departments = department_obj.search([('child_ids', '=', False)])
+
+ company_departments = {}
+ for dept in root_departments:
+ company_id = dept.company_id.id
+ if company_id not in company_departments:
+ company_departments[company_id] = []
+ company_departments[company_id].append(dept)
+
+ # 遍历分组后的公司和部门,创建库存位置
+ for company_id, depts in company_departments.items():
+ company = self.env['res.company'].browse(company_id)
+ if not company:
+ continue
+ location_id = self.search([('complete_name', '=', company.name)])
+ for dept in depts:
+ existing_location = self.search([
+ ('name', '=', dept.name),
+ ('company_id', '=', company_id),
+ ('usage', '=', 'internal')
+ ], limit=1)
+ if existing_location:
+ continue
+ self.create({
+ 'name': dept.name,
+ 'location_id': location_id.id,
+ 'complete_name': company.name,
+ 'usage': 'internal',
+ 'company_id': company_id,
+ })
diff --git a/yuthon_stock/models/inherit_stock_picking.py b/yuthon_stock/models/inherit_stock_picking.py
index 03a4e4b57..22bcc9afd 100644
--- a/yuthon_stock/models/inherit_stock_picking.py
+++ b/yuthon_stock/models/inherit_stock_picking.py
@@ -8,6 +8,8 @@ class StockPicking(models.Model):
document_ids = fields.Many2many('ir.attachment', string="附件")
employee_id = fields.Many2one('hr.employee', string="验收人")
+ department_id = fields.Many2one('hr.department', string="部门")
+ certifier_id = fields.Many2one('res.users', string="证明人")
user_id = fields.Many2one('res.users', string="采购人员", compute="_compute_origin")
json_display = fields.Char(
string="物品详情",
@@ -15,6 +17,13 @@ class StockPicking(models.Model):
store=True
)
+ @api.onchange('employee_id')
+ def _onchange_employee_id(self):
+ if self.employee_id:
+ self.department_id = self.employee_id.department_id.id
+ else:
+ self.department_id = False
+
@api.depends(
'move_ids_without_package.product_id',
'move_ids_without_package.product_uom_qty',
diff --git a/yuthon_stock/views/inherit_stock_picking.xml b/yuthon_stock/views/inherit_stock_picking.xml
index 731545098..9e55b0f0b 100644
--- a/yuthon_stock/views/inherit_stock_picking.xml
+++ b/yuthon_stock/views/inherit_stock_picking.xml
@@ -12,10 +12,17 @@
-
+
+
+
+
+
+
+ 确认入库
+
1