forked from Som-Energia/openerp_som_addons
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgiscedata_serveis_generacio.py
52 lines (42 loc) · 1.73 KB
/
giscedata_serveis_generacio.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
# -*- coding: utf-8 -*-
from osv import osv, fields
class GiscedataServeiGeneracio(osv.osv):
_name = "giscedata.servei.generacio"
_inherit = "giscedata.servei.generacio"
def create(self, cursor, uid, vals, context=None):
if context is None:
context = {}
res_id = super(GiscedataServeiGeneracio, self).create(cursor, uid, vals, context)
if vals.get('name'):
imd_obj = self.pool.get('ir.model.data')
categ_obj = self.pool.get('giscedata.polissa.category')
new_name = " [AUVI] " + vals.get('name')
new_code = "AUVI" + ''.join([x[0] for x in vals.get('name').split()]).upper()
auvidi_categ_id = imd_obj.get_object_reference(
cursor, uid, 'som_auvidi', 'polissa_category_auvidi_base'
)[1]
existing_ids = categ_obj.search(cursor, uid, [('name', '=', new_name)])
new_vals = {}
if len(existing_ids):
new_vals.update({
'categoria_polissa': existing_ids[0]
})
else:
categ_vals = {
'name': new_name,
'code': new_code,
'parent_id': auvidi_categ_id,
}
new_categ_id = categ_obj.create(cursor, uid, categ_vals, context=context)
new_vals.update({
'categoria_polissa': new_categ_id
})
self.write(cursor, uid, [res_id], new_vals)
return res_id
_columns = {
"categoria_polissa": fields.many2one("giscedata.polissa.category", "Categoria pòlissa"),
}
_defaults = {
'mode_factura': lambda *a: 'contracte'
}
GiscedataServeiGeneracio()