-
Notifications
You must be signed in to change notification settings - Fork 0
/
is_gabarit_controle.py
215 lines (171 loc) · 9.53 KB
/
is_gabarit_controle.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
# -*- coding: utf-8 -*-
from openerp import models,fields,api,tools,SUPERUSER_ID
from openerp.tools.translate import _
from openerp.exceptions import Warning
from datetime import datetime
from dateutil.relativedelta import relativedelta
from openerp.osv import osv
import xmlrpclib
from is_outillage import date_prochain_controle
class is_gabarit_controle(models.Model):
_name='is.gabarit.controle'
_order='code_pg'
_rec_name='code_pg'
_sql_constraints = [('code_pg_uniq','UNIQUE(code_pg)', u'Ce code existe déjà')]
code_pg = fields.Char("Code PG" , required=True)
designation = fields.Char("Désignation", required=True)
fabriquant = fields.Char("Fabricant")
date_reception = fields.Date("Date de réception")
reference_plan = fields.Char("Référence plan")
indice_plan = fields.Char("Indice plan")
moule_ids = fields.Many2many('is.mold' ,'is_gabarit_mold_rel' ,'gabarit_id','mold_id' , string="Moules affectés")
dossierf_ids = fields.Many2many('is.dossierf','is_gabarit_dossierf_rel','gabarit_id','dossierf_id', string="Dossiers F affectés")
client_id = fields.Many2one("res.partner","Client")
site_id = fields.Many2one('is.database', string='Site')
lieu_stockage = fields.Char("Lieu de stockage")
periodicite = fields.Selection([
('24','24 mois (standard)'),
('48','48 mois ( qté annuelle < 10000p)'),
], string="Périodicité ( en mois )")
type_controle = fields.Many2one("is.type.controle.gabarit","Type de contrôle")
date_prochain_controle = fields.Date("Date prochain contrôle", compute='_compute_date_prochain_controle', readonly=True, store=True)
controle_ids = fields.One2many('is.historique.controle', 'gabarit_id', string='Historique des contrôles')
is_database_origine_id = fields.Integer("Id d'origine", readonly=True)
active = fields.Boolean('Active', default=True)
@api.multi
@api.depends('controle_ids','periodicite')
def _compute_date_prochain_controle(self):
for rec in self:
date_prochain_controle(rec)
@api.multi
def write(self, vals):
try:
res=super(is_gabarit_controle, self).write(vals)
for obj in self:
obj.copy_other_database_gabarit_controle()
return res
except Exception as e:
raise Warning(e)
@api.model
def create(self, vals):
try:
obj=super(is_gabarit_controle, self).create(vals)
obj.copy_other_database_gabarit_controle()
return obj
except Exception as e:
raise osv.except_osv(_('Controle!'),
_('(%s).') % str(e).decode('utf-8'))
@api.multi
def copy_other_database_gabarit_controle(self):
cr , uid, context = self.env.args
context = dict(context)
database_obj = self.env['is.database']
database_lines = database_obj.search([])
for controle in self:
for database in database_lines:
if not database.ip_server or not database.database or not database.port_server or not database.login or not database.password:
continue
DB = database.database
USERID = SUPERUSER_ID
DBLOGIN = database.login
USERPASS = database.password
DB_SERVER = database.ip_server
DB_PORT = database.port_server
sock = xmlrpclib.ServerProxy('http://%s:%s/xmlrpc/object' % (DB_SERVER, DB_PORT))
gabarit_controle_vals = self.get_gabarit_controle_vals(controle, DB, USERID, USERPASS, sock)
dest_gabarit_controle_ids = sock.execute(DB, USERID, USERPASS, 'is.gabarit.controle', 'search', [('is_database_origine_id', '=', controle.id),
'|',('active','=',True),('active','=',False)], {})
if dest_gabarit_controle_ids:
sock.execute(DB, USERID, USERPASS, 'is.gabarit.controle', 'write', dest_gabarit_controle_ids, gabarit_controle_vals, {})
gabarit_controle_created_id = dest_gabarit_controle_ids[0]
else:
gabarit_controle_created_id = sock.execute(DB, USERID, USERPASS, 'is.gabarit.controle', 'create', gabarit_controle_vals, {})
return True
@api.model
def get_gabarit_controle_vals(self, controle, DB, USERID, USERPASS, sock):
is_controle_vals ={
'code_pg' : tools.ustr(controle.code_pg or ''),
'designation' : tools.ustr(controle.designation or ''),
'fabriquant' : tools.ustr(controle.fabriquant or ''),
'date_reception' : controle.date_reception ,
'reference_plan' : tools.ustr(controle.reference_plan or ''),
'indice_plan' : controle.indice_plan,
'moule_ids' : self._get_moule_ids(controle , DB, USERID, USERPASS, sock),
'dossierf_ids' : self._get_dossierf_ids(controle , DB, USERID, USERPASS, sock),
'client_id' : self._get_client_id(controle, DB, USERID, USERPASS, sock),
'site_id' : self._get_site_id(controle, DB, USERID, USERPASS, sock),
'lieu_stockage' : tools.ustr(controle.lieu_stockage or ''),
'periodicite' : controle.periodicite ,
'type_controle' : self._get_type_controle(controle, DB, USERID, USERPASS, sock),
'is_database_origine_id': controle.id,
'active' : controle.site_id and controle.site_id.database == DB and True or False,
}
return is_controle_vals
@api.model
def _get_fabriquant_id(self, controle, DB, USERID, USERPASS, sock):
if controle.fabriquant_id:
fabriquant_ids = sock.execute(DB, USERID, USERPASS, 'res.partner', 'search', [('is_database_origine_id', '=', controle.fabriquant_id.id)], {})
if fabriquant_ids:
return fabriquant_ids[0]
return False
@api.model
def _get_dossierf_ids(self, controle , DB, USERID, USERPASS, sock):
ids = []
for obj in controle.dossierf_ids:
res = sock.execute(DB, USERID, USERPASS, 'is.dossierf', 'search', [('is_database_origine_id', '=', obj.id)], {})
if res:
ids.append(res[0])
return [(6,0,ids)]
@api.model
def _get_moule_ids(self, controle , DB, USERID, USERPASS, sock):
lst_moule_ids = []
for moule in controle.moule_ids:
is_moule_ids = sock.execute(DB, USERID, USERPASS, 'is.mold', 'search', [('is_database_origine_id', '=', moule.id)], {})
if is_moule_ids:
lst_moule_ids.append(is_moule_ids[0])
return [(6,0,lst_moule_ids)]
@api.model
def _get_client_id(self, controle, DB, USERID, USERPASS, sock):
if controle.client_id:
client_ids = sock.execute(DB, USERID, USERPASS, 'res.partner', 'search', [('is_database_origine_id', '=', controle.client_id.id)], {})
if client_ids:
return client_ids[0]
return False
@api.model
def _get_site_id(self, controle, DB, USERID, USERPASS, sock):
if controle.site_id:
site_ids = sock.execute(DB, USERID, USERPASS, 'is.database', 'search', [('is_database_origine_id', '=', controle.site_id.id)], {})
if site_ids:
return site_ids[0]
return False
@api.model
def _get_type_controle(self, controle, DB, USERID, USERPASS, sock):
if controle.type_controle:
type_controle_ids = sock.execute(DB, USERID, USERPASS, 'is.type.controle.gabarit', 'search', [('is_database_origine_id', '=', controle.type_controle.id)], {})
if not type_controle_ids:
controle.type_controle.copy_other_database_controle_gabarit()
type_controle_ids = sock.execute(DB, USERID, USERPASS, 'is.type.controle.gabarit', 'search', [('is_database_origine_id', '=', controle.type_controle.id)], {})
if type_controle_ids:
return type_controle_ids[0]
return False
@api.model
def _get_fournisseur_id(self, controle, DB, USERID, USERPASS, sock):
if controle.fournisseur_id:
fournisseur_ids = sock.execute(DB, USERID, USERPASS, 'res.partner', 'search', [('is_database_origine_id', '=', controle.fournisseur_id.id)], {})
if fournisseur_ids:
return fournisseur_ids[0]
return False
# @api.model
# def _get_controle_ids(self, controle, DB, USERID, USERPASS, sock):
# list_controle_ids =[]
# for is_controle in controle.controle_ids:
# is_controle_ids = sock.execute(DB, USERID, USERPASS, 'is.historique.controle', 'search', [('is_database_origine_id', '=', is_controle.id)], {})
# if is_controle_ids:
# list_controle_ids.append(is_controle_ids[0])
# return [(6, 0, list_controle_ids)]
class is_emplacement_outillage(models.Model):
_name = "is.emplacement.outillage"
name = fields.Char("Name")
class is_type_controle_gabarit(models.Model):
_name = "is.type.controle.gabarit"
name = fields.Char("Name")