[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.

bzr revid: mdi@tinyerp.com-20120717071731-mbc91xnbuirbc6o2
This commit is contained in:
Divyesh Makwana (Open ERP) 2012-07-17 12:47:31 +05:30
parent ede044fa92
commit edaedb7455
4 changed files with 9 additions and 29 deletions

View File

@ -86,11 +86,11 @@ class hr_expense_expense(osv.osv):
('cancelled', 'Refused'),
('confirm', 'Waiting Approval'),
('accepted', 'Approved'),
('receipted', 'Receipted'),
('receipted', 'Waiting Reimbursement'),
('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 a receipt is made for the expense request, the status is \'Receipted\'.\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 \'Waiting Reimbursement\'.\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),
@ -134,27 +134,6 @@ class hr_expense_expense(osv.osv):
self.write(cr, uid, ids, {'state':'paid'})
return True
def receipt(self, cr, uid, ids, context=None):
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, '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')
return {
'name': _('Expense Receipt'),
'view_type': 'form',
'view_mode': 'form',
'res_model': 'account.voucher',
'view_id': [res and res[1] or False],
'type': 'ir.actions.act_window',
'target': 'new',
'nodestroy': True,
'res_id': voucher_ids and voucher_ids[0] or False,
}
def action_receipt_create(self, cr, uid, ids, context=None):
res = False
property_obj = self.pool.get('ir.property')
@ -162,6 +141,7 @@ class hr_expense_expense(osv.osv):
analytic_journal_obj = self.pool.get('account.analytic.journal')
account_journal = self.pool.get('account.journal')
voucher_obj = self.pool.get('account.voucher')
wkf_service = netsvc.LocalService("workflow")
for exp in self.browse(cr, uid, ids, context=context):
company_id = exp.company_id.id
@ -212,6 +192,7 @@ class hr_expense_expense(osv.osv):
if analytic_journal_ids:
account_journal.write(cr, uid, [journal.id], {'analytic_journal_id': analytic_journal_ids[0]}, context=context)
voucher_id = voucher_obj.create(cr, uid, voucher, context=context)
wkf_service.trg_validate(uid, 'account.voucher', voucher_id, 'proforma_voucher', cr)
self.write(cr, uid, [exp.id], {'voucher_id': voucher_id, 'state': 'receipted'}, context=context)
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="receipt" states="accepted" string="Issue Receipt" type="object" groups="base.group_hr_user" class="oe_highlight"/>
<button name="receipt" states="accepted" string="Issue Receipt" type="workflow" groups="base.group_hr_user" class="oe_highlight"/>
<button name="action_view_receipt" states="receipted" string="Open Receipt" type="object" 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"}'/>

View File

@ -50,8 +50,7 @@
<record id="act_receipt" model="workflow.activity">
<field name="wkf_id" ref="wkf_expenses"/>
<field name="name">receipt</field>
<field name="kind">subflow</field>
<field name="subflow_id" ref="account_voucher.wkf"/>
<field name="kind">function</field>
<field name="action">action_receipt_create()</field>
</record>
@ -99,7 +98,7 @@
<record id="t9" model="workflow.transition">
<field name="act_from" ref="act_receipt"/>
<field name="act_to" ref="act_paid"/>
<field name="signal">subflow.done</field>
<field name="signal">paid</field>
<field name="group_id" ref="base.group_hr_user"/>
</record>

View File

@ -20,13 +20,13 @@
I make Receipt for the expense.
-
!python {model: hr.expense.expense}: |
self.receipt(cr, uid, [ref('sep_expenses')])
self.action_receipt_create(cr, uid, [ref('sep_expenses')])
-
I check receipt details.
-
!python {model: hr.expense.expense}: |
sep_expenses = self.browse(cr, uid, ref("sep_expenses"), context=context)
assert sep_expenses.state == 'receipted', "Expense should be in 'Receipted' state."
assert sep_expenses.state == 'receipted', "Expense should be in 'Waiting Reimbursement' state."
assert sep_expenses.voucher_id.name == sep_expenses.name,"Receipt name is not correspond with expense name."
assert sep_expenses.voucher_id.type == 'purchase', "Receipt type is not purchase receipt."
assert sep_expenses.voucher_id.amount == sep_expenses.amount,"Receipt total amount is not correspond with expense total."