From c030213fa3b822b1ea373c77b552bfda716a3900 Mon Sep 17 00:00:00 2001 From: d-fence Date: Thu, 15 Sep 2016 11:16:28 +0200 Subject: [PATCH] [IMP] hr_expense: Allow a user to refuse an expense sheet from a line Purpose ======= Currently, a manager or a accountant can only refuse one expense report with a justification message. If there are a lot of lines too comment individually or if only one line should be modified, the manager or the accountant can now refused one line and give a reason for it. That will refused the expense report automatically while waiting the employee to make the modifications. Specification ============= - Rename wizard files, models and ids according to the model - Allow to refuse one or several lines with a reason - Use a qweb template to log messages, use message_post_with_view instead of message_post - Print expense name instead of sheet name. In the log when expense is refused, it prints expense report name instead of expense - Prevent modifying approved expenses * A user should not be able to modify an expense once approved * Method refuse_expense renamed to refuse_sheet when applied to a whole expense report/sheet * 'model' dict key renamed to something more explicit and less prone to confusion (passed in context to the refuse wizard) * Usage of explicit fields in the wizard to avoid confusion * Overriding 'default_get' to get default values for those fields - When an expense is paid or reported, it must be impossible to refuse it. - Replace refused expenses tree Purpose: The menu 'Refused expenses' is confusing. This improvement replaces it by 'Refused Reports' and leads to the refused reports tree view. That way, it's easier for the user to find back his refused expenses reports. - Hide create button on refused --- addons/hr_expense/__manifest__.py | 4 +- addons/hr_expense/models/hr_expense.py | 17 ++++-- addons/hr_expense/security/ir_rule.xml | 5 +- addons/hr_expense/views/hr_expense.xml | 6 ++ addons/hr_expense/views/hr_expense_views.xml | 57 ++++++++----------- addons/hr_expense/wizard/__init__.py | 3 +- .../wizard/hr_expense_refuse_reason.py | 36 ++++++++++-- ...xml => hr_expense_refuse_reason_views.xml} | 10 ++-- ...y => hr_expense_sheet_register_payment.py} | 6 +- ... => hr_expense_sheet_register_payment.xml} | 12 ++-- addons/hr_expense_check/models/payment.py | 2 +- addons/hr_expense_check/views/payment.xml | 6 +- 12 files changed, 100 insertions(+), 64 deletions(-) rename addons/hr_expense/wizard/{hr_expense_refuse_reason.xml => hr_expense_refuse_reason_views.xml} (75%) rename addons/hr_expense/wizard/{hr_expense_register_payment.py => hr_expense_sheet_register_payment.py} (96%) rename addons/hr_expense/wizard/{hr_expense_register_payment.xml => hr_expense_sheet_register_payment.xml} (80%) diff --git a/addons/hr_expense/__manifest__.py b/addons/hr_expense/__manifest__.py index e6fc131ba8a..77bea25f140 100644 --- a/addons/hr_expense/__manifest__.py +++ b/addons/hr_expense/__manifest__.py @@ -32,8 +32,8 @@ This module also uses analytic accounting and is compatible with the invoice on 'security/ir.model.access.csv', 'data/hr_expense_data.xml', 'data/hr_expense_sequence.xml', - 'wizard/hr_expense_refuse_reason.xml', - 'wizard/hr_expense_register_payment.xml', + 'wizard/hr_expense_refuse_reason_views.xml', + 'wizard/hr_expense_sheet_register_payment.xml', 'views/hr_expense_views.xml', 'security/ir_rule.xml', 'report/report_expense_sheet.xml', diff --git a/addons/hr_expense/models/hr_expense.py b/addons/hr_expense/models/hr_expense.py index a5a26185b50..d30810eeb1e 100644 --- a/addons/hr_expense/models/hr_expense.py +++ b/addons/hr_expense/models/hr_expense.py @@ -44,6 +44,7 @@ class HrExpense(models.Model): help="Status of the expense.") sheet_id = fields.Many2one('hr.expense.sheet', string="Expense Report", readonly=True, copy=False) reference = fields.Char(string="Bill Reference") + is_refused = fields.Boolean(string="Explicitely Refused by manager or acccountant", readonly=True, copy=False) @api.depends('sheet_id', 'sheet_id.account_move_id', 'sheet_id.state') def _compute_state(self): @@ -307,6 +308,13 @@ class HrExpense(models.Model): res['context'] = {'default_res_model': 'hr.expense', 'default_res_id': self.id} return res + @api.multi + def refuse_expense(self,reason): + self.write({'is_refused': True}) + self.sheet_id.write({'state': 'cancel'}) + self.sheet_id.message_post_with_view('hr_expense.hr_expense_template_refuse_reason', + values={'reason': reason, 'is_sheet':False, 'name':self.name}) + @api.model def get_empty_list_help(self, help_message): if help_message: @@ -392,7 +400,7 @@ class HrExpenseSheet(models.Model): ('done', 'Paid'), ('cancel', 'Refused') ], string='Status', index=True, readonly=True, track_visibility='onchange', copy=False, default='submit', required=True, - help='Expense Report State') + help='Expense Report State') employee_id = fields.Many2one('hr.employee', string="Employee", required=True, readonly=True, states={'submit': [('readonly', False)]}, default=lambda self: self.env['hr.employee'].search([('user_id', '=', self.env.uid)], limit=1)) address_id = fields.Many2one('res.partner', string="Employee Home Address") payment_mode = fields.Selection([("own_account", "Employee (to reimburse)"), ("company_account", "Company")], related='expense_line_ids.payment_mode', default='own_account', readonly=True, string="Payment By") @@ -512,11 +520,11 @@ class HrExpenseSheet(models.Model): self.attachment_number = sum(self.expense_line_ids.mapped('attachment_number')) @api.multi - def refuse_expenses(self, reason): + def refuse_sheet(self, reason): self.write({'state': 'cancel'}) for sheet in self: - body = (_("Your Expense %s has been refused.
") % (sheet.name, reason)) - sheet.message_post(body=body) + sheet.message_post_with_view('hr_expense.hr_expense_template_refuse_reason', + values={'reason': reason ,'is_sheet':True ,'name':self.name}) @api.multi def approve_expense_sheets(self): @@ -528,6 +536,7 @@ class HrExpenseSheet(models.Model): @api.multi def reset_expense_sheets(self): + self.mapped('expense_line_ids').write({'is_refused': False}) return self.write({'state': 'submit'}) @api.multi diff --git a/addons/hr_expense/security/ir_rule.xml b/addons/hr_expense/security/ir_rule.xml index e86d91211d8..7148e828231 100644 --- a/addons/hr_expense/security/ir_rule.xml +++ b/addons/hr_expense/security/ir_rule.xml @@ -6,7 +6,10 @@ Manager Expense [(1, '=', 1)] - + Employee Expense diff --git a/addons/hr_expense/views/hr_expense.xml b/addons/hr_expense/views/hr_expense.xml index 03d0900c00a..d6b3e3ce828 100644 --- a/addons/hr_expense/views/hr_expense.xml +++ b/addons/hr_expense/views/hr_expense.xml @@ -7,5 +7,11 @@ + diff --git a/addons/hr_expense/views/hr_expense_views.xml b/addons/hr_expense/views/hr_expense_views.xml index 362c37f1fc1..fe09c69d18c 100644 --- a/addons/hr_expense/views/hr_expense_views.xml +++ b/addons/hr_expense/views/hr_expense_views.xml @@ -225,26 +225,6 @@ - - Refused Expenses - hr.expense - tree,kanban,form,graph,pivot - - [('employee_id.user_id', '=', uid)] - {'search_default_refused': 1} - -

- The steps to process expenses are: -

    -
  1. You record expenses,
  2. -
  3. Periodically, you submit expenses report to your manager,
  4. -
  5. Once approved, your expense report, goes to the accounting,
  6. -
  7. The accountant validates entries and reimburse you.
  8. -
-

-
-
- product.template.expense.form product.template @@ -387,7 +367,7 @@ hr.expense.sheet.tree hr.expense.sheet - + @@ -407,11 +387,10 @@
@@ -443,8 +422,8 @@ - - + + @@ -455,6 +434,8 @@