[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
This commit is contained in:
@@ -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',
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -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>
|
||||
@@ -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')]"
|
||||
|
||||
@@ -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">
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user