gpt4 book ai didi

Odoo 同时创建多条记录时崩溃

转载 作者:行者123 更新时间:2023-12-04 08:38:18 27 4
gpt4 key购买 nike

我创建了一种方法,我可以在其中导入 csv 文件并使用其中包含的数据创建新记录。该方法适用于大约 1000 行的 csv。 (该方法可以创建大约 1000 条新记录),但是当 csv 文件超过 1200 行时,Odoo 服务器崩溃,我必须重新启动服务器。这是我的方法和odoo日志

   @api.multi
@profile
def action_import_csv(self):
cuenta = 0
self._chequear_extension_csv(self.archivo_filename)
res = base64.b64decode(self.archivo)
text = res.decode("UTF-8")
reader = csv.DictReader(io.StringIO(text))
brigadista = self.env['utepda_brigadas.brigadista']
brigada = self.env['utepda_brigadas.brigada']
brigada_cr = self.env.cr

brigadista_brigada = self.env['utepda_brigadas.brigadista_brigada']
count = 0
campos = [
'BRIGADA', 'NOMBRE', 'CEDULA', 'CARGO', 'JORNALES', 'COSTO_JORNADA'
]

rows = list(reader)
totalrows = len(rows)
print("La cantidad de filas es {}".format(totalrows))
for index,row in enumerate(rows):
print("Index -> {} -> {}".format(index,row))
if count == 0:
count = 1
self._chequear_campos_csv(campos, row.keys())
else:
codigo_brigada = row['BRIGADA']
nombre = row['NOMBRE']
cedula = row['CEDULA'].replace('-', '')
cargo = row['CARGO']
dias_trabajados = row['JORNALES']
total_jornada = row['COSTO_JORNADA']
fecha = self.fecha
total = int(dias_trabajados) * int(total_jornada)
existe_brigadista = brigadista.search([['cedula', '=', cedula]],limit=1)

brigada_actual = brigada.search([['codigo', '=', codigo_brigada]],limit=1)
#brigada_cr.execute(
# "SELECT id FROM public.utepda_brigada_brigada WHERE codigo=%s"
# % codigo_brigada)
#res = brigada_cr.fetchone()
#brigada_actual = brigada.search([['codigo', '=', codigo_brigada]],
#limit=1)
#brigada_actual = res[0]
if not existe_brigadista.id:
new = {
'name':
nombre,
'cedula':
cedula,
'cargo':
cargo,
'estado':
"nuevo",
'brigada_ids': [(0, _, {
'fecha': fecha,
'dias_trabajados': dias_trabajados,
'total': total,
'brigada_id': brigada_actual.id
})]
}
nuevo_brigadista = brigadista.create(new)
if nuevo_brigadista.id:
cuenta = cuenta+1
print("""{} Se ha insertado el brigadista {} con nombre {}""".format(cuenta,nuevo_brigadista.id,
nuevo_brigadista.name))
#existe_brigadista = existe_brigadista[0]

else:
existe_brigadista.write({
'estado':
"reportado",
'brigada_ids': [(0, _, {
'fecha': fecha,
'dias_trabajados': dias_trabajados,
'total': total,
'brigada_id': brigada_actual.id
})]
})

fecha_format = datetime.strftime(self.fecha, '%m/%Y')
no_reportados = brigadista.search(
[['fecha_ultimo_reporte', '!=', fecha_format]])
no_reportados.write({'estado': "no_reportado"})

return {
'type': 'ir.actions.client',
'tag': 'reload',
}
这是 Odoo 日志
2020-11-04 11:44:23,285 15044 WARNING odoo odoo.service.server: Thread <Thread(odoo.service.http.request.140355723687680, started 140355723687680)> virtual real time limit (152/120s) reached. 
2020-11-04 11:44:23,289 15044 INFO odoo odoo.service.server: Dumping stacktrace of limit exceeding threads before reloading
2020-11-04 11:44:23,520 15044 INFO odoo odoo.tools.misc:
# Thread: <Thread(odoo.service.http.request.140355723687680, started 140355723687680)> (db:odoo) (uid:2) (url:http://localhost:8069/web/dataset/call_button)
File: "/home/ernesto/.vscode/extensions/ms-python.python-2020.5.86806/pythonFiles/lib/python/debugpy/no_wheels/debugpy/_vendored/pydevd/_pydev_bundle/pydev_monkey.py", line 823, in __call__
ret = self.original_func(*self.args, **self.kwargs)
File: "/usr/lib/python3.6/threading.py", line 884, in _bootstrap
self._bootstrap_inner()
File: "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner
self.run()
File: "/usr/lib/python3.6/threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File: "/usr/lib/python3.6/socketserver.py", line 654, in process_request_thread
self.finish_request(request, client_address)
File: "/usr/lib/python3.6/socketserver.py", line 364, in finish_request
self.RequestHandlerClass(request, client_address, self)
File: "/usr/lib/python3.6/socketserver.py", line 724, in __init__
self.handle()
File: "/usr/local/lib/python3.6/dist-packages/werkzeug/serving.py", line 228, in handle
rv = BaseHTTPRequestHandler.handle(self)
File: "/usr/lib/python3.6/http/server.py", line 418, in handle
self.handle_one_request()
File: "/usr/local/lib/python3.6/dist-packages/werkzeug/serving.py", line 263, in handle_one_request
return self.run_wsgi()
File: "/usr/local/lib/python3.6/dist-packages/werkzeug/serving.py", line 205, in run_wsgi
execute(self.server.app)
File: "/usr/local/lib/python3.6/dist-packages/werkzeug/serving.py", line 193, in execute
application_iter = app(environ, start_response)
File: "/home/ernesto/odoo12/odoo/service/server.py", line 434, in app
return self.app(e, s)
File: "/home/ernesto/odoo12/odoo/service/wsgi_server.py", line 142, in application
return application_unproxied(environ, start_response)
File: "/home/ernesto/odoo12/odoo/service/wsgi_server.py", line 117, in application_unproxied
result = odoo.http.root(environ, start_response)
File: "/home/ernesto/odoo12/odoo/http.py", line 1320, in __call__
return self.dispatch(environ, start_response)
File: "/home/ernesto/odoo12/odoo/http.py", line 1293, in __call__
return self.app(environ, start_wrapped)
File: "/usr/local/lib/python3.6/dist-packages/werkzeug/wsgi.py", line 599, in __call__
return self.app(environ, start_response)
File: "/home/ernesto/odoo12/odoo/http.py", line 1488, in dispatch
result = ir_http._dispatch()
File: "/home/ernesto/odoo12/addons/auth_signup/models/ir_http.py", line 19, in _dispatch
return super(Http, cls)._dispatch()
File: "/home/ernesto/odoo12/addons/web_editor/models/ir_http.py", line 22, in _dispatch
return super(IrHttp, cls)._dispatch()
File: "/home/ernesto/odoo12/odoo/addons/base/models/ir_http.py", line 203, in _dispatch
result = request.dispatch()
File: "/home/ernesto/odoo12/odoo/http.py", line 698, in dispatch
result = self._call_function(**self.params)
File: "/home/ernesto/odoo12/odoo/http.py", line 346, in _call_function
return checked_call(self.db, *args, **kwargs)
File: "/home/ernesto/odoo12/odoo/service/model.py", line 98, in wrapper
return f(dbname, *args, **kwargs)
File: "/home/ernesto/odoo12/odoo/http.py", line 339, in checked_call
result = self.endpoint(*a, **kw)
File: "/home/ernesto/odoo12/odoo/http.py", line 941, in __call__
return self.method(*args, **kw)
File: "/home/ernesto/odoo12/odoo/http.py", line 519, in response_wrap
response = f(*args, **kw)
File: "/home/ernesto/odoo12/addons/web/controllers/main.py", line 966, in call_button
action = self._call_kw(model, method, args, {})
File: "/home/ernesto/odoo12/addons/web/controllers/main.py", line 954, in _call_kw
return call_kw(request.env[model], method, args, kwargs)
File: "/home/ernesto/odoo12/odoo/api.py", line 759, in call_kw
return _call_kw_multi(method, model, args, kwargs)
File: "/home/ernesto/odoo12/odoo/api.py", line 746, in _call_kw_multi
result = method(recs, *args, **kwargs)
File: "<decorator-gen-127>", line 2, in action_import_csv
File: "/home/ernesto/odoo12/odoo/tools/profiler.py", line 128, in _odooProfile
result = method(*args, **kwargs)
File: "/home/ernesto/odoo12/extra_addons/utepda_brigadas/models/model_wizard.py", line 81, in action_import_csv
nuevo_brigadista = brigadista.create(new)
File: "<decorator-gen-111>", line 2, in create
File: "/home/ernesto/odoo12/odoo/api.py", line 461, in _model_create_multi
return create(self, [arg])
File: "/home/ernesto/odoo12/addons/mail/models/mail_thread.py", line 278, in create
thread._message_log(body=_('%s created') % doc_name)
File: "/home/ernesto/odoo12/addons/mail/models/mail_thread.py", line 2230, in _message_log
message = self.env['mail.message'].sudo().create(message_values)
File: "<decorator-gen-107>", line 2, in create
File: "/home/ernesto/odoo12/odoo/api.py", line 440, in _model_create_single
return create(self, arg)
File: "/home/ernesto/odoo12/addons/mail/models/mail_message.py", line 990, in create
message = super(Message, self).create(values)
File: "<decorator-gen-3>", line 2, in create
File: "/home/ernesto/odoo12/odoo/api.py", line 461, in _model_create_multi
return create(self, [arg])
File: "/home/ernesto/odoo12/odoo/models.py", line 3583, in create
records = self._create(data_list)
File: "/home/ernesto/odoo12/odoo/models.py", line 3669, in _create
col_val = field.convert_to_column(val, self, stored)
File: "/home/ernesto/odoo12/odoo/fields.py", line 1555, in convert_to_column
strip_classes=self.strip_classes)
File: "/home/ernesto/odoo12/odoo/tools/mail.py", line 227, in html_sanitize
cleaned = cleaner.clean_html(src)
File: "/usr/local/lib/python3.6/dist-packages/lxml/html/clean.py", line 517, in clean_html
doc = fromstring(html)
File: "/usr/local/lib/python3.6/dist-packages/lxml/html/__init__.py", line 876, in fromstring
doc = document_fromstring(html, parser=parser, base_url=base_url, **kw)
File: "/usr/local/lib/python3.6/dist-packages/lxml/html/__init__.py", line 762, in document_fromstring
value = etree.fromstring(html, parser, **kw)
2020-11-04 11:44:23,522 15044 INFO odoo odoo.service.server: Initiating server reload

最佳答案

由于记录的数量庞大,它可能会超时。将以下内容添加到您的配置文件中,但请尝试设置以查看最适合您的设置。

--limit-time-real 10000

limit_time_real = 480
如果可以不减慢 Odoo 的速度,我也会增加 worker
https://www.odoo.com/documentation/14.0/setup/deploy.html#builtin-server

关于Odoo 同时创建多条记录时崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64683529/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com