47 lines
1.8 KiB
Python
47 lines
1.8 KiB
Python
from datetime import datetime
|
|
from odoo import models, fields, api
|
|
|
|
|
|
class SummaryCreateButtonWizard(models.TransientModel):
|
|
_name = 'summary.create.button.wizard'
|
|
_description = '初始化周期任务'
|
|
|
|
def action_confirm(self):
|
|
self.ensure_one()
|
|
summary_settings = self.env['summary.table.setting'].search([
|
|
('employee_ids', '!=', False)
|
|
])
|
|
if not summary_settings:
|
|
return self._show_notification('无有效项目配置(需关联人员)', 'warning')
|
|
|
|
current_month = str(datetime.now().month)
|
|
for setting in summary_settings:
|
|
employees = setting.employee_ids
|
|
for employee in employees:
|
|
summary_table = self.env['information.summary.table'].search([
|
|
('employee_id', '=', employee.id),
|
|
('month', '=', current_month)
|
|
], limit=1) #
|
|
|
|
if not summary_table:
|
|
summary_table = self.env['information.summary.table'].create({
|
|
'employee_id': employee.id,
|
|
'month': current_month,
|
|
'account_type': 'to',
|
|
'create_date': fields.Datetime.now()
|
|
})
|
|
|
|
existing_line = self.env['information.summary.line'].search([
|
|
('summary_id', '=', summary_table.id),
|
|
('table_id', '=', setting.id)
|
|
], limit=1)
|
|
|
|
if not existing_line:
|
|
self.env['information.summary.line'].create({
|
|
'summary_id': summary_table.id,
|
|
'table_id': setting.id,
|
|
'this_year': 0.0,
|
|
'remake': ''
|
|
})
|
|
|