From 55d977914ed7b13165cbfd7cb6e60f19a11bb79f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bidoul=20=28ACSONE=29?= Date: Sat, 1 Jul 2017 14:39:08 +0200 Subject: [PATCH] [10.0] hr_expense_usability improvements (#37) * [FIX] hr_expense_usability: set default move number Otherwise it's not possible to post the account move. * [FIX] hr_expense_usability: prevent deleting draft move This prevents deleting a draft account move that is linked to an expense. Without this the expense could stay in posted while the related move has been deleted, which is inconsitent and impossible to recover for the user. * [IMP] hr_expense_usability: preserve product/quantity on move line When possible, preserve product and quantity on move line. This is important when generating analytic lines to reinvoice expenses * add contributor * [FIX] hr_expense_usability: readonly account move on expense sheet * [IMP] hr_expense_usablility: preserve employee name in move line name This is important when reinvoicing expenses, so the correct label is visible on the sale order. --- hr_expense_usability/README.rst | 1 + hr_expense_usability/hr_expense.py | 20 +++++++++++++++++++- hr_expense_usability/hr_expense_view.xml | 1 + 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/hr_expense_usability/README.rst b/hr_expense_usability/README.rst index 5b88692..0ca2985 100644 --- a/hr_expense_usability/README.rst +++ b/hr_expense_usability/README.rst @@ -15,3 +15,4 @@ Contributors ------------ * Alexis de Lattre +* Stéphane Bidoul diff --git a/hr_expense_usability/hr_expense.py b/hr_expense_usability/hr_expense.py index e1d4a49..43c8ec3 100644 --- a/hr_expense_usability/hr_expense.py +++ b/hr_expense_usability/hr_expense.py @@ -262,6 +262,8 @@ class HrExpenseSheet(models.Model): compute='compute_total_company_currency', currency_field='company_currency_id', readonly=True, store=True, string='Tax Amount', help="Tax amount in company currency") + account_move_id = fields.Many2one( + ondelete='restrict') @api.depends( 'expense_line_ids.total_amount_company_currency', @@ -292,6 +294,7 @@ class HrExpenseSheet(models.Model): % self.display_name) date = self.accounting_date or fields.Date.context_today(self) vals = { + 'name': '/', 'journal_id': self.journal_id.id, 'date': date, 'ref': self.number, @@ -344,7 +347,10 @@ class HrExpenseSheet(models.Model): 'account_id': account.id, 'analytic_account_id': exp.analytic_account_id.id or False, 'amount': exp.untaxed_amount_company_currency, - 'name': exp.name.split('\n')[0][:64], + 'name': exp.employee_id.name + ': ' + exp.name.split('\n')[0][:64], + 'product_id': exp.product_id.id, + 'product_uom_id': exp.product_uom_id.id, + 'quantity': exp.quantity, }) # TAX tax_cmp = float_compare( @@ -384,6 +390,15 @@ class HrExpenseSheet(models.Model): if key in group_mlines: group_mlines[key]['amount'] += mline['amount'] group_mlines[key]['name'] = self.name[:64] + group_mlines[key]['quantity'] += mline['quantity'] + if 'product_id' in group_mlines[key] and \ + group_mlines[key]['product_id'] != \ + mline['product_id']: + del group_mlines[key]['product_id'] + if 'product_uom_id' in group_mlines[key] and \ + group_mlines[key]['product_uom_id'] != \ + mline['product_uom_id']: + del group_mlines[key]['product_uom_id'] else: group_mlines[key] = mline res_mlines = [] @@ -403,6 +418,9 @@ class HrExpenseSheet(models.Model): 'partner_id': gmlines['partner_id'], 'account_id': gmlines['account_id'], 'analytic_account_id': gmlines['analytic_account_id'], + 'product_id': gmlines.get('product_id', False), + 'product_uom_id': gmlines.get('product_uom_id', False), + 'quantity': gmlines.get('quantity', 1), 'name': gmlines['name'], 'debit': debit, 'credit': credit, diff --git a/hr_expense_usability/hr_expense_view.xml b/hr_expense_usability/hr_expense_view.xml index 0bb1d25..ef5e02b 100644 --- a/hr_expense_usability/hr_expense_view.xml +++ b/hr_expense_usability/hr_expense_view.xml @@ -114,6 +114,7 @@ 0 account.group_account_user post + 1