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

Comission in payslip (integrate sale_commission module and hr_payroll module) #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
35 changes: 35 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:alt: License: AGPL-3

HR Commission in Payslip
===========

This module allows to integrate sale_commission module and hr_payroll module. Creating a salary rule for commission and auto complete the commission input in the payslip.

Usage
=====

To use this module, you need to add the created salary rule to the salary structure which will use commission

Credits
=======

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

* Daniel Sadamo <[email protected]> - KMEE

Maintainer
----------

.. image:: http://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: http://odoo-community.org

This module is maintained by the OCA.

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

To contribute to this module, please visit http://odoo-community.org.
2 changes: 2 additions & 0 deletions hr_commission_payslip/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# coding: utf-8
from . import model
41 changes: 41 additions & 0 deletions hr_commission_payslip/__openerp__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# KMEE, KM Enterprising Engineering
# Copyright(C) 2015 - Daniel Sadamo <[email protected]>
#
# This program is free software: you can redistribute it and /or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#

{
'name': u'Commission in Payslip',
'version': '1.0',
'category': 'Other',
'description': u"""Module to integrate sale_commission module and
hr_payroll module. Creating a salary rule for commission and auto
complete the commission input in the payslip""",
'author': 'KMEE/Odoo Community Association(OCA)',
'website': 'http://www.kmee.com.br',
'depends': [
'sale_commission',
'hr_payroll',
],
'init_xml': [
'data/commission_salary_rule_data.xml'
],
'data': [
'view/hr_payslip.xml'
],
'installable': True,
}
25 changes: 25 additions & 0 deletions hr_commission_payslip/data/commission_salary_rule_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>

<!-- Salary Rule -->

<record id="hr_salary_rule_sales_commission_in_payslip" model="hr.salary.rule">
<field name="amount_select">code</field>
<field name="code">COMMISSION</field>
<field name="category_id" ref="hr_payroll.ALW"/>
<field name="name">Get commission</field>
<field name="sequence" eval="95"/>
<field name="amount_python_compute">result = inputs.COM.amount</field>
</record>

<!-- Rule Inputs -->

<record id="hr_rule_input_commission_in_payslip" model="hr.rule.input">
<field name="code">COM</field>
<field name="name">Commission</field>
<field name="input_id" ref="hr_salary_rule_sales_commission_in_payslip"/>
</record>

</data>
</openerp>
2 changes: 2 additions & 0 deletions hr_commission_payslip/model/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# coding: utf-8
from . import hr_payslip
61 changes: 61 additions & 0 deletions hr_commission_payslip/model/hr_payslip.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# KMEE, KM Enterprising Engineering
# Copyright(C) 2015 - Daniel Sadamo <[email protected]>
#
# This program is free software: you can redistribute it and /or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

from openerp.osv import osv


class hr_payslip(osv.osv):

_inherit = 'hr.payslip'

def onchange_input_line_ids(self, cr, uid, ids, input_line_ids,
date_from, date_to,
employee_id=False, context=None):
if context is None:
context = {}

res = {'value': {}}
if not employee_id:
return res
# Get the total commission for the date interval
settlement_obj = self.pool.get('settlement')
settlements_ids = settlement_obj.search(
cr, uid,
[('date_from', '>=', date_from), ('date_to', '<=', date_to)],
context=context)
commission_amount = 0.0
settlements = settlement_obj.browse(cr, uid, settlements_ids, context)
for settlement in settlements:
for agent in settlement.settlement_agent_id:
if agent.agent_id.employee_id.id == employee_id:
commission_amount += agent.total
# Insert the commission value in the input list
for input_line in input_line_ids:
if input_line[2]:
if 'code' in input_line[2] and\
(input_line[2]['code'] == 'COM'):
input_line[2]['amount'] = commission_amount

res['value'].update({
'input_line_ids': input_line_ids,
})

return res
17 changes: 17 additions & 0 deletions hr_commission_payslip/view/hr_payslip.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>

<record id="view_hr_commission_in_payslip_form" model="ir.ui.view">
<field name="name">hr.commission.in.payslip.form</field>
<field name="model">hr.payslip</field>
<field name="inherit_id" ref="hr_payroll.view_hr_payslip_form"/>
<field name="arch" type="xml">
<field name="input_line_ids" position="attributes">
<attribute name="on_change">onchange_input_line_ids(input_line_ids, date_from, date_to, employee_id)</attribute>
</field>
</field>
</record>

</data>
</openerp>