Odoo v9 Webservice Report without layout - web-services

After following the documentation in https://www.odoo.com/documentation/9.0/api_integration.html I have encountered a problem with the generated PDF report.
I call the webservice to generate an invoice report and after rendering the pdf report, it returns without its layout ( located: account.report_invoice )
I do the following to render the report:
url = 'http://{0}:{1}/xmlrpc/2/report'.format(self._connect['host'], self._connect['port'])
sock_print = xmlrpclib.ServerProxy(url)
#Here, the 'render_report' function returns the base64 pdf without the specified layout
result = sock_print.render_report(db_name, uid, pwd, report_name, ids, {'model': 'account.invoice', 'report_type': 'qweb-pdf'})
string_pdf = base64.decodestring(report['result'])
return True, string_pdf
After, the function above is done, I save the file in a directory to check if the file was generated with the correct layout.
So far, the pdf was generated but without its layout for account.report_invoice.
Any ideas on what might be happening or what I might be missing?
Thank you for your time.
[EDIT 1]
2018-09-17 14:34:09,599 30522 INFO ? werkzeug: 127.0.0.1 - - [17/Sep/2018 14:34:09] "GET /web/content/323-c1e807b/report.assets_common.0.css HTTP/1.1" 404 -
2018-09-17 14:34:09,617 30522 INFO ? werkzeug: 127.0.0.1 - - [17/Sep/2018 14:34:09] "GET /web/content/328-9a5a204/report.assets_pdf.0.css HTTP/1.1" 404 -
2018-09-17 14:34:09,879 30522 INFO ? werkzeug: 127.0.0.1 - - [17/Sep/2018 14:34:09] "GET /web/content/328-9a5a204/report.assets_pdf.0.css HTTP/1.1" 404 -
2018-09-17 14:34:09,883 30522 INFO ? werkzeug: 127.0.0.1 - - [17/Sep/2018 14:34:09] "GET /web/content/323-c1e807b/report.assets_common.0.css HTTP/1.1" 404 -
Found this when trying to call via webservice.
When I print the reports directly from odoo interface it's O.K, but via webservice it doesn't recognise its own core css.

Related

Debugging graphql queries in Django

How can I get my GraphQL API to show more query/post data in the console? I'm running a Django app that is powered by GraphQL and served via a react frontend. With regular Django paths I would see something like this in the development server:
[04/Sep/2020 11:53:08] "GET /my_app/2020/09/01/5cc4e7cc-7.png HTTP/1.1" 200 11330
But with GraphQL all I see is this:
[04/Sep/2020 11:53:18] "POST /graphql HTTP/1.1" 200 32
[04/Sep/2020 11:53:18] "POST /graphql HTTP/1.1" 200 2993
[04/Sep/2020 11:53:29] "POST /graphql HTTP/1.1" 200 11635
Any ideas?
I highly suggest checking out Silky. It's a profiling tool that can show you
the request body - that's where you'll find the graphql
speed of the response
all the DB queries sent during your request
(if you set it up) cprofiler for the request

Flask REST API very slow on simple endpoint

I'm using a Flask REST API for my application and I've noticed that when I send requests from outside my own network, it's sometimes very, very slow. Most calls get completed within 150ms, but some take 8 seconds. The database connection is to a MySQL database using DBUtils.PersistentDB
The code for the endpoint:
#app.route("/name", methods=["POST"])
#jwt_refresh_token_required
def get_name_and_company():
user = get_jwt_identity()
response_object = server_functions.get_name_and_company(user)
return response_object
The function it uses:
def get_name_and_company(user):
sql = "SELECT fysios.firstname, fysios.lastname, companies.name FROM
fysios " +\
"INNER JOIN companies ON fysios.companyID = companies.id WHERE fysios.email = %s"
cursor = flask_server.get_db().cursor()
cursor.execute(sql, user)
data = cursor.fetchall()
first_name = data[0]['firstname']
last_name = data[0]['lastname']
company = data[0]['name']
response_object = name_and_company(first_name, last_name, company)
return make_response(jsonify(response_object)), 200
Here are the timestamps on the Flask server (it is the internal dev server, but I am running it with threaded=True):
[08/Mar/2019 22:16:54] "OPTIONS /login HTTP/1.1" 200 -
[08/Mar/2019 22:16:55] "POST /login HTTP/1.1" 200 -
[08/Mar/2019 22:16:55] "OPTIONS /clients HTTP/1.1" 200 -
[08/Mar/2019 22:16:55] "OPTIONS /verifyLogin HTTP/1.1" 200 -
[08/Mar/2019 22:16:55] "POST /clients HTTP/1.1" 200 -
[08/Mar/2019 22:16:57] "POST /verifyLogin HTTP/1.1" 200 -
[08/Mar/2019 22:16:57] "OPTIONS /name HTTP/1.1" 200 -
[08/Mar/2019 22:16:58] "POST /clients HTTP/1.1" 200 -
[08/Mar/2019 22:17:05] "POST /name HTTP/1.1" 200 -
As you can see, /name takes a total of 8 seconds and I can't find out why. This call to /name is just an example, it can happen on any of the calls. Is there a way to find out where the Flask application is actually stuck on?
Deploying to AWS Beanstalk solved the problem. I don't know if the limitations of the build-in dev server is to blame, but that's what did it for me.

Django SAML integration

I am using Django 1.9, Python 3, running locally on Docker (for testing)
Trying to integrate django-saml2-auth into my application.
Pretty much followed all the steps in the docs:
1) All installations were successful
2) New URLs were imported above the rest
3) Installed apps includes 'django_saml2_auth'
4) 'SAML2_AUTH' dict was placed in settings (and all attributes were mapped)
5) In the SAML2 identity provider (using OneLogin), the Single-sign-on URL and Audience URI(SP Entity ID) was set to http://127.0.0.1:8000/saml2_auth/acs/
What happens is that when I get to http://127.0.0.1:8000/admin the browser goes into an infinite redirect loop:
...
[02/May/2018 15:43:06] "GET /admin/ HTTP/1.1" 302 0
[02/May/2018 15:43:06] "GET /admin/login/?next=/admin/ HTTP/1.1" 302 0
[02/May/2018 15:43:07] "POST /saml2_auth/acs/ HTTP/1.1" 302 0
[02/May/2018 15:43:07] "GET /admin/ HTTP/1.1" 302 0
[02/May/2018 15:43:07] "GET /admin/login/?next=/admin/ HTTP/1.1" 302 0
[02/May/2018 15:43:08] "POST /saml2_auth/acs/ HTTP/1.1" 302 0
[02/May/2018 15:43:08] "GET /admin/ HTTP/1.1" 302 0
...
When I disable django-saml2-auth I see that a staff user was created.
In the OneLogin interface I can see that I logged in successfully.
Overriding django_saml2_auth.views.signin(r), where r is a django.core.handlers.wsgi.WSGIRequest, for <WSGIRequest: GET '/admin/login/?next=/admin/'>, and in the request, the user is set to AnonymousUser, COOKIES contain sessionid and csrftoken.
I would expect that a session would start for the user that was created/fetched, and that I will get to an /admin/<whatever> page.
I will appreciate any help in debugging this, thank you!
EDIT: I was able to get it to work by removing AUTHENTICATION_BACKENDS from settings.py- I have 3 other backends that I use. It seems like they conflict with django-saml2-auth.
Is there any way to get django-saml2-auth to work with other backends?
EDIT 2: Will try to integrate django-saml2-pro-auth, which has a backend so will not conflict. I would really appreciate some insight though.
EDIT 3: back to EDIT 2, when I remove all the backends and they don't conflict, the log flow looks like that:
[04/May/2018 15:24:26] "GET /admin/ HTTP/1.1" 302 0
[04/May/2018 15:24:27] "GET /admin/login/?next=/admin/ HTTP/1.1" 302
[04/May/2018 15:26:27] "POST /saml2_auth/acs/ HTTP/1.1" 302 0
[04/May/2018 15:26:27] "GET /admin/ HTTP/1.1" 200 38398
Where the last GET does not get redirected, with 200.
Issue resolved:
After taking a deeper dive- it seems like this code is the issue:
In django_saml2_auth/views.py, acs():
if target_user.is_active:
target_user.backend = 'django.contrib.auth.backends.ModelBackend'
login(r, target_user)
else:
return HttpResponseRedirect(get_reverse([denied, 'denied', 'django_saml2_auth:denied']))
It seems like the default ModelBackend is necessary.
When other backends are used, the default is no longer used by Django, and hence the infinite loop.
If the default backend is added to the list of backends, everything works as intended.

Flask extension, failing to return image path when using sub-path of root

I'm working on adding additional functionality to Flask-Resize, specifically adding a feature that should serve the original file instead of generating a cached file if the size and other parameters are the same as the original.
I have everything worked out in the checks and so forth, and everything works fine if the image is in the RESIZE_ROOT directory but if not, when the image generator detects that it doesn't need to do anything and returns the original file path, jinja2 doesn't seem to fetch the image.
Using an image test_img.jpg with a size of 200x300px, in the RESIZE_ROOT directory works fine:
<img src="{{ 'test_img.jpg'|resize('200') }}"></img>
Output:
http://127.0.0.1:5000/static/images/test_img.jpg
127.0.0.1 - - [23/Oct/2015 03:44:28] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [23/Oct/2015 03:44:28] "GET /static/css/main.css HTTP/1.1" 200 -
127.0.0.1 - - [23/Oct/2015 03:44:28] "GET /static/images/test_img.jpg HTTP/1.1" 200 -
-- test_img.jpg fetched and displayed correctly
However when the image is moved to a sub-directory say ad/test_img.jpg, then the console output doesn't even indicate that it is fetching the image
http://127.0.0.1:5000/static/images/ad/test_img.jpg
127.0.0.1 - - [23/Oct/2015 03:58:42] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [23/Oct/2015 03:58:42] "GET /static/css/main.css HTTP/1.1" 200 -
-- ad/test_img.jpg isn't even being fetched
Putting image generates a valid link to the image, so the file path is getting returned correctly so I have no idea what's going on.
This is the relevant code; generate_image raises a exc.StopImageGeneration exception if it detects that it should not generate an image.
if not os.path.exists(full_cache_path):
try:
generate_image(inpath=original_path, outpath=full_cache_path,
format=format, width=width, height=height,
bgcolor=bgcolor, upscale=upscale, fill=fill,
anchor=anchor, quality=quality,
progressive=progressive,
placeholder_reason=placeholder_reason,
force_cache=force_cache)
except exc.StopImageGeneration:
full_cache_url = unicode(resize_url+image_url)
print (full_cache_url)
return full_cache_url.replace('\\', '/')
And my Flask-Resize initialisation parameters if it matters:
(RESIZE_URL='http://127.0.0.1:5000/static/images/', RESIZE_ROOT='static/images/')
So turns out this has nothing to do with Flask/Jinja2, it's Adblock's fault; it was blocking the images silently.
After I added an exception for localhost and 127.0.0.1 there was no problem.

wso2 api manager how to close http_access.log

I finid that at {wso2am_home}repository/logs/ have logs:
http_access_2013-10-28.log
tm.out wso2-apigw-errors.log
wso2-apigw-service.log
wso2-apigw-trace.log
wso2carbon-trace-messages.log
wso2carbon.log
and I configure all the log4j.properties INFO to OFF. I don't know where to close the http_access.log.
I find when I call 1 time api,it write the http_access.log: gwmanager.apim-wso2.com:8280 - - - "GET /direct/1.0.5 HTTP/1.1" - - "-" "Jakarta Commons-HttpClient/3.1" 128.6.X.X:80 - - - "GET http://128.6.X.X:80 HTTP/1.1" - - "-" "Synapse-HttpComponents-NIO so,as I call api time more and more ,the file is more and ---------- more big.
Do you know how to close the http_access.log?
If you want to disable http access logs in WSO2 products then go to catalina-server.xml which is located {CARBON_HOME}/repository/conf/tomcat directory, and remove the following property
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="${carbon.home}/repository/logs"
prefix="http_access_" suffix=".log"
pattern="combined" />
Please refer this for more details