# -*- coding: utf-8 -*-

from odoo import models, fields, api, _


class PayrollAccountingMapping(models.Model):
    """
    Payroll Accounting Mapping
    Maps payroll items to chart of accounts.
    Only available if account module is installed.
    """
    _name = 'payroll.accounting.mapping'
    _description = 'Payroll Accounting Mapping'
    _rec_name = 'payroll_item'

    config_id = fields.Many2one(
        'payroll.config.settings',
        string='Payroll Settings',
        required=True,
        ondelete='cascade',
    )
    company_id = fields.Many2one(
        related='config_id.company_id',
        string='Company',
        store=True,
    )
    payroll_item = fields.Selection([
        ('bank_account', 'Bank Account'),
        ('wage_expense', 'Wage Expenses'),
        ('employer_tax_expense', 'Employer Tax Expenses'),
        ('federal_tax_liability', 'Federal Tax Liability'),
        ('ontario_tax_liability', 'Ontario Tax Liability'),
        ('vacation_pay_liability', 'Vacation Pay Liability'),
    ], string='Payroll Item', required=True)
    account_id = fields.Many2one(
        'account.account',
        string='Chart of Accounts',
        required=True,
        domain="[('company_id', '=', company_id)]",
    )

    _sql_constraints = [
        ('unique_payroll_item_per_config', 
         'unique(config_id, payroll_item)',
         'Each payroll item can only be mapped once per configuration.'),
    ]
