[IMP] hr_expense : After the confirmation of the expense, the button should create an account.voucher (instead of an invoice) and confirmed it. It must creates the accounting entries exactly as the current invoice does and its related changes.

bzr revid: mdi@tinyerp.com-20120713113812-pv886hx31397viv5
This commit is contained in:
Divyesh Makwana (Open ERP) 2012-07-13 17:08:12 +05:30
parent 6e0dc212c7
commit 9fe6cdd4ee
4 changed files with 26 additions and 22 deletions

View File

@ -40,12 +40,16 @@ class hr_expense_expense(osv.osv):
if context is None:
context = {}
if not default: default = {}
default.update({'invoice_id': False, 'date_confirm': False, 'date_valid': False, 'user_valid': False})
default.update({'voucher_id': False, 'date_confirm': False, 'date_valid': False, 'user_valid': False})
return super(hr_expense_expense, self).copy(cr, uid, id, default, context=context)
def _amount(self, cr, uid, ids, field_name, arg, context=None):
cr.execute("SELECT s.id,COALESCE(SUM(l.unit_amount*l.unit_quantity),0) AS amount FROM hr_expense_expense s LEFT OUTER JOIN hr_expense_line l ON (s.id=l.expense_id) WHERE s.id IN %s GROUP BY s.id ", (tuple(ids),))
res = dict(cr.fetchall())
res= {}
for expense in self.browse(cr, uid, ids, context=context):
total = 0.0
for line in expense.line_ids:
total += line.unit_amount * line.unit_quantity
res[expense.id] = total
return res
def _get_currency(self, cr, uid, context=None):
@ -73,7 +77,7 @@ class hr_expense_expense(osv.osv):
'line_ids': fields.one2many('hr.expense.line', 'expense_id', 'Expense Lines', readonly=True, states={'draft':[('readonly',False)]} ),
'note': fields.text('Note'),
'amount': fields.function(_amount, string='Total Amount'),
'voucher_id': fields.many2one('account.voucher', "Employee's Voucher"),
'voucher_id': fields.many2one('account.voucher', "Employee's Receipt"),
'currency_id': fields.many2one('res.currency', 'Currency', required=True),
'department_id':fields.many2one('hr.department','Department'),
'company_id': fields.many2one('res.company', 'Company', required=True),
@ -82,11 +86,11 @@ class hr_expense_expense(osv.osv):
('cancelled', 'Refused'),
('confirm', 'Waiting Approval'),
('accepted', 'Approved'),
('invoiced', 'Invoiced'),
('receipted', 'Receipted'),
('paid', 'Reimbursed')
],
'Status', readonly=True, help='When the expense request is created the status is \'Draft\'.\n It is confirmed by the user and request is sent to admin, the status is \'Waiting Confirmation\'.\
\nIf the admin accepts it, the status is \'Accepted\'.\n If an invoice is made for the expense request, the status is \'Invoiced\'.\n If the expense is paid to user, the status is \'Reimbursed\'.'),
\nIf the admin accepts it, the status is \'Accepted\'.\n If a receipt is made for the expense request, the status is \'Receipted\'.\n If the expense is paid to user, the status is \'Reimbursed\'.'),
}
_defaults = {
'company_id': lambda s, cr, uid, c: s.pool.get('res.company')._company_default_get(cr, uid, 'hr.employee', context=c),
@ -130,14 +134,14 @@ class hr_expense_expense(osv.osv):
self.write(cr, uid, ids, {'state':'paid'})
return True
def invoice(self, cr, uid, ids, context=None):
def receipt(self, cr, uid, ids, context=None):
if not ids: return []
mod_obj = self.pool.get('ir.model.data')
wkf_service = netsvc.LocalService("workflow")
voucher_ids = []
for id in ids:
wkf_service.trg_validate(uid, 'hr.expense.expense', id, 'invoice', cr)
wkf_service.trg_validate(uid, 'hr.expense.expense', id, 'receipt', cr)
voucher_ids.append(self.browse(cr, uid, id, context=context).voucher_id.id)
res = mod_obj.get_object_reference(cr, uid, 'account_voucher', 'view_purchase_receipt_form')
res_id = res and res[1] or False
@ -153,9 +157,9 @@ class hr_expense_expense(osv.osv):
'nodestroy': True,
'res_id': voucher_ids and voucher_ids[0] or False,
}
def action_voucher_create(self, cr, uid, ids, context=None):
def action_receipt_create(self, cr, uid, ids, context=None):
res = False
invoice_obj = self.pool.get('account.invoice')
property_obj = self.pool.get('ir.property')
sequence_obj = self.pool.get('ir.sequence')
account_journal = self.pool.get('account.journal')
@ -200,12 +204,12 @@ class hr_expense_expense(osv.osv):
voucher['journal_id'] = exp.journal_id.id
journal = exp.journal_id
else:
journal_id = invoice_obj._get_journal(cr, uid, context={'type': 'in_invoice', 'company_id': company_id})
journal_id = voucher_obj._get_journal(cr, uid, context={'type': 'purchase', 'company_id': company_id})
if journal_id:
voucher['journal_id'] = journal_id
journal = account_journal.browse(cr, uid, journal_id)
voucher_id = voucher_obj.create(cr, uid, voucher, context)
aaa = self.write(cr, uid, [exp.id], {'voucher_id': voucher_id, 'state': 'invoiced'})
self.write(cr, uid, [exp.id], {'voucher_id': voucher_id, 'state': 'receipted'})
res = voucher_id
return res

View File

@ -68,7 +68,7 @@
<button name="confirm" states="draft" string="Submit to Manager" type="workflow" class="oe_highlight"/>
<button name="validate" states="confirm" string="Approve" type="workflow" groups="base.group_hr_user" class="oe_highlight"/>
<button name="draft" states="confirm,cancelled" string="Set to Draft" type="workflow" groups="base.group_hr_user" />
<button name="invoice" states="accepted" string="Invoice" type="object" groups="base.group_hr_user" class="oe_highlight"/>
<button name="receipt" states="accepted" string="Issue Receipt" type="object" groups="base.group_hr_user" class="oe_highlight"/>
<button name="refuse" states="confirm,accepted" string="Refuse" type="workflow" groups="base.group_hr_user" />
<field name="state" widget="statusbar" statusbar_visible="draft,confirm,accepted" statusbar_colors='{"confirm":"blue","cancelled":"red"}'/>
</header>

View File

@ -47,12 +47,12 @@
<field name="action">expense_canceled()</field>
</record>
<record id="act_invoice" model="workflow.activity">
<record id="act_receipt" model="workflow.activity">
<field name="wkf_id" ref="wkf_expenses"/>
<field name="name">invoice</field>
<field name="name">receipt</field>
<field name="kind">subflow</field>
<field name="subflow_id" ref="account_voucher.wkf"/>
<field name="action">action_voucher_create()</field>
<field name="action">action_receipt_create()</field>
</record>
<record id="t1" model="workflow.transition">
@ -91,13 +91,13 @@
<record id="t8" model="workflow.transition">
<field name="act_from" ref="act_accepted"/>
<field name="act_to" ref="act_invoice"/>
<field name="signal">invoice</field>
<field name="act_to" ref="act_receipt"/>
<field name="signal">receipt</field>
<field name="group_id" ref="base.group_hr_user"/>
</record>
<record id="t9" model="workflow.transition">
<field name="act_from" ref="act_invoice"/>
<field name="act_from" ref="act_receipt"/>
<field name="act_to" ref="act_paid"/>
<field name="signal">subflow.done</field>
<field name="group_id" ref="base.group_hr_user"/>

View File

@ -20,18 +20,18 @@
I make Voucher for the expense.
-
!python {model: hr.expense.expense}: |
self.invoice(cr, uid, [ref('sep_expenses')])
self.receipt(cr, uid, [ref('sep_expenses')])
-
I check voucher details.
-
!python {model: hr.expense.expense}: |
sep_expenses = self.browse(cr, uid, ref("sep_expenses"), context=context)
assert sep_expenses.state == 'invoiced', "Expense should be in 'Invoiced' state."
assert sep_expenses.state == 'receipted', "Expense should be in 'Receipted' state."
assert sep_expenses.voucher_id.name == sep_expenses.name,"Voucher name is not correspond with expense name."
assert sep_expenses.voucher_id.type == 'purchase', "Voucher type is not purchase voucher."
assert sep_expenses.voucher_id.amount == sep_expenses.amount,"Voucher total amount is not correspond with expense total."
assert len(sep_expenses.voucher_id.line_dr_ids) == len(sep_expenses.line_ids),"Lines of Voucher and expense line are not correspond."
#TODO: check invoice line details with Expenses lines
-
I pay the expenses.
-