summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwan <wan@odoo.com>2019-09-18 08:41:27 +0000
committerwan <wan@odoo.com>2019-09-18 14:07:38 +0000
commitebbc9accae34d114550d01c64cfadec746434e65 (patch)
tree7f73f927bd46a1a3488e42be455fa126006e6c89
parent5b3509daaabfed3f73feab4c749e38bed75fe077 (diff)
[FIX] account_facturx: posting a pdf on draft move
When a draft move is created and saved, we cannot post a pdf on it anymore because facturx expects a default journal entry type to be in the context in _import_facturx_invoice. In this case, it is not in the context anymore because it has already been saved on the account.move on which we try to post the pdf. closes odoo/odoo#37055 Signed-off-by: Quentin De Paoli (qdp) <qdp@openerp.com>
-rw-r--r--addons/account_facturx/models/account_move.py18
1 files changed, 15 insertions, 3 deletions
diff --git a/addons/account_facturx/models/account_move.py b/addons/account_facturx/models/account_move.py
index 548953beff1..757164370b4 100644
--- a/addons/account_facturx/models/account_move.py
+++ b/addons/account_facturx/models/account_move.py
@@ -54,13 +54,21 @@ class AccountMove(models.Model):
'''
amount_total_import = None
+ default_type = False
if self._context.get('default_journal_id'):
journal = self.env['account.journal'].browse(self.env.context['default_journal_id'])
default_type = 'out_invoice' if journal.type == 'sale' else 'in_invoice'
elif self._context.get('default_type'):
default_type = self._context['default_type']
- else:
+ elif self.type in self.env['account.move'].get_invoice_types(include_receipts=True):
+ # in case an attachment is saved on a draft invoice previously created, we might
+ # have lost the default value in context but the type was already set
+ default_type = self.type
+
+ if not default_type:
raise UserError(_("No information about the journal or the type of invoice is passed"))
+ if default_type == 'entry':
+ return
# Total amount.
elements = tree.xpath('//ram:GrandTotalAmount', namespaces=tree.nsmap)
@@ -74,6 +82,7 @@ class AccountMove(models.Model):
elements = tree.xpath('//rsm:ExchangedDocument/ram:TypeCode', namespaces=tree.nsmap)
type_code = elements[0].text
+ default_type.replace('_refund', '_invoice')
if type_code == '381':
default_type = 'out_refund' if default_type == 'out_invoice' else 'in_refund'
refund_sign = -1
@@ -221,7 +230,10 @@ class AccountMove(models.Model):
# /!\ 'default_res_id' in self._context is used to don't process attachment when using a form view.
res = super(AccountMove, self).message_post(**kwargs)
- if 'no_new_invoice' not in self.env.context and len(self) == 1 and self.state == 'draft':
+ if not self.env.context.get('no_new_invoice') and len(self) == 1 and self.state == 'draft' and (
+ self.env.context.get('default_type', self.type) in self.env['account.move'].get_invoice_types(include_receipts=True)
+ or self.env['account.journal'].browse(self.env.context.get('default_journal_id')).type in ('sale', 'purchase')
+ ):
for attachment in self.env['ir.attachment'].browse(kwargs.get('attachment_ids', [])):
self._create_invoice_from_attachment(attachment)
return res
@@ -317,4 +329,4 @@ class AccountMove(models.Model):
raise UserError(_('No decoder was found for the xml file: {}. The file is badly formatted, not supported or the decoder is not installed').format(attachment.name))
def _remove_ocr_option(self):
- self.write({'extract_state': 'done'}) \ No newline at end of file
+ self.write({'extract_state': 'done'})