diff options
| author | Thomas Carlier <thc@odoo.com> | 2019-09-17 08:53:31 +0000 |
|---|---|---|
| committer | Thomas Carlier <thc@odoo.com> | 2020-01-28 14:41:37 +0000 |
| commit | 4eeeb4f172c10f2a8e190fb9afcf440ddaaf5d34 (patch) | |
| tree | 5ccb655f73dbcf69d576278a49f6ed48380e0250 /addons/hr_expense/models | |
| parent | b5d608036654189a1d233236d3b1f1319c92e0e2 (diff) | |
[ADD] hr_expense : add the ability to install OCR module
- if checked in settings, OCR can be used to get infos from the attached receipt image
- set default product to EXP_GEN when created from picture
- use "register_as_main attachment" when expenses are created from receipt images
- Add the upload button to the kanban view to see it immediately in the mobile version
and use it to create expenses from pictures. (with or without OCR installed)
closes odoo/odoo#39559
Related: odoo/enterprise#6493
Signed-off-by: Florian Daloze (fda) <fda@odoo.com>
Diffstat (limited to 'addons/hr_expense/models')
| -rw-r--r-- | addons/hr_expense/models/__init__.py | 1 | ||||
| -rw-r--r-- | addons/hr_expense/models/hr_expense.py | 12 | ||||
| -rw-r--r-- | addons/hr_expense/models/res_company.py | 14 | ||||
| -rw-r--r-- | addons/hr_expense/models/res_config_settings.py | 4 |
4 files changed, 28 insertions, 3 deletions
diff --git a/addons/hr_expense/models/__init__.py b/addons/hr_expense/models/__init__.py index af1e04d2dd2..4b256421e3b 100644 --- a/addons/hr_expense/models/__init__.py +++ b/addons/hr_expense/models/__init__.py @@ -7,3 +7,4 @@ from . import hr_expense from . import product_template from . import res_config_settings from . import account_journal_dashboard +from . import res_company diff --git a/addons/hr_expense/models/hr_expense.py b/addons/hr_expense/models/hr_expense.py index f2037823216..07fa8835927 100644 --- a/addons/hr_expense/models/hr_expense.py +++ b/addons/hr_expense/models/hr_expense.py @@ -181,15 +181,21 @@ class HrExpense(models.Model): if any(attachment.res_id or attachment.res_model != 'hr.expense' for attachment in attachments): raise UserError(_("Invalid attachments!")) + product = self.env['product.product'].search([('default_code', '=', 'EXP_GEN')]) + for attachment in attachments: expense = self.env['hr.expense'].create({ 'name': attachment.name.split('.')[0], 'unit_amount': 0, + 'product_id': product.id + }) + expense.message_post(body=_('Uploaded Attachment')) + attachment.write({ + 'res_model': 'hr.expense', + 'res_id': expense.id, }) - attachment.write({'res_id': expense.id}) - expense.message_post(body=_('Uploaded Attachment'), attachment_ids=[attachment.id]) + attachment.register_as_main_attachment() expenses += expense - if len(expenses) == 1: return { 'name': _('Generated Expense'), diff --git a/addons/hr_expense/models/res_company.py b/addons/hr_expense/models/res_company.py new file mode 100644 index 00000000000..7c2549f47bf --- /dev/null +++ b/addons/hr_expense/models/res_company.py @@ -0,0 +1,14 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import fields, models + + +class ResCompany(models.Model): + _inherit = 'res.company' + + expense_extract_show_ocr_option_selection = fields.Selection([ + ('no_send', 'Do not digitalize bills'), + ('manual_send', "Digitalize bills on demand only"), + ('auto_send', 'Digitalize all bills automatically')], string="Send mode on expense attachments", + required=True, default='auto_send') diff --git a/addons/hr_expense/models/res_config_settings.py b/addons/hr_expense/models/res_config_settings.py index 1dfe455cad9..17d290531fb 100644 --- a/addons/hr_expense/models/res_config_settings.py +++ b/addons/hr_expense/models/res_config_settings.py @@ -11,6 +11,10 @@ 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_extract_show_ocr_option_selection = fields.Selection(related='company_id.expense_extract_show_ocr_option_selection', + string='Expense processing option', readonly=False) + @api.model def get_values(self): |
