summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurent Smet <las@openerp.com>2018-08-14 14:55:51 +0200
committerqdp-odoo <qdp@odoo.com>2018-08-14 16:40:39 +0200
commitc99eb1b8fb48eef80300aae90c08b54d28e093a7 (patch)
treeb82b04197f5e2b0e6e273f68da6cca4e1132e433
parent1ab2a4d47d5eaff7811e205468732f43637b39bc (diff)
[ADD] account: import vendor bills files from dashboard
This adds a button to import several bills from the accounting dashboard: will create a new vendor bill for each, with the file attached to it. That file will be visible in the chatter (in enterprise) and allow easilly completion/encoding of it. This task also comes along with the import/export of xml files attached to the PDF files created from the invoice report. Was task 1859277 Was PR #26339
-rw-r--r--addons/account/__manifest__.py1
-rw-r--r--addons/account/models/__init__.py1
-rw-r--r--addons/account/models/account_invoice_import_wizard.py43
-rw-r--r--addons/account/views/account_invoice_import_wizard_view.xml29
-rw-r--r--addons/account/views/account_invoice_view.xml2
-rw-r--r--addons/account/views/account_journal_dashboard_view.xml3
-rw-r--r--addons/web/static/src/js/fields/relational_fields.js7
7 files changed, 84 insertions, 2 deletions
diff --git a/addons/account/__manifest__.py b/addons/account/__manifest__.py
index e79c388f6f3..a7af38a3f6f 100644
--- a/addons/account/__manifest__.py
+++ b/addons/account/__manifest__.py
@@ -61,6 +61,7 @@ You could use this simplified accounting in case you work with an (external) acc
'views/tax_adjustments.xml',
'wizard/wizard_tax_adjustments_view.xml',
'views/res_config_settings_views.xml',
+ 'views/account_invoice_import_wizard_view.xml',
'views/account_journal_dashboard_view.xml',
'views/account_portal_templates.xml',
'report/account_report_payment_receipt_templates.xml',
diff --git a/addons/account/models/__init__.py b/addons/account/models/__init__.py
index 50b2b4adcf0..b6459570b8e 100644
--- a/addons/account/models/__init__.py
+++ b/addons/account/models/__init__.py
@@ -18,3 +18,4 @@ from . import reconciliation_widget
from . import res_users
from . import account_incoterms
from . import digest
+from . import account_invoice_import_wizard
diff --git a/addons/account/models/account_invoice_import_wizard.py b/addons/account/models/account_invoice_import_wizard.py
new file mode 100644
index 00000000000..936d0d30904
--- /dev/null
+++ b/addons/account/models/account_invoice_import_wizard.py
@@ -0,0 +1,43 @@
+# -*- coding: utf-8 -*-
+from odoo import api, fields, models, _
+from odoo.tests.common import Form
+
+
+class ImportInvoiceImportWizard(models.TransientModel):
+ _name = 'account.invoice.import.wizard'
+ _description = 'Import Your Vendor Bills from Files.'
+
+ attachment_ids = fields.Many2many('ir.attachment', string='Files')
+
+ @api.multi
+ def _create_invoice_from_file(self, attachment):
+ invoice_form = Form(self.env['account.invoice'], view='account.invoice_supplier_form')
+ invoice = invoice_form.save()
+ invoice.message_post(attachment_ids=[attachment.id])
+ return invoice
+
+ @api.multi
+ def create_invoices(self):
+ ''' Create the invoices from files.
+ :return: A action redirecting to account.invoice tree/form view.
+ '''
+ if not self.attachment_ids:
+ return
+
+ invoices = self.env['account.invoice']
+ for attachment in self.attachment_ids:
+ invoices += self._create_invoice_from_file(attachment)
+
+ action_vals = {
+ 'name': _('Invoices'),
+ 'domain': [('id', 'in', invoices.ids)],
+ 'view_type': 'form',
+ 'res_model': 'account.invoice',
+ 'view_id': False,
+ 'type': 'ir.actions.act_window',
+ }
+ if len(invoices) == 1:
+ action_vals.update({'res_id': invoices[0].id, 'view_mode': 'form'})
+ else:
+ action_vals['view_mode'] = 'tree,form'
+ return action_vals
diff --git a/addons/account/views/account_invoice_import_wizard_view.xml b/addons/account/views/account_invoice_import_wizard_view.xml
new file mode 100644
index 00000000000..51fb53cf013
--- /dev/null
+++ b/addons/account/views/account_invoice_import_wizard_view.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8"?>
+<odoo>
+ <data>
+ <record id="account_invoice_import_wizard_form_view" model="ir.ui.view">
+ <field name="name">account.invoice.import.wizard.form</field>
+ <field name="model">account.invoice.import.wizard</field>
+ <field name="arch" type="xml">
+ <form>
+ <group>
+ <field name="attachment_ids" widget="many2many_binary" colspan="2"
+ string="Upload Files" nolabel="1"/>
+ </group>
+ <footer>
+ <button string="Import" name="create_invoices" type="object" class="oe_highlight"/>
+ <button string="Cancel" class="btn btn-default" special="cancel"/>
+ </footer>
+ </form>
+ </field>
+ </record>
+
+ <record id="account_invoice_import_wizard_action" model="ir.actions.act_window">
+ <field name="name">Import Vendor Bills</field>
+ <field name="res_model">account.invoice.import.wizard</field>
+ <field name="view_mode">form</field>
+ <field name="target">new</field>
+ <field name="context">{'type': 'in_invoice', 'journal_id': active_id}</field>
+ </record>
+ </data>
+</odoo>
diff --git a/addons/account/views/account_invoice_view.xml b/addons/account/views/account_invoice_view.xml
index 0aabfbb7ae6..28a1028546e 100644
--- a/addons/account/views/account_invoice_view.xml
+++ b/addons/account/views/account_invoice_view.xml
@@ -284,7 +284,7 @@
<group>
<field string="Vendor" name="partner_id"
context="{'default_customer': 0, 'search_default_supplier': 1, 'default_supplier': 1, 'default_company_type': 'company'}"
- domain="[('supplier', '=', True)]" required="1"/>
+ domain="[('supplier', '=', True)]"/>
<field name="reference" string="Vendor Reference"/>
<field name="vendor_bill_id" attrs="{'invisible': [('state','not in',['draft'])]}"
domain="[('partner_id','child_of', [partner_id]), ('state','in',('open','paid')), ('type','=','in_invoice')]"
diff --git a/addons/account/views/account_journal_dashboard_view.xml b/addons/account/views/account_journal_dashboard_view.xml
index 24f1fe4468e..5ae40689e8d 100644
--- a/addons/account/views/account_journal_dashboard_view.xml
+++ b/addons/account/views/account_journal_dashboard_view.xml
@@ -271,6 +271,9 @@
<button type="object" name="action_create_new" class="btn btn-primary">
<span>New Bill</span>
</button>
+ <button type="action" name="%(account_invoice_import_wizard_action)d" class="btn btn-primary">
+ <span>Import Bills</span>
+ </button>
</t>
</div>
<div class="col-7 o_kanban_primary_right">
diff --git a/addons/web/static/src/js/fields/relational_fields.js b/addons/web/static/src/js/fields/relational_fields.js
index b8eb106caab..692d27e0ca8 100644
--- a/addons/web/static/src/js/fields/relational_fields.js
+++ b/addons/web/static/src/js/fields/relational_fields.js
@@ -1475,6 +1475,7 @@ var FieldMany2Many = FieldX2Many.extend({
*/
var FieldMany2ManyBinaryMultiFiles = AbstractField.extend({
template: "FieldBinaryFileUploader",
+ template_files: "FieldBinaryFileUploader.files",
supportedFieldTypes: ['many2many'],
fieldsToFetch: {
name: {type: 'char'},
@@ -1549,7 +1550,7 @@ var FieldMany2ManyBinaryMultiFiles = AbstractField.extend({
// _setValue, we put the rendering here to ensure they will be updated
this._generatedMetadata();
this.$('.oe_placeholder_files, .oe_attachments')
- .replaceWith($(qweb.render('FieldBinaryFileUploader.files', {
+ .replaceWith($(qweb.render(this.template_files, {
widget: this,
})));
this.$('.oe_fileupload').show();
@@ -1611,6 +1612,10 @@ var FieldMany2ManyBinaryMultiFiles = AbstractField.extend({
var files = ev.target.files;
var attachment_ids = this.value.res_ids;
+ // Don't create an attachment if the upload window is cancelled.
+ if(files.length == 0)
+ return;
+
_.each(files, function (file) {
var record = _.find(self.value.data, function (attachment) {
return attachment.data.name === file.name;