-
Notifications
You must be signed in to change notification settings - Fork 344
/
od13.py
50 lines (44 loc) · 1.32 KB
/
od13.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
import logging
_logger = logging.getLogger(__name__)
def multi(method):
method._api = 'multi'
return method
def model_cr(method):
method._api = 'model_cr'
return method
from odoo import api
api.multi = multi
api.model_cr = model_cr
try:
from odoo import api
api.multi = multi
api.model_cr = model_cr
except:
import traceback;traceback.print_exc()
from odoo import models
origin_write = models.BaseModel.write
def write(self, vals):
_vals = {}
for k,v in vals.items():
if k in self._fields:
_vals[k] = v
else:
_logger.warning('>>> odoo 13 hook: model %s has no field %s', self._name, k)
#vals = { k:v for k,v in vals.items() if k in self._fields}
return origin_write(self, _vals)
models.BaseModel.write = write
origin_create = models.BaseModel.create
@api.model_create_multi
def create(self, vals_list):
_vals_list = []
for vals in vals_list:
_vals = {}
for k,v in vals.items():
if k in self._fields:
_vals[k] = v
else:
_logger.warning('>>> odoo 13 hook: model %s has no field %s', self._name, k)
#vals = { k:v for k,v in vals.items() if k in self._fields}
_vals_list.append(_vals)
return origin_create(self, _vals_list)
models.BaseModel.create = create