Files
gzth/yuthon_account_report/wizard/collection_create_button_wizard.py
T
2025-12-01 20:21:07 +08:00

55 lines
2.2 KiB
Python

from datetime import datetime
from odoo import models, fields, api
class CollectionCreateButtonWizard(models.TransientModel):
_name = 'collection.create.button.wizard'
_description = '财务数据表项目配置弹窗'
def action_confirm(self):
self.ensure_one()
collection_settings = self.env['sheet.collection.setting'].search([('employee_ids', '!=', False)])
# 计算当前时间对应的本年第几周
today = datetime.now()
first_day_of_year = datetime(today.year, 1, 1)
days_since_year_start = (today - first_day_of_year).days
first_weekday = first_day_of_year.weekday() # 0=周一,6=周日
current_week = (days_since_year_start + first_weekday + 1) // 7
if first_weekday == 6:
current_week = (days_since_year_start + 1) // 7
cycle = str(min(max(current_week, 1), 53))
for setting in collection_settings:
employees = setting.employee_ids
for employee in employees:
sheet_collection = self.env['financial.sheet.collection'].search([
('employee_id', '=', employee.id),
('cycle', '=', cycle)
], limit=1)
if not sheet_collection:
sheet_collection = self.env['financial.sheet.collection'].create({
'employee_id': employee.id,
'cycle': cycle,
'account_type': 'to',
'create_date': fields.Datetime.now()
})
existing_line = self.env['financial.sheet.line'].search([
('sheet_id', '=', sheet_collection.id),
('collection_id', '=', setting.id)
], limit=1)
if not existing_line:
self.env['financial.sheet.line'].create({
'sheet_id': sheet_collection.id,
'collection_id': setting.id,
'employee_ids': [(6, 0, [employee.id])],
'this_issue_number': 0,
'same_last_year': 0,
'remake': ''
})