Odoo Help

4

0
4 Answers
1
Avatar

Atchuthan - Technical Consultant, Sodexis Inc India

--Atchuthan - Technical Consultant, Sodexis Inc--
4377
| 6 6 10
Puducherry, India
--Atchuthan - Technical Consultant, Sodexis Inc--
Passionate coder in Python/Odoo(formerly known as OpenERP).

Contact me via GMail: atchuthantu@gmail.com via Skype: atchuthan_skype
via Linkedin: http://in.linkedin.com/in/atchuthantu
Atchuthan - Technical Consultant, Sodexis Inc India
12/16/14, 2:33 AM

You could use TIMEDELTA to increase or decrease date value.

from datetime import datetime, timedelta
print (datetime.today() + timedelta(days=(1))).strftime('%Y-%m-%d')    // for next day
print (datetime.today() + timedelta(days=(-1))).strftime('%Y-%m-%d')    // for previous day

For more info: https://docs.python.org/2/library/datetime.html#timedelta-objects

1 Comment
Miftahussalam Indonesia
6/7/17, 1:52 AM

ok, thanks you mr. Atchuthan

0
mohammad ali India
4/30/18, 2:57 AM

It is better to use underscore in filename than any other special character since it widely accepted Therefore constructing file name as below:

from elasticsearch import Elasticsearch
import csv

es = Elasticsearch(["9200"])

# Replace the following Query with your own Elastic Search Query
res = es.search(index="search", body=
                {
                    "_source": ["DTDT", "TRDT", "SPLE", "RPLE"],
                    "query": {
                        "bool": {
                            "should": [
                                {"wildcard": {"CN": "TEST1"}}

                            ]
                        }
                    }
}, size=10)

from datetime import datetime
import os

file_path = <PASS YOUR FILE HERE>

csv_file = 'myfile_' + str(datetime.now().strftime('%Y_%m_%d_%H_%M_%S')) + '.csv'

csv_file_full = os.path.join(file_path, os.sep, csv_file)

header_names = { 'DTDT': 'DATE', 'TRDT': 'TIME', ...}

with open(csv_file_full, 'w') as f:  # Just use 'w' mode in 3.x
    header_present  = False
    for doc in res['hits']['hits']:
        my_dict = doc['_source']
        if not header_present:
            w = csv.DictWriter(f, my_dict.keys())
            w.writerow(header_names)  # will write DATE, TIME, ... in correct place
            header_present = True


        w.writerow(my_dict)
Ask a Question
Writer
Keep Informed
1 follower(s)
About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register
Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now