0

I am trying to get the data from 'date' field that 'date' field is in 'hr.employee' to 'hr.payslip'.I create a function for that task.

Code:

class employee_datecheck(models.Model):
    _inherit = 'hr.payslip'

    @api.onchange('employee_id')
    @api.constrains('employee_id')
    def date_check(self):
        if self.employee_id:
            self.t2 = self.date_from
            self.tax 
            product_obj = self.env['hr.employee'].search([('name' , '=' ,self.employee_id.name)])
            if product_obj:
                for products in product_obj:
                    product_new_obj = self.env['hr.employee'].browse([products.id])

                    for tax in product_new_obj.joindate:
                        raise Warning(self.tax) 

problem is:

The date was not fetching properly i.e it just showing the '2' instead of '2017-09-21'.Please help me.

Naglis
  • 2,583
  • 1
  • 19
  • 24
phani
  • 121
  • 1
  • 15
  • what type of field is self.t2? – Dayana Sep 21 '17 at 12:56
  • 'date_from' is a start date of 'hr.payslip' and t2 is local variable to store the date. – phani Sep 21 '17 at 14:38
  • then t2 is the date you say shows 'a'? ....t2 is a date field, a datetime field, a char field? – Dayana Sep 21 '17 at 14:47
  • 'date_from' is date field like :'date_from': fields.date('Date From', required=True) and 'self.t2' is local dummy variable – phani Sep 21 '17 at 14:55
  • ' for tax in product_new_obj.joindate' : in this line I am facing the problem especially in 'joindate' this the date field of 'hr.employe' model.In the place of 'joindate' i tried with many2one field it's working fine.so please help me to solve this – phani Sep 21 '17 at 15:02

2 Answers2

0

I think you could try to print directly the joindate without doing a loop:

for products in product_obj:
    product_new_obj = self.env['hr.employee'].browse([products.id])
    self.tax = product_new_obj.joindate:
    raise Warning(self.tax) 

I hope this help you.

Dayana
  • 1,500
  • 1
  • 16
  • 29
0

phani,

1) You code does not look from v8 as tagged on the question, code is v9+ new API.

2) Not sure why are you searching on Model product and employee because hr.playslp Modle itself has employee field employee_id that you can use to get the date. Also, you should not use onchange and constrains together

Below is sample code:

class employee_datecheck(models.Model):
    _inherit = 'hr.payslip'

    @api.onchange('employee_id')
    def date_check(self):
        if self.employee_id:
            raise Warning(self.employee_id.joindate) 

It will be good if you can give more detail for an accurate answer.

Bests

Naglis
  • 2,583
  • 1
  • 19
  • 24
ifixthat
  • 6,137
  • 5
  • 25
  • 42