采购
This commit is contained in:
@@ -57,6 +57,12 @@ class StockPicking(models.Model):
|
||||
compute='_compute_can_certify',
|
||||
store=False
|
||||
)
|
||||
# 触发器字段:用于在打开记录时触发自动填充
|
||||
trigger_auto_fill = fields.Boolean(
|
||||
string="触发自动填充",
|
||||
compute='_compute_trigger_auto_fill',
|
||||
store=False
|
||||
)
|
||||
|
||||
@api.depends('user_id', 'employee_id')
|
||||
def _compute_can_certify(self):
|
||||
@@ -74,23 +80,70 @@ class StockPicking(models.Model):
|
||||
# 其他情况可以证明
|
||||
record.can_certify = True
|
||||
|
||||
def read(self, fields=None, load='_classic_read'):
|
||||
"""重写read方法,打开验收/证明状态的入库单时自动更新时间"""
|
||||
result = super(StockPicking, self).read(fields, load)
|
||||
# 导入Fields模块
|
||||
@api.depends('receipt_status')
|
||||
def _compute_trigger_auto_fill(self):
|
||||
"""计算触发器字段,在打开记录时自动填充验收人/证明人(仅当字段为空时)"""
|
||||
from odoo import fields as odoo_fields
|
||||
current_user = self.env.user
|
||||
|
||||
for record in self:
|
||||
record.trigger_auto_fill = False # 默认值
|
||||
|
||||
# 只在已保存的记录中执行(有id)
|
||||
if not record.id or isinstance(record.id, models.NewId):
|
||||
continue
|
||||
|
||||
if record.receipt_status == 'acceptance':
|
||||
# 使用write方法更新验收时间
|
||||
record.write({
|
||||
'acceptance_date': odoo_fields.Datetime.now()
|
||||
})
|
||||
# 验收状态:只在验收人为空时才自动填充
|
||||
if not record.employee_id:
|
||||
current_employee = current_user.employee_ids[:1] if current_user.employee_ids else False
|
||||
if current_employee:
|
||||
record.sudo().write({
|
||||
'employee_id': current_employee.id,
|
||||
'acceptance_date': odoo_fields.Datetime.now()
|
||||
})
|
||||
elif record.receipt_status == 'certification':
|
||||
# 使用write方法更新证明时间
|
||||
record.write({
|
||||
'certification_date': odoo_fields.Datetime.now()
|
||||
})
|
||||
return result
|
||||
# 证明状态:只在证明人为空时才自动填充
|
||||
# 且需要检查当前用户不是验收人
|
||||
if not record.certifier_id:
|
||||
# 检查当前用户是否是验收人
|
||||
is_acceptor = False
|
||||
if record.employee_id and record.employee_id.user_id:
|
||||
is_acceptor = record.employee_id.user_id.id == current_user.id
|
||||
|
||||
# 只有当前用户不是验收人时,才自动填充为证明人
|
||||
if not is_acceptor:
|
||||
record.sudo().write({
|
||||
'certifier_id': current_user.id,
|
||||
'certification_date': odoo_fields.Datetime.now()
|
||||
})
|
||||
|
||||
@api.onchange('receipt_status')
|
||||
def _onchange_receipt_status_auto_fill(self):
|
||||
"""当receipt_status变化时,自动填充验收人/证明人(仅当字段为空时)"""
|
||||
from odoo import fields as odoo_fields
|
||||
current_user = self.env.user
|
||||
|
||||
if self.receipt_status == 'acceptance':
|
||||
# 验收状态:只在验收人为空时才自动填充
|
||||
if not self.employee_id:
|
||||
current_employee = current_user.employee_ids[:1] if current_user.employee_ids else False
|
||||
if current_employee:
|
||||
self.employee_id = current_employee.id
|
||||
self.acceptance_date = odoo_fields.Datetime.now()
|
||||
elif self.receipt_status == 'certification':
|
||||
# 证明状态:只在证明人为空时才自动填充
|
||||
# 且需要检查当前用户不是验收人
|
||||
if not self.certifier_id:
|
||||
# 检查当前用户是否是验收人
|
||||
is_acceptor = False
|
||||
if self.employee_id and self.employee_id.user_id:
|
||||
is_acceptor = self.employee_id.user_id.id == current_user.id
|
||||
|
||||
# 只有当前用户不是验收人时,才自动填充为证明人
|
||||
if not is_acceptor:
|
||||
self.certifier_id = current_user.id
|
||||
self.certification_date = odoo_fields.Datetime.now()
|
||||
|
||||
@api.depends('location_id', 'picking_type_code')
|
||||
def _compute_available_product_ids(self):
|
||||
@@ -230,9 +283,13 @@ class StockPicking(models.Model):
|
||||
}
|
||||
|
||||
def action_acceptance(self):
|
||||
"""验收按钮"""
|
||||
"""验收按钮:自动填充验收人和验收时间"""
|
||||
self.ensure_one()
|
||||
# 获取当前用户对应的员工记录
|
||||
current_employee = self.env.user.employee_ids[:1] if self.env.user.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
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<attribute name="domain">[('id', 'in', available_location_ids)]</attribute>
|
||||
</xpath>
|
||||
<xpath expr="//field[@name='picking_type_id']" position="attributes">
|
||||
<attribute name="readonly">state != 'draft' and receipt_status in ['acceptance', 'certification']</attribute>
|
||||
<attribute name="readonly">state != 'draft' and (receipt_status in ['acceptance', 'certification'] or receipt_status == 'receipt')</attribute>
|
||||
</xpath>
|
||||
<xpath expr="//field[@name='origin']" position="attributes">
|
||||
<attribute name="invisible">1</attribute>
|
||||
@@ -24,6 +24,7 @@
|
||||
<field name="available_location_ids" invisible="1"/>
|
||||
<field name="state" invisible="1"/>
|
||||
<field name="can_certify" invisible="1"/>
|
||||
<field name="trigger_auto_fill" invisible="1"/>
|
||||
</xpath>
|
||||
<xpath expr="//page[@name='operations']//field[@name='move_ids_without_package']//field[@name='product_id']" position="attributes">
|
||||
<attribute name="options">{'no_create': True}</attribute>
|
||||
@@ -35,14 +36,14 @@
|
||||
<xpath expr="//page[@name='operations']/field[@name='move_ids_without_package']" position="after">
|
||||
<group>
|
||||
<group>
|
||||
<field name="employee_id" string="验收人" required="1" options="{'no_create': True}" readonly="state != 'draft' and receipt_status == 'certification'"/>
|
||||
<field name="document_ids" widget="preview_many2many" readonly="state != 'draft' and receipt_status == 'certification'"/>
|
||||
<field name="acceptance_date" readonly="state != 'draft' and receipt_status == 'certification'"/>
|
||||
<field name="employee_id" string="验收人" required="1" options="{'no_create': True}" readonly="receipt_status in ['certification', 'receipt']"/>
|
||||
<field name="document_ids" widget="preview_many2many" readonly="receipt_status in ['certification', 'receipt']"/>
|
||||
<field name="acceptance_date" readonly="receipt_status in ['certification', 'receipt']"/>
|
||||
</group>
|
||||
<group>
|
||||
<field name="certifier_id" options="{'no_create': True}" readonly="state != 'draft' and receipt_status == 'acceptance'"/>
|
||||
<field name="certifier_document_ids" widget="preview_many2many" readonly="state != 'draft' and receipt_status == 'acceptance'"/>
|
||||
<field name="certification_date" readonly="state != 'draft' and receipt_status == 'acceptance'"/>
|
||||
<field name="certifier_id" options="{'no_create': True}" readonly="receipt_status in ['acceptance', 'receipt']"/>
|
||||
<field name="certifier_document_ids" widget="preview_many2many" readonly="receipt_status in ['acceptance', 'receipt']"/>
|
||||
<field name="certification_date" readonly="receipt_status in ['acceptance', 'receipt']"/>
|
||||
</group>
|
||||
</group>
|
||||
</xpath>
|
||||
@@ -70,10 +71,10 @@
|
||||
</xpath>
|
||||
<xpath expr="//field[@name='partner_id']" position="attributes">
|
||||
<attribute name="string">供应商</attribute>
|
||||
<attribute name="readonly">state != 'draft' and receipt_status in ['acceptance', 'certification']</attribute>
|
||||
<attribute name="readonly">state != 'draft' and (receipt_status in ['acceptance', 'certification'] or receipt_status == 'receipt')</attribute>
|
||||
</xpath>
|
||||
<xpath expr="//field[@name='scheduled_date']" position="attributes">
|
||||
<attribute name="readonly">state != 'draft' and receipt_status in ['acceptance', 'certification']</attribute>
|
||||
<attribute name="readonly">state != 'draft' and (receipt_status in ['acceptance', 'certification'] or receipt_status == 'receipt')</attribute>
|
||||
</xpath>
|
||||
<xpath expr="(//field[@name='state'][@widget='statusbar'])[1]" position="replace">
|
||||
<field name="receipt_status" widget="statusbar" statusbar_visible="acceptance,certification,receipt" invisible="picking_type_code != 'incoming'"/>
|
||||
|
||||
Reference in New Issue
Block a user