Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP][16.0] imp payroll account group entries #145

Draft
wants to merge 2 commits into
base: 16.0
Choose a base branch
from
Draft
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
4 changes: 3 additions & 1 deletion payroll_account/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Payroll Accounting
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:653a0c1054563da937bc111ee0541f4208dd379ec0f37ba7d7d8f4fe03216a84
!! source digest: sha256:5bdfba50457cc2a2920d5ffdf3c32cd43ab3533339bedf79c110b47f3ef95a15
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand Down Expand Up @@ -68,6 +68,8 @@ Contributors

* Odoo SA <[email protected]>
* Saran Lim. <[email protected]>
* Moana FABER <[email protected]>
* Cyril VINH-TUNG <[email protected]>

Maintainers
~~~~~~~~~~~
Expand Down
5 changes: 4 additions & 1 deletion payroll_account/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
"summary": "Manage your payroll to accounting",
"author": "Odoo SA, Odoo Community Association (OCA)",
"depends": ["payroll", "account"],
"data": ["views/hr_payroll_account_views.xml"],
"data": [
"views/hr_payroll_account_views.xml",
"views/res_config_settings_views.xml",
],
"demo": ["demo/hr_payroll_account_demo.xml"],
"maintainers": ["appstogrow", "nimarosa"],
}
2 changes: 2 additions & 0 deletions payroll_account/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from . import hr_payroll_account
from . import res_config_settings
from . import company
12 changes: 12 additions & 0 deletions payroll_account/models/company.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo import fields, models


class ResCompany(models.Model):
_inherit = "res.company"

action_group_payslips = fields.Boolean(
string="Group payslips in accounting",
help="Allow companies to group payslips in accounting",
)
106 changes: 94 additions & 12 deletions payroll_account/models/hr_payroll_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,77 @@
def action_payslip_cancel(self):
for payslip in self:
if not payslip.move_id.journal_id.restrict_mode_hash_table:
# TODO : cancel all the grouped payslips
payslip.move_id.with_context(force_delete=True).button_cancel()
payslip.move_id.with_context(force_delete=True).unlink()
else:
payslip.move_id._reverse_moves()
payslip.move_id = False
return super(HrPayslip, self).action_payslip_cancel()

def _check_can_merge(self, move_date, move_journal):
# Check that payslips can be accounted together
for slip in self:
# Check date
date = slip.date or slip.date_to

Check warning on line 95 in payroll_account/models/hr_payroll_account.py

View check run for this annotation

Codecov / codecov/patch

payroll_account/models/hr_payroll_account.py#L95

Added line #L95 was not covered by tests
if date != move_date:
raise UserError(

Check warning on line 97 in payroll_account/models/hr_payroll_account.py

View check run for this annotation

Codecov / codecov/patch

payroll_account/models/hr_payroll_account.py#L97

Added line #L97 was not covered by tests
_(
"Only payslips with the same date can be accounted together."
" The payslip '%s' has a different date!"
)
% (slip.number)
)
# Check journal
journal = slip.journal_id.id

Check warning on line 105 in payroll_account/models/hr_payroll_account.py

View check run for this annotation

Codecov / codecov/patch

payroll_account/models/hr_payroll_account.py#L105

Added line #L105 was not covered by tests
if journal != move_journal:
raise UserError(

Check warning on line 107 in payroll_account/models/hr_payroll_account.py

View check run for this annotation

Codecov / codecov/patch

payroll_account/models/hr_payroll_account.py#L107

Added line #L107 was not covered by tests
_(
"Only payslips with the same salary journal can be accounted together."
" The payslip '%s' has a different salary journal!"
)
% (slip.number)
)

def _merge_move_lines(self, move_lines, line_ids):
for line in line_ids:
del line[2]["partner_id"]
account_in_move = False

Check warning on line 118 in payroll_account/models/hr_payroll_account.py

View check run for this annotation

Codecov / codecov/patch

payroll_account/models/hr_payroll_account.py#L117-L118

Added lines #L117 - L118 were not covered by tests
for move_line in move_lines:
if (
line[2]["account_id"] == move_line[2]["account_id"]
and line[2]["analytic_distribution"]
== move_line[2]["analytic_distribution"]
and line[2]["debit"] == move_line[2]["debit"] == 0
):
account_in_move = True
move_line[2]["credit"] += line[2]["credit"]
break

Check warning on line 128 in payroll_account/models/hr_payroll_account.py

View check run for this annotation

Codecov / codecov/patch

payroll_account/models/hr_payroll_account.py#L126-L128

Added lines #L126 - L128 were not covered by tests
if (
line[2]["account_id"] == move_line[2]["account_id"]
and line[2]["analytic_distribution"]
== move_line[2]["analytic_distribution"]
and line[2]["credit"] == move_line[2]["credit"] == 0
):
account_in_move = True
move_line[2]["debit"] += line[2]["debit"]
break

Check warning on line 137 in payroll_account/models/hr_payroll_account.py

View check run for this annotation

Codecov / codecov/patch

payroll_account/models/hr_payroll_account.py#L135-L137

Added lines #L135 - L137 were not covered by tests
if not account_in_move:
move_lines.append(line)
return move_lines

Check warning on line 140 in payroll_account/models/hr_payroll_account.py

View check run for this annotation

Codecov / codecov/patch

payroll_account/models/hr_payroll_account.py#L139-L140

Added lines #L139 - L140 were not covered by tests

def action_payslip_done(self):
res = super(HrPayslip, self).action_payslip_done()
# Check if we can merge payslips in accounting
if len(self) > 1 and self.env.company.action_group_payslips:
# Define account move general information based on the first slip
move_date = self[0].date or self[0].date_to
move_journal = self[0].journal_id.id
self._check_can_merge(move_date, move_journal)

Check warning on line 148 in payroll_account/models/hr_payroll_account.py

View check run for this annotation

Codecov / codecov/patch

payroll_account/models/hr_payroll_account.py#L146-L148

Added lines #L146 - L148 were not covered by tests

# Initialize account move and account move lines
move = False
move_lines = []

Check warning on line 152 in payroll_account/models/hr_payroll_account.py

View check run for this annotation

Codecov / codecov/patch

payroll_account/models/hr_payroll_account.py#L151-L152

Added lines #L151 - L152 were not covered by tests
# Compute account move lines
for slip in self:
line_ids = []
debit_sum = 0.0
Expand All @@ -99,13 +160,6 @@
slip.company_id.currency_id or slip.journal_id.company_id.currency_id
)

name = _("Payslip of %s") % (slip.employee_id.name)
move_dict = {
"narration": name,
"ref": slip.number,
"journal_id": slip.journal_id.id,
"date": date,
}
for line in slip.line_ids:
amount = currency.round(slip.credit_note and -line.total or line.total)
if currency.is_zero(amount):
Expand Down Expand Up @@ -273,14 +327,42 @@
)
line_ids.append(adjust_debit)
if len(line_ids) > 0:
move_dict["line_ids"] = line_ids
move = self.env["account.move"].create(move_dict)
slip.write({"move_id": move.id, "date": date})
move.action_post()
if len(self) == 1 or not self.env.company.action_group_payslips:
# We do a single account move
name = _("Payslip of %s") % (slip.employee_id.name)
move_dict = {
"narration": name,
"ref": slip.number,
"journal_id": slip.journal_id.id,
"date": date,
}
move_dict["line_ids"] = line_ids
move_slip = self.env["account.move"].create(move_dict)
slip.write({"move_id": move_slip.id})
move_slip.action_post()

else:
# We want to merge account entries in a single account move
if not move:
move = self.env["account.move"].create({})
move_lines = self._merge_move_lines(move_lines, line_ids)
slip.write({"move_id": move.id})

Check warning on line 349 in payroll_account/models/hr_payroll_account.py

View check run for this annotation

Codecov / codecov/patch

payroll_account/models/hr_payroll_account.py#L347-L349

Added lines #L347 - L349 were not covered by tests
else:
logger.warning(
f"Payslip {slip.number} did not generate any account move lines"
)
res = super(HrPayslip, slip).action_payslip_done()

# Add account move lines into the global account move
if len(self) > 1 and self.env.company.action_group_payslips:
move_dict = {

Check warning on line 358 in payroll_account/models/hr_payroll_account.py

View check run for this annotation

Codecov / codecov/patch

payroll_account/models/hr_payroll_account.py#L358

Added line #L358 was not covered by tests
"narration": _("Payslips of %s") % (move_date),
"journal_id": move_journal,
"date": move_date,
}
move_dict["line_ids"] = move_lines
move.write(move_dict)
move.action_post()

Check warning on line 365 in payroll_account/models/hr_payroll_account.py

View check run for this annotation

Codecov / codecov/patch

payroll_account/models/hr_payroll_account.py#L363-L365

Added lines #L363 - L365 were not covered by tests
return res


Expand Down
15 changes: 15 additions & 0 deletions payroll_account/models/res_config_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo import fields, models


class ResConfigSettings(models.TransientModel):
_inherit = "res.config.settings"

action_group_payslips = fields.Boolean(
string="Group payslips in accounting",
related="company_id.action_group_payslips",
help="Allow companies to group payslips in accounting",
readonly=False,
store=True,
)
2 changes: 2 additions & 0 deletions payroll_account/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
* Odoo SA <[email protected]>
* Saran Lim. <[email protected]>
* Moana FABER <[email protected]>
* Cyril VINH-TUNG <[email protected]>
5 changes: 4 additions & 1 deletion payroll_account/static/description/index.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
Expand Down Expand Up @@ -366,7 +367,7 @@ <h1 class="title">Payroll Accounting</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:653a0c1054563da937bc111ee0541f4208dd379ec0f37ba7d7d8f4fe03216a84
!! source digest: sha256:5bdfba50457cc2a2920d5ffdf3c32cd43ab3533339bedf79c110b47f3ef95a15
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/payroll/tree/16.0/payroll_account"><img alt="OCA/payroll" src="https://img.shields.io/badge/github-OCA%2Fpayroll-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/payroll-16-0/payroll-16-0-payroll_account"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/payroll&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>Generic Payroll system Integrated with Accounting.</p>
Expand Down Expand Up @@ -412,6 +413,8 @@ <h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
<ul class="simple">
<li>Odoo SA &lt;<a class="reference external" href="mailto:info&#64;odoo.com">info&#64;odoo.com</a>&gt;</li>
<li>Saran Lim. &lt;<a class="reference external" href="mailto:saranl&#64;ecosoft.co.th">saranl&#64;ecosoft.co.th</a>&gt;</li>
<li>Moana FABER &lt;<a class="reference external" href="mailto:moana.faber&#64;hotmail.com">moana.faber&#64;hotmail.com</a>&gt;</li>
<li>Cyril VINH-TUNG &lt;<a class="reference external" href="mailto:cyril&#64;invitu.com">cyril&#64;invitu.com</a>&gt;</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand Down
30 changes: 30 additions & 0 deletions payroll_account/views/res_config_settings_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="res_config_settings_view_form" model="ir.ui.view">
<field
name="name"
>res.config.settings.view.form.inherit.hr.payroll.account</field>
<field name="model">res.config.settings</field>
<field name="inherit_id" ref="payroll.res_config_settings_view_form" />
<field name="arch" type="xml">
<xpath expr="//div[@id='payroll_accountant']" position="after">
<div class="row mt16 o_settings_container" id="action_group_payslips">
<div class="col-lg-6 col-12 o_setting_box">
<div class="o_setting_left_pane">
<field name="action_group_payslips" />
</div>
<div class="o_setting_right_pane">
<label
for="action_group_payslips"
string="Group payslips in accounting"
/>
<div class="text-muted">
Allow companies to group payslips in accounting
</div>
</div>
</div>
</div>
</xpath>
</field>
</record>
</odoo>
1 change: 1 addition & 0 deletions payroll_account/wizard/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from . import hr_payroll_payslips_by_employees
from . import hr_payslip_change_state
35 changes: 35 additions & 0 deletions payroll_account/wizard/hr_payslip_change_state.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo import models
from odoo.exceptions import UserError
from odoo.tools.translate import _


class HrPayslipChangeState(models.TransientModel):

_inherit = "hr.payslip.change.state"

def change_state_confirm(self):
company_id = self.env.company.id
config_settings = self.env["res.config.settings"].search(

Check warning on line 14 in payroll_account/wizard/hr_payslip_change_state.py

View check run for this annotation

Codecov / codecov/patch

payroll_account/wizard/hr_payslip_change_state.py#L13-L14

Added lines #L13 - L14 were not covered by tests
[("company_id", "=", company_id)], limit=1
)
action_group_payslips = config_settings.action_group_payslips

Check warning on line 17 in payroll_account/wizard/hr_payslip_change_state.py

View check run for this annotation

Codecov / codecov/patch

payroll_account/wizard/hr_payslip_change_state.py#L17

Added line #L17 was not covered by tests

if action_group_payslips and self.state == "done":
record_ids = self.env.context.get("active_ids", False)
payslip_obj = self.env["hr.payslip"]
records = payslip_obj.browse(record_ids)

Check warning on line 22 in payroll_account/wizard/hr_payslip_change_state.py

View check run for this annotation

Codecov / codecov/patch

payroll_account/wizard/hr_payslip_change_state.py#L20-L22

Added lines #L20 - L22 were not covered by tests
for rec in records:
if rec.state not in ("verify", "draft"):
raise UserError(

Check warning on line 25 in payroll_account/wizard/hr_payslip_change_state.py

View check run for this annotation

Codecov / codecov/patch

payroll_account/wizard/hr_payslip_change_state.py#L25

Added line #L25 was not covered by tests
_(
"Only payslips in states verify or draft"
" can be confirmed, the payslip %(nm)s is in "
"%(st)s state"
)
% {"nm": rec.name, "st": rec.state}
)
records.action_payslip_done()

Check warning on line 33 in payroll_account/wizard/hr_payslip_change_state.py

View check run for this annotation

Codecov / codecov/patch

payroll_account/wizard/hr_payslip_change_state.py#L33

Added line #L33 was not covered by tests
else:
return super(HrPayslipChangeState, self).change_state_confirm()

Check warning on line 35 in payroll_account/wizard/hr_payslip_change_state.py

View check run for this annotation

Codecov / codecov/patch

payroll_account/wizard/hr_payslip_change_state.py#L35

Added line #L35 was not covered by tests
Loading