Files
gzth/yuthon_salary/wizard/salary_meal_wizard.py
T
2026-01-06 20:57:35 +08:00

77 lines
2.6 KiB
Python

# -*- coding: utf-8 -*-
from odoo import models, fields, api, _, SUPERUSER_ID
from odoo.exceptions import ValidationError, UserError
from pypinyin import pinyin, Style
import xlrd
import base64
import datetime
from datetime import datetime
# -*- coding: utf-8 -*-
from odoo import models, fields, api, _, SUPERUSER_ID
from odoo.exceptions import ValidationError, UserError
from pypinyin import pinyin, Style
import xlrd
import base64
import datetime
from datetime import datetime
import calendar
# -*- coding: utf-8 -*-
from odoo import models, fields, api, _, SUPERUSER_ID
from odoo.exceptions import ValidationError, UserError
from pypinyin import pinyin, Style
import xlrd
import base64
import datetime
from datetime import datetime, timedelta
class SalaryMealWizard(models.TransientModel):
_name = 'salary.meal.wizard'
_description = '餐费导入弹窗'
excel_file = fields.Binary(string="上传Excel表")
excel_name = fields.Char(string="文件名")
def confirm(self):
if not self.excel_file:
raise ValidationError('请上传文件。')
book = xlrd.open_workbook(file_contents=base64.decodebytes(self.excel_file))
sh = book.sheet_by_index(0)
for rx in range(1, sh.nrows):
row = sh.row(rx)
self.salary_meal_data(row)
def salary_meal_data(self, row):
select_year = row[0].value
select_time = row[1].value
employee_id = self.env['hr.employee'].search([('identification_id', '=', row[3].value)], limit=1)
card = row[3].value
number_breakfasts = row[4].value
number_lunches = row[5].value
total_payment = row[6].value
if employee_id:
party_id = self.env['yuthon.meal.expenses'].search([
('employee_id', '=', employee_id.id),
('select_year', '=', select_year),
('select_time', '=', select_time)
])
if not party_id:
self.env['yuthon.meal.expenses'].create({
'employee_id': employee_id.id,
'select_year': select_year,
'select_time': select_time,
'card': card,
'number_breakfasts': number_breakfasts,
'number_lunches': number_lunches,
'total_payment': total_payment,
})
else:
party_id.write({
'card': card,
'number_breakfasts': number_breakfasts,
'number_lunches': number_lunches,
'total_payment': total_payment,
}
)