-
Notifications
You must be signed in to change notification settings - Fork 1
/
models.py
executable file
·1482 lines (1330 loc) · 76.7 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
from openerp import fields
from openerp import models, api
import datetime, time
from email.utils import formataddr
from email.header import Header
class base_class(models.Model):
_name = "cinda_cmdb.base_class"
_rec_name = 'class_name'
_description = '总类编码表'
_inherit = ['mail.thread', 'ir.needaction_mixin']
_mail_post_access = 'read'
class_number = fields.Char(string="总类编号")
class_name = fields.Char(string="总类名称")
comment = fields.Char(string="备注")
class base_type(models.Model):
_name = "cinda_cmdb.base_type"
_rec_name = 'type_name'
_description = '细类编码表'
_inherit = ['mail.thread', 'ir.needaction_mixin']
_mail_post_access = 'read'
type_number = fields.Char(string="细类编号")
type_name = fields.Char(string="细类名称")
class_id = fields.Many2one("cinda_cmdb.base_class", string="所属父类")
comment = fields.Char(string="备注")
class base_data(models.Model):
_name = "cinda_cmdb.base_data"
_inherit = ['mail.thread', 'ir.needaction_mixin']
_mail_post_access = 'read'
base_data_id = fields.Char(string="基础数据ID")
value = fields.Char(string="值")
pare_id = fields.Char(string="父id")
pare_lnk_mod = fields.Integer(string="父节点连接类型")
pare_val = fields.Char(string="父值")
last_id = fields.Integer(string="前节点id")
last_lnk_mod = fields.Integer(string="前节点连接类型")
last_val = fields.Char(string="前节点值")
next_id = fields.Integer(string="后节点id")
next_lnk_mod = fields.Integer(string="后节点连接类型")
next_val = fields.Char(string="后节点值")
chld_id = fields.Integer(string="子节点id")
chld_lnk_mod = fields.Integer(string="子节点连接类型")
chld_val = fields.Char(string="子节点值")
comment = fields.Char(string="备注")
last_upd = fields.Datetime(default=fields.datetime.now(), require=True)
class device(models.Model):
_name = "cinda_cmdb.device"
_rec_name = "sn"
_description = '硬件设备表'
_inherit = ['mail.thread', 'ir.needaction_mixin']
_mail_post_access = 'read'
# _track = {
# 'stage_id': {
# 'project.mt_task_new': lambda self, cr, uid, obj, ctx=None: obj.stage_id and obj.stage_id.sequence <= 1,
# 'project.mt_task_stage': lambda self, cr, uid, obj, ctx=None: obj.stage_id.sequence > 1,
# },
# 'user_id': {
# 'project.mt_task_assigned': lambda self, cr, uid, obj, ctx=None: obj.user_id and obj.user_id.id,
# },
# }
device_id = fields.Char(string="硬件ID")
lab_id = fields.Many2one("cinda_cmdb.base_type", string='机房', domain=[('class_id', 'ilike', "机房")])
cab = fields.Many2one("cinda_cmdb.cabinet", string="机柜")
pos_seq = fields.Integer(string="位置序号")
u_pos = fields.Many2one("cinda_cmdb.base_type", string="位置U", domain=[('class_id', 'ilike', "位置代号")])
u_space = fields.Integer(string="占位U")
env_id = fields.Many2one("cinda_cmdb.base_type", string="环境", domain=[('class_id', 'ilike', "环境")])
use_mode = fields.Selection([('using', '使用中'), ('un_use', '未使用'),], default="", Require="False", string="使用状态")
dev_start = fields.Selection([('start up', '开机'), ('shut down', '关机'),], default="", Require="False", string="设备状态")
type_id = fields.Many2one("cinda_cmdb.base_type", string="设备类型", domain=[('class_id', 'ilike', "设备类型")])
brand_id = fields.Many2one("cinda_cmdb.base_type", string="品牌", domain=[('class_id', 'ilike', "设备品牌")])
product_name = fields.Char(string="产品型号")
host_name = fields.Char(string="设备命名")
model = fields.Char(string="Model")
asset_num_old = fields.Char(string="旧资产编号")
asset_num = fields.Char(string="资产编号")
sn = fields.Char(string="序列号")
purpose = fields.Char(string="用途")
accept_date = fields.Char(string="初验日期", compute='min_contract_date', store=True)
reject_date = fields.Char(string="过保日期", compute='max_contract_date', store=True)
owner_id = fields.Many2one("cinda_cmdb.base_type", string="资产所有人", domain=[('class_id', 'ilike', "资产所有者")])
user = fields.Many2one("cinda_cmdb.member_list", string="使用人")
srve_prvd = fields.Many2one("cinda_cmdb.vendor_list", string="服务商")
admin = fields.Many2one("cinda_cmdb.member_list", string="管理人")
comment = fields.Char(string="备注")
last_upd = fields.Datetime(default=fields.datetime.now(), require=True, string="最后修改日期")
contract_ids = fields.Many2many("cinda_cmdb.contract_purchase","device_contract_ref", "device_id", "contract_id", string="采购合同编号")
interface_ids = fields.One2many('cinda_cmdb.interface', 'device_id', string="接口")
#以下是server表中引用过来的字段
# server_ids = fields.One2many('cinda_cmdb.server','dev_id', string="服务器信息1")
# server_ids_a = fields.Many2one('cinda_cmdb.server', string="服务器信息2", compute='_get_record_id', store=True)
# app_sys = fields.Char(related="server_ids_a.app_sys", string="所属系统")
# os = fields.Char(related="server_ids_a.os", string="底层操作系统")
# last_upd_a = fields.Datetime(related="server_ids_a.last_upd_a", require=True, string="最后截止日期")
# 将设备所对应的多个合同的初验日期的最早那天选出来
@api.multi
@api.depends('contract_ids.accept_date')
def min_contract_date(self):
# print '#'*80
datas=[]
for r in self:
for contract in r.contract_ids:
if contract.accept_date:
datas.append(contract.accept_date)
if datas:
r.accept_date=min(datas)
# 将设备所对应的多个合同的初验日期的最晚那天选出来
@api.multi
@api.depends('contract_ids.reject_date')
def max_contract_date(self):
# print '#'*80
datas=[]
for r in self:
for contract in r.contract_ids:
if contract.reject_date:
datas.append(contract.reject_date)
if datas:
r.reject_date=max(datas)
# 在device表中新建一条数据,然后根据设备类型,在相对应的表里面创建一条数据,并且将刚才数据的id赋给新数据的dev_id
def create(self, cr, uid, vals, context=None):
vals['device_id'] = self.pool.get('ir.sequence').get(cr, uid, 'cinda_cmdb.device')
id = super(device, self).create(cr, uid, vals, context=context)
if self.browse(cr, uid, id, context=context)[0].type_id:
record = self.browse(cr, uid, id, context=context)[0].type_id.type_name
if record == "小型计算机":
self.pool.get('cinda_cmdb.mini_pc').create(cr, uid, {'dev_id':id}, context=context)
elif record in ["存储", "磁盘阵列", "存储扩展柜"]:
self.pool.get('cinda_cmdb.st_dev').create(cr, uid, {'dev_id':id}, context=context)
elif record == "PC服务器":
self.pool.get('cinda_cmdb.server').create(cr, uid, {'dev_id':id}, context=context)
elif record in ["光纤交换机", "光纤连接器"]:
self.pool.get('cinda_cmdb.fc_switch').create(cr, uid, {'dev_id':id}, context=context)
elif record in ["磁带机", "磁带库"]:
self.pool.get('cinda_cmdb.tape_station').create(cr, uid, {'dev_id':id}, context=context)
return id
#修改作为外键时的显示
@api.multi
@api.depends('sn', 'host_name')
def name_get(self):
datas=[]
for r in self:
if r.host_name:
datas.append((r.id, (r.sn + '(' + (r.host_name) + ')')))
else:
datas.append((r.id, (r.sn)))
return datas
# 将sever表里的字段引用到device表里面。。。(将)
# @api.one
# @api.depends('server_ids')
# def _get_record_id(self):
# for r in self:
# r.server_ids_a = r.server_ids
class server(models.Model):
_name = "cinda_cmdb.server"
_description = 'PC服务器表'
_inherit = ['mail.thread', 'ir.needaction_mixin']
_mail_post_access = 'read'
_rec_name = "sn_id"
vm_ids = fields.One2many("cinda_cmdb.vm", "server_ids", string="虚拟机信息")
dev_id = fields.Many2one("cinda_cmdb.device", string="设备资产id", domain=[('type_id.type_name', 'ilike', "PC服务器")])
sn_id = fields.Char(related="dev_id.sn", string="所属设备序列号")
interface_ids_a = fields.One2many('cinda_cmdb.interface', 'server_id', string="HBA卡接口", domain=[('type', '=', "hba")])
interface_ids_b = fields.One2many('cinda_cmdb.interface', 'server_id', string="网卡接口", domain=[('type', 'in', ['ethernet_electricity', 'ethernet_fiber'])])
# server_info_ids_a = fields.Char(related="server_info_ids", string="服务器信息合同")
server_id = fields.Char(string="服务器id")
app_sys = fields.Char(string="所属系统")
buss_ip_addr = fields.Char(string="业务网IP地址")
stor_ip_addr = fields.Char(string="存储网IP地址")
bck_ip_addr = fields.Char(string="备份网IP地址")
mng_ip_addr = fields.Char(string="管理网IP地址")
admin_ip = fields.Char(string="管理口IP")
admin_info = fields.Char(string="管理口信息点")
# os_id = fields.Char(string="底层操作系统id")
os = fields.Char(string="底层操作系统")
cpu_num = fields.Integer(string="CPU数量")
single_cpu_num = fields.Integer(string="单CPU核数")
cpu_sum = fields.Integer(string="CPU总核数", compute="_cpu_sum", store="True")
cpu_spec = fields.Char(string="CPU规格")
mem_num = fields.Integer(string="内存条数")
single_mem_size = fields.Float(string="单条内存容量")
mem_sum = fields.Float(string="内存总容量", compute="_mem_sum", store="True")
mem_spec = fields.Char(string="内存规格")
disk_size = fields.Integer(string="硬盘数量")
single_disk_size = fields.Float(string="单硬盘容量")
disk_sum = fields.Float(string="硬盘总容量", compute="_disk_sum", store="True")
disk_spec = fields.Char(string="硬盘规格")
ext_st_size = fields.Float(string="外接存储容量(TB)")
hba_config = fields.Char(string="HBA卡配置")
hba_used = fields.Char(string="HBA卡已用情况")
g_netcard_config = fields.Char(string="千兆网卡配置")
g_netcard_used = fields.Char(string="千兆网卡已用情况")
t_netcard_config = fields.Char(string="万兆网卡配置")
t_netcard_used = fields.Char(string="万兆网卡已用情况")
netcard_band = fields.Char(string="网卡绑定")
exten_mod = fields.Char(string="扩展模块")
vir_mark = fields.Many2one("cinda_cmdb.cluster", string="虚拟化标志")
comment1 = fields.Char(string="备注1")
comment2 = fields.Char(string="备注2")
last_upd = fields.Datetime(default=fields.datetime.now(), require=True)
san_wwn = fields.Char(string="san网络wwn号")
ha_mode = fields.Char(string="主备状态")
four_g_hba_num = fields.Integer(string="4G HBA卡数量")
four_g_hba_used_num = fields.Integer(string="4G HBA卡已用数量")
eight_g_hba_num = fields.Integer(string="8G HBA卡数量")
eight_g_hba_used_num = fields.Integer(string="8G HBA卡已用数量")
sixteen_g_hba_num = fields.Integer(string="16G HBA卡数量")
sixteen_g_hba_used_num = fields.Integer(string="16G HBA卡已用数量")
thirty_two_g_hba_num = fields.Integer(string="32G HBA卡数量")
thirty_two_g_hba_used_num = fields.Integer(string="32G HBA卡已用数量")
g_netcard_num = fields.Integer(string="千兆网口数量")
g_netcard_used_num = fields.Integer(string="千兆网口已用数量")
t_netcard_num = fields.Integer(string="万兆网口数量")
t_netcard_used_num = fields.Integer(string="万兆网口已用数量")
#以下是device表中引用过来用来展示的字段
host_name = fields.Char(related="dev_id.host_name", string="设备命名")
type_id = fields.Many2one(related="dev_id.type_id", string="设备类型", domain=[('type_name', 'ilike', "PC服务器")], store="Ture")
brand_id = fields.Many2one(related="dev_id.brand_id", string="品牌")
product_name = fields.Char(related="dev_id.product_name", string="产品型号")
# sn = fields.Char(related="dev_id.sn", string="序列号")
model = fields.Char(related="dev_id.model", string="Model")
use_mode = fields.Selection(related="dev_id.use_mode", string="使用状态")
dev_start = fields.Selection(related="dev_id.dev_start", string="设备状态")
asset_num_old = fields.Char(related="dev_id.asset_num_old", string="旧资产编号")
asset_num = fields.Char(related="dev_id.asset_num", string="资产编号")
purpose = fields.Char(related="dev_id.purpose", string="用途")
owner_id = fields.Many2one(related="dev_id.owner_id", string="资产所有人")
user = fields.Many2one(related="dev_id.user", string="使用人")
admin = fields.Many2one(related="dev_id.admin", string="管理人")
comment = fields.Char(related="dev_id.comment", string="备注")
lab_id = fields.Many2one(related="dev_id.lab_id", string="机房")
cab = fields.Many2one(related="dev_id.cab", string="机柜")
pos_seq = fields.Integer(related="dev_id.pos_seq", string="位置序号")
u_pos = fields.Many2one(related="dev_id.u_pos", string="位置U")
u_space = fields.Integer(related="dev_id.u_space", string="占位U")
env_id = fields.Many2one(related="dev_id.env_id", string="环境")
srve_prvd = fields.Many2one(related="dev_id.srve_prvd", string="服务商")
contract_ids = fields.Many2many(related="dev_id.contract_ids", string="采购合同编号")
accept_date = fields.Char(related="dev_id.accept_date", string="初验日期")
reject_date = fields.Char(related="dev_id.reject_date", string="过保日期")
# 计算内存总容量
@api.multi
@api.depends('mem_num', 'single_mem_size')
def _mem_sum(self):
for r in self:
r.mem_sum = r.mem_num * r.single_mem_size
# 计算硬盘总容量
@api.multi
@api.depends('disk_size', 'single_disk_size')
def _disk_sum(self):
for r in self:
r.disk_sum = r.disk_size * r.single_disk_size
#计算CPU核数量
@api.multi
@api.depends('cpu_num', 'single_cpu_num')
def _cpu_sum(self):
for r in self:
r.cpu_sum = r.single_cpu_num * r.cpu_num
#
@api.multi
def action_to_confirm(self):
import patter
patter.patter()
class net_dev(models.Model):
_name = "cinda_cmdb.net_dev"
_description = '网络信息表'
_rec_name = "host_name"
_inherit = ['mail.thread', 'ir.needaction_mixin']
_mail_post_access = 'read'
# name = fields.Char(string="设备命名")
# area = fields.Selection([('east_ring', '东环'), ('yi_zh', '亦庄'), ('money_center', '金融中心'), ('fen_firm', '分公司'), ('son_firm', '子公司')], default="", Require="False", string="物理位置")
area = fields.Char( string="物理位置")
region = fields.Char( string="所属区域")
version = fields.Char(string="软件版本")
admin_ip = fields.Char(string="管理口IP")
account = fields.Char(string="账号")
comment = fields.Char(string="备注")
online_time = fields.Date(string="上线日期")
offline_time = fields.Date(string="下线日期")
scrap_time = fields.Date(string="报废日期")
fixed_assets_project = fields.Char(string="固定资产项目名称")
config_backup_method = fields.Selection([('auto', '自动备份'), ('manual', '手动')], default='manual', string="配置备份方式")
config_backup_frequency = fields.Selection(
[('per_day', '每天'),
('per_week', '每周'),
('per_month', '每月'),
('per_year', '每年')],
string="配置备份频率"
)
interface_ids = fields.One2many(related='dev_id.interface_ids', string="接口")
last_upd = fields.Datetime(default=fields.datetime.now(), require=True, string="最后修改日期")
dev_id = fields.Many2one("cinda_cmdb.device", string="序列号", domain=['|','|','|','|','|','|','|','|','|','|','|','|','|',
('type_id.type_name','ilike',"网络设备"),
('type_id.type_name','ilike',"交换机"),
('type_id.type_name','ilike',"路由器"),
('type_id.type_name','ilike',"安全设备"),
('type_id.type_name','ilike',"防火墙"),
('type_id.type_name','ilike',"负载均衡"),
('type_id.type_name','ilike',"邮件网关"),
('type_id.type_name','ilike',"PIX"),
('type_id.type_name','ilike',"IDS探针"),
('type_id.type_name','ilike',"SG"),
('type_id.type_name','ilike',"SSL_VPN"),
('type_id.type_name','ilike',"IPSEC_VPN"),
('type_id.type_name','ilike',"CITRIX"),
('type_id.type_name','ilike',"备邮数据中心"),
])
sn_id = fields.Char(related="dev_id.sn", string="所属设备序列号")
#以下是device表中引用过来用来展示的字段
host_name = fields.Char(related="dev_id.host_name", string="设备命名")
brand_id = fields.Many2one(related="dev_id.brand_id", string="品牌")
type_id = fields.Many2one(related="dev_id.type_id", string="设备类型", domain=['|','|','|','|','|','|','|','|','|','|','|','|','|',
('type_name','ilike',"网络设备"),
('type_name','ilike',"交换机"),
('type_name','ilike',"路由器"),
('type_name','ilike',"安全设备"),
('type_name','ilike',"防火墙"),
('type_name','ilike',"负载均衡"),
('type_name','ilike',"邮件网关"),
('type_name','ilike',"PIX"),
('type_name','ilike',"IDS探针"),
('type_name','ilike',"SG"),
('type_name','ilike',"SSL_VPN"),
('type_name','ilike',"IPSEC_VPN"),
('type_name','ilike',"CITRIX"),
('type_name','ilike',"备邮数据中心"),
], store="Ture")
product_name = fields.Char(related="dev_id.product_name", string="产品型号")
# sn = fields.Char(related="dev_id.sn", string="序列号")
model = fields.Char(related="dev_id.model", string="Model")
use_mode = fields.Selection(related="dev_id.use_mode", string="使用状态")
dev_start = fields.Selection(related="dev_id.dev_start", string="设备状态")
asset_num_old = fields.Char(related="dev_id.asset_num_old", string="旧资产编号")
asset_num = fields.Char(related="dev_id.asset_num", string="资产编号")
purpose = fields.Char(related="dev_id.purpose", string="用途")
owner_id = fields.Many2one(related="dev_id.owner_id", string="资产所有人")
user = fields.Many2one(related="dev_id.user", string="使用人")
admin = fields.Many2one(related="dev_id.admin", string="管理人")
comment = fields.Char(related="dev_id.comment", string="备注")
lab_id = fields.Many2one(related="dev_id.lab_id", string="机房")
cab = fields.Many2one(related="dev_id.cab", string="机柜")
pos_seq = fields.Integer(related="dev_id.pos_seq", string="位置序号")
u_pos = fields.Many2one(related="dev_id.u_pos", string="位置U")
u_space = fields.Integer(related="dev_id.u_space", string="占位U")
env_id = fields.Many2one(related="dev_id.env_id", string="环境")
srve_prvd = fields.Many2one(related="dev_id.srve_prvd", string="服务商")
contract_ids = fields.Many2many(related="dev_id.contract_ids", string="采购合同编号")
accept_date = fields.Char(related="dev_id.accept_date", string="初验日期")
reject_date = fields.Char(related="dev_id.reject_date", string="过保日期")
# net_dev_id = fields.Char(string="网络设备id")
# area_id = fields.Integer(string="区域id")
# root_acc = fields.Char(string="根用户")
# chg_acc = fields.Char(string="变更用户")
# mon_acc = fields.Char(string="监控用户")
# ha_mode = fields.Char(string="主备状态")
# dev_id = fields.Integer(string="设备资产id")
class board(models.Model):
_name = "cinda_cmdb.board"
_description = 'net_board'
_inherit = ['mail.thread', 'ir.needaction_mixin']
_mail_post_access = 'read'
board_id = fields.Char(string="板卡id")
area_id = fields.Integer(string="区域id")
area = fields.Char(string="区域")
dev_id = fields.Integer(string="设备资产id")
net_dev_id = fields.Integer(string="网络设备id")
srv_dev_id = fields.Integer(string="服务器设备id")
card_type = fields.Char(string="板卡类型")
card_sn = fields.Char(string="板卡序列号")
slot = fields.Char(string="槽位")
comment1 = fields.Char(string="备注")
comment2 = fields.Char(string="备注2")
last_upd = fields.Datetime(default=fields.datetime.now(), require=True)
class st_dev(models.Model):
_name = "cinda_cmdb.st_dev"
_description = 'storage'
_inherit = ['mail.thread', 'ir.needaction_mixin']
_mail_post_access = 'read'
st_dev_id = fields.Char(string="存储id")
interface_ids = fields.One2many(related='dev_id.interface_ids', string="接口")
st_part_ids = fields.One2many('cinda_cmdb.st_part', 'st_id', string="存储组件")
st_part_ids_a = fields.One2many(related='st_part_ids', string="组件磁盘")
st_part_ids_b = fields.One2many(related='st_part_ids', string="组件容量")
interface_ids = fields.One2many('cinda_cmdb.interface', 'st_dev_id', string="光口", domain=[('type', 'in', ["ethernet_fiber", "hba"])])
interface_ids_a = fields.One2many('cinda_cmdb.interface', 'st_dev_id', string="电口", domain=[('type', '=', "ethernet_electricity")])
dev_id = fields.Many2one("cinda_cmdb.device", string="设备资产id",
domain=['|','|','|','|','|',
('type_id.type_name', 'ilike', "磁带机"),
('type_id.type_name', 'ilike', "磁带库"),
('type_id.type_name', 'ilike', "磁盘阵列"),
('type_id.type_name', 'ilike', "存储扩展柜"),
('type_id.type_name', 'ilike', "光纤连接器"),
('type_id.type_name', 'ilike', "光纤交换机")])
type = fields.Many2one("cinda_cmdb.base_type", string="存储类型", domain=[('class_id.class_name', 'ilike', '存储类型')])
pc_control_num = fields.Integer(string="整机控制器数")
pc_cage_num = fields.Integer(string="整机笼子数")
each_cage_disk_num = fields.Integer(string="每个笼子可容纳磁盘数")
pc_all_size = fields.Float(string="整机裸容量(T)")
pc_enable_size = fields.Float(string="整机总可使用容量(T)")
pc_used_size = fields.Float(string="整机已经分配容量(T)")
pc_remain_size = fields.Float(string="整机剩余可使用容量(T)")
ip = fields.Char(string="IP")
app_sys = fields.Char(string="所属系统")
# type_id_a = fields.Many2one("cinda_cmdb.base_type", domain=[('class_id', 'ilike', "设备类型")])
#以下是device表中引用过来用来展示的字段
host_name = fields.Char(related="dev_id.host_name", string="设备命名")
type_id = fields.Many2one(related="dev_id.type_id", string="设备类型", domain=['|','|','|','|','|',
('type_name', 'ilike', "磁带机"),
('type_name', 'ilike', "磁带库"),
('type_name', 'ilike', "磁盘阵列"),
('type_name', 'ilike', "存储扩展柜"),
('type_name', 'ilike', "光纤交换机"),
('type_name', 'ilike', "光纤连接器")], store="Ture")
brand_id = fields.Many2one(related="dev_id.brand_id", string="品牌")
product_name = fields.Char(related="dev_id.product_name", string="产品型号")
sn = fields.Char(related="dev_id.sn", string="序列号")
model = fields.Char(related="dev_id.model", string="Model")
use_mode = fields.Selection(related="dev_id.use_mode", string="使用状态")
dev_start = fields.Selection(related="dev_id.dev_start", string="设备状态")
asset_num_old = fields.Char(related="dev_id.asset_num_old", string="旧资产编号")
asset_num = fields.Char(related="dev_id.asset_num", string="资产编号")
purpose = fields.Char(related="dev_id.purpose", string="用途")
owner_id = fields.Many2one(related="dev_id.owner_id", string="资产所有人")
user = fields.Many2one(related="dev_id.user", string="使用人")
admin = fields.Many2one(related="dev_id.admin", string="管理人")
comment = fields.Char(related="dev_id.comment", string="备注")
lab_id = fields.Many2one(related="dev_id.lab_id", string="机房")
cab = fields.Many2one(related="dev_id.cab", string="机柜")
pos_seq = fields.Integer(related="dev_id.pos_seq", string="位置序号")
u_pos = fields.Many2one(related="dev_id.u_pos", string="位置U")
u_space = fields.Integer(related="dev_id.u_space", string="占位U")
env_id = fields.Many2one(related="dev_id.env_id", string="环境")
srve_prvd = fields.Many2one(related="dev_id.srve_prvd", string="服务商")
contract_ids = fields.Many2many(related="dev_id.contract_ids", string="采购合同编号")
accept_date = fields.Char(related="dev_id.accept_date", string="初验日期")
reject_date = fields.Char(related="dev_id.reject_date", string="过保日期")
class srv_room_dev(models.Model):
_name = "cinda_cmdb.srv_room_dev"
_description = '机房设备表'
_inherit = ['mail.thread', 'ir.needaction_mixin']
_mail_post_access = 'read'
srv_room_dev_id = fields.Char(string="机房设备id")
asset_type = fields.Char(string="资产大类")
num = fields.Integer(string="数量")
start_date = fields.Date(string="启用日期")
elec_power = fields.Integer(string="总功率")
ampere = fields.Integer(string="电流")
comment = fields.Char(string="备注")
last_upd = fields.Datetime(default=fields.datetime.now(), require=True)
dev_id = fields.Integer(string="设备资产id")
class san_port(models.Model):
_name = "cinda_cmdb.san_port"
_description = 'SAN端口表'
_inherit = ['mail.thread', 'ir.needaction_mixin']
_mail_post_access = 'read'
san_port_id = fields.Char(string="SAN端口id")
dev_id = fields.Integer(string="设备资产id")
type_id = fields.Integer(string="设备类型")
port = fields.Char(string="端口号")
module = fields.Char(string="模块")
# port = fields.Char(string="本端端口号")
end_port_id = fields.Integer(string="对端端口ID")
end_on_port = fields.Char(string="对端的端口号")
end_on_wwn = fields.Char(string="对端的WWN")
protocl = fields.Char(string="使用协议")
device_code = fields.Char(string="设备编号")
end_on_dev_id = fields.Integer(string="对端设备id")
wwn = fields.Char(string="本端WWN")
speed = fields.Char(string="速率")
fc_card_name = fields.Char(string="光纤卡名")
slot = fields.Char(string="槽位")
alias = fields.Char(string="别名")
captain = fields.Char(string="说明")
comment = fields.Char(string="备注")
last_upd = fields.Datetime(default=fields.datetime.now(), require=True, string='最后截止日期')
class ip_port(models.Model):
_name = "cinda_cmdb.ip_port"
_description = 'ip端口表'
_inherit = ['mail.thread', 'ir.needaction_mixin']
_mail_post_access = 'read'
ip_port_id = fields.Char(string="IP端口ID")
dev_id = fields.Integer(string="设备id")
net_dev_id = fields.Integer(string="网络设备id")
card_id = fields.Integer(string="板卡id")
port = fields.Char(string="本端物理端口号")
port_num = fields.Char(string="本端端口名")
port_mac = fields.Char(string="本端MAC")
port_ip = fields.Char(string="本端IP地址")
port_type = fields.Char(string="本端端口类型")
end_on_dev_id = fields.Integer(string="对端设备id")
end_on_card_id = fields.Integer(string="对端板卡id")
end_on_port = fields.Char(string="对端物理端口号")
end_on_nam = fields.Char(string="对端端口名")
end_on_port_mac = fields.Char(string="对端MAC")
end_on_port_ip = fields.Char(string="对端ip地址")
end_on_port_type = fields.Char(string="对端端口类型")
port_status = fields.Char(string="端口状态")
port_speed = fields.Char(string="端口速率")
port_info = fields.Char(string="端口描述")
mod_type = fields.Char(string="模块类型")
mod_sn = fields.Char(string="模块序列号")
last_upd = fields.Datetime(default=fields.datetime.now(), require=True)
class cabinet(models.Model):
_name = "cinda_cmdb.cabinet"
_description = '机柜表'
_rec_name = "cab_num"
_inherit = ['mail.thread', 'ir.needaction_mixin']
_mail_post_access = 'read'
cab_num = fields.Char(string="机柜号", require=True)
lab = fields.Many2one("cinda_cmdb.base_type", string="机房", domain=[('class_id', 'ilike', "机房")])
pdu_num = fields.Integer(string="PDU数目")
elec_power = fields.Integer(string="电源功率")
ampere = fields.Integer(string="电流")
u_num = fields.Integer(string="U位数目")
purpose = fields.Char(string="用途")
comment = fields.Char(string="备注")
last_upd = fields.Datetime(default=fields.datetime.now(), require=True)
class soft(models.Model):
_name = "cinda_cmdb.soft"
_description = '软件总表'
_inherit = ['mail.thread', 'ir.needaction_mixin']
_mail_post_access = 'read'
_rec_name = 'soft_code'
soft_id = fields.Char(string="软件总id")
total_class = fields.Char(string="总类别", require=True)
subclass = fields.Char(string="明细类别", require=True)
soft_code = fields.Char(string="软件编号", require=True)
soft_name = fields.Char(string="全称")
purpose = fields.Char(string="用途")
license_type = fields.Char(string="许可类型")
license_company = fields.Char(string="许可单位")
num = fields.Integer(string="数量")
developer = fields.Char(string="开发商")
status = fields.Char(string="状态")
media_type = fields.Char(string="介质类型")
reject_date = fields.Datetime(string="支持到期时间")
contact_info = fields.Char(string="支持联系方式")
license_pos = fields.Char(string="许可证位置")
comment = fields.Char(string="备注")
last_upd = fields.Datetime(default=fields.datetime.now(), require=True)
class soft_detail(models.Model):
_name = "cinda_cmdb.soft_detail"
_description = '软件明细表'
_inherit = ['mail.thread', 'ir.needaction_mixin']
_mail_post_access = 'read'
soft_detail_id = fields.Char(string="软件明细id")
soft_code_id = fields.Many2one("cinda_cmdb.soft", string="软件编号", required="True")
detail_code = fields.Char(string="明细编号")
detail_name = fields.Char(string="细项名称")
version = fields.Char(string="版本号")
num = fields.Integer(string="购买数量")
auth_info = fields.Char(string="授权信息")
buy_date = fields.Date(string="购买时间")
over_date = fields.Date(string="服务截止时间")
vendor = fields.Char(string="供应商")
buyer = fields.Char(string="购买单位")
owner = fields.Char(string="资产所有人")
user = fields.Char(string="使用人")
media_type = fields.Char(string="介质类型")
license_key = fields.Char(string="许可密钥")
license_path = fields.Char(string="许可保存路径")
comment = fields.Char(string="备注")
last_upd = fields.Datetime(default=fields.datetime.now(), require=True)
class vendor_list(models.Model):
_name = "cinda_cmdb.vendor_list"
_description = '厂商信息表'
_rec_name = "vendor"
_inherit = ['mail.thread', 'ir.needaction_mixin']
_mail_post_access = 'read'
vendor_list_id = fields.Char(string="服务商ID")
vendor = fields.Char(string="名称", require=True)
attr = fields.Char(string="性质")
address = fields.Char(string="地址")
contact = fields.One2many("cinda_cmdb.member_list", "address", string="联系人")
# position = fields.Char(string="职位")
fixed_phone = fields.Char(string="电话")
mobile_phone = fields.Char(string="手机")
mail = fields.Char(string="邮件")
comment = fields.Char(string="备注")
last_upd = fields.Datetime(default=fields.datetime.now(), require=True)
class member_list(models.Model):
_name = "cinda_cmdb.member_list"
_description = '人员表'
_rec_name = "name"
_inherit = ['mail.thread', 'ir.needaction_mixin']
_mail_post_access = 'read'
member_list_id = fields.Char(string="人员表ID")
name = fields.Char(string="名称", require=True)
attr = fields.Char(string="性质")
address = fields.Many2one("cinda_cmdb.vendor_list", string="公司")
position = fields.Char(string="职位")
fixed_phone = fields.Char(string="电话")
mobile_phone = fields.Char(string="手机")
mail = fields.Char(string="邮件")
comment = fields.Char(string="备注")
last_upd = fields.Datetime(default=fields.datetime.now(), require=True)
class chg_log(models.Model):
_name = "cinda_cmdb.chg_log"
_description = '变更记录表'
_inherit = ['mail.thread', 'ir.needaction_mixin']
_mail_post_access = 'read'
exe_date = fields.Date(string="日期")
executor = fields.Many2one("cinda_cmdb.member_list", string="实施人", require=True)
chg_dev_id = fields.Many2one('cinda_cmdb.device', string="设备")
chg_type = fields.Char(string="类型")
action = fields.Char(string="动作", require=True)
class device_chg_log(models.Model):
_name = "cinda_cmdb.device_chg_log"
_description = '硬件变更记录表'
_inherit = ['mail.thread', 'ir.needaction_mixin']
_mail_post_access = 'read'
exe_date = fields.Date(string="日期")
executor = fields.Many2one("cinda_cmdb.member_list", string="实施人", require=True)
chg_dev_id = fields.Many2one('cinda_cmdb.device', string="设备")
chg_type = fields.Char(string="类型")
action = fields.Char(string="动作", require=True)
class soft_chg_log(models.Model):
_name = "cinda_cmdb.soft_chg_log"
_description = '软件变更记录表'
_inherit = ['mail.thread', 'ir.needaction_mixin']
_mail_post_access = 'read'
exe_date = fields.Date(string="日期")
executor = fields.Many2one("cinda_cmdb.member_list", string="实施人", require=True)
chg_dev_id = fields.Many2one('cinda_cmdb.device', string="设备")
chg_type = fields.Char(string="类型")
action = fields.Char(string="动作", require=True)
class vm_chg_log(models.Model):
_name = "cinda_cmdb.vm_chg_log"
_description = '虚拟资源变更记录表'
_inherit = ['mail.thread', 'ir.needaction_mixin']
_mail_post_access = 'read'
exe_date = fields.Date(string="日期")
executor = fields.Many2one("cinda_cmdb.member_list", string="实施人", require=True)
chg_dev_id = fields.Many2one('cinda_cmdb.device', string="设备")
chg_type = fields.Char(string="类型")
action = fields.Char(string="动作", require=True)
class auth_chg_log(models.Model):
_name = "cinda_cmdb.auth_chg_log"
_description = '授权变更记录表'
_inherit = ['mail.thread', 'ir.needaction_mixin']
_mail_post_access = 'read'
exe_date = fields.Date(string="日期")
executor = fields.Many2one("cinda_cmdb.member_list", string="实施人", require=True)
chg_dev_id = fields.Many2one('cinda_cmdb.device', string="设备")
chg_type = fields.Char(string="类型")
action = fields.Char(string="动作", require=True)
class net_config(models.Model):
_name = "cinda_cmdb.net_config"
_description = '网络配置表'
_inherit = ['mail.thread', 'ir.needaction_mixin']
_mail_post_access = 'read'
net_config_id = fields.Char(string="网络配置管理id")
logic_area = fields.Char(string="逻辑区域")
admin_ip = fields.Char(string="管理IP")
version = fields.Char(string="软件版本")
license_date = fields.Date(string="许可证日期")
port_num = fields.Integer(string="端口数量")
port_info = fields.Char(string="端口信息")
vlan_info = fields.Char(string="VLAN信息")
fw_policy1 = fields.Char(string="防火墙策略1")
fw_policy2 = fields.Char(string="防火墙策略2")
mail_gw_policy = fields.Char(string="邮件网关策略")
class st_zone_lun(models.Model):
_name = "cinda_cmdb.st_zone_lun"
_description = 'LUN信息表'
_inherit = ['mail.thread', 'ir.needaction_mixin']
_mail_post_access = 'read'
st_zone_lun_id = fields.Char(string="存储zone_lun划分id")
zone_lun_id = fields.Char(string="ZONE_LUN_ID")
lun_id = fields.Char(string="lun号")
ioport = fields.Char(string="ioport")
total_size = fields.Float(string="总容量")
used_size = fields.Float(string="使用容量")
free_size = fields.Float(string="剩余容量")
host_name = fields.Char(string="使用的主机")
system = fields.Char(string="业务系统")
raid_type = fields.Char(string="RAID类型")
volumes_name = fields.Char(string="volumes_name")
aggregate = fields.Char(string="aggregata")
ip_addr = fields.Char(string="IP地址")
config_info = fields.Char(string="配置信息")
comment = fields.Char(string="备注")
class vlan(models.Model):
_name = "cinda_cmdb.vlan"
_description = 'VLAN信息表'
_inherit = ['mail.thread', 'ir.needaction_mixin']
_mail_post_access = 'read'
vlan_id_id = fields.Char(string="VLAN表ID")
vlan_id = fields.Char(string="VLAN号")
vlan_name = fields.Char(string="VLAN名称")
vlan_segment = fields.Char(string="VLAN网段")
comment = fields.Char(string="备注")
class fw_policy1(models.Model):
_name = "cinda_cmdb.fw_policy1"
_description = '防火墙策略表1'
_inherit = ['mail.thread', 'ir.needaction_mixin']
_mail_post_access = 'read'
fw_policy1_id = fields.Char(string="防火墙策略1id")
fw_name = fields.Char(string="防火墙名称")
s_addrname = fields.Char(string="源地址命名")
s_ip = fields.Char(string="源地址")
d_addrname = fields.Char(string="目的地址命名")
d_ip = fields.Char(string="目的地址")
service_name = fields.Char(string="服务命名")
service_port = fields.Char(string="服务端口")
policy_date = fields.Date(string="策略时间")
class fw_policy2(models.Model):
_name = "cinda_cmdb.fw_policy2"
_description = '防火墙策略表2'
_inherit = ['mail.thread', 'ir.needaction_mixin']
_mail_post_access = 'read'
fw_policy2_id = fields.Char(string="防火墙策略2id")
fw_name = fields.Char(string="防火墙名称")
switch_mode = fields.Char(string="转换模式")
s_addrname = fields.Char(string="源地址命名")
s_ip = fields.Char(string="源地址")
d_addrname = fields.Char(string="目的地址命名")
d_ip = fields.Char(string="目的地址")
switch_addrname = fields.Char(string="转换后地址命名")
switch_ip = fields.Char(string="转换后地址")
service_name = fields.Char(string="服务命令")
service = fields.Char(string="服务")
class spam_policy(models.Model):
_name = "cinda_cmdb.spam_policy"
_description = 'spam策略表'
_inherit = ['mail.thread', 'ir.needaction_mixin']
_mail_post_access = 'read'
spam_policy_id = fields.Char(stirng="SPAM策略id")
industry = fields.Char(string="行业")
company_name = fields.Char(string="公司名称")
domain_name = fields.Char(string="域名")
mx_name = fields.Char(string="mx名称")
ip_addr = fields.Char(string="IP")
desc = fields.Char(string="描述")
comment = fields.Char(string="备注")
class account(models.Model):
_name = "cinda_cmdb.account"
_description = '账户表'
_inherit = ['mail.thread', 'ir.needaction_mixin']
_mail_post_access = 'read'
account_id = fields.Char(string="账户id")
dev_id = fields.Integer(string="设备id", require=True)
soft_id = fields.Integer(string="软件id")
acc_nam = fields.Char(string="账户名称", require=True)
encr_pasw = fields.Char(string="加密密码", require=True)
use_purp = fields.Char(string="使用目的", require=True)
use_mode = fields.Char(string="使用类型", require=True)
authority = fields.Char(string="账户权限", require=True)
owner_id = fields.Integer(string="账户负责人", require=True)
auth_owner = fields.Integer(string="授权负责人", require=True)
crt_date = fields.Char(string="创建日期")
crt_pers = fields.Integer(string="创建人")
crt_appr_pers = fields.Integer(string="创建批准人")
crt_chg_num = fields.Char(string="创建的变更号")
curr_user = fields.Integer(string="当前使用人")
use_appr_pers = fields.Integer(string="当前使用授权人")
appr_date = fields.Date(string="当前授权日期")
last_recovery = fields.Date(string="上次回收日期")
comment1 = fields.Char(string="备注1")
comment2 = fields.Char(string="备注2")
last_upd = fields.Datetime(default=fields.datetime.now(), require=True)
class auth_log(models.Model):
_name = "cinda_cmdb.auth_log"
_description = '授权记录表'
_inherit = ['mail.thread', 'ir.needaction_mixin']
_mail_post_access = 'read'
auth_log_id = fields.Char(string="授权记录id")
exe_date = fields.Char(string="",require=True)
executor = fields.Integer(string="",require=True)
chg_num = fields.Char(string="")
action = fields.Char(string="",require=True)
per_user = fields.Integer(string="")
aft_user = fields.Integer(string="")
per_owner = fields.Integer(string="")
aft_owner = fields.Integer(string="")
comment1 = fields.Char(string="")
comment2 = fields.Char(string="")
last_upd = fields.Datetime(default=fields.datetime.now(), require=True)
# u位表
class position_u(models.Model):
_name = "cinda_cmdb.position_u"
_inherit = ['mail.thread', 'ir.needaction_mixin']
_description = 'U位表'
_mail_post_access = 'read'
name = fields.Char(string="名称")
status = fields.Boolean(string="状态", default=False)
cabinet_id = fields.Many2one("cinda_cmdb.cabinet", string="所在机柜", required="True")
class cluster(models.Model):
_name = "cinda_cmdb.cluster"
_description = '集群表'
_rec_name = "name"
_inherit = ['mail.thread', 'ir.needaction_mixin']
_mail_post_access = 'read'
environment = fields.Many2one("cinda_cmdb.base_type", string="环境", domain=[('class_id', 'ilike', "环境")])
name = fields.Char(string="集群")
vm_num = fields.Integer(string="虚机数量")
action_vm_num = fields.Integer(string="活动虚机数量")
server_id = fields.One2many("cinda_cmdb.server", "vir_mark")
vm_id = fields.One2many("cinda_cmdb.vm", "cluster_id")
class vm(models.Model):
_name = "cinda_cmdb.vm"
_description = '虚拟机信息表'
_inherit = ['mail.thread', 'ir.needaction_mixin']
_mail_post_access = 'read'
_rec_name = "cluster_id"
server_ids = fields.Many2one("cinda_cmdb.server", string="主机")
host_computer = fields.Char( string="主机")
cluster_id = fields.Many2one("cinda_cmdb.cluster", string="集群")
app_user_id = fields.Char(string="应用联系人")
sequence = fields.Integer(string='序号')
name = fields.Char(string='虚拟机名称')
vm_num = fields.Integer(string='虚机数量(台)')
state = fields.Selection([('start', '开机'),('shutdown', '关机'),], default="", Require="False", string="状况")
reserve_space = fields.Float(string="置备空间")
used_space = fields.Float(string="已用空间")
client_operate_sys = fields.Char(string="客户机操作系统")
memory_size = fields.Integer(string="内存大小(MB)", track_visibility='onchange')
cpu = fields.Integer(string="CPU数量")
vm_ip = fields.Char(string="虚机IP地址")
vm_run_state = fields.Selection([('running', '正在运行'), ('shutdown', '未运行'),], default="", Require="False", string="VMware Tools 运行状况")
comment = fields.Char(string="备注")
sys_module = fields.Char(string="系统模块名称")
deliver_date = fields.Date(string="交付日期")
business_type = fields.Char(string="业务类型")
back_date = fields.Date(string="计划归还日期")
class contract_purchase(models.Model):
_name = "cinda_cmdb.contract_purchase"
_description = '采购合同表'
_rec_name = "number"
_inherit = ['mail.thread', 'ir.needaction_mixin']
_mail_post_access = 'read'
device_ids = fields.Many2many("cinda_cmdb.device","device_contract_ref", "contract_id","device_id", string="序列号")
# device_id = fields.Char(string="序列号")
name = fields.Char(string="合同名称")
number = fields.Char(string="合同编号")
vendor = fields.Many2one("cinda_cmdb.vendor_list", stirng="服务商")
vendor_a = fields.Many2one("cinda_cmdb.vendor_list", stirng="供应商")
accept_date = fields.Date(string="初验日期")
reject_date = fields.Date(string="过保日期")
# reject_device = fields.Char(string="过保设备", compute="reject", store=True)
# 自动根据合同结束时间提醒邮件--距离合同结束一个月内 频率--每周
@api.multi
def email_contract_reject_date(self):
subject = '您有合同即将过期,请及时处理!'
date = fields.Date.to_string(fields.date.today()+datetime.timedelta(days=30))
user_ids=[]
for contracts in self.env['cinda_cmdb.contract_purchase'].search([('reject_date','<=',date),]):
if contracts.header_id not in user_ids:
user_ids.append(contracts.header_id)
for user_id in user_ids:
datas=''
user_contracts = self.env['cinda_cmdb.contract_purchase'].search([('date_end', '<=', date),('header_id','=',user_id.id)])
for user_contract in user_contracts:
text=u'合同名:'+user_contract.name+u'-----过期时间 '+user_contract.reject_date
datas+=u'<p>'+text+u'</p>'
body= u'<div>'+u'<p>您好:</p>'+u'<p> 以下合同即将过期或已经过期,请您及时续签或关闭,您可登录:<a href="http://123.56.147.94:8000">http://123.56.147.94:8000</a>查看详细信息</p>' + datas + u'</div>'
self.send_email(user_id,body,subject)
#邮件发送函数
def send_email(self, cr, uid, users, body='',subject='',context=None):
to_list = []
for user in users:
to_list.append(formataddr((Header(user.name, 'utf-8').encode(), user.email)))
mail_mail = self.pool.get('mail.mail')
mail_id = mail_mail.create(cr, uid, {
'body_html': body,
'subject': subject,
'email_to': to_list,
'auto_delete': True,
}, context=context)
mail_mail.browse(cr,uid,[mail_id],context=context).email_from = '<nantian_erp@nantian>'
mail_mail.send(cr, uid, [mail_id], context=context)
# @api.one
# @api.depends('reject_date')
# def reject(self):
# print self
# now = int(time.time())
# timeArray = time.strptime(self.reject_date, "%Y-%m-%d")
# old = int(time.mktime(timeArray))
# print self.device_ids.device_id, self.id, type(self.id)
# print self.name, type(now), type(old)
# print now, old
# print now < old
# if now < old: