Showing posts with label Information Technology. Show all posts
Showing posts with label Information Technology. Show all posts

How to change date format from any format to MM/DD/YY using Python Pandas.



Provided code will work for following scenarios.

  • Change date format from M/D/YY to MM/DD/YY (5/2/2009 to 05/02/2009)
  • change form ANY FORMAT to MM/DD/YY

import pandas as pd  
'''
       * checking provided input file date format correct or not
       * if format is correct change date format from M/D/YY to MM/DD/YY
       * else date format is not correct in input file
         Date format  change form ANY FORMAT to MM/DD/YY
  '''
input_file_name = 'C:/Users/Admin/Desktop/Emp_SarenderReddy/predictions.csv'
dest_file_name = 'C:/Users/Admin/Desktop/Emp_SarenderReddy/Enrich.csv'
#input_file_name = 'C:/Users/Admin/Desktop/Emp_SarenderReddy/enrichment.csv'
read_data = pd.read_csv(input_file_name)
print(pd.to_datetime(read_data['Date'], format='%m/%d/%Y', errors='coerce').notnull().all())

if pd.to_datetime(read_data['Date'], format='%m/%d/%Y', errors='coerce').notnull().all():
    print("Provided correct input date format in input file....!")
    read_data['Date'] = pd.to_datetime(read_data['Date'],format='%m/%d/%Y')
    read_data['Date'] = read_data['Date'].dt.strftime('%m/%d/%Y')
    read_data.to_csv(dest_file_name,index=False)
    print(read_data['Date'])
else:
    print("NOT... Provided correct input date format in input file....!")
    data_format = pd.read_csv(input_file_name,parse_dates=['Date'], dayfirst=True)
    #print(df['Date'])
    data_format['Date'] = pd.to_datetime(data_format['Date'],format='%m/%d/%Y')
    data_format['Date'] = data_format['Date'].dt.strftime('%m/%d/%Y')
    data_format.to_csv(dest_file_name,index=False)
    print(data_format['Date'])
    

Django Basic Commands while developing Application


1) Go to: /var/www/html/django-apps (Your project directory) 

2) Activate virtual environment:  
.  env/bin/activate

3) TO create tables at backend(First time):
python manage.py migrate                 

4) To Run server:
 python manage.py runserver 10.0.1.89:8000     

5) TO create admin user in Django application: 
python manage.py createsuperuser      

6) TO create new app in Django:
django-admin startapp boards

7) To generate SQL Queries in boards/migrations/0001_initial.py file :
python manage.py makemigrations

8) Above SQL Queries will execute in database:
python manage.py sqlmigrate boards 0001

9) The next step now is to apply the migration we generated to the database:
python manage.py migrate

10) TO create new app in project:
django-admin startapp accounts

11) If you get error like Run 'manage.py makemigrations' to make new migrations, and then re-run 'manage.py migrate' to apply them.
Run below commands:
python manage.py makemigrations
python manage.py migrate
python manage.py sqlmigrate boards 0001


How to upgrade Odoo Database.


Upgrade Odoo Database.

You have to follow below procedure while upgrading Odoo(OpenERP).
Below procedure is for DB Upgrade from Odoo9 to Odoo11

Install Openupgrade module:
Using below link Need to install Openupgrade module in server file path: 
   /var/tmp https://github.com/OCA/openupgrade

Go to,  /opt/odoo and change the file path in migrate.py near line 208, for the attribute ‘default’ as below.
   default='/var/tmp/openupgrade'


Login as Odoo user and run below commands.
DB name: DB_Production
command  for converting odoo9 DB to 10 DB :
python migrate.py config=/etc/odoo.conf -database=DB_Production    runmigrations=10.0

After some time the above command will generate DB_Production_migrated database.
Keep generate database using  below command.

Converting Odoo10 to 11 command :
python migrate.py config=/etc/odoo.conf -database=DB_Production_migrated runmigrations=11

Above command will give DB_Production_migrated_migrated database.
If you want to view log use below command in other terminal.
   /var/tmp/openupgrade$ tail - migration.log

Post generate database, we will access odoo11 database(DB_Production_migrated_migrated) with odoo 11 files(Website URL).
While you are accessing odoo11 database, you will mostly get below errors.
Open odoo 11 database and resolve errors. Below solutions useful for resolve errors.  

For displaying errors use below commands.
1)Login as odoo user in terminal
2)cd /opt/odoo11/odoo (odoo directory)
3)./odoo-bin (it will give server log, in this log errors will display while access website URL)


Below are server error logs we found.

---------------------------------------------------------------------
delete from ir_cron;
Field `notify_email` does not exist
Error context:
View `res.partner.view.form.inherit.mail`
[view_id: 1217, xml_id: n/a, model: res.partner, parent_id: 123]
None" while parsing /opt/Proj__Upgrade/Prroj_Upgrade_Branch/addons/mail/views/res_partner_views.xml:5, near
<record id="res_partner_view_form_inherit_mail" model="ir.ui.view">
           <field name="name">res.partner.view.form.inherit.mail</field>
           <field name="model">res.partner</field>
           <field name="inherit_id" ref="base.view_partner_form"/>
           <field name="arch" type="xml">
               <data><xpath expr="//field[@name='user_id']" position="after">
                   <field name="opt_out" string="Mailing Opt-Out" groups="base.group_no_one"/>
                   <field name="message_bounce" groups="base.group_no_one"/>
               </xpath>
               <xpath expr="//sheet" position="after">
                   <div class="oe_chatter">
                       <field name="message_follower_ids" widget="mail_followers"/>
                       <field name="activity_ids" widget="mail_activity"/>
                       <field name="message_ids" widget="mail_thread"/>
                   </div>
               </xpath>
           </data></field>
       </record>
Solution:
DB_Production_migrated_migrated=# delete from ir_ui_view where id=267;
DELETE 1
---------------------------------------------------------------------
odoo.tools.convert.ParseError: "duplicate key value violates unique constraint "res_groups_name_uniq"
DETAIL:  Key (category_id, name)=(70, Manual Attendance) already exists.
" while parsing /opt/Proj__Upgrade/Prroj_Upgrade_Branch/addons/hr_attendance/security/hr_attendance_security.xml:17, near
<record id="group_hr_attendance" model="res.groups">
       <field name="name">Manual Attendance</field>
       <field name="category_id" ref="base.module_category_hr_attendance"/>
       <field name="comment">The user will gain access to the human resources attendance menu, enabling him to manage his own attendance.</field>
   </record>
Solution:
delete from res_groups where id=16;
DELETE 1
---------------------------------------------------------------------
Element '<field name="use_tasks">' cannot be located in parent view
Error context:
View `project.project.kanban.inherited`
[view_id: 631, xml_id: project_issue.view_project_kanban_inherited, model: project.project, parent_id: 601]
Solution:
DB_Production_migrated_migrated=# delete from ir_ui_view where id=631;
DELETE 1
---------------------------------------------------------------------
odoo.tools.convert.ParseError: "duplicate key value violates unique constraint "res_groups_name_uniq"
DETAIL:  Key (category_id, name)=(5, Pro-forma Invoices) already exists.
" while parsing /opt/Proj__Upgrade/Prroj_Upgrade_Branch/addons/sale/security/sale_security.xml:48, near
<record id="group_proforma_sales" model="res.groups">
       <field name="name">Pro-forma Invoices</field>
       <field name="category_id" ref="base.module_category_hidden"/>
   </record>
Solution:
DB_Production_migrated_migrated=# delete from res_groups where id=29;
DELETE 1
---------------------------------------------------------------------
Style error
The style compilation failed, see the error below. Your recent actions may be the cause, please try reverting the changes you made.
Could not get content for /rating/static/src/css/rating_common.css defined in bundle 'web.assets_common'.

Solution:
DB_Production_migrated_migrated=# delete from ir_ui_view where id =638;
DELETE 1
DB_Production_migrated_migrated=# delete from ir_ui_view where inherit_id=159;
DELETE 29
DB_Production_migrated_migrated=# delete from ir_ui_view where id=159;
DELETE 1
---------------------------------------------------------------------
Style error
The style compilation failed, see the error below. Your recent actions may be the cause, please try reverting the changes you made.
Could not get content for /report/static/src/less/report_backend.less defined in bundle 'web.assets_backend'.
Solution:
DB_Production_migrated_migrated=# delete from ir_ui_view where id =186;
DELETE 1
---------------------------------------------------------------------
Could not get content for /web_calendar/static/src/less/web_calendar.less defined in bundle 'web.assets_backend'.
Could not get content for /web_kanban/static/src/less/kanban_dashboard.less defined in bundle 'web.assets_backend'.
Could not get content for /web_kanban/static/src/less/kanban_view.less defined in bundle 'web.assets_backend'.
Could not get content for /hr_timesheet_sheet/static/src/less/timesheet.less defined in bundle 'web.assets_backend'.
Could not get content for /web_calendar/static/lib/fullcalendar/css/fullcalendar.css defined in bundle 'web.assets_backend'.
Could not get content for /sale/static/src/css/sale.css defined in bundle 'web.assets_backend'.
Style error
The style compilation failed, see the error below. Your recent actions may be the cause, please try reverting the changes you made.
Could not get content for /website_mail/static/src/css/website_mail.css defined in bundle 'web.assets_frontend'.
2018-04-14 06:42:57,198 13899 INFO DB_Production_migrated_migrated odoo.addons.base.ir.ir_ui_view: Field `percentage_satisfaction_issue` does not exist
Error context:
View `n/a`
[view_id: n/a, xml_id: n/a, model: n/a, parent_id: n/a]
2018-04-14 06:42:57,199 13899 ERROR DB_Production_migrated_migrated odoo.http: Exception during JSON request handling.
Solution:
DB_Production_migrated_migrated=# delete from ir_ui_view where id=647;
DELETE 1
---------------------------------------------------------------------
ValueError: Field `sales_to_invoice_amount` does not exist
Error context:
View `n/a`
[view_id: n/a, xml_id: n/a, model: n/a, parent_id: n/a]
Solution:
DB_Production_migrated_migrated=# delete from ir_ui_view where id=568;
DELETE 1
---------------------------------------------------------------------
ValueError: Element '<xpath expr="//page[@name='more_info']">' cannot be located in parent view
Error context:
View `crm.team.form`
[view_id: 556, xml_id: sale.crm_team_salesteams_view_form, model: crm.team, parent_id: 298]
Solution:
DB_Production_migrated_migrated=# delete from ir_ui_view where id=556;
DELETE 1
---------------------------------------------------------------------
ValueError: Field `sheet_id` does not exist
Error context:
View `n/a`
[view_id: n/a, xml_id: n/a, model: n/a, parent_id: n/a]
Solution:
Deleted below ids from ir_ui_view table
518,519,524,524
--------------------------------------------------------------------
ValueError: Field `procurement_id` does not exist
Error context:
View `n/a`
[view_id: n/a, xml_id: n/a, model: n/a, parent_id: n/a]
Solution:
DB_Production_migrated_migrated=# delete from ir_ui_view where id=615;
DELETE 1
---------------------------------------------------------------------
ValueError: Field `rating_ids` does not exist
Error context:
View `project.issue.view.kanban.inherit.no.group.create`
[view_id: 1113, xml_id: project_issue.project_issue_view_kanban_inherit_no_group_create, model: project.issue, parent_id: 621]
Solution:
DB_Production_migrated_migrated=# select * from ir_ui_view;
DB_Production_migrated_migrated=# delete from ir_ui_view where id=1117;
DELETE 1
DB_Production_migrated_migrated=# select * from ir_ui_view;
DB_Production_migrated_migrated=# delete from ir_ui_view where id=1132;
DELETE 1
---------------------------------------------------------------------
ValueError: Field `progress` does not exist
Error context:
View `project.issue.tree.view`
[view_id: 618, xml_id: project_issue.project_issue_tree_view, model: project.issue, parent_id: n/a]
Solution:
MA_Prod_migrated_migrated=# select * from ir_ui_view where id=618;
DB_Production_migrated_migrated=# select * from ir_ui_view;
DB_Production_migrated_migrated=# delete from ir_ui_view where id=648;
DELETE 1
DB_Production_migrated_migrated=# select * from ir_ui_view;
DB_Production_migrated_migrated=# delete from ir_ui_view where id=1376;
DELETE 1
DB_Production_migrated_migrated=# select * from ir_ui_view;
DB_Production_migrated_migrated=# delete from ir_ui_view where id=1377;
DELETE 1
DB_Production_migrated_migrated=# select * from ir_ui_view;
DB_Production_migrated_migrated=# delete from ir_ui_view where id=1379;
Rating_count
DELETE 1
DB_Production_migrated_migrated=# select * from ir_ui_view;
DB_Production_migrated_migrated=# delete from ir_ui_view where id=641;
DELETE 1
DB_Production_migrated_migrated=# select * from ir_ui_view;
DB_Production_migrated_migrated=# delete from ir_ui_view where id=649;
DELETE 1
DB_Production_migrated_migrated=# delete from ir_ui_view where id=1116;
DELETE 1
DB_Production_migrated_migrated=# select * from ir_ui_view;
DB_Production_migrated_migrated=# delete from ir_ui_view where id=1131;
DELETE 1
---------------------------------------------------------------------
ValueError: Element '<xpath expr="//group[@name='account_grp']">' cannot be located in parent view
Error context:
View `res.company.form.inherit.users_ldap`
[view_id: 651, xml_id: n/a, model: res.company, parent_id: 110]
Solution:
delete from ir_ui_view where id=651;
DELETE 1
---------------------------------------------------------------------
ValueError: Field `timesheet_to_approve_count` does not exist
Error context:
View `n/a`
[view_id: n/a, xml_id: n/a, model: n/a, parent_id: n/a]
Solution:
DB_Production_migrated_migrated=# delete from ir_ui_view where id=536;
DELETE 1
---------------------------------------------------------------------
ValueError: Field `timesheet_count` does not exist
Error context:
View `n/a`
[view_id: n/a, xml_id: n/a, model: n/a, parent_id: n/a]
Solution:
DB_Production_migrated_migrated=# delete from ir_ui_view where id=531;
DELETE 1
---------------------------------------------------------------------
ValueError: Field `timesheet_cost` does not exist
Error context:
View `n/a`
[view_id: n/a, xml_id: n/a, model: n/a, parent_id: n/a]
Field `track_service` does not exist
Error context:
View `product.product.sale.order`
[view_id: 550, xml_id: sale.product_form_view_sale_order_button, model: product.product, parent_id: 327]
None" while parsing /opt/Proj__Upgrade/Prroj_Upgrade_Branch/addons/sale/views/sale_views.xml:644, near
<record model="ir.ui.view" id="product_form_view_sale_order_button">
           <field name="name">product.product.sale.order</field>
           <field name="model">product.product</field>
           <field name="inherit_id" ref="product.product_normal_form_view"/>
           <field name="groups_id" eval="[(4, ref('sales_team.group_sale_salesman'))]"/>
           <field name="arch" type="xml">
               <data><button name="toggle_active" position="before">
                   <button class="oe_stat_button" name="%(action_product_sale_list)d" type="action" icon="fa-usd">
                       <field string="Sales" name="sales_count" widget="statinfo"/>
                   </button>
               </button>
               <group name="sale_warning" position="replace">
                   <group string="Warning when Selling this Product" groups="sale.group_warning_sale">
                       <field name="sale_line_warn" nolabel="1"/>
                       <field name="sale_line_warn_msg" colspan="3" nolabel="1" attrs="{'required':[('sale_line_warn','!=','no-message')],'readonly':[('sale_line_warn','=','no-message')]}"/>
                   </group>
               </group>
           </data></field>
       </record>
Solution:
delete from ir_ui_view where id=572;
DELETE 1
DB_Production_migrated_migrated=# select * from ir_ui_view;
DB_Production_migrated_migrated=# delete from ir_ui_view where id=552;
DELETE 1
---------------------------------------------------------------------
2018-04-14 12:52:42,809 4846 WARNING DB_Production_migrated_migrated odoo.modules.graph: module procurement: not installable, skipped
2018-04-14 12:52:42,816 4846 WARNING DB_Production_migrated_migrated odoo.modules.graph: module email_template_dateutil: not installable, skipped
2018-04-14 12:52:42,832 4846 WARNING DB_Production_migrated_migrated odoo.modules.graph: module portal_sale: not installable, skipped
2018-04-14 12:52:42,835 4846 WARNING DB_Production_migrated_migrated odoo.modules.graph: module report: not installable, skipped
2018-04-14 12:52:42,841 4846 WARNING DB_Production_migrated_migrated odoo.modules.graph: module hr_timesheet_sheet: not installable, skipped
2018-04-14 12:52:42,861 4846 WARNING DB_Production_migrated_migrated odoo.modules.graph: module rating_project_issue: not installable, skipped
2018-04-14 12:52:42,874 4846 WARNING DB_Production_migrated_migrated odoo.modules.graph: module project_issue_sheet: not installable, skipped
   raise ValueError(message)
ValueError: Element '<group name="options">' cannot be located in parent view
Error context:
View `project.project.view.form.simplified.inherit.issue`
[view_id: 1114, xml_id: project_issue.project_project_view_form_simplified_inherit_issue, model: project.project, parent_id: 1088]
Solution: 
DB_Production_migrated_migrated=# delete from ir_ui_view where id = 1114;
DELETE 1
---------------------------------------------------------------------
Traceback (most recent call last):
 File "/opt/Proj__Upgrade/Prroj_Upgrade_Branch/odoo/tools/convert.py", line 741, in parse
   self._tags[rec.tag](rec, de, mode=mode)
 File "/opt/Proj__Upgrade/Prroj_Upgrade_Branch/odoo/tools/convert.py", line 320, in _tag_report
   id = self.env['ir.model.data']._update("ir.actions.report", self.module, res, xml_id, noupdate=self.isnoupdate(data_node), mode=self.mode)
 File "/opt/Proj__Upgrade/Prroj_Upgrade_Branch/odoo/addons/base/ir/ir_model.py", line 1425, in _update
   " you can't define a `%s` record with this ID." % (xml_id, imd_model, model)
AssertionError: External ID conflict, report_ir_model_overview already refers to a `ir.actions.report.xml` record, you can't define a `ir.actions.report` record with this ID.
Solution:
delete from ir_act_report_xml;

How to configure moodle configuration file.

File: config.php


$CFG->dblibrary = 'native';
$CFG->dbhost    = '11.0.1.94';
$CFG->dbname    = 'dbname';
$CFG->dbuser    = 'dbusername';
$CFG->dbpass    = 'dbpassword';
$CFG->prefix    = 'mdl_';
$CFG->dboptions = array (
  'dbpersist' => 0,
  'dbsocket' => 0,
);
$CFG->wwwroot   = 'http://mysite.leeway.org';
$CFG->dirroot   = '/usr/share/nginx/html/My_Proj/My_branch';   // moodle file dir  root
$CFG->dataroot  = '/usr/share/nginx/html/My_Proj/moodledata/';  moodle data root
$CFG->admin     = 'admin';
$CFG->localcachedir = '/usr/share/nginx/html/My_Proj/My_branch/cache_data';
$CFG->directorypermissions = 0777;
$CFG->passwordsaltmain = '1MlzkL&C](u,PZsJPIM8s&B,/i';
$CFG->showuseridentity = 'username';
require_once(dirname(__FILE__) . '/lib/setup.php');