123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- from openerp import models, fields, api, _
- class HrPayslip(models.Model):
- _inherit = 'hr.payslip'
- @api.one
- @api.depends(
- 'move_id.line_id.account_id',
- 'move_id.line_id.reconcile_id')
- def _compute_payments(self):
- lines = []
- if self.move_id:
- lines = []
- for p_line_id in self.move_id.line_id:
- temp_lines = []
- if p_line_id.reconcile_id:
- temp_lines = [
- line.id for line in p_line_id.reconcile_id.line_id
- if line != p_line_id]
- elif p_line_id.reconcile_partial_id:
- temp_lines = [
- line.id for line in
- p_line_id.reconcile_partial_id.line_partial_ids
- if line != p_line_id]
- lines += [x for x in temp_lines if x not in lines]
- self.payment_ids = lines
- @api.one
- @api.depends(
- 'move_id.line_id.account_id',
- 'move_id.line_id.reconcile_id')
- def _compute_reconciled(self):
- self.reconciled = self.test_paid()
- state = fields.Selection(
- selection_add=[('paid', _('Pagado'))],
- help="* When the payslip is created the status is 'Draft'.\
- \n* If the payslip is under verification, the status is 'Waiting'.\
- \n* If the payslip is confirmed then status is set to 'Done'.\
- \n* When user cancel payslip the status is 'Rejected'.\
- \n* When the payment is done the status id 'Paid'.")
- payment_ids = fields.Many2many(
- 'account.move.line', string='Payments', compute='_compute_payments')
- reconciled = fields.Boolean(
- string='Paid/Reconciled', store=True, readonly=True,
- compute='_compute_reconciled', help="It indicates that the payslip has"
- " been paid and the journal entry of the payslip has been reconciled "
- "with one or several journal entries of payment.")
- @api.multi
- def move_line_id_payment_get(self):
-
- res = {}
- if not self.id:
- return res
- account_ids = []
- for det in self.details_by_salary_rule_category:
- if det.salary_rule_id.account_credit.id:
- account = det.salary_rule_id.account_credit
- if account.type == 'payable' and account.reconcile:
- account_ids.append(account.id)
- if not account_ids:
- return res
- query = '''SELECT i.id, l.id
- FROM account_move_line l
- LEFT JOIN hr_payslip i ON (i.move_id=l.move_id)
- WHERE i.id IN %s
- AND l.account_id=%s'''
- self._cr.execute(query, (tuple(self.ids), account_ids[0]))
- for result in self._cr.fetchall():
- res.setdefault(result[0], [])
- res[result[0]].append(result[1])
- return res.get(self.id, [])
- @api.multi
- def test_paid(self):
-
- line_ids = self.move_line_id_payment_get()
- if not line_ids:
- return False
- query = "SELECT reconcile_id FROM account_move_line WHERE id IN %s"
- self._cr.execute(query, (tuple(line_ids),))
- return all(row[0] for row in self._cr.fetchall())
|