Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/import to existing invoice upstream #141

Open
wants to merge 3 commits into
base: 8.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion nfe_import/models/nfe_import_edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,30 @@ def confirm_values(self):
def save_invoice_values(self, inv_values):
self.ensure_one()

existing_invoice = self.env['account.invoice'].search([
('company_id', '=', inv_values['company_id']),
('nfe_access_key', '=', inv_values['nfe_access_key']),
])

if existing_invoice and not self.account_invoice_id:
self.account_invoice_id = existing_invoice.ensure_one()

if self.account_invoice_id:
selected_nfe_key = self.account_invoice_id.nfe_access_key
if existing_invoice:
existing_key = existing_invoice.nfe_access_key
if selected_nfe_key and selected_nfe_key != existing_key:
raise UserError(
'Existe NFe cadastrada na empresa com a chave de ' +
'acesso que consta no XML fornecedido. Esta chave ' +
'difere da chave de acesso da NFe a ser vinculada.')
else:
if (selected_nfe_key and
selected_nfe_key != inv_values['nfe_access_key']):
raise UserError(
'A NFe a ser vinculada possui chave de acesso ' +
'diferente da que consta no XML fornecido.')

vals = {
'vendor_serie': inv_values['vendor_serie'],
'fiscal_document_id': inv_values['fiscal_document_id'],
Expand Down Expand Up @@ -290,11 +313,12 @@ def create_stock_picking(self, invoice):
'origin': 'Fatura: %s-%s' % (invoice.internal_number,
invoice.vendor_serie),
'partner_id': invoice.partner_id.id,
'invoice_state': 'none',
'invoice_state': 'invoiced',
'fiscal_category_id': invoice.fiscal_category_id.id,
'fiscal_position': invoice.fiscal_position.id,
'picking_type_id': picking_type_id.id,
'move_lines': [],
'invoice_ids': [(4, invoice.id)],
}
for line in invoice.invoice_line:
move_vals = {
Expand Down
3 changes: 3 additions & 0 deletions nfe_import/service/nfe_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from datetime import datetime
from decimal import Decimal

from openerp import tools
from openerp.tools.translate import _
from openerp.exceptions import Warning as UserError

Expand Down Expand Up @@ -133,6 +134,8 @@ def _get_nfe_identification(self):
res['ind_final'] = self.nfe.infNFe.ide.indFinal.valor
res['ind_pres'] = self.nfe.infNFe.ide.indPres.valor
res['date_hour_invoice'] = self.nfe.infNFe.ide.dhEmi.valor
res['date_invoice'] = res['date_hour_invoice'].strftime(
tools.DEFAULT_SERVER_DATE_FORMAT)
res['nfe_version'] = '3.10'
res['type'] = 'in_invoice' # Fixo por hora - apenas nota de entrada
return res
Expand Down