From f79ff3fb374650670e89f231aaf17bb8d6596c25 Mon Sep 17 00:00:00 2001 From: det Date: Fri, 13 Jan 2023 12:26:47 +0000 Subject: [PATCH] [IMP] hr_expense: do not create purchase.receipt Rework of the hr.expense workflow so that: - expenses paid by employee generate purchase.order - expenses paid by company generate entry that look like payments Main reason being that purchase.receipt are not active by default. That makes the entry hard to find, holes in sequences, inconsitency with payment states. It also remove the refusal of expenses as this was dead / inaccessible code, only reports can be refused. task-id: 3126550 [community](https://github.com/odoo/odoo/pull/110518) [enterprise](https://github.com/odoo/enterprise/pull/36090) closes odoo/odoo#110518 Related: odoo/upgrade#4266 Related: odoo/enterprise#36090 Signed-off-by: Laurent Smet --- addons/account/__manifest__.py | 1 + addons/account/models/account_move.py | 5 +- .../account/models/account_payment_method.py | 5 + .../account/views/account_payment_method.xml | 15 + addons/account/views/account_payment_view.xml | 4 +- addons/hr_expense/__manifest__.py | 1 + .../data/mail_message_subtype_data.xml | 12 + addons/hr_expense/data/mail_templates.xml | 2 +- addons/hr_expense/models/__init__.py | 1 + addons/hr_expense/models/account_move.py | 53 +- addons/hr_expense/models/account_move_line.py | 17 +- addons/hr_expense/models/account_payment.py | 39 ++ addons/hr_expense/models/hr_expense.py | 654 ++++++++++-------- addons/hr_expense/models/res_company.py | 9 +- .../hr_expense/models/res_config_settings.py | 6 +- addons/hr_expense/static/src/views/list.js | 20 +- addons/hr_expense/static/src/views/list.xml | 2 +- addons/hr_expense/tests/test_expenses.py | 154 +++-- .../tests/test_expenses_access_rights.py | 9 +- .../tests/test_expenses_multi_company.py | 10 +- .../views/account_payment_views.xml | 21 + addons/hr_expense/views/hr_expense_views.xml | 58 +- .../views/res_config_settings_views.xml | 6 +- .../wizard/hr_expense_approve_duplicate.py | 4 +- .../wizard/hr_expense_refuse_reason.py | 34 +- .../wizard/hr_expense_refuse_reason_views.xml | 5 +- addons/project/models/project.py | 5 + addons/project_hr_expense/models/project.py | 13 +- .../tests/test_project_profitability.py | 4 +- addons/project_purchase/models/project.py | 2 +- .../models/project_project.py | 2 +- .../tests/test_project_profitability.py | 2 +- addons/sale_expense/tests/test_reinvoice.py | 2 +- .../sale_expense/tests/test_sale_expense.py | 10 +- .../views/hr_expense_sheet_views.xml | 2 +- .../tests/test_so_expense_purchase_price.py | 2 +- 36 files changed, 699 insertions(+), 492 deletions(-) create mode 100644 addons/account/views/account_payment_method.xml create mode 100644 addons/hr_expense/models/account_payment.py create mode 100644 addons/hr_expense/views/account_payment_views.xml diff --git a/addons/account/__manifest__.py b/addons/account/__manifest__.py index 9d0564a9060..f1601089207 100644 --- a/addons/account/__manifest__.py +++ b/addons/account/__manifest__.py @@ -39,6 +39,7 @@ You could use this simplified accounting in case you work with an (external) acc 'views/account_tax_views.xml', 'views/account_full_reconcile_views.xml', 'views/account_payment_term_views.xml', + 'views/account_payment_method.xml', 'views/res_partner_bank_views.xml', 'views/report_statement.xml', 'views/terms_template.xml', diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index 15be42ca4c9..97ff29c754d 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -2092,7 +2092,7 @@ class AccountMove(models.Model): # Only invoice-like and journal entries in "auto tax mode" are synced tax_container['records'] = container['records'].filtered(lambda m: (m.is_invoice(True) or m.line_ids.tax_ids and not m.tax_cash_basis_origin_move_id)) invoice_container['records'] = container['records'].filtered(lambda m: m.is_invoice(True)) - misc_container['records'] = container['records'].filtered(lambda m: m.move_type == 'entry' and not m.tax_cash_basis_origin_move_id) + misc_container['records'] = container['records'].filtered(lambda m: m.is_entry() and not m.tax_cash_basis_origin_move_id) tax_container, invoice_container, misc_container = ({} for __ in range(3)) update_containers() @@ -3672,6 +3672,9 @@ class AccountMove(models.Model): def is_invoice(self, include_receipts=False): return self.is_sale_document(include_receipts) or self.is_purchase_document(include_receipts) + def is_entry(self): + return self.move_type == 'entry' + @api.model def get_sale_types(self, include_receipts=False): return ['out_invoice', 'out_refund'] + (include_receipts and ['out_receipt'] or []) diff --git a/addons/account/models/account_payment_method.py b/addons/account/models/account_payment_method.py index 1a5126ef606..89e8a73aa46 100644 --- a/addons/account/models/account_payment_method.py +++ b/addons/account/models/account_payment_method.py @@ -119,6 +119,11 @@ class AccountPaymentMethodLine(models.Model): company_id = fields.Many2one(related='journal_id.company_id') available_payment_method_ids = fields.Many2many(related='journal_id.available_payment_method_ids') + def name_get(self): + if self.env.context.get('show_payment_journal_id'): + return [(method.id, "%s (%s)" % (method.name, method.journal_id.name)) for method in self] + return super().name_get() + @api.depends('payment_method_id.name') def _compute_name(self): for method in self: diff --git a/addons/account/views/account_payment_method.xml b/addons/account/views/account_payment_method.xml new file mode 100644 index 00000000000..089ad49b718 --- /dev/null +++ b/addons/account/views/account_payment_method.xml @@ -0,0 +1,15 @@ + + + + + account.payment.method.line.tree + account.payment.method.line + + + + + + + + + diff --git a/addons/account/views/account_payment_view.xml b/addons/account/views/account_payment_view.xml index 38704aadb77..db8d26da13e 100644 --- a/addons/account/views/account_payment_view.xml +++ b/addons/account/views/account_payment_view.xml @@ -227,7 +227,9 @@ -