diff --git a/yuthon_stock/__init__.py b/yuthon_stock/__init__.py
index 9a7e03ede..c536983e2 100644
--- a/yuthon_stock/__init__.py
+++ b/yuthon_stock/__init__.py
@@ -1 +1,2 @@
-from . import models
\ No newline at end of file
+from . import models
+from . import wizard
\ No newline at end of file
diff --git a/yuthon_stock/__manifest__.py b/yuthon_stock/__manifest__.py
index 11b566af9..6dfce5be3 100644
--- a/yuthon_stock/__manifest__.py
+++ b/yuthon_stock/__manifest__.py
@@ -9,6 +9,8 @@
'depends': ['base', 'stock', 'purchase_stock', 'documents', 'maintenance', 'funenc_json_widget'],
'data': [
'security/ir.model.access.csv',
+ 'security/company_rule.xml',
+ 'wizard/stock_picking_transfer_wizard_views.xml',
'views/menu.xml',
'views/inherit_stock_picking.xml',
'views/Inherit_stock_picking_type_views.xml',
diff --git a/yuthon_stock/models/inherit_stock_picking.py b/yuthon_stock/models/inherit_stock_picking.py
index 3f66a913b..04f357e4d 100644
--- a/yuthon_stock/models/inherit_stock_picking.py
+++ b/yuthon_stock/models/inherit_stock_picking.py
@@ -2,6 +2,7 @@
from odoo import api, fields, models
from odoo.exceptions import UserError
import json
+from lxml import etree
class StockPicking(models.Model):
@@ -24,7 +25,10 @@ class StockPicking(models.Model):
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")
+ acceptance_user_id = fields.Many2one('res.users', string="指定验收人")
+ certifier_user_id = fields.Many2one('res.users', string="指定证明人")
+ is_admin = fields.Boolean(string='是否管理员', compute='_compute_is_admin')
+ user_id = fields.Many2one('res.users', string="采购人员", compute="_compute_origin", store=True)
receipt_status = fields.Selection([
('acceptance', '验收'),
('certification', '证明'),
@@ -65,6 +69,11 @@ class StockPicking(models.Model):
store=False
)
+ def _compute_is_admin(self):
+ is_admin = self.env.user.has_group('base.group_system')
+ for rec in self:
+ rec.is_admin = is_admin
+
@api.depends('user_id', 'employee_id')
def _compute_can_certify(self):
"""计算当前用户是否可以证明(不是采购人也不是验收人)"""
@@ -240,16 +249,19 @@ class StockPicking(models.Model):
record.user_id = False
def button_validate(self):
- """重写确认入库方法,改名为证明按钮"""
+ """重写确认入库方法,改名为证明按鈕"""
for record in self:
if record.receipt_status == 'certification':
- # 使用write方法强制写入只读字段
+ # 如果已指定证明人,检查当前用户是否是指定证明人
+ if record.certifier_user_id and record.certifier_user_id.id != self.env.user.id:
+ raise UserError('只有指定的证明人才能执行证明!')
+ certifier = record.certifier_user_id or self.env.user
+ # 自动填充证明人和时间,状态变为入库
record.write({
- 'certifier_id': self.env.user.id,
+ 'certifier_id': certifier.id,
'certification_date': fields.Datetime.now(),
- 'receipt_status': 'receipt' # 状态变为入库
+ 'receipt_status': 'receipt'
})
- # 自动为标签含"固定资产"的产品创建 maintenance.equipment 记录
for move in record.move_ids_without_package:
product = move.product_id
if product and '固定资产' in product.product_tag_ids.mapped('name'):
@@ -311,15 +323,49 @@ class StockPicking(models.Model):
return True
def action_acceptance(self):
- """验收按钮:自动填充验收人和验收时间"""
+ """验收按鈕:检查是否指定验收人,自动填充验收人和验收时间"""
self.ensure_one()
- # 获取当前用户对应的员工记录
- current_employee = self.env.user.employee_ids[:1] if self.env.user.employee_ids else False
+ # 如果已指定验收人,检查当前用户是否是指定验收人
+ if self.acceptance_user_id and self.acceptance_user_id.id != self.env.user.id:
+ raise UserError('只有指定的验收人才能执行验收!')
+ # 用指定验收人填充,没有指定则取当前用户
+ acceptor = self.acceptance_user_id or self.env.user
+ current_employee = acceptor.employee_ids[:1] if acceptor.employee_ids else False
self.acceptance_date = fields.Datetime.now()
if current_employee:
self.employee_id = current_employee.id
self.receipt_status = 'certification' # 状态变为证明
return True
+
+ def action_transfer_acceptance(self):
+ """转交验收:弹出选人 wizard"""
+ self.ensure_one()
+ return {
+ 'type': 'ir.actions.act_window',
+ 'name': '转交验收',
+ 'res_model': 'stock.picking.transfer.wizard',
+ 'view_mode': 'form',
+ 'target': 'new',
+ 'context': {
+ 'default_picking_id': self.id,
+ 'default_transfer_type': 'acceptance',
+ },
+ }
+
+ def action_transfer_certifier(self):
+ """转交证明:弹出选人 wizard"""
+ self.ensure_one()
+ return {
+ 'type': 'ir.actions.act_window',
+ 'name': '转交证明',
+ 'res_model': 'stock.picking.transfer.wizard',
+ 'view_mode': 'form',
+ 'target': 'new',
+ 'context': {
+ 'default_picking_id': self.id,
+ 'default_transfer_type': 'certifier',
+ },
+ }
def _generate_sh_sequence(self, date=None):
"""生成 SH+年月+三位序号 格式的编号,按月重置"""
diff --git a/yuthon_stock/security/ir.model.access.csv b/yuthon_stock/security/ir.model.access.csv
index 97dd8b917..2b54aa105 100644
--- a/yuthon_stock/security/ir.model.access.csv
+++ b/yuthon_stock/security/ir.model.access.csv
@@ -1 +1,2 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
+access_stock_picking_transfer_wizard,stock.picking.transfer.wizard,model_stock_picking_transfer_wizard,,1,1,1,1
diff --git a/yuthon_stock/views/inherit_stock_picking.xml b/yuthon_stock/views/inherit_stock_picking.xml
index 2c610fff8..777e53ff1 100644
--- a/yuthon_stock/views/inherit_stock_picking.xml
+++ b/yuthon_stock/views/inherit_stock_picking.xml
@@ -25,16 +25,37 @@
+
+
+
{'no_create': True}
[('id', 'in', parent.available_product_ids)]
-
-
-
-
-
+
+ 1
+
+
+ 1
+
+
+ 1
+
+
+
+
+
+
+
+
+
+
+
@@ -55,7 +76,7 @@
证明
- receipt_status != 'certification' or not can_certify
+ receipt_status != 'certification' or certifier_user_id == False or certifier_user_id != uid
1
@@ -268,6 +289,19 @@
收货
+ {'contact_display': 'partner_address', 'default_company_id': allowed_company_ids[0], 'restricted_picking_type_code': 'incoming', 'search_default_reception': 1, 'search_default_my_pickings': 1}
+
+
+
+ inherit.view.picking.internal.search.my
+ stock.picking
+
+
+
+
+
+