diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 17:14:58 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 17:14:58 +0700 |
| commit | 1ca3b3df3421961caec3b747a364071c80f5c7da (patch) | |
| tree | 6778a1f0f3f9b4c6e26d6d87ccde16e24da6c9d6 /ohrms_loan_accounting/models | |
| parent | b57188be371d36d96caac4b8d65a40745c0e972c (diff) | |
initial commit
Diffstat (limited to 'ohrms_loan_accounting/models')
| -rw-r--r-- | ohrms_loan_accounting/models/__init__.py | 5 | ||||
| -rw-r--r-- | ohrms_loan_accounting/models/account_move_line.py | 8 | ||||
| -rw-r--r-- | ohrms_loan_accounting/models/hr_loan_acc.py | 177 | ||||
| -rw-r--r-- | ohrms_loan_accounting/models/hr_loan_config.py | 22 |
4 files changed, 212 insertions, 0 deletions
diff --git a/ohrms_loan_accounting/models/__init__.py b/ohrms_loan_accounting/models/__init__.py new file mode 100644 index 0000000..e75d04e --- /dev/null +++ b/ohrms_loan_accounting/models/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +from . import hr_loan_config +from . import hr_loan_acc +from . import account_move_line + diff --git a/ohrms_loan_accounting/models/account_move_line.py b/ohrms_loan_accounting/models/account_move_line.py new file mode 100644 index 0000000..f384323 --- /dev/null +++ b/ohrms_loan_accounting/models/account_move_line.py @@ -0,0 +1,8 @@ +# -*- coding: utf-8 -*- +from odoo import models, api, fields + + +class AccountMoveLine(models.Model): + _inherit = "account.move.line" + + loan_id = fields.Many2one('hr.loan', 'Loan Id') diff --git a/ohrms_loan_accounting/models/hr_loan_acc.py b/ohrms_loan_accounting/models/hr_loan_acc.py new file mode 100644 index 0000000..f189c3a --- /dev/null +++ b/ohrms_loan_accounting/models/hr_loan_acc.py @@ -0,0 +1,177 @@ +# -*- coding: utf-8 -*- +import time +from odoo import models, api, fields +from odoo.exceptions import UserError + + +class HrLoanAcc(models.Model): + _inherit = 'hr.loan' + + employee_account_id = fields.Many2one('account.account', string="Loan Account") + treasury_account_id = fields.Many2one('account.account', string="Treasury Account") + journal_id = fields.Many2one('account.journal', string="Journal") + + state = fields.Selection([ + ('draft', 'Draft'), + ('waiting_approval_1', 'Submitted'), + ('waiting_approval_2', 'Waiting Approval'), + ('approve', 'Approved'), + ('refuse', 'Refused'), + ('cancel', 'Canceled'), + ], string="State", default='draft', track_visibility='onchange', copy=False, ) + + def action_approve(self): + """This create account move for request. + """ + loan_approve = self.env['ir.config_parameter'].sudo().get_param('account.loan_approve') + contract_obj = self.env['hr.contract'].search([('employee_id', '=', self.employee_id.id)]) + if not contract_obj: + raise UserError('You must Define a contract for employee') + if not self.loan_lines: + raise UserError('You must compute installment before Approved') + if loan_approve: + self.write({'state': 'waiting_approval_2'}) + else: + if not self.employee_account_id or not self.treasury_account_id or not self.journal_id: + raise UserError("You must enter employee account & Treasury account and journal to approve ") + if not self.loan_lines: + raise UserError('You must compute Loan Request before Approved') + timenow = time.strftime('%Y-%m-%d') + for loan in self: + amount = loan.loan_amount + loan_name = loan.employee_id.name + reference = loan.name + journal_id = loan.journal_id.id + debit_account_id = loan.treasury_account_id.id + credit_account_id = loan.employee_account_id.id + debit_vals = { + 'name': loan_name, + 'account_id': debit_account_id, + 'journal_id': journal_id, + 'date': timenow, + 'debit': amount > 0.0 and amount or 0.0, + 'credit': amount < 0.0 and -amount or 0.0, + 'loan_id': loan.id, + } + credit_vals = { + 'name': loan_name, + 'account_id': credit_account_id, + 'journal_id': journal_id, + 'date': timenow, + 'debit': amount < 0.0 and -amount or 0.0, + 'credit': amount > 0.0 and amount or 0.0, + 'loan_id': loan.id, + } + vals = { + 'name': 'Loan For' + ' ' + loan_name, + 'narration': loan_name, + 'ref': reference, + 'journal_id': journal_id, + 'date': timenow, + 'line_ids': [(0, 0, debit_vals), (0, 0, credit_vals)] + } + move = self.env['account.move'].create(vals) + move.post() + self.write({'state': 'approve'}) + return True + + def action_double_approve(self): + """This create account move for request in case of double approval. + """ + if not self.employee_account_id or not self.treasury_account_id or not self.journal_id: + raise UserError("You must enter employee account & Treasury account and journal to approve ") + if not self.loan_lines: + raise UserError('You must compute Loan Request before Approved') + timenow = time.strftime('%Y-%m-%d') + for loan in self: + amount = loan.loan_amount + loan_name = loan.employee_id.name + reference = loan.name + journal_id = loan.journal_id.id + debit_account_id = loan.treasury_account_id.id + credit_account_id = loan.employee_account_id.id + debit_vals = { + 'name': loan_name, + 'account_id': debit_account_id, + 'journal_id': journal_id, + 'date': timenow, + 'debit': amount > 0.0 and amount or 0.0, + 'credit': amount < 0.0 and -amount or 0.0, + 'loan_id': loan.id, + } + credit_vals = { + 'name': loan_name, + 'account_id': credit_account_id, + 'journal_id': journal_id, + 'date': timenow, + 'debit': amount < 0.0 and -amount or 0.0, + 'credit': amount > 0.0 and amount or 0.0, + 'loan_id': loan.id, + } + vals = { + 'name': 'Loan For' + ' ' + loan_name, + 'narration': loan_name, + 'ref': reference, + 'journal_id': journal_id, + 'date': timenow, + 'line_ids': [(0, 0, debit_vals), (0, 0, credit_vals)] + } + move = self.env['account.move'].create(vals) + move.post() + self.write({'state': 'approve'}) + return True + + +class HrLoanLineAcc(models.Model): + _inherit = "hr.loan.line" + + def action_paid_amount(self): + """This create the account move line for payment of each installment. + """ + timenow = time.strftime('%Y-%m-%d') + for line in self: + if line.loan_id.state != 'approve': + raise UserError("Loan Request must be approved") + amount = line.amount + loan_name = line.employee_id.name + reference = line.loan_id.name + journal_id = line.loan_id.journal_id.id + debit_account_id = line.loan_id.employee_account_id.id + credit_account_id = line.loan_id.treasury_account_id.id + debit_vals = { + 'name': loan_name, + 'account_id': debit_account_id, + 'journal_id': journal_id, + 'date': timenow, + 'debit': amount > 0.0 and amount or 0.0, + 'credit': amount < 0.0 and -amount or 0.0, + } + credit_vals = { + 'name': loan_name, + 'account_id': credit_account_id, + 'journal_id': journal_id, + 'date': timenow, + 'debit': amount < 0.0 and -amount or 0.0, + 'credit': amount > 0.0 and amount or 0.0, + } + vals = { + 'name': 'Loan For' + ' ' + loan_name, + 'narration': loan_name, + 'ref': reference, + 'journal_id': journal_id, + 'date': timenow, + 'line_ids': [(0, 0, debit_vals), (0, 0, credit_vals)] + } + move = self.env['account.move'].create(vals) + move.post() + return True + + +class HrPayslipAcc(models.Model): + _inherit = 'hr.payslip' + + def action_payslip_done(self): + for line in self.input_line_ids: + if line.loan_line_id: + line.loan_line_id.action_paid_amount() + return super(HrPayslipAcc, self).action_payslip_done() diff --git a/ohrms_loan_accounting/models/hr_loan_config.py b/ohrms_loan_accounting/models/hr_loan_config.py new file mode 100644 index 0000000..d823d6c --- /dev/null +++ b/ohrms_loan_accounting/models/hr_loan_config.py @@ -0,0 +1,22 @@ +from odoo import models, fields, api, _ + + +class AccConfig(models.TransientModel): + _inherit = 'res.config.settings' + + loan_approve = fields.Boolean(default=False, string="Approval from Accounting Department", + help="Loan Approval from account manager") + + @api.model + def get_values(self): + res = super(AccConfig, self).get_values() + res.update( + loan_approve=self.env['ir.config_parameter'].sudo().get_param('account.loan_approve') + ) + return res + + + def set_values(self): + super(AccConfig, self).set_values() + self.env['ir.config_parameter'].sudo().set_param('account.loan_approve', self.loan_approve) + |
