<commit_before># -*- coding: utf-8 -*-
# Copyright 2017 KMEE
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from openerp import api, fields, models, _
from openerp.exceptions import Warning as UserError


class HrPayslip(models.Model):

    _inherit = 'hr.payslip'

    payment_mode_id = fields.Many2one(
        string="Payment Mode",
        comodel_name='payment.mode',
        # domain="[('type', '=', type)]"
    )

    payment_line_ids = fields.One2many(
        string="Ordens de Pagamento",
        comodel_name="payment.line",
        inverse_name="payslip_id",
    )

    def _compute_set_employee_id(self):
        super(HrPayslip, self)._compute_set_employee_id()
        for record in self:
            if record.contract_id:
                partner_id = \
                    record.contract_id.employee_id.parent_id.user_id.partner_id
                record.payment_mode_id = partner_id.supplier_payment_mode

        # self, type, partner_id, date_invoice=False,
        #     payment_term=False, partner_bank_id=False, company_id=False):
        # res = super(HrPayslip, self).onchange_partner_id(
        #     type, partner_id, date_invoice=date_invoice,
        #     payment_term=payment_term, partner_bank_id=partner_bank_id,
        #     company_id=company_id)
        # if partner_id:
        #     partner = self.env['res.partner'].browse(partner_id)
        #     if type == 'in_invoice':
        #         res['value']['payment_mode_id'] = \
        #             partner.supplier_payment_mode.id
        #     elif type == 'out_invoice':
        #         res['value']['payment_mode_id'] = \
        #             partner.customer_payment_mode.id
        #         # Do not change the default value of partner_bank_id if
        #         # partner.customer_payment_mode is False
        #         if partner.customer_payment_mode.bank_id:
        #             res['value']['partner_bank_id'] = \
        #                 partner.supplier_payment_mode.bank_id.id
        # else:
        #     res['value']['payment_mode_id'] = False<commit_msg>[FIX] variaveis de controle do workflow<commit_after># -*- coding: utf-8 -*-
# Copyright 2017 KMEE
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from openerp import api, fields, models, _
from openerp.exceptions import Warning as UserError


class HrPayslip(models.Model):

    _inherit = 'hr.payslip'

    payment_mode_id = fields.Many2one(
        string="Payment Mode",
        comodel_name='payment.mode',
        # domain="[('type', '=', type)]"
    )

    payment_line_ids = fields.One2many(
        string="Ordens de Pagamento",
        comodel_name="payment.line",
        inverse_name="payslip_id",
    )
    paid = fields.Boolean(
        compute='_compute_paid',
        default=False
    )

    # done = fields.Boolean(
    #     compute='_compute_done'
    # )

    # confirmar os states
    # def test_done(self):
    #     for line in self.payment_line_ids:
    #         if line.state != 'done':
    #             return False
    #     return True

    # confirmar os states
    def test_paid(self):
        if not self.payment_line_ids:
            print "vazio"
            return False
        for line in self.payment_line_ids:
            if line.state != 'paid':
                print line.state
                return False
        return True

    # @api.depends('payment_line_ids')
    # def _compute_done(self):
    #     self.reconciled = self.test_done()

    @api.depends('payment_line_ids')
    def _compute_paid(self):
        self.paid = self.test_paid()

    def _compute_set_employee_id(self):
        super(HrPayslip, self)._compute_set_employee_id()
        for record in self:
            if record.contract_id:
                partner_id = \
                    record.contract_id.employee_id.parent_id.user_id.partner_id
                record.payment_mode_id = partner_id.supplier_payment_mode

        # self, type, partner_id, date_invoice=False,
        #     payment_term=False, partner_bank_id=False, company_id=False):
        # res = super(HrPayslip, self).onchange_partner_id(
        #     type, partner_id, date_invoice=date_invoice,
        #     payment_term=payment_term, partner_bank_id=partner_bank_id,
        #     company_id=company_id)
        # if partner_id:
        #     partner = self.env['res.partner'].browse(partner_id)
        #     if type == 'in_invoice':
        #         res['value']['payment_mode_id'] = \
        #             partner.supplier_payment_mode.id
        #     elif type == 'out_invoice':
        #         res['value']['payment_mode_id'] = \
        #             partner.customer_payment_mode.id
        #         # Do not change the default value of partner_bank_id if
        #         # partner.customer_payment_mode is False
        #         if partner.customer_payment_mode.bank_id:
        #             res['value']['partner_bank_id'] = \
        #                 partner.supplier_payment_mode.bank_id.id
        # else:
        #     res['value']['payment_mode_id'] = False
{'fraction_non_alphanumeric': 0.10656704679512387, 'fraction_numerical': 0.003539127015336217, 'mean_word_length': 2.1170343137254903, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1075707', 'n_tokens_mistral': 1621, 'n_tokens_neox': 1565, 'n_words': 270}