Skip to content

Commit e800ab4

Browse files
committed
[ADD] l10n_th_doctype_salary
1 parent d9efa3a commit e800ab4

19 files changed

+230
-75
lines changed

account_cancel_reversal/__openerp__.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@
44
'version': '1.0',
55
'author': 'Ecosoft',
66
'summary': """
7-
8-
Cancel Invoice / Voucher / Bank receipt by create reversed journal entry
9-
7+
Cancel Invoice / Voucher / Bank receipt / Salary Expense
8+
by create reversed journal entry
109
""",
1110
'description': """
12-
1311
This module put more accounting control into invoice cancellation.
1412
1513
As-Is:
@@ -38,12 +36,14 @@
3836
'account_invoice_cancel_hooks',
3937
'account_voucher_cancel_hooks',
4038
'account_bank_receipt',
39+
'hr_salary',
4140
],
4241
'demo': [],
4342
'data': [
4443
'views/voucher_payment_receipt_view.xml',
4544
'views/account_invoice_view.xml',
4645
'views/account_bank_receipt_view.xml',
46+
'views/hr_salary_view.xml',
4747
],
4848
'test': [
4949
],

account_cancel_reversal/models/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
from . import account_voucher
44
from . import account
55
from . import account_bank_receipt
6+
from . import hr_salary

account_cancel_reversal/models/account.py

+10
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@
55
class AccountMove(models.Model):
66
_inherit = 'account.move'
77

8+
@api.model
9+
def _switch_move_dict_dr_cr(self, move_dict):
10+
move_lines = []
11+
for line_dict in move_dict['line_id']:
12+
line_dict[2].update({'credit': line_dict[2]['debit'],
13+
'debit': line_dict[2]['credit'],
14+
})
15+
move_lines.append((0, 0, line_dict[2]))
16+
return move_dict
17+
818
@api.multi
919
def _switch_dr_cr(self):
1020
self.ensure_one()

account_cancel_reversal/models/account_bank_receipt.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,18 @@ def _cancel_move(self):
2121
line.reconcile_id.unlink()
2222
move = self.move_id
2323
period = self.env['account.period'].find()
24-
rev_move = move.copy({'name': move.name + '_VOID',
25-
'ref': move.ref,
26-
'period_id': period.id,
27-
'date': fields.Date.context_today(self)})
28-
rev_move._switch_dr_cr()
24+
AccountMove = self.env['account.move']
25+
move_dict = move.copy_data({
26+
'name': move.name + '_VOID',
27+
'ref': move.ref,
28+
'period_id': period.id,
29+
'date': fields.Date.context_today(self), })[0]
30+
move_dict = AccountMove._switch_move_dict_dr_cr(move_dict)
31+
rev_move = AccountMove.create(move_dict)
2932
self.cancel_move_id = rev_move
3033
# As account both DR and CR are balance sheet item, do one by one
3134
accounts = move.line_id.mapped('account_id')
3235
for account in accounts:
33-
self.env['account.move'].\
36+
AccountMove.\
3437
_reconcile_voided_entry_by_account([move.id, rev_move.id],
3538
account.id)

account_cancel_reversal/models/account_invoice.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,15 @@ def action_cancel(self):
2828
for inv in self: # For each cancel invoice with internal_number
2929
move = inv.move_id
3030
if move:
31-
rev_move = move.copy({'name': move.name + '_VOID',
32-
'ref': move.ref,
33-
'period_id': period.id,
34-
'date': fields.Date.context_today(self)})
35-
rev_move._switch_dr_cr()
36-
self.env['account.move'].\
31+
AccountMove = self.env['account.move']
32+
move_dict = move.copy_data({
33+
'name': move.name + '_VOID',
34+
'ref': move.ref,
35+
'period_id': period.id,
36+
'date': fields.Date.context_today(self), })[0]
37+
move_dict = AccountMove._switch_move_dict_dr_cr(move_dict)
38+
rev_move = AccountMove.create(move_dict)
39+
AccountMove.\
3740
_reconcile_voided_entry([move.id, rev_move.id])
3841
rev_move.button_validate()
3942
inv.cancel_move_id = rev_move

account_cancel_reversal/models/account_voucher.py

+10-6
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,21 @@ class AccountVoucher(models.Model):
1818
def voucher_move_cancel_hook(self, voucher):
1919
move = voucher.move_id
2020
period = self.env['account.period'].find()
21-
rev_move = move.copy({'name': move.name + '_VOID',
22-
'ref': move.ref,
23-
'period_id': period.id,
24-
'date': fields.Date.context_today(self)})
25-
rev_move._switch_dr_cr()
21+
AccountMove = self.env['account.move']
22+
move_dict = move.copy_data({
23+
'name': move.name + '_VOID',
24+
'ref': move.ref,
25+
'period_id': period.id,
26+
'date': fields.Date.context_today(self), })[0]
27+
move_dict = AccountMove._switch_move_dict_dr_cr(move_dict)
28+
rev_move = AccountMove.create(move_dict)
29+
2630
voucher.cancel_move_id = rev_move
2731
# Delete reconcile, and receconcile with reverse entry
2832
move.line_id.filtered('reconcile_id').reconcile_id.unlink()
2933
accounts = move.line_id.mapped('account_id')
3034
for account in accounts:
31-
self.env['account.move'].\
35+
AccountMove.\
3236
_reconcile_voided_entry_by_account([move.id, rev_move.id],
3337
account.id)
3438

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# -*- coding: utf-8 -*-
2+
from openerp import models, api, fields, _
3+
from openerp.exceptions import Warning as UserError
4+
5+
6+
class HRSalaryExpense(models.Model):
7+
_inherit = 'hr.salary.expense'
8+
9+
cancel_move_id = fields.Many2one(
10+
'account.move',
11+
string='Cancel Journal Entry',
12+
readonly=True,
13+
index=True,
14+
ondelete='restrict',
15+
copy=False,
16+
)
17+
18+
@api.model
19+
def action_cancel_hook(self, moves=False):
20+
# Just change state, do not delete moves
21+
self.write({'state': 'cancel'})
22+
return
23+
24+
@api.multi
25+
def action_cancel(self):
26+
res = super(HRSalaryExpense, self).action_cancel()
27+
period = self.env['account.period'].find()
28+
# First, set the invoices as cancelled and detach the move ids
29+
for salary in self: # For each cancel invoice with internal_number
30+
move = salary.move_id
31+
if move:
32+
AccountMove = self.env['account.move']
33+
if move.line_id.filtered(lambda l: l.reconcile_id or
34+
l.reconcile_partial_id):
35+
raise UserError(
36+
_('This salary expensed has been partially '
37+
'reconciles, cancellaion not allowed!'))
38+
move_dict = move.copy_data({
39+
'name': move.name + '_VOID',
40+
'ref': move.ref,
41+
'period_id': period.id,
42+
'date': fields.Date.context_today(self), })[0]
43+
move_dict = AccountMove._switch_move_dict_dr_cr(move_dict)
44+
rev_move = AccountMove.create(move_dict)
45+
AccountMove._reconcile_voided_entry([move.id, rev_move.id])
46+
rev_move.button_validate()
47+
salary.cancel_move_id = rev_move
48+
return res
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<openerp>
3+
<data>
4+
<record id="view_hr_salary_expense_form" model="ir.ui.view">
5+
<field name="name">view.hr.salary.expense.view</field>
6+
<field name="model">hr.salary.expense</field>
7+
<field name="inherit_id" ref="hr_salary.view_hr_salary_expense_form"/>
8+
<field name="arch" type="xml">
9+
<button name="action_draft" position="replace" />
10+
<xpath expr="/form/sheet/notebook//field[@name='move_id']" position="after">
11+
<field name="cancel_move_id" />
12+
</xpath>
13+
</field>
14+
</record>
15+
</data>
16+
</openerp>

hr_salary/__openerp__.py

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
1414
""",
1515
"data": [
16+
"security/ir.model.access.csv",
1617
"data/hr_salary_sequence.xml",
1718
"views/hr_salary_view.xml",
1819
],

hr_salary/models/hr_salary.py

+15-31
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class HRSalaryExpense(models.Model):
88
_name = "hr.salary.expense"
99
_inherit = ['mail.thread']
1010
_description = "Salary Expense"
11+
_rec_name = 'number'
1112
_order = "id desc"
1213

1314
number = fields.Char(
@@ -35,26 +36,31 @@ class HRSalaryExpense(models.Model):
3536
readonly=True,
3637
states={'draft': [('readonly', False)]},
3738
default=lambda self: fields.Date.context_today(self),
39+
copy=False,
3840
)
3941
date_submit = fields.Date(
4042
string='Submitted Date',
4143
index=True,
4244
readonly=True,
45+
copy=False,
4346
)
4447
submit_user_id = fields.Many2one(
4548
'res.users',
4649
string='Submited By',
4750
readonly=True,
51+
copy=False,
4852
)
4953
date_approve = fields.Date(
5054
string='Approved Date',
5155
index=True,
5256
readonly=True,
57+
copy=False,
5358
)
5459
approve_user_id = fields.Many2one(
5560
'res.users',
5661
string='Approved By',
5762
readonly=True,
63+
copy=False,
5864
)
5965
journal_id = fields.Many2one(
6066
'account.journal',
@@ -169,6 +175,14 @@ def _validate_salary_line(self):
169175
else:
170176
return True
171177

178+
@api.multi
179+
def action_cancel_hook(self, moves=False):
180+
self.write({'state': 'cancel', 'move_id': False})
181+
if moves:
182+
moves.button_cancel()
183+
moves.unlink()
184+
return
185+
172186
@api.model
173187
def create(self, vals):
174188
if vals.get('number', '/') == '/':
@@ -190,10 +204,7 @@ def action_draft(self):
190204
@api.multi
191205
def action_cancel(self):
192206
moves = self.mapped('move_id')
193-
for move in moves:
194-
move.button_cancel()
195-
move.unlink()
196-
self.write({'state': 'cancel'})
207+
self.action_cancel_hook(moves)
197208
return True
198209

199210
@api.multi
@@ -320,12 +331,10 @@ def _write(self, vals):
320331
""" As is_paid is triggered, so do the state """
321332
for rec in self:
322333
if 'is_paid' in vals:
323-
print rec.state
324334
if rec.state == 'open' and vals['is_paid'] is True:
325335
vals['state'] = 'paid'
326336
if rec.state == 'paid' and vals['is_paid'] is False:
327337
vals['state'] = 'open'
328-
print vals
329338
return super(HRSalaryExpense, self)._write(vals)
330339

331340

@@ -370,28 +379,3 @@ class HRSalaryLine(models.Model):
370379
'account.analytic.account',
371380
string='Analytic Account',
372381
)
373-
374-
375-
# class AccountMoveLine(models.Model):
376-
# _inherit = "account.move.line"
377-
#
378-
# def reconcile(self, cr, uid, ids, type='auto', writeoff_acc_id=False, writeoff_period_id=False, writeoff_journal_id=False, context=None):
379-
# res = super(account_move_line, self).reconcile(cr, uid, ids, type=type, writeoff_acc_id=writeoff_acc_id, writeoff_period_id=writeoff_period_id, writeoff_journal_id=writeoff_journal_id, context=context)
380-
# #when making a full reconciliation of account move lines 'ids', we may need to recompute the state of some hr.expense
381-
# account_move_ids = [aml.move_id.id for aml in self.browse(cr, uid, ids, context=context)]
382-
# expense_obj = self.pool.get('hr.expense.expense')
383-
# currency_obj = self.pool.get('res.currency')
384-
# if account_move_ids:
385-
# expense_ids = expense_obj.search(cr, uid, [('account_move_id', 'in', account_move_ids)], context=context)
386-
# for expense in expense_obj.browse(cr, uid, expense_ids, context=context):
387-
# if expense.state == 'done':
388-
# #making the postulate it has to be set paid, then trying to invalidate it
389-
# new_status_is_paid = True
390-
# for aml in expense.account_move_id.line_id:
391-
# if aml.account_id.type == 'payable' and not currency_obj.is_zero(cr, uid, expense.company_id.currency_id, aml.amount_residual):
392-
# new_status_is_paid = False
393-
# if new_status_is_paid:
394-
# expense_obj.write(cr, uid, [expense.id], {'state': 'paid'}, context=context)
395-
# return res
396-
397-
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
+4-21
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,5 @@
11
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
2-
access_hr_expense_expense_user,hr.expense.expense.user,model_hr_expense_expense,base.group_hr_user,1,1,1,1
3-
access_hr_expense_expense_employee,hr.expense.expense.employee,model_hr_expense_expense,base.group_user,1,1,1,1
4-
access_hr_expense_line_user,hr.expense.line.user,model_hr_expense_line,base.group_hr_user,1,1,1,1
5-
access_hr_expense_line_employee,hr.expense.line.employee,model_hr_expense_line,base.group_user,1,1,1,1
6-
access_hr_expense_report_manager,hr.expense.report.manager,model_hr_expense_report,base.group_hr_manager,1,1,1,1
7-
access_product_product_hr_expense_user,product.product.hr.expense.user,product.model_product_product,base.group_hr_user,1,1,1,1
8-
access_product_template_hr_expense_user,product.template.hr.expense.user,product.model_product_template,base.group_hr_user,1,1,1,1
9-
access_product_uom_hr_expense_user,product.uom.hr.expense.user,product.model_product_uom,base.group_hr_user,1,1,1,1
10-
access_product_price_type_user,product.price.type.user,product.model_product_price_type,base.group_hr_user,1,1,1,1
11-
access_account_journal_user,account.journal.user,account.model_account_journal,base.group_hr_user,1,1,1,1
12-
access_account_journal_employee,account.journal.employee,account.model_account_journal,base.group_user,1,0,0,0
13-
access_account_invoice_user,account.invoice.user,account.model_account_invoice,base.group_hr_user,1,1,1,1
14-
access_account_invoice_line_user,account.invoice.line.user,account.model_account_invoice_line,base.group_hr_user,1,1,1,1
15-
access_account_analytic_journal_user,account.ianalytic.journal.user,account.model_account_analytic_journal,base.group_hr_user,1,1,1,1
16-
access_account_invoice_tax_user,account.invoice.tax.user,account.model_account_invoice_tax,base.group_hr_user,1,1,1,1
17-
access_account_period_user,account.period.user,account.model_account_period,base.group_hr_user,1,1,1,1
18-
access_account_fiscalyear_user,account.fiscalyear.user,account.model_account_fiscalyear,base.group_hr_user,1,1,1,1
19-
access_account_move_user,account.move.user,account.model_account_move,base.group_hr_user,1,1,1,1
20-
access_account_move_line_user,account.move.line.user,account.model_account_move_line,base.group_hr_user,1,1,1,1
21-
access_account_analytic_line_user,account.ianalytic.line.user,account.model_account_analytic_line,base.group_hr_user,1,1,1,1
22-
access_account_journal_period_manager,account.journal.period.manager,account.model_account_journal_period,base.group_hr_manager,1,1,1,1
2+
access_hr_salary_user,hr.salary.expense.user,model_hr_salary_expense,base.group_hr_manager,1,1,1,1
3+
access_hr_salary_line_user,hr.salary.line.user,model_hr_salary_line,base.group_hr_manager,1,1,1,1
4+
access_hr_salary_user,hr.salary.expense.user,model_hr_salary_expense,,1,0,0,0
5+
access_hr_salary_line_user,hr.salary.line.user,model_hr_salary_line,,1,0,0,0

hr_salary/views/hr_salary_view.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@
147147
</field>
148148
</record>
149149

150-
<menuitem action="action_hr_salary_expense" id="menu_hr_salary_expense" name="Salary Expense" parent="menu_hr_salary_root"/>
150+
<menuitem action="action_hr_salary_expense" id="menu_hr_salary_expense" name="Salary Expense" parent="menu_hr_salary_root" groups="base.group_hr_manager"/>
151151

152152
</data>
153153
</openerp>

l10n_th_doctype_salary/__init__.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# -*- coding: utf-8 -*-
2+
# © <YEAR(S)> <AUTHOR(S)>
3+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
4+
5+
from . import models

l10n_th_doctype_salary/__openerp__.py

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# -*- coding: utf-8 -*-
2+
{
3+
"name": "Sequence Number by Document Type for Expense",
4+
"summary": "",
5+
"version": "8.0.1.0.0",
6+
"category": "Accounting & Finance",
7+
"description": """
8+
9+
New menu, > Settings > Technical > Sequences & Identifiers > Doctype
10+
11+
List of Doctype
12+
13+
* Employee Expense
14+
* Employee Advance
15+
16+
""",
17+
"website": "https://ecosoft.co.th/",
18+
"author": "Kitti U.",
19+
"license": "AGPL-3",
20+
"application": False,
21+
"installable": True,
22+
"depends": [
23+
'l10n_th_doctype_base',
24+
'hr_salary',
25+
],
26+
"data": [
27+
"data/ir_sequence_data.xml",
28+
"data/doctype_data.xml",
29+
],
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- © <YEAR(S)> <AUTHOR(S)>
3+
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -->
4+
<openerp>
5+
<data noupdate="1">
6+
<record id="doctype_salary_expense" model="res.doctype" >
7+
<field name="name">Salary Expense</field>
8+
<field name="sequence_id" ref="doctype_salary_expense_seq"/>
9+
<field name="refer_type">salary_expense</field>
10+
</record>
11+
</data>
12+
</openerp>

0 commit comments

Comments
 (0)