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 @@ + + + + + account.invoice.import.wizard.form + account.invoice.import.wizard + +
+ + + +
+
+
+
+
+ + + Import Vendor Bills + account.invoice.import.wizard + form + new + {'type': 'in_invoice', 'journal_id': active_id} + +
+
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 @@ + domain="[('supplier', '=', True)]"/> New Bill +
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;