From 540134eff201fda537bd5d6273093b9cae17baee Mon Sep 17 00:00:00 2001 From: "Hemendra Paregi (Open ERP)" Date: Fri, 9 Dec 2011 12:11:32 +0530 Subject: [PATCH] [MERGE]Improvement in yml file bzr revid: hpa@tinyerp.com-20111209064132-88p4ym4t451xqrwf --- .../hr_timesheet/test/test_hr_timesheet.yml | 122 +++--------------- .../test/test_hr_timesheet_sheet.yml | 94 ++++---------- addons/project_timesheet/__openerp__.py | 1 + .../project_timesheet/test/work_timesheet.yml | 32 +++++ 4 files changed, 76 insertions(+), 173 deletions(-) create mode 100644 addons/project_timesheet/test/work_timesheet.yml diff --git a/addons/hr_timesheet/test/test_hr_timesheet.yml b/addons/hr_timesheet/test/test_hr_timesheet.yml index 30c97c3eb70..3635f59fb3c 100644 --- a/addons/hr_timesheet/test/test_hr_timesheet.yml +++ b/addons/hr_timesheet/test/test_hr_timesheet.yml @@ -1,110 +1,38 @@ - In order to test hr_timesheet Module in OpenERP, I make "Sign In/Sign Out for Project" to encode and track time spent on the different projects. - - - I create a new employee “Mark Johnson” to test Timesheet. + I create employee "Quentin Paolino" as "User". - - !record {model: hr.employee, id: hr_employee_employee0}: - address_home_id: base.res_partner_address_1 - company_id: base.main_company - gender: male - marital: single - name: Mark Johnson - user_id: base.user_root - -- - I create new user "test_timesheet_user1". -- - !record {model: res.users, id: test_timesheet_user1}: - company_id: base.main_company - context_lang: en_US - groups_id: - - base.group_hr_user - - base.group_user - - base.group_extended - - base.group_hr_manager - login: test_timesheet_user1 - name: test_timesheet_user1 - password: test_timesheet_user1 - -- - I create another new employee "Francline" as "test_timesheet_user1". -- - !record {model: hr.employee, id: hr_employee_fracline1}: + !record {model: hr.employee, id: hr.employee2}: address_home_id: base.res_partner_address_8 - name: Francline - parent_id: 'hr_employee_employee0' - user_id: 'test_timesheet_user1' - -- - I create a product as "Consultancy - Senior Developer". -- - !record {model: product.product, id: product_consultant}: - categ_id: product.product_category_10 - default_code: DEV - list_price: 75.0 - name: Consultancy - Senior Developer - procure_method: make_to_order - purchase_ok: False - standard_price: 30.0 - supply_method: produce - type: service - uom_id: product.uom_hour - uom_po_id: product.uom_hour - -- - I assigned product and journal to "Mark Johnson" -- - !record {model: hr.employee, id: hr_employee_employee0}: - product_id: product_consultant - journal_id: analytic_journal -- - I assigned product and journal to "Francline". -- - !record {model: hr.employee, id: hr_employee_fracline1}: - product_id: product_consultant - journal_id: analytic_journal -- - I create attendance and perform "Sign In" action with proper reason. -- - !record {model: hr.attendance, id: hr_attendance_0}: - action: sign_in - employee_id: 'hr_employee_fracline1' - name: !eval (datetime.now()-timedelta(hours=2)).strftime('%Y-%m-%d %H:%M:%S') - -- - I create attendance and perform "Sign Out" action. -- - !record {model: hr.attendance, id: hr_attendance_1}: - action: sign_out - employee_id: 'hr_employee_fracline1' - name: !eval (datetime.now()-timedelta(hours=1)).strftime('%Y-%m-%d %H:%M:%S') - + name: Quentin Paolino + parent_id: 'hr.employee3' + user_id: 'base.user_demo' - On "Sign In/Sign Out by Project" wizard i click on "Sign In/Sign Out" button of this wizard. - !python {model: hr.sign.in.project}: | - uid = ref('test_timesheet_user1') - self.check_state(cr, uid, [ref("hr_employee_fracline1")], {"active_ids": [ref("hr_timesheet.action_hr_timesheet_sign_in")]}) + uid = ref('base.user_demo') + self.check_state(cr, uid, [ref("hr.employee2")], {"active_ids": [ref("hr_timesheet.action_hr_timesheet_sign_in")]}) - I select start date and Perform start work on project. - !python {model: hr.sign.in.project}: | import time - uid = ref('test_timesheet_user1') - new_id = self.create(cr, uid, {'emp_id': ref('hr_employee_fracline1'), 'name': 'Francline', 'server_date': time.strftime('%Y-%m-%d %H:%M:%S'), 'state': 'absent'}) + uid = ref('base.user_demo') + new_id = self.create(cr, uid, {'emp_id': ref('hr.employee2'), 'name': 'Quentin Paolino', 'server_date': time.strftime('%Y-%m-%d %H:%M:%S'), 'state': 'absent'}) self.sign_in_result(cr, uid, [new_id], context) - - I create a timesheet line manually to check several default values. + I create a timesheet line manually to check several default values. I also assign proper date and user for that line. - !python {model: hr.analytic.timesheet}: | import time - uid = ref('test_timesheet_user1') + uid = ref('base.user_demo') current_date = time.strftime('%Y-%m-%d') vals = {'name': 'Worked on project', - 'user_id': ref('test_timesheet_user1'), + 'user_id': ref('base.user_demo'), 'account_id': ref('account.analytic_project_1_development'), 'unit_amount': 5.00, 'journal_id': ref('analytic_journal') @@ -120,30 +48,16 @@ Which check state in hr attendace form for user. - !python {model: hr.sign.in.project}: | - uid = ref('test_timesheet_user1') - ids = self.search(cr, uid, [('emp_id', '=', ref('hr_employee_fracline1')),('name', '=', 'Francline')]) + uid = ref('base.user_demo') + ids = self.search(cr, uid, [('emp_id', '=', ref('hr.employee2')),('name', '=', 'Quentin Paolino')]) self.check_state(cr, uid, ids, {"active_ids": [ref("hr_timesheet.action_hr_timesheet_sign_in")] }) - - I Create an analytic account "Project2". -- - !record {model: account.analytic.account, id: account_analytic_account_project0}: - company_id: base.main_company - name: Project2 - parent_id: account.analytic_root - quantity_max: 0.0 - state: open - -- - My work for this project is over and I stop working by clicking on "Stop Work" button of this wizard. + My work for this project 1 is over and I stop working by clicking on "Stop Work" button of this wizard. - !python {model: hr.sign.out.project}: | import time from datetime import datetime, date, timedelta - uid = ref('test_timesheet_user1') - new_id = self.create(cr, uid, {'account_id': ref('account_analytic_account_project0'), 'analytic_amount': 7.0, 'date': (datetime.now()+timedelta(1)).strftime('%Y-%m-%d %H:%M:%S'), 'date_start': time.strftime('%Y-%m-%d %H:%M:%S'), 'info': 'Create Yaml for hr module', 'name': 'Francline', 'server_date': time.strftime('%Y-%m-%d %H:%M:%S'), 'state': 'absent'}) - self.sign_out_result_end(cr, uid, [new_id], context) - -- | - I can see employee timesheet for particular month using "Employee Timesheet" report. - + uid = ref('base.user_demo') + new_id = self.create(cr, uid, {'account_id': ref('account.analytic_project_1'), 'analytic_amount': 7.0, 'date': (datetime.now()+timedelta(1)).strftime('%Y-%m-%d %H:%M:%S'), 'date_start': time.strftime('%Y-%m-%d %H:%M:%S'), 'info': 'Create Yaml for hr module', 'name': 'Francline', 'server_date': time.strftime('%Y-%m-%d %H:%M:%S'), 'state': 'absent'}) + self.sign_out_result_end(cr, uid, [new_id], context) \ No newline at end of file diff --git a/addons/hr_timesheet_sheet/test/test_hr_timesheet_sheet.yml b/addons/hr_timesheet_sheet/test/test_hr_timesheet_sheet.yml index 58b1b38ad2f..3aede6bd15b 100644 --- a/addons/hr_timesheet_sheet/test/test_hr_timesheet_sheet.yml +++ b/addons/hr_timesheet_sheet/test/test_hr_timesheet_sheet.yml @@ -1,56 +1,22 @@ - - In order to test hr_timesheet_sheet module in OpenERP, I create timesheet and check validation process done by manager. + In order to test hr_timesheet_sheet module in OpenERP, + I create Timesheet and check validation process done by manager. - - I create a new employee "Mark Johnson". + I assign this product and journal to employee "Quentin Paolino" - - !record {model: hr.employee, id: hr_employee_employee0}: - address_home_id: base.res_partner_address_1 - gender: male - marital: single - name: Mark Johnson - user_id: base.user_demo - + !record {model: hr.employee, id: hr.employee2}: + product_id: product.product_consultant + journal_id: hr_timesheet.analytic_journal - - I create new Timesheet journal for employee. + I create my current timesheet for employee "Quentin Paolinon". - - !record {model: account.analytic.journal, id: analytic_journal}: - code: TS - name: Timesheet Journal - type: general - -- - I create a new product "Consultancy - Senior Developer". -- - !record {model: product.product, id: product_consultant}: - categ_id: product.product_category_10 - default_code: DEV - list_price: 75.0 - name: Consultancy - Senior Developer - procure_method: make_to_order - purchase_ok: False - standard_price: 30.0 - supply_method: produce - type: service - uom_id: product.uom_hour - uom_po_id: product.uom_hour - -- - I assign this product and journal to "Mark Johnson" -- - !record {model: hr.employee, id: hr_employee_employee0}: - product_id: product_consultant - journal_id: analytic_journal - -- - I create my current timesheet for "Mark Johnson". -- !record {model: hr_timesheet_sheet.sheet, id: hr_timesheet_sheet_sheet_deddk0}: date_current: !eval time.strftime('%Y-%m-%d') date_from: !eval time.strftime('%Y-%m-01') - name: !eval time.strftime('%U') + name: !eval time.strftime('%U') state: new user_id: base.user_demo - employee_id: 'hr_employee_employee0' + employee_id: 'hr.employee2' - Now, at the time of login, I create Attendances and perform "Sign In" action. - @@ -66,24 +32,23 @@ - !python {model: hr_timesheet_sheet.sheet}: | self.date_today(cr, uid, [ref('hr_timesheet_sheet_sheet_deddk0')], None) -- - I want to go to a particular date and see attendance then I select the date and click on "Go to:" button. -- - !python {model: hr_timesheet_sheet.sheet}: | - self.button_dummy(cr, uid, [ref('hr_timesheet_sheet_sheet_deddk0')], None) - I can also move to next day by clicking on -> button. - !python {model: hr_timesheet_sheet.sheet}: | self.date_next(cr, uid, [ref('hr_timesheet_sheet_sheet_deddk0')], None) +- + I want to go to a particular date and see attendance then I select the date and click on "Go to:" button. +- + !python {model: hr_timesheet_sheet.sheet}: | + self.button_dummy(cr, uid, [ref('hr_timesheet_sheet_sheet_deddk0')], None) - At the time of logout, I create attendance and perform "Sign Out". - !record {model: hr.attendance, id: hr_attendance_1}: action: sign_out - employee_id: 'hr_employee_employee0' + employee_id: 'hr.employee2' name: !eval time.strftime('%Y-%m-%d')+' '+'%s:%s:%s' %(min(23,datetime.now().hour+2),min(59,datetime.now().minute+1),min(59,datetime.now().second+1)) - - I create Timesheet Entry for time spend on today work. - @@ -94,27 +59,23 @@ name: 'Develop yaml for hr module' unit_amount: 3.00 amount: -90.00 - product_id: product_consultant + product_id: product.product_consultant general_account_id: account.a_expense user_id: base.user_root journal_id: hr_timesheet.analytic_journal - - - I confirm my timesheet at end of period by click on "Confirm" button, - if the difference between timesheet hour and attendance hour is more than 1 hour it will give message. + I confirm my Timesheet at end of period by click on "Confirm" button, + if the difference between Timesheet hour and attendance hour is more than 1 hour it will give message. - !python {model: hr_timesheet_sheet.sheet}: | uid = ref('base.user_root') import netsvc try: - self.button_confirm(cr, uid, [ref('hr_timesheet_sheet_sheet_deddk0')], {"lang": 'en_US', "active_ids": - [ref("hr_timesheet_sheet.menu_act_hr_timesheet_sheet_form")], "tz": False, "active_model": - "ir.ui.menu", "department_id": False, "section_id": False, "search_default_my_timesheet": - 1, "search_default_user_id": 1, "project_id": False, "active_id": ref("hr_timesheet_sheet.menu_act_hr_timesheet_sheet_form"), + self.button_confirm(cr, uid, [ref('hr_timesheet_sheet_sheet_deddk0')], {"active_ids": + [ref("hr_timesheet_sheet.menu_act_hr_timesheet_sheet_form")],"active_id": ref("hr_timesheet_sheet.menu_act_hr_timesheet_sheet_form"), }) except: pass - - I Modified the timesheet record and make the difference less than 1 hour. - @@ -125,25 +86,21 @@ name: 'Develop yaml for hr module' unit_amount: 2.0 amount: -90.00 - product_id: product_consultant + product_id: product.product_consultant general_account_id: account.a_expense user_id: base.user_root journal_id: hr_timesheet.analytic_journal - - I tried again to confirm the timesheet after modification. - !python {model: hr_timesheet_sheet.sheet}: | uid = ref('base.user_root') - self.button_confirm(cr, uid, [ref('hr_timesheet_sheet_sheet_deddk0')], {"lang": 'en_US', "active_ids": - [ref("hr_timesheet_sheet.menu_act_hr_timesheet_sheet_form")], "tz": False, "active_model": - "ir.ui.menu", "department_id": False, "section_id": False, "search_default_my_timesheet": - 1, "search_default_user_id": 1, "project_id": False, "active_id": ref("hr_timesheet_sheet.menu_act_hr_timesheet_sheet_form"), + self.button_confirm(cr, uid, [ref('hr_timesheet_sheet_sheet_deddk0')], {"active_ids": + [ref("hr_timesheet_sheet.menu_act_hr_timesheet_sheet_form")],"active_id": ref("hr_timesheet_sheet.menu_act_hr_timesheet_sheet_form"), }) - - This time timesheet confirmed successfully. - I check that state is "Confirmed". + I check that state is "Confirmed". - !assert {model: hr_timesheet_sheet.sheet, id: hr_timesheet_sheet_sheet_deddk0}: - state == 'confirm' @@ -157,5 +114,4 @@ I check that state is "Done". - !assert {model: hr_timesheet_sheet.sheet, id: hr_timesheet_sheet_sheet_deddk0}: - - state == 'done' - + - state == 'done' \ No newline at end of file diff --git a/addons/project_timesheet/__openerp__.py b/addons/project_timesheet/__openerp__.py index b90d3d745a1..7cd36e770ab 100644 --- a/addons/project_timesheet/__openerp__.py +++ b/addons/project_timesheet/__openerp__.py @@ -40,6 +40,7 @@ the Timesheet line entries for particular date and particular user with the eff 'demo_xml': ["project_timesheet_demo.xml"], 'test': [ 'test/worktask_entry_to_timesheetline_entry.yml', + 'test/work_timesheet.yml', ], 'installable': True, 'active': False, diff --git a/addons/project_timesheet/test/work_timesheet.yml b/addons/project_timesheet/test/work_timesheet.yml new file mode 100644 index 00000000000..129840c74d9 --- /dev/null +++ b/addons/project_timesheet/test/work_timesheet.yml @@ -0,0 +1,32 @@ +- + I set work entry for employee +- + !record {model: project.task.work, id: project_task_work1}: + date: !eval time.strftime('%Y-%m-%d %H:%M:%S') + name: Test Timesheet records + task_id: project.project_task_1 + hours: 20.0 + user_id: project.res_users_analyst + company_id: base.main_company +- + I set timesheet line for employee in current timesheet +- + !python {model: hr.analytic.timesheet}: | + import datetime + uid = ref('project.res_users_analyst') + current_date = (datetime.date.today().strftime('%Y-%m-%d')) + vals = {'name': 'Test Timesheet records', + 'user_id': ref('project.res_users_analyst'), + 'account_id': ref('account.analytic_project_1_development'), + 'unit_amount': 5.00, + 'journal_id': ref('hr_timesheet.analytic_journal') + } + line_id = self.create(cr, uid, vals, None) + res = self.on_change_date(cr, uid, [line_id], current_date) + values = dict([('date', current_date)] + res['value'].items()) + res1 = self.on_change_user_id(cr, uid, [line_id], ref('project.res_users_analyst')) + values.update(dict([('user_id', ref('project.res_users_analyst'))] + res1['value'].items())) + self.write(cr, uid, [line_id], values, None) + + +