Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions project_analysis/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
.. image:: https://img.shields.io/badge/license-AGPL--3-blue.png
:target: https://www.gnu.org/licenses/agpl
:alt: License: AGPL-3

================
Project Analysis
================


Bug Tracker
===========

Bugs are tracked on `GitHub Issues
<https://github.com/avanzosc/project-addons/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smash it by providing detailed and welcomed feedback.

Credits
=======

Contributors
------------

* Oihane Crucelaegui <oihanecrucelaegi@avanzosc.es>
* Ana Juaristi <anajuaristi@avanzosc.es>

Do not contact contributors directly about support or help with technical issues.

4 changes: 4 additions & 0 deletions project_analysis/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright 2018 Oihane Crucelaegui - AvanzOSC
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from . import models
24 changes: 24 additions & 0 deletions project_analysis/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2018 Oihane Crucelaegui - AvanzOSC
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

{
"name": "Project Analysis",
"version": "11.0.1.0.0",
"category": "Project",
"license": "AGPL-3",
"author": "AvanzOSC",
"website": "http://www.avanzosc.es",
"depends": [
"project",
"hr_timesheet",
"project_characterization",
],
"data": [
# "security/ir.model.access.csv",
"data/employee_payroll_data.xml",
"views/hr_employee_view.xml",
"views/project_project_view.xml",

],
"installable": True,
}
7 changes: 7 additions & 0 deletions project_analysis/data/employee_payroll_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo noupdate="True">
<record id="employee_payroll_account" model="account.analytic.account">
<field name="name">Employees Payroll</field>
</record>

</odoo>
5 changes: 5 additions & 0 deletions project_analysis/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Copyright 2018 Oihane Crucelaegui - AvanzOSC
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from . import hr_employee
from . import project_project
67 changes: 67 additions & 0 deletions project_analysis/models/hr_employee.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Copyright 2018 Oihane Crucelaegui - AvanzOSC
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from odoo import fields, models
from dateutil.relativedelta import relativedelta
from .project_project import get_month_startdate_enddate

date2str = fields.Date.to_string
str2date = fields.Date.from_string


class HrEmployee(models.Model):
_inherit = 'hr.employee'

payroll_ids = fields.One2many(
comodel_name='hr.employee.payroll', inverse_name='employee_id',
string='Monthly Payroll')

def button_compute_monthly_payroll(self):
self.compute_monthly_payroll()
return True

def compute_monthly_payroll(self, date=None):
if not date:
date = fields.Date.today()
account = self.env.ref('project_analysis.employee_payroll_account')
analytic_line_obj = self.env['account.analytic.line']
startdate, enddate = get_month_startdate_enddate(date)
for employee in self:
employee.payroll_ids.filtered(
lambda p: p.date == date2str(startdate)).unlink()
analytic_lines = analytic_line_obj.search([
('date', '>=', startdate), ('date', '<=', enddate),
('move_id.partner_id', '=', employee.address_id.id),
('account_id', '=', account.id),
])
employee.payroll_ids.create({
'date': startdate,
'employee_id': employee.id,
'payroll': sum(analytic_lines.mapped('amount')),
})

def button_compute_all_monthly_payroll(self):
account = self.env.ref('project_analysis.employee_payroll_account')
analytic_lines = self.env['account.analytic.line'].search([
('account_id', '=', account.id),
], limit=1, order='date ASC')
today = str2date(fields.Date.today())
date = str2date(analytic_lines[:1].date) or today
while date < today:
self.compute_monthly_payroll(date=date)
date += relativedelta(months=1)


class HrEmployeePayroll(models.Model):
_name = 'hr.employee.payroll'

date = fields.Date(string='Date')
employee_id = fields.Many2one(
comodel_name='hr.employee', required=True, string='Employee')
payroll = fields.Float(string='Payroll')

_sql_constraints = [
('employee_payroll_month_unique',
'unique(date, employee_id)',
'There can only be one payroll per month'),
]
Loading