From 41d56e2e98aa7eb930e236c5fad94a4bf8e8bd0f Mon Sep 17 00:00:00 2001 From: Yosua Nicolaus Date: Fri, 7 Jul 2023 13:37:00 +0000 Subject: [PATCH] [IMP] expense: default expense category on scan MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Description of the issue/feature this PR addresses: - Expenses are automatically created when uploading or scanning receipts. This is a feature often used by employees who have a lot of tickets and upload them in batch. The expenses created have a random category (product_id) specified. Companies may however want to specify the default category for accounting or management purposes. They are currently unable to do so. Current behavior before PR: - Companies can't specify default category for scanned/uploaded expenses Desired behavior after PR is merged: - In the Expenses setting, combine the "Default Journals" and "Payment" block into one and name the new block "Accounting" - Add new setting in Expenses for specifying default category for scanned/uploaded expenses - If that setting is set, use the value inside it for the category field of new scanned/uploaded expenses closes odoo/odoo#124205 Task-id: 3354763 Signed-off-by: Quentin De Paoli --- addons/hr_expense/models/hr_expense.py | 2 +- addons/hr_expense/models/res_company.py | 6 ++++++ addons/hr_expense/models/res_config_settings.py | 1 + addons/hr_expense/views/res_config_settings_views.xml | 7 ++++--- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/addons/hr_expense/models/hr_expense.py b/addons/hr_expense/models/hr_expense.py index 747a49dbf0a..392c560cba3 100644 --- a/addons/hr_expense/models/hr_expense.py +++ b/addons/hr_expense/models/hr_expense.py @@ -389,7 +389,7 @@ class HrExpense(models.Model): vals = { 'name': attachment_name, 'unit_amount': 0, - 'product_id': product.id, + 'product_id': self.env.company.expense_product_id.id or product.id, } if product.property_account_expense_id: vals['account_id'] = product.property_account_expense_id.id diff --git a/addons/hr_expense/models/res_company.py b/addons/hr_expense/models/res_company.py index 0bf97fd58ce..4cf9f410025 100644 --- a/addons/hr_expense/models/res_company.py +++ b/addons/hr_expense/models/res_company.py @@ -6,6 +6,12 @@ from odoo import fields, models class ResCompany(models.Model): _inherit = "res.company" + expense_product_id = fields.Many2one( + "product.product", + string="Default Expense Category", + check_company=True, + domain="[('can_be_expensed', '=', True), '|', ('company_id', '=', False), ('company_id', '=', company_id)]", + ) expense_journal_id = fields.Many2one( "account.journal", string="Default Expense Journal", diff --git a/addons/hr_expense/models/res_config_settings.py b/addons/hr_expense/models/res_config_settings.py index 1769169a574..f59562b0cd4 100644 --- a/addons/hr_expense/models/res_config_settings.py +++ b/addons/hr_expense/models/res_config_settings.py @@ -15,6 +15,7 @@ class ResConfigSettings(models.TransientModel): config_parameter='hr_expense.use_mailgateway') module_hr_payroll_expense = fields.Boolean(string='Reimburse Expenses in Payslip') module_hr_expense_extract = fields.Boolean(string='Send bills to OCR to generate expenses') + expense_product_id = fields.Many2one('product.product', related='company_id.expense_product_id', readonly=False) expense_journal_id = fields.Many2one('account.journal', related='company_id.expense_journal_id', readonly=False) company_expense_allowed_payment_method_line_ids = fields.Many2many( comodel_name='account.payment.method.line', diff --git a/addons/hr_expense/views/res_config_settings_views.xml b/addons/hr_expense/views/res_config_settings_views.xml index 60a4d5e0e81..6cbf64f4cd8 100644 --- a/addons/hr_expense/views/res_config_settings_views.xml +++ b/addons/hr_expense/views/res_config_settings_views.xml @@ -32,13 +32,14 @@ + + + - + - -