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

12.0 imp w awards sending mail #2

Open
wants to merge 14 commits into
base: 12.0
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
78 changes: 78 additions & 0 deletions hr_expense_portal/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
=================
HR Expense Portal
=================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fhr-lightgray.png?logo=github
:target: https://github.com/OCA/hr/tree/12.0/hr_expense_portal
:alt: OCA/hr
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/hr-12-0/hr-12-0-hr_expense_portal
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/116/12.0
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|

Show current expenses in a website.

**Table of contents**

.. contents::
:local:

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

Bugs are tracked on `GitHub Issues <https://github.com/OCA/hr/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/hr/issues/new?body=module:%20hr_expense_portal%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

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

Credits
=======

Authors
~~~~~~~

* Open Source Integrators

Contributors
~~~~~~~~~~~~

* Ammar Offciewala <[email protected]>

Other credits
~~~~~~~~~~~~~

* Open Source Integrators <[email protected]>

Maintainers
~~~~~~~~~~~

This module is maintained by the OCA.

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

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.

This module is part of the `OCA/hr <https://github.com/OCA/hr/tree/12.0/hr_expense_portal>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
4 changes: 4 additions & 0 deletions hr_expense_portal/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright (C) 2020 Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import controllers
21 changes: 21 additions & 0 deletions hr_expense_portal/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright (C) 2020 Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
'name': 'HR Expense Portal',
'version': '12.0.1.0.1',
'license': 'AGPL-3',
'category': 'Generic Modules/Human Resources',
'summary': "Show current expense in a website.",
"author": "Open Source Integrators, Odoo Community Association (OCA)",
'website': 'https://github.com/OCA/hr',
'depends': [
'sale_expense', 'website'
],
'data': [
'security/ir.model.access.csv',
'security/security.xml',
'views/expense_template.xml'
],
'installable': True,
}
4 changes: 4 additions & 0 deletions hr_expense_portal/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright (C) 2020 Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import expense_portal
104 changes: 104 additions & 0 deletions hr_expense_portal/controllers/expense_portal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Copyright (C) 2020 Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import http, _
from odoo.exceptions import AccessError, MissingError
from odoo.http import request
from odoo.addons.portal.controllers.portal import CustomerPortal, pager as portal_pager


class ExpensePortal(CustomerPortal):

def _prepare_portal_layout_values(self):
values = super(ExpensePortal, self)._prepare_portal_layout_values()
values['expense_count'] = request.env['hr.expense'].search_count([])
return values

def _expense_get_page_view_values(self, expense, access_token, **kwargs):
values = {
'page_name': 'expense',
'expense': expense,
'user': request.env.user
}
return self._get_page_view_values(
expense,
access_token,
values,
'my_expense_history',
False,
**kwargs
)

@http.route(
['/my/expenses', '/my/expenses/page/<int:page>'],
type='http', auth="user", website=True
)
def portal_my_expenses(
self, page=1, date_begin=None, date_end=None, sortby=None, **kw):
values = self._prepare_portal_layout_values()
hr_expense = request.env['hr.expense']

domain = []

searchbar_sortings = {
'date': {'label': _('Date'), 'order': 'date desc'},
'name': {'label': _('Description'), 'order': 'name'},
'stage': {'label': _('Stage'), 'order': 'state'},
'sale_order_id': {'label': _('Sale Order'), 'order': 'sale_order_id'},
}

# default sortby order
if not sortby:
sortby = 'date'
sort_order = searchbar_sortings[sortby]['order']

archive_groups = self._get_archive_groups('hr.expense', domain)
if date_begin and date_end:
domain += [('create_date', '>', date_begin),
('create_date', '<=', date_end)]

# count for pager
expense_count = hr_expense.search_count(domain)
# make pager
pager = portal_pager(
url="/my/expenses",
url_args={'sortby': sortby},
total=expense_count,
page=page,
step=self._items_per_page
)
# search the count to display, according to the pager data
expense = hr_expense.search(
domain,
order=sort_order,
limit=self._items_per_page,
offset=pager['offset']
)
request.session['my_expense_history'] = expense.ids[:100]
values.update({
'date': date_begin,
'expenses': expense.sudo(),
'page_name': 'expense',
'pager': pager,
'archive_groups': archive_groups,
'default_url': '/my/expenses',
'searchbar_sortings': searchbar_sortings,
'sortby': sortby,
})
return request.render("hr_expense_portal.portal_my_expenses", values)

@http.route(
['/my/expense/<int:expense_id>'], type='http', auth="public", website=True
)
def portal_my_expense(self, expense_id, access_token=None, **kw):
try:
expense_sudo = self._document_check_access(
'hr.expense', expense_id, access_token)
except (AccessError, MissingError):
return request.redirect('/my')
attachment_ids = request.env['ir.attachment'].sudo().search(
[('res_model', '=', 'hr.expense'), ('res_id', '=', expense_id)])
values = self._expense_get_page_view_values(
expense_sudo, access_token, **kw)
values['attachment_ids'] = attachment_ids
return request.render("hr_expense_portal.portal_my_expense", values)
1 change: 1 addition & 0 deletions hr_expense_portal/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Ammar Offciewala <[email protected]>
1 change: 1 addition & 0 deletions hr_expense_portal/readme/CREDITS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Open Source Integrators <[email protected]>
1 change: 1 addition & 0 deletions hr_expense_portal/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Show current expenses in a website.
2 changes: 2 additions & 0 deletions hr_expense_portal/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_hr_expense_portal,HR Expense,hr_expense.model_hr_expense,base.group_portal,1,0,0,0
15 changes: 15 additions & 0 deletions hr_expense_portal/security/security.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>

<record id="hr_expense_rule_portal" model="ir.rule">
<field name="name">Portal HR Expense</field>
<field name="model_id" ref="hr_expense.model_hr_expense"/>
<field name="domain_force">[('sale_order_id.partner_id', 'child_of', user.partner_id.commercial_partner_id.id)]</field>
<field name="groups" eval="[(4, ref('base.group_portal'))]"/>
<field name="perm_create" eval="0"/>
<field name="perm_write" eval="0"/>
<field name="perm_unlink" eval="0"/>
<field name="perm_read" eval="1"/>
</record>

</odoo>
Binary file added hr_expense_portal/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading