diff --git a/__init__.py b/__init__.py index 57c50e8ca5c8bc4fe7f5158127dcb7301032272f..aef8bbc7fa3be73ac5dce80355bcffeca71d148c 100644 --- a/__init__.py +++ b/__init__.py @@ -21,3 +21,4 @@ ################################################################################### from . import models +from . import wizard diff --git a/__manifest__.py b/__manifest__.py index 8c0972ba630bfc50606db428d486ca77d8da5e14..4921ae5385e62f98585f5efce00f9afd836d0a4e 100644 --- a/__manifest__.py +++ b/__manifest__.py @@ -28,15 +28,17 @@ 'hr_payroll_import', ], 'data': [ + 'security/ir.model.access.csv', + 'security/security_rules.xml', 'views/hr_employee_loans_view.xml', 'views/hr_employee_loans_line_view.xml', 'views/hr_employee_loans_data.xml', 'views/res_config_settings_views.xml', 'views/res_company_inherit.xml', + 'wizard/extra_concept.xml', 'report/report_employee_loan.xml', 'report/report_employee_template.xml', - 'security/ir.model.access.csv', - 'security/security_rules.xml', + ], 'application': False, 'installable': True, diff --git a/models/hr_employee_loans.py b/models/hr_employee_loans.py index 602b0ca2346ee893597713ca2c11b903404ae446..4cf284da085f633a14277f1d832e82c6a2a2acd0 100644 --- a/models/hr_employee_loans.py +++ b/models/hr_employee_loans.py @@ -85,9 +85,7 @@ class HREmployeeLoans(models.Model): res.append((record.id, name)) return res - def get_loan_salary_rule(self): - loan_salary_rule = self.env['ir.config_parameter'].sudo().get_param('hr_employee_loans.loans_salary_rule_id') or False - return loan_salary_rule + def get_settlement_loan_salary_rule(self): settlement_loans_salary_rule = self.env['ir.config_parameter'].sudo().get_param('hr_employee_loans.settlement_loans_salary_rule_id') or False @@ -183,30 +181,7 @@ class HREmployeeLoans(models.Model): def set_cancel(self): return self.write({'state': 'cancel'}) - @api.multi - def create_extra_concept(self): - - loan_salary_rule_id = self.get_loan_salary_rule() - loan_lines = [] - loans = self.env['hr.employee.loans'].search([('state', '=', 'in_progress')]) - for loan in loans: - loan_lines.append(loan.employee_loan_ids.filtered(lambda - r: r.start_date <= fields.Date.today() and r.end_date >= fields.Date.today() and r.state == 'draft')) - for line in loan_lines: - if line.fee_import: - self.env['hr.payroll.extra.concept'].create({ - 'employee_id': line.employee_loan_id.employee_id.id, - 'salary_rule_id': loan_salary_rule_id, - 'start_date': line.start_date, - 'end_date': line.end_date, - 'quantity': line.fee_import, - }) - line.write({'state': 'done'}) - - if all(line.state == 'done' for line in loan.employee_loan_ids): - loan.write({'state': 'done'}) - return True @api.multi def settle_loan(self): diff --git a/security/ir.model.access.csv b/security/ir.model.access.csv index 08ef4c6f4e98b8f56a3a2070e48664b0e6d3c1b5..d93a0b34dc0b426886af82c590511523756b533a 100644 --- a/security/ir.model.access.csv +++ b/security/ir.model.access.csv @@ -1,4 +1,4 @@ id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink -access_hr_employee_loans_hr_hr_manager,hr.employee.loans Manager,model_hr_employee_loans,hr.group_hr_manager,1,1,1,1 -access_hr_employee_loans_line_hr_hr_manager,hr.employee.loans.line Manager,model_hr_employee_loans_line,hr.group_hr_manager,1,1,1,1 -access_hr_employee_loans_payment_method_hr_hr_manager,hr.employee.loans.payment.method Manager,model_hr_employee_loans_payment_method,hr.group_hr_manager,1,1,1,1 +access_hr_employee_loans_hr_hr_manager,hr.employee.loans,model_hr_employee_loans,,1,1,1,1 +access_hr_employee_loans_line_hr_hr_manager,hr.employee.loans.line,model_hr_employee_loans_line,,1,1,1,1 +access_hr_employee_loans_payment_method_hr_hr_manager,hr.employee.loans.payment.method,model_hr_employee_loans_payment_method,,1,1,1,1 diff --git a/security/security_rules.xml b/security/security_rules.xml index 161c90e7f2241df1d41f0adf57f1dfee4419f5a0..7e9d3265530389dd9a061256dadfa14ded030146 100644 --- a/security/security_rules.xml +++ b/security/security_rules.xml @@ -1,21 +1,25 @@ <?xml version="1.0" encoding="utf-8"?> <odoo> - <record id="account_assets_loans_groups" model="ir.module.category"> - <field name="name">Loans Management</field> - <field name="description">Category for loans</field> - <field name="sequence">14</field> - </record> + <record id="account_assets_loans_groups" model="ir.module.category"> + <field name="name">Loans</field> + </record> - <record id="group_loans_employee" model="res.groups"> - <field name="name">Employee</field> - <field name="category_id" ref="account_assets_loans_groups"/> - </record> + <record id="group_loans_manager" model="res.groups"> + <field name="name">User</field> + <field name="category_id" ref="account_assets_loans_groups"/> + </record> + + <record id="group_loans_admin" model="res.groups"> + <field name="name">Administrator</field> + <field name="category_id" ref="account_assets_loans_groups"/> + <field name="implied_ids" eval="[(4, ref('group_loans_manager'))]"/> + </record> + + <record id="group_loans_authorizer" model="res.groups"> + <field name="name">Authorizer</field> + <field name="category_id" ref="account_assets_loans_groups"/> + </record> - <record id="group_loans_manager" model="res.groups"> - <field name="name">Manager</field> - <field name="category_id" ref="account_assets_loans_groups"/> - <field name="implied_ids" eval="[(4, ref('group_loans_employee'))]"/> - </record> </odoo> diff --git a/views/hr_employee_loans_view.xml b/views/hr_employee_loans_view.xml index 4449e8bb93db0a019341093acef2a1a0c44c3c29..981164c75d97e704c1d16a75c5137b7bc54ff5ad 100644 --- a/views/hr_employee_loans_view.xml +++ b/views/hr_employee_loans_view.xml @@ -27,9 +27,12 @@ <button name="set_paused_to_in_progress" string="In Progress" type="object" states="paused" class="btn-primary"/> <button name="set_paused" string="Pause" type="object" states="in_progress" class="btn-primary"/> - <button name="set_draft" string="Set Draft" type="object" states="approve,in_progress" class="btn-primary"/> - <button name="settle_loan" string="Settlement" type="object" states="in_progress" class="btn-primary"/> - <button name="manager_approve" string="Approve" type="object" states="approve" class="btn-success" groups="hr_payroll.group_hr_payroll_manager"/> + <button name="set_draft" string="Set Draft" type="object" states="approve,in_progress" + class="btn-primary"/> + <button name="settle_loan" string="Settlement" type="object" states="in_progress" + class="btn-primary"/> + <button name="manager_approve" string="Approve" type="object" states="approve" class="btn-success" + groups="hr_employee_loans.group_loans_authorizer"/> <field name="state" widget="statusbar"/> </header> <sheet> @@ -83,19 +86,26 @@ <field name="view_mode">tree,form</field> </record> + <menuitem id="menu_loans_root" + name="Loans" + sequence="46" + groups="hr_employee_loans.group_loans_authorizer,hr_employee_loans.group_loans_manager,hr_employee_loans.group_loans_admin" + /> <menuitem id="hr_employee_loans_root" name="Loans" - parent="hr_payroll.menu_hr_payroll_root" - groups="hr_payroll.group_hr_payroll_user" + sequence="1" + parent="menu_loans_root" + groups="hr_employee_loans.group_loans_authorizer,hr_employee_loans.group_loans_manager,hr_employee_loans.group_loans_admin" /> <menuitem id="hr_employee_loans_menu" name="Loans" parent="hr_employee_loans_root" - action="hr_employee_loans_action" groups="hr_payroll.group_hr_payroll_user" + action="hr_employee_loans_action" + groups="hr_employee_loans.group_loans_authorizer,hr_employee_loans.group_loans_manager,hr_employee_loans.group_loans_admin" /> diff --git a/wizard/__init__.py b/wizard/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..5719b29da62ac7400a1e582a4de61ce158b73a33 --- /dev/null +++ b/wizard/__init__.py @@ -0,0 +1 @@ +from . import extra_concept \ No newline at end of file diff --git a/wizard/extra_concept.py b/wizard/extra_concept.py new file mode 100644 index 0000000000000000000000000000000000000000..017f467ce4f1b09ace0483d1cb4a21c825bfcb90 --- /dev/null +++ b/wizard/extra_concept.py @@ -0,0 +1,44 @@ +from odoo import models, fields, _, api + + +class ExtraConcept(models.TransientModel): + _name = 'hr.extra_concept' + _description = 'HR extra concept generator' + + employee_id = fields.Many2one('hr.employee', string='Employee') + extra_concept_month_date = fields.Date(string='Start Moth') + extra_concept_month_end_date = fields.Date(string='End Moth') + + + def get_loan_salary_rule(self): + loan_salary_rule = self.env['ir.config_parameter'].sudo().get_param( + 'hr_employee_loans.loans_salary_rule_id') or False + return loan_salary_rule + + @api.multi + def create_extra_concept(self): + # TODO: crear el wizzard para que use la fecha selecionada para liquidar los prestamos + loan_salary_rule_id = self.get_loan_salary_rule() + loan_lines = [] + loans = self.env['hr.employee.loans'].search([('state', '=', 'in_progress')]) + for loan in loans: + if self.employee_id: + loan_lines.append(loan.employee_loan_ids.filtered(lambda + r: r.employee_id.id == self.employee_id.id and r.start_date <= self.extra_concept_month_date and r.end_date >= self.extra_concept_month_end_date and r.state == 'draft')) + else: + loan_lines.append(loan.employee_loan_ids.filtered(lambda + r: r.start_date <= self.extra_concept_month_date and r.end_date >= self.extra_concept_month_end_date and r.state == 'draft')) + for line in loan_lines: + if line.fee_import: + self.env['hr.payroll.extra.concept'].create({ + 'employee_id': line.employee_loan_id.employee_id.id, + 'salary_rule_id': loan_salary_rule_id, + 'start_date': line.start_date, + 'end_date': line.end_date, + 'quantity': line.fee_import, + }) + line.write({'state': 'done'}) + + if all(line.state == 'done' for line in loan.employee_loan_ids): + loan.write({'state': 'done'}) + return True diff --git a/wizard/extra_concept.xml b/wizard/extra_concept.xml new file mode 100644 index 0000000000000000000000000000000000000000..c8ff32d9af803d17418eb60f0145f8bf36ecfa6d --- /dev/null +++ b/wizard/extra_concept.xml @@ -0,0 +1,39 @@ +<?xml version="1.0" encoding="utf-8"?> +<odoo> + <record id="extra_concept_form" model="ir.ui.view"> + <field name="name">hr.extra.concept.wizard</field> + <field name="model">hr.extra_concept</field> + <field name="arch" type="xml"> + <form string="HR Extra Concept"> + <group> + <field name="employee_id"/> + <field name="extra_concept_month_date"/> + <field name="extra_concept_month_end_date"/> + </group> + <footer> + <button string="Cancel" special="cancel" class="btn-secondary" /> + <button name='create_extra_concept' type="object" string="Generate" class="btn-success" /> + </footer> + </form> + </field> + </record> + + <record id="action_hr_loan_extra_concept" model="ir.actions.act_window"> + <field name="name">hr Create Extra Concept</field> + <field name="type">ir.actions.act_window</field> + <field name="res_model">hr.extra_concept</field> + <field name="view_type">form</field> + <field name="view_mode">form</field> + <field name="view_id" ref="extra_concept_form"/> + <field name="target">new</field> + </record> + + <menuitem + id="menu_hr_loan_extra_concept_root" + name="Novelties" + sequence="2" + parent="hr_employee_loans.menu_loans_root" + action="action_hr_loan_extra_concept" + /> + +</odoo>