Skip to content

Commit 70acfc6

Browse files
committed
Merge PR OCA#679 into 12.0
Signed-off-by Saran440
2 parents ae3d38e + ac66e8d commit 70acfc6

21 files changed

+1325
-0
lines changed

hr_expense_petty_cash/README.rst

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
==========
2+
Petty Cash
3+
==========
4+
5+
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6+
!! This file is generated by oca-gen-addon-readme !!
7+
!! changes will be overwritten. !!
8+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
9+
10+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
11+
:target: https://odoo-community.org/page/development-status
12+
:alt: Beta
13+
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
14+
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
15+
:alt: License: AGPL-3
16+
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fhr-lightgray.png?logo=github
17+
:target: https://github.com/OCA/hr/tree/12.0/hr_expense_petty_cash
18+
:alt: OCA/hr
19+
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
20+
:target: https://translation.odoo-community.org/projects/hr-12-0/hr-12-0-hr_expense_petty_cash
21+
:alt: Translate me on Weblate
22+
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
23+
:target: https://runbot.odoo-community.org/runbot/116/12.0
24+
:alt: Try me on Runbot
25+
26+
|badge1| |badge2| |badge3| |badge4| |badge5|
27+
28+
This module work about expense that paid by petty cash.
29+
30+
General Process:
31+
32+
#. Create Petty Cash Holder
33+
#. Transfer cash to Petty Cash Holder By Vendor bill
34+
#. You can create expense paid by petty cash and select petty cash holder.
35+
#. Then balance of petty cash holder less than amount of expense, you must transfer cash to petty cash holder before Submit Report to Manager.
36+
37+
**Table of contents**
38+
39+
.. contents::
40+
:local:
41+
42+
Configuration
43+
=============
44+
45+
**Create a Petty Cash Account**
46+
47+
#. Go to Invoicing > Configuration > Chart of accounts
48+
#. Create a new petty cash account
49+
#. Type = Bank and Cash or Account type that is asset
50+
51+
Note:
52+
53+
* You will need the "Show Full Accounting Features" to see accounting data
54+
55+
Usage
56+
=====
57+
58+
**Create a Petty Cash Holder**
59+
60+
#. Go to Invoicing > Configuration > Petty Cash
61+
#. Create a new petty cash holder
62+
#. Select Petty Cash Account
63+
64+
**Add Balance for Petty Cash Holder**
65+
66+
#. Go to Invoicing > Vendor > Bill
67+
#. Create a new vendor bill
68+
#. Select Vendor (Petty Cash Holder)
69+
#. Check Petty Cash will auto line with Unit Price = Max Limit - Balance
70+
71+
**Create an Expense paid by Petty Cash**
72+
73+
#. Go to Expenses > My Expenses
74+
#. Create a new expense
75+
#. Select Paid by = Petty Cash and Select Petty Cash Holder
76+
77+
**Create an Expense Report paid by Petty Cash**
78+
79+
#. Go to Expenses > My Expense Reports
80+
#. Create a new expense report
81+
#. Select or Create expenses Paid by Petty Cash and same Petty Cash Holder
82+
83+
Bug Tracker
84+
===========
85+
86+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/hr/issues>`_.
87+
In case of trouble, please check there if your issue has already been reported.
88+
If you spotted it first, help us smashing it by providing a detailed and welcomed
89+
`feedback <https://github.com/OCA/hr/issues/new?body=module:%20hr_expense_petty_cash%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
90+
91+
Do not contact contributors directly about support or help with technical issues.
92+
93+
Credits
94+
=======
95+
96+
Authors
97+
~~~~~~~
98+
99+
* Ecosoft
100+
101+
Contributors
102+
~~~~~~~~~~~~
103+
104+
* `Ecosoft <http://ecosoft.co.th>`__:
105+
106+
* Pimolnat Suntian <[email protected]>
107+
108+
Maintainers
109+
~~~~~~~~~~~
110+
111+
This module is maintained by the OCA.
112+
113+
.. image:: https://odoo-community.org/logo.png
114+
:alt: Odoo Community Association
115+
:target: https://odoo-community.org
116+
117+
OCA, or the Odoo Community Association, is a nonprofit organization whose
118+
mission is to support the collaborative development of Odoo features and
119+
promote its widespread use.
120+
121+
This module is part of the `OCA/hr <https://github.com/OCA/hr/tree/12.0/hr_expense_petty_cash>`_ project on GitHub.
122+
123+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

hr_expense_petty_cash/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Copyright 2019 Ecosoft Co., Ltd. (http://ecosoft.co.th)
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
3+
4+
from . import models

hr_expense_petty_cash/__manifest__.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Copyright 2019 Ecosoft Co., Ltd. (http://ecosoft.co.th)
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
3+
4+
{
5+
'name': 'Petty Cash',
6+
'version': '12.0.1.0.0',
7+
'category': 'Human Resources',
8+
'author': 'Ecosoft, Odoo Community Association (OCA)',
9+
'license': 'AGPL-3',
10+
'website': 'https://github.com/OCA/hr',
11+
'depends': [
12+
'hr_expense',
13+
],
14+
'data': [
15+
'security/ir.model.access.csv',
16+
'views/account_invoice_views.xml',
17+
'views/hr_expense_sheet_views.xml',
18+
'views/hr_expense_views.xml',
19+
'views/petty_cash_views.xml',
20+
],
21+
'installable': True,
22+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Copyright 2019 Ecosoft Co., Ltd. (http://ecosoft.co.th)
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
3+
4+
from . import account_invoice
5+
from . import hr_expense
6+
from . import hr_expense_sheet
7+
from . import petty_cash
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Copyright 2019 Ecosoft Co., Ltd. (http://ecosoft.co.th)
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
3+
4+
from odoo import api, fields, models, _
5+
from odoo.exceptions import ValidationError
6+
7+
8+
class AccountInvoice(models.Model):
9+
_inherit = 'account.invoice'
10+
11+
is_petty_cash = fields.Boolean(
12+
string='Petty Cash',
13+
readonly=True,
14+
states={'draft': [('readonly', False)]},
15+
)
16+
17+
@api.multi
18+
@api.constrains('invoice_line_ids')
19+
def _check_petty_cash_amount(self):
20+
petty_cash_env = self.env['petty.cash']
21+
for rec in self.filtered('is_petty_cash'):
22+
petty_cash = petty_cash_env.search(
23+
[('partner_id', '=', rec.partner_id.id)], limit=1)
24+
if not petty_cash:
25+
raise ValidationError(_('%s is not a petty cash holder') %
26+
rec.partner_id.name)
27+
balance = petty_cash.petty_cash_balance
28+
limit = petty_cash.petty_cash_limit
29+
max_amount = limit - balance
30+
account = petty_cash.account_id
31+
amount = sum(rec.invoice_line_ids.filtered(
32+
lambda l: l.account_id == account).mapped('price_subtotal'))
33+
company_currency = rec.company_id.currency_id
34+
amount_company = rec.currency_id._convert(
35+
amount, company_currency, rec.company_id,
36+
rec.date_invoice or fields.Date.today())
37+
if amount_company > max_amount:
38+
raise ValidationError(
39+
_('Petty Cash balance is %s %s.\n'
40+
'Max amount to add is %s %s.') %
41+
('{:,.2f}'.format(balance), company_currency.symbol,
42+
'{:,.2f}'.format(max_amount), company_currency.symbol))
43+
44+
@api.multi
45+
def _add_petty_cash_invoice_line(self, petty_cash):
46+
self.ensure_one()
47+
# Get suggested currency amount
48+
amount = petty_cash.petty_cash_limit - petty_cash.petty_cash_balance
49+
company_currency = self.env.user.company_id.currency_id
50+
amount_doc_currency = company_currency._convert(
51+
amount, self.currency_id, self.company_id,
52+
self.date_invoice or fields.Date.today())
53+
54+
inv_line = self.env['account.invoice.line'].new({
55+
'name': petty_cash.account_id.name,
56+
'invoice_id': self.id,
57+
'account_id': petty_cash.account_id.id,
58+
'price_unit': amount_doc_currency,
59+
'quantity': 1,
60+
})
61+
return inv_line
62+
63+
@api.multi
64+
@api.onchange('is_petty_cash', 'partner_id')
65+
def _onchange_is_petty_cash(self):
66+
self.invoice_line_ids = False
67+
if self.is_petty_cash:
68+
if not self.partner_id:
69+
raise ValidationError(_('Please select petty cash holder'))
70+
# Selected parenter must be petty cash holder
71+
petty_cash = self.env['petty.cash'].search(
72+
[('partner_id', '=', self.partner_id.id)], limit=1)
73+
if not petty_cash:
74+
raise ValidationError(_('%s is not a petty cash holder') %
75+
self.partner_id.name)
76+
self._add_petty_cash_invoice_line(petty_cash)
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Copyright 2019 Ecosoft Co., Ltd. (http://ecosoft.co.th)
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
3+
4+
from odoo import api, fields, models, _
5+
from odoo.exceptions import ValidationError
6+
7+
8+
class HrExpense(models.Model):
9+
_inherit = 'hr.expense'
10+
11+
payment_mode = fields.Selection(
12+
selection_add=[('petty_cash', 'Petty Cash')],
13+
)
14+
petty_cash_id = fields.Many2one(
15+
string='Petty cash holder',
16+
comodel_name='petty.cash',
17+
ondelete='restrict',
18+
readonly=True,
19+
states={'draft': [('readonly', False)]},
20+
)
21+
22+
@api.multi
23+
def action_submit_expenses(self):
24+
res = super().action_submit_expenses()
25+
context = res['context']
26+
context['default_expense_line_ids'] = self.ids
27+
context['default_name'] = self[0].name if len(self) == 1 else ''
28+
set_petty_cash_ids = set()
29+
for rec in self:
30+
set_petty_cash_ids.add(rec.petty_cash_id.id)
31+
if set_petty_cash_ids:
32+
if len(set_petty_cash_ids) == 1:
33+
context['default_petty_cash_id'] = set_petty_cash_ids.pop()
34+
return res
35+
raise ValidationError(_('You cannot create report from '
36+
'many petty cash holders.'))
37+
38+
@api.multi
39+
def _get_account_move_line_values(self):
40+
res = super()._get_account_move_line_values()
41+
for expense in self.filtered(
42+
lambda p: p.payment_mode == 'petty_cash'):
43+
line = res[expense.id][1]
44+
line['account_id'] = expense.petty_cash_id.account_id.id
45+
line['partner_id'] = expense.petty_cash_id.partner_id.id
46+
res[expense.id][1] = line
47+
return res
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Copyright 2019 Ecosoft Co., Ltd. (http://ecosoft.co.th)
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
3+
4+
from odoo import api, fields, models, _
5+
from odoo.exceptions import ValidationError
6+
7+
8+
class HrExpenseSheet(models.Model):
9+
_inherit = 'hr.expense.sheet'
10+
11+
payment_mode = fields.Selection(
12+
selection_add=[('petty_cash', 'Petty Cash')],
13+
)
14+
petty_cash_id = fields.Many2one(
15+
string='Petty cash holder',
16+
comodel_name='petty.cash',
17+
ondelete='restrict',
18+
readonly=True,
19+
compute='_compute_petty_cash',
20+
)
21+
22+
@api.depends('expense_line_ids', 'payment_mode')
23+
def _compute_petty_cash(self):
24+
for rec in self:
25+
if rec.payment_mode == 'petty_cash':
26+
set_petty_cash_ids = set()
27+
for line in rec.expense_line_ids:
28+
set_petty_cash_ids.add(line.petty_cash_id.id)
29+
if len(set_petty_cash_ids) == 1:
30+
rec.petty_cash_id = rec.env['petty.cash'].browse(
31+
set_petty_cash_ids.pop())
32+
else:
33+
raise ValidationError(_('You cannot create report from '
34+
'many petty cash holders.'))
35+
36+
@api.multi
37+
@api.constrains('expense_line_ids', 'total_amount')
38+
def _check_petty_cash_amount(self):
39+
for rec in self:
40+
if rec.payment_mode == 'petty_cash':
41+
petty_cash = rec.petty_cash_id
42+
balance = petty_cash.petty_cash_balance
43+
amount = rec.total_amount
44+
company_currency = rec.company_id.currency_id
45+
amount_company = rec.currency_id._convert(
46+
amount, company_currency, rec.company_id,
47+
rec.accounting_date or fields.Date.today())
48+
if amount_company > balance:
49+
raise ValidationError(
50+
_('Not enough money in petty cash holder.\n'
51+
'You are requesting %s%s, '
52+
'but the balance is %s%s.') %
53+
('{:,.2f}'.format(amount_company),
54+
company_currency.symbol, '{:,.2f}'.format(balance),
55+
company_currency.symbol))
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Copyright 2019 Ecosoft Co., Ltd. (http://ecosoft.co.th)
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
3+
4+
from odoo import api, fields, models
5+
6+
7+
class PettyCash(models.Model):
8+
_name = 'petty.cash'
9+
_description = 'Petty Cash'
10+
_rec_name = 'partner_id'
11+
12+
partner_id = fields.Many2one(
13+
comodel_name='res.partner',
14+
string='Petty Cash Holder',
15+
domain=[('supplier', '=', True)],
16+
required=True,
17+
)
18+
account_id = fields.Many2one(
19+
comodel_name='account.account',
20+
string='Petty Cash Account',
21+
required=True,
22+
)
23+
petty_cash_limit = fields.Float(
24+
string='Max Limit',
25+
required=True,
26+
)
27+
petty_cash_balance = fields.Float(
28+
string='Balance',
29+
compute='_compute_petty_cash_balance',
30+
)
31+
_sql_constraints = [
32+
('partner_uniq', 'unique(partner_id)',
33+
'Petty Cash Holder must be unique!'),
34+
]
35+
36+
@api.depends('partner_id', 'account_id')
37+
def _compute_petty_cash_balance(self):
38+
aml_env = self.env['account.move.line']
39+
for rec in self:
40+
aml = aml_env.search([('partner_id', '=', rec.partner_id.id),
41+
('account_id', '=', rec.account_id.id)])
42+
balance = sum([line.debit - line.credit for line in aml])
43+
rec.petty_cash_balance = balance
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
**Create a Petty Cash Account**
2+
3+
#. Go to Invoicing > Configuration > Chart of accounts
4+
#. Create a new petty cash account
5+
#. Type = Bank and Cash or Account type that is asset
6+
7+
Note:
8+
9+
* You will need the "Show Full Accounting Features" to see accounting data
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
* `Ecosoft <http://ecosoft.co.th>`__:
2+
3+
* Pimolnat Suntian <[email protected]>

0 commit comments

Comments
 (0)