[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>
This commit is contained in:
Thomas Carlier
2020-01-28 14:41:37 +00:00
parent b5d6080366
commit 4eeeb4f172
7 changed files with 49 additions and 6 deletions
+1
View File
@@ -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
+9 -3
View File
@@ -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
})
attachment.write({'res_id': expense.id})
expense.message_post(body=_('Uploaded Attachment'), attachment_ids=[attachment.id])
expense.message_post(body=_('Uploaded Attachment'))
attachment.write({
'res_model': 'hr.expense',
'res_id': expense.id,
})
attachment.register_as_main_attachment()
expenses += expense
if len(expenses) == 1:
return {
'name': _('Generated Expense'),
+14
View File
@@ -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')
@@ -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):
@@ -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);
});
+2 -2
View File
@@ -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)]}"/>
@@ -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>