12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- # -*- coding: utf-8 -*-
- from datetime import datetime
- from odoo import models, fields, api
- from odoo.exceptions import ValidationError
- class SetAuxiliaryName(models.TransientModel):
- _name = 'archives.set_auxiliary_name'
- _module = 'archives'
- _description = u'自定义设置'
- user_id = fields.Many2one('res.users', string=u'用户', readonly=True, index=True, default=lambda self: self.env.user)
- company_id = fields.Many2one('res.company', string=u'公司', readonly=True,
- default=lambda self: self.env['res.company']._company_default_get())
- table = fields.Char(string=u'表名', index=True)
- table_name = fields.Char(string=u'表名', readonly=True)
- year = fields.Boolean(string=u'年')
- month = fields.Boolean(string=u'月')
- day = fields.Boolean(string=u'日')
- serial_number_digits = fields.Integer(string=u'流水号位数', default=5)
- # 打开设置对话框
- def send_and_open(self, table, table_name):
- context = {
- 'default_user_id': self.env.user.id,
- 'default_company_id': self.env.company.id,
- 'default_table': table,
- 'default_table_name': table_name,
- }
- setting = self.env["archives.auxiliary_name"].search(
- [('user_id', '=', self.env.user.id), ('table', '=', table)])
- if setting:
- context['default_year'] = setting.year
- context['default_month'] = setting.month
- context['default_day'] = setting.day
- context['default_serial_number_digits'] = setting.serial_number_digits
- return {
- 'type': 'ir.actions.act_window',
- 'res_model': 'archives.set_auxiliary_name',
- 'view_type': 'form',
- 'view_mode': 'form',
- 'context': context
- }
- def subscribe(self):
- setting = self.env["archives.auxiliary_name"].search(
- [('user_id', '=', self.user_id.id), ('table', '=', self.table)])
- if setting:
- setting.unlink()
- self.create_setting()
- return {}
- def create_setting(self):
- values = {
- 'user_id': self.user_id.id,
- 'company_id': self.company_id.id,
- 'table': self.table,
- 'table_name': self.table_name,
- 'year': self.year,
- 'month': self.month,
- 'day': self.day,
- 'serial_number_digits': self.serial_number_digits,
- }
- self.env['archives.auxiliary_name'].create(values)
|