Sign In/Out by Project total amount not computed

Bug #1293067 reported by Christian Lambricht
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
HR - Timesheet Management
New
Undecided
Unassigned

Bug Description

The account.analytic.line amount is not automatically calculated when we use sign in sign out by project.

Revision history for this message
Christian Lambricht (christian-lambricht) wrote :

After some investigation, I found that the ''journal_id' value is mandatory for on_change_unit_amount(). I correct _write() function in hr_timesheet_sign_in_sign_out.py

Original function

    def _write(self, cr, uid, data, emp_id, context=None):
        timesheet_obj = self.pool.get('hr.analytic.timesheet')
        emp_obj = self.pool.get('hr.employee')
        if context is None:
            context = {}
        hour = (time.mktime(time.strptime(data['date'] or time.strftime('%Y-%m-%d %H:%M:%S'), '%Y-%m-%d %H:%M:%S')) -
            time.mktime(time.strptime(data['date_start'], '%Y-%m-%d %H:%M:%S'))) / 3600.0
        minimum = data['analytic_amount']
        if minimum:
            hour = round(round((hour + minimum / 2) / minimum) * minimum, 2)
        res = timesheet_obj.default_get(cr, uid, ['product_id','product_uom_id'], context=context)

        if not res['product_uom_id']:
            raise osv.except_osv(_('User Error!'), _('Please define cost unit for this employee.'))
 ** up = timesheet_obj.on_change_unit_amount(cr, uid, False, res['product_id'], hour,False, res['product_uom_id'])['value']

        res['name'] = data['info']
        res['account_id'] = data['account_id'].id
        res['unit_amount'] = hour
        emp_journal = emp_obj.browse(cr, uid, emp_id, context=context).journal_id
        res['journal_id'] = emp_journal and emp_journal.id or False
        res.update(up)
        up = timesheet_obj.on_change_account_id(cr, uid, [], res['account_id']).get('value', {})
        res.update(up)
        return timesheet_obj.create(cr, uid, res, context=context)

Corrected function

    def _write(self, cr, uid, data, emp_id, context=None):
        timesheet_obj = self.pool.get('hr.analytic.timesheet')
        emp_obj = self.pool.get('hr.employee')
        if context is None:
            context = {}
        hour = (time.mktime(time.strptime(data['date'] or time.strftime('%Y-%m-%d %H:%M:%S'), '%Y-%m-%d %H:%M:%S')) -
            time.mktime(time.strptime(data['date_start'], '%Y-%m-%d %H:%M:%S'))) / 3600.0
        minimum = data['analytic_amount']
        if minimum:
            hour = round(round((hour + minimum / 2) / minimum) * minimum, 2)
        res = timesheet_obj.default_get(cr, uid, ['product_id','product_uom_id'], context=context)

        if not res['product_uom_id']:
            raise osv.except_osv(_('User Error!'), _('Please define cost unit for this employee.'))

        res['name'] = data['info']
        res['account_id'] = data['account_id'].id
        res['unit_amount'] = hour
        emp_journal = emp_obj.browse(cr, uid, emp_id, context=context).journal_id
        res['journal_id'] = emp_journal and emp_journal.id or False
 ** up = timesheet_obj.on_change_unit_amount(cr, uid, False, res['product_id'], hour,False, res['product_uom_id'], res['journal_id'])['value']
        res.update(up)
        up = timesheet_obj.on_change_account_id(cr, uid, [], res['account_id']).get('value', {})
        res.update(up)
        return timesheet_obj.create(cr, uid, res, context=context)

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.