Impacted versions: Odoo 10

Steps to reproduce: 
1. Create a contract for the Employee and select the Working Schedule as Day shift.

2. Go to Payroll -> Employee Payslips -> Create. Select Employee and the Contract, Period must be automatically selected. In Worked days, the WORK100 shows no of days and hours by calculating the period and Working schedule.

3. Now try selecting the previous month(1st day to last day). And the worked Days will miscalculate the no of days and hours.(Check Screenshots).

Current behavior: Miscalculation in Worked Days( No of days and Hours) if the period is change e.g. Select a last month

Expected behavior: No of days and hours must be calculated properly after changing the period.

Video/Screenshot link (optional):
![payroll_period](https://cloud.githubusercontent.com/assets/14011478/22732830/a449a954-ee15-11e6-8909-9d714d306bdb.png)
![payroll_hours](https://cloud.githubusercontent.com/assets/14011478/22732819/9e7c34e2-ee15-11e6-9924-a8dc42ce9a5a.png)



addons/hr_payroll/models/hr_payroll.py
], string="Condition Based on", default='none', required=True)
    condition_range = fields.Char(string='Range Based on', default='contract.wage',
        help='This will be used to compute the % fields values; in general it is on basic, '
             'but you can also use categories code fields in lowercase as a variable names '
             '(hra, ma, lta, etc.) and the variable basic.')
    condition_python = fields.Text(string='Python Condition', required=True,
        default='''
                    # Available variables:
                    #----------------------
                    # payslip: object containing the payslips
                    # employee: hr.employee object
                    # contract: hr.contract object
                    # rules: object containing the rules code (previously computed)
                    # categories: object containing the computed salary rule categories (sum of amount of all rules belonging to that category).
                    # worked_days: object containing the computed worked days
                    # inputs: object containing the computed inputs
                    # Note: returned value have to be set in the variable 'result'
                    result = rules.NET > categories.NET * 0.10''',
        help='Applied this rule for calculation if condition is true. You can specify condition like basic > 1000.')
    condition_range_min = fields.Float(string='Minimum Range', help="The minimum amount, applied for this rule.")
    condition_range_max = fields.Float(string='Maximum Range', help="The maximum amount, applied for this rule.")
    amount_select = fields.Selection([
        ('percentage', 'Percentage (%)'),
        ('fix', 'Fixed Amount'),
        ('code', 'Python Code'),
    ], string='Amount Type', index=True, required=True, default='fix', help="The computation method for the rule amount.")
    amount_fix = fields.Float(string='Fixed Amount', digits=dp.get_precision('Payroll'))
    amount_percentage = fields.Float(string='Percentage (%)', digits=dp.get_precision('Payroll Rate'),
        help='For example, enter 50.0 to apply a percentage of 50%')
    amount_python_compute = fields.Text(string='Python Code',