summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorThomas Carlier <thc@odoo.com>2019-09-17 08:53:31 +0000
committerThomas Carlier <thc@odoo.com>2020-01-28 14:41:37 +0000
commit4eeeb4f172c10f2a8e190fb9afcf440ddaaf5d34 (patch)
tree5ccb655f73dbcf69d576278a49f6ed48380e0250 /addons
parentb5d608036654189a1d233236d3b1f1319c92e0e2 (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')
-rw-r--r--addons/hr_expense/models/__init__.py1
-rw-r--r--addons/hr_expense/models/hr_expense.py12
-rw-r--r--addons/hr_expense/models/res_company.py14
-rw-r--r--addons/hr_expense/models/res_config_settings.py4
-rw-r--r--addons/hr_expense/static/src/js/upload_mixin.js5
-rw-r--r--addons/hr_expense/views/hr_expense_views.xml4
-rw-r--r--addons/hr_expense/views/res_config_settings_views.xml15
7 files changed, 49 insertions, 6 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):
diff --git a/addons/hr_expense/static/src/js/upload_mixin.js b/addons/hr_expense/static/src/js/upload_mixin.js
index c94df1c6616..4f6660c8039 100644
--- a/addons/hr_expense/static/src/js/upload_mixin.js
+++ b/addons/hr_expense/static/src/js/upload_mixin.js
@@ -2,6 +2,7 @@ odoo.define('hr_expense.documents.upload.mixin', function (require) {
"use strict";
var core = require('web.core');
+var config = require('web.config');
var _t = core._t;
var qweb = core.qweb;
@@ -43,11 +44,13 @@ var DocumentUploadMixin = {
if (!attachent_ids.length) {
return self.do_notify(_t("Error"), _t("An error occurred during the upload"));
}
+ var myContext = this.initialState.context
+ myContext['isMobile'] = config.device.isMobile
return this._rpc({
model: 'hr.expense',
method: 'create_expense_from_attachments',
args: ["", attachent_ids, this.viewType],
- context: this.initialState.context,
+ context: myContext,
}).then(function(result) {
self.do_action(result);
});
diff --git a/addons/hr_expense/views/hr_expense_views.xml b/addons/hr_expense/views/hr_expense_views.xml
index 3b830ee613c..5393460bdd9 100644
--- a/addons/hr_expense/views/hr_expense_views.xml
+++ b/addons/hr_expense/views/hr_expense_views.xml
@@ -70,8 +70,8 @@
<form string="Expenses" class="o_expense_form">
<header>
<button name="action_submit_expenses" string="Create Report" type="object" class="oe_highlight o_expense_submit" attrs="{'invisible': ['|', ('attachment_number', '&lt;=', 0), ('sheet_id', '!=', False)]}"/>
- <widget name="attach_document" string="Attach Document" action="message_post" attrs="{'invisible': ['|', ('attachment_number', '&lt;', 1), ('id','=',False)]}"/>
- <widget name="attach_document" string="Attach Document" action="message_post" highlight="1" attrs="{'invisible': ['|',('attachment_number', '&gt;=', 1), ('id','=',False)]}"/>
+ <widget name="attach_document" string="Attach Receipt" action="message_post" attrs="{'invisible': ['|', ('attachment_number', '&lt;', 1), ('id','=',False)]}"/>
+ <widget name="attach_document" string="Attach Receipt" action="message_post" highlight="1" attrs="{'invisible': ['|',('attachment_number', '&gt;=', 1), ('id','=',False)]}"/>
<button name="action_submit_expenses" string="Create Report" type="object" class="o_expense_submit" attrs="{'invisible': ['|', ('attachment_number', '&gt;=', 1), ('sheet_id', '!=', False)]}"/>
<field name="state" widget="statusbar" statusbar_visible="draft,reported,approved,done,refused"/>
<button name="action_view_sheet" type="object" string="View Report" class="oe_highlight" attrs="{'invisible': [('sheet_id', '=', False)]}"/>
diff --git a/addons/hr_expense/views/res_config_settings_views.xml b/addons/hr_expense/views/res_config_settings_views.xml
index 84709dd6f78..f85825a87b9 100644
--- a/addons/hr_expense/views/res_config_settings_views.xml
+++ b/addons/hr_expense/views/res_config_settings_views.xml
@@ -48,6 +48,21 @@
</div>
</div>
</div>
+ <div class="col-xs-12 col-md-6 o_setting_box" title="use OCR to fill data from a picture of the bill">
+ <div class="o_setting_left_pane">
+ <field name="module_hr_expense_extract" widget="upgrade_boolean"/>
+ </div>
+ <div class="o_setting_right_pane">
+ <label string="Expense Digitalization (OCR)" for="module_hr_expense_extract"/>
+ <span class="fa fa-lg fa-building-o" title="Values set here are company-specific."/>
+ <div class="text-muted">
+ Digitalize your receipts with OCR and Artificial Intelligence
+ </div>
+ <div class="mt16" attrs="{'invisible': [('module_hr_expense_extract', '=', False)]}">
+ <field name="expense_extract_show_ocr_option_selection" class="o_light_label" widget="radio"/>
+ </div>
+ </div>
+ </div>
</div>
</div>
</xpath>