summaryrefslogtreecommitdiff
path: root/addons/account_edi_ubl
diff options
context:
space:
mode:
authorBenjamin Frantzen (bfr) <bfr@odoo.com>2021-04-02 12:38:56 +0000
committerBenjamin Frantzen (bfr) <bfr@odoo.com>2021-04-09 10:14:02 +0000
commitbd91f1bc1a9d8eab20847ef95c08bfd6ed225d11 (patch)
tree93b55ae540abeda2609c1deee0e35be87f2f42da /addons/account_edi_ubl
parent530c5a6412198c1eab1f0314bbd18d0496614478 (diff)
[FIX] account_edi_ubl: remove wrong move creation when importing xml
The move was created before its type was determined and the type was ignored. This could cause an issue when this method was called directly if 'default_move_type' was not set in the context (the move would therefore be an entry). Thankfully, this shadowed another bug: when determining the type of the invoice, the context was ignored, and therefore if the file was imported as an invoice, the type determined was 'in_invoice' instead of 'out_invoice', this didn't cause any problem since the type was ignored. This commit fixes that also. closes odoo/odoo#68702 Signed-off-by: Laurent Smet <smetl@users.noreply.github.com>
Diffstat (limited to 'addons/account_edi_ubl')
-rw-r--r--addons/account_edi_ubl/models/account_edi_format.py29
1 files changed, 17 insertions, 12 deletions
diff --git a/addons/account_edi_ubl/models/account_edi_format.py b/addons/account_edi_ubl/models/account_edi_format.py
index da75818f58a..d1f2cb17bf5 100644
--- a/addons/account_edi_ubl/models/account_edi_format.py
+++ b/addons/account_edi_ubl/models/account_edi_format.py
@@ -16,6 +16,22 @@ _logger = logging.getLogger(__name__)
class AccountEdiFormat(models.Model):
_inherit = 'account.edi.format'
+ def _create_invoice_from_ubl(self, tree):
+ invoice = self.env['account.move']
+ journal = invoice._get_default_journal()
+
+ move_type = 'out_invoice' if journal.type == 'sale' else 'in_invoice'
+ element = tree.find('.//{*}InvoiceTypeCode')
+ if element is not None and element.text == '381':
+ move_type = 'in_refund' if move_type == 'in_invoice' else 'out_refund'
+
+ invoice = invoice.with_context(default_move_type=move_type, default_journal_id=journal.id)
+ return self._import_ubl(tree, invoice)
+
+ def _update_invoice_from_ubl(self, tree, invoice):
+ invoice = invoice.with_context(default_move_type=invoice.move_type, default_journal_id=invoice.journal_id.id)
+ return self._import_ubl(tree, invoice)
+
def _import_ubl(self, tree, invoice):
""" Decodes an UBL invoice into an invoice.
@@ -37,20 +53,9 @@ class AccountEdiFormat(models.Model):
return namespaces
namespaces = _get_ubl_namespaces()
- if not invoice:
- invoice = self.env['account.move'].create({})
-
- elements = tree.xpath('//cbc:InvoiceTypeCode', namespaces=namespaces)
- if elements:
- type_code = elements[0].text
- move_type = 'in_refund' if type_code == '381' else 'in_invoice'
- else:
- move_type = 'in_invoice'
- default_journal = invoice.with_context(default_move_type=move_type)._get_default_journal()
+ with Form(invoice.with_context(account_predictive_bills_disable_prediction=True)) as invoice_form:
- with Form(invoice.with_context(default_move_type=move_type, default_journal_id=default_journal.id,
- account_predictive_bills_disable_prediction=True)) as invoice_form:
# Reference
elements = tree.xpath('//cbc:ID', namespaces=namespaces)
if elements: