Skip to content
Permalink
Browse files

[ADD] account: add ocr to customer invoices

Task 1942983
Accounting firms need to upload PDF of customer invoices and refunds (not only vendor bills).
  • Loading branch information...
william-andre committed Mar 6, 2019
1 parent 83abca9 commit 9e750291c38c432da6f34b415b859dacc973bc4f
@@ -70,7 +70,7 @@ def _check_user_type_id(self):
result = self.read_group([('user_type_id', '=', data_unaffected_earnings.id)], ['company_id'], ['company_id'])
for res in result:
if res.get('company_id_count', 0) >= 2:
account_unaffected_earnings = self.search([('company_id', '=', res['company_id'][0]),
account_unaffected_earnings = self.search([('company_id', '=', res['company_id'][0]),
('user_type_id', '=', data_unaffected_earnings.id)])
raise ValidationError(_('You cannot have more than one account with "Current Year Earnings" as type. (accounts: %s)') % [a.code for a in account_unaffected_earnings])

@@ -474,10 +474,10 @@ def _get_bank_statements_available_sources(self):
bank_id = fields.Many2one('res.bank', related='bank_account_id.bank_id', readonly=False)
post_at_bank_rec = fields.Boolean(string="Post At Bank Reconciliation", help="Whether or not the payments made in this journal should be generated in draft state, so that the related journal entries are only posted when performing bank reconciliation.")

# alias configuration for 'purchase' type journals
# alias configuration for journals
alias_id = fields.Many2one('mail.alias', string='Alias', copy=False)
alias_domain = fields.Char('Alias domain', compute='_compute_alias_domain', default=lambda self: self.env["ir.config_parameter"].sudo().get_param("mail.catchall.domain"))
alias_name = fields.Char('Alias Name for Vendor Bills', related='alias_id.alias_name', help="It creates draft vendor bill by sending an email.", readonly=False)
alias_name = fields.Char('Alias Name', related='alias_id.alias_name', help="It creates draft invoices and bills by sending an email.", readonly=False)

_sql_constraints = [
('code_company_uniq', 'unique (code, name, company_id)', 'The code and name of the journal must be unique per company !'),
@@ -8,10 +8,11 @@ class ImportInvoiceImportWizard(models.TransientModel):
_description = 'Import Your Vendor Bills from Files.'

def _get_default_journal_id(self):
return self.env['account.journal'].search([('type', '=', 'purchase')], limit=1)
type = self.env.context.get('type') == 'out_invoice' and 'sale' or 'purchase'
return self.env['account.journal'].search([('type', '=', type)], limit=1)

attachment_ids = fields.Many2many('ir.attachment', string='Files')
journal_id = fields.Many2one(string="Journal", comodel_name="account.journal", required=True, domain="[('type', '=', 'purchase')]", default=_get_default_journal_id, help="Journal where to generate the bills")
journal_id = fields.Many2one(string="Journal", comodel_name="account.journal", required=True, domain="[('type', 'in', ('sale', 'purchase'))]", default=_get_default_journal_id, help="Journal where to generate the bills")

@api.multi
def _create_invoice_from_file(self, attachment):
@@ -22,7 +22,6 @@ odoo.define('account.bills.tree', function (require) {
this.$buttons.on('click', '.o_button_upload_bill', function () {
var state = self.model.get(self.handle, {raw: true});
var context = state.getContext()
context['type'] = 'in_invoice'
self.do_action({
type: 'ir.actions.act_window',
res_model: 'account.invoice.import.wizard',
@@ -41,5 +40,5 @@ odoo.define('account.bills.tree', function (require) {
}),
});

viewRegistry.add('account_bills_tree', BillsListView);
viewRegistry.add('account_tree', BillsListView);
});
@@ -153,7 +153,7 @@
<field name="name">account.invoice.tree</field>
<field name="model">account.invoice</field>
<field name="arch" type="xml">
<tree decoration-info="state == 'draft'" decoration-muted="state == 'cancel'" string="Invoice">
<tree decoration-info="state == 'draft'" decoration-muted="state == 'cancel'" string="Invoice" js_class="account_tree">
<field name="partner_id" groups="base.group_user" string="Customer"/>
<field name="date_invoice"/>
<field name="number"/>
@@ -233,7 +233,7 @@
<field name="name">account.invoice.supplier.tree</field>
<field name="model">account.invoice</field>
<field name="arch" type="xml">
<tree decoration-info="state == 'draft'" decoration-muted="state == 'cancel'" decoration-bf="not partner_id" string="Vendor Bill" js_class="account_bills_tree">
<tree decoration-info="state == 'draft'" decoration-muted="state == 'cancel'" decoration-bf="not partner_id" string="Vendor Bill" js_class="account_tree">
<field name="partner_id" invisible="1"/>
<field name="source_email" invisible="1"/>
<field name="invoice_icon" string=" "/>
@@ -631,6 +631,7 @@
</page>
</notebook>
</sheet>
<div class="o_attachment_preview" attrs="{'invisible': ['|',('type', '!=', 'out_invoice'),('state', '!=', 'draft')]}" />
<div class="oe_chatter">
<field name="message_follower_ids" widget="mail_followers" groups="base.group_user"/>
<field name="activity_ids" widget="mail_activity"/>
@@ -276,6 +276,9 @@
<button type="object" name="action_create_new" class="btn btn-primary o_invoice_new">
<span>New Invoice</span>
</button>
<button type="action" name="%(account_invoice_import_wizard_action)d" class="btn btn-primary">
<span>Import Invoices</span>
</button>
</t>
<t t-if="journal_type == 'purchase'">
<button type="object" name="action_create_new" class="btn btn-primary">
@@ -250,13 +250,13 @@
<field name="inbound_payment_method_ids" widget="many2many_checkboxes"/>
<field name="outbound_payment_method_ids" widget="many2many_checkboxes"/>
</group>
<group string="Accounting App Options">
<group string="Accounting App Options" attrs="{'invisible': [('type', 'not in', ['bank', 'cash', 'sale', 'purchase'])]}">
<field name="profit_account_id" attrs="{'invisible': [('type', '!=', 'cash')]}"/>
<field name="loss_account_id" attrs="{'invisible': [('type', '!=', 'cash')]}"/>
<field name="group_invoice_lines" attrs="{'invisible': [('type', 'not in', ['sale', 'purchase'])]}"/>
<field name="post_at_bank_rec" attrs="{'invisible': [('type', 'not in', ['bank', 'cash'])]}"/>
</group>
<group name="group_alias" string="Email your Vendor Bills" attrs="{'invisible': [('type', '!=', 'purchase')]}">
<group name="group_alias" string="Email your Invoices/Bills" attrs="{'invisible': [('type', 'not in', ('sale' ,'purchase'))]}">
<label string="Email Alias" attrs="{'invisible': [('alias_domain', '=', False)]}" for="alias_id"/>
<div name="alias_def" attrs="{'invisible': [('alias_domain', '=', False)]}">
<field name="alias_id" class="oe_read_only oe_inline"/>
@@ -762,7 +762,7 @@
<div class="oe_button_box" name="button_box">
<button type="object" name="action_reconcile_stat"
class="oe_stat_button" icon="fa-book">
<field name="number_entries" string="Journal Entries" widget="statinfo"/>
<field name="number_entries" string="Journal Entries" widget="statinfo"/>
</button>
</div>
<div class="oe_title">
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
{
'name' : 'Import Vendor Bills From XML',
'name' : 'Import Bills/Invoices From XML',
'version' : '1.0',
'category': 'Accounting',
'depends' : ['account'],
@@ -138,7 +138,7 @@
<!-- Partners. -->
<ram:ApplicableHeaderTradeAgreement>
<!-- Seller. -->
<ram:SellerTradeParty>
<ram:SellerTradeParty t-if="record.type in ('out_invoice', 'out_refund')">
<!-- Address. -->
<t t-call="account_facturx.account_invoice_partner_facturx_export">
<t t-set="partner" t-value="record.company_id.partner_id"/>
@@ -149,9 +149,20 @@
<ram:ID schemeID="VA" t-esc="record.company_id.vat"/>
</ram:SpecifiedTaxRegistration>
</ram:SellerTradeParty>
<ram:SellerTradeParty t-else="">
<!-- Address. -->
<t t-call="account_facturx.account_invoice_partner_facturx_export">
<t t-set="partner" t-value="record.commercial_partner_id"/>
</t>

<!-- VAT. -->
<ram:SpecifiedTaxRegistration t-if="record.commercial_partner_id.vat">
<ram:ID schemeID="VA" t-esc="record.commercial_partner_id.vat"/>
</ram:SpecifiedTaxRegistration>
</ram:SellerTradeParty>

<!-- Customer. -->
<ram:BuyerTradeParty>
<ram:BuyerTradeParty t-if="record.type in ('out_invoice', 'out_refund')">
<!-- Address. -->
<t t-call="account_facturx.account_invoice_partner_facturx_export">
<t t-set="partner" t-value="record.commercial_partner_id"/>
@@ -162,6 +173,17 @@
<ram:ID schemeID="VA" t-esc="record.commercial_partner_id.vat"/>
</ram:SpecifiedTaxRegistration>
</ram:BuyerTradeParty>
<ram:BuyerTradeParty t-else="">
<!-- Address. -->
<t t-call="account_facturx.account_invoice_partner_facturx_export">
<t t-set="partner" t-value="record.company_id.partner_id"/>
</t>

<!-- VAT. -->
<ram:SpecifiedTaxRegistration t-if="record.company_id.vat">
<ram:ID schemeID="VA" t-esc="record.company_id.vat"/>
</ram:SpecifiedTaxRegistration>
</ram:BuyerTradeParty>

<!-- Reference. -->
<ram:BuyerOrderReferencedDocument>
@@ -15,7 +15,7 @@ def _post_pdf(self, save_in_attachment, pdf_content=None, res_ids=None):
# OVERRIDE
if self.model == 'account.invoice' and res_ids and len(res_ids) == 1:
invoice = self.env['account.invoice'].browse(res_ids)
if invoice.type in ('out_invoice', 'out_refund') and invoice.state != 'draft':
if invoice.state != 'draft':
xml_content = invoice._export_as_facturx_xml()

# Add attachment.

0 comments on commit 9e75029

Please sign in to comment.
You can’t perform that action at this time.