Metadata-Version: 2.1
Name: odoo-addon-l10n_py_edi_sifende
Version: 18.0.1.0.0.1
Requires-Python: >=3.10
Requires-Dist: odoo-addon-l10n_py_edi_base==18.0.*
Requires-Dist: odoo==18.0.*
Requires-Dist: requests
Summary: Electronic invoicing for Paraguay through Sifende
Home-page: https://github.com/OCA/l10n-paraguay
License: LGPL-3
Author: ITH, Odoo Community Association (OCA)
Author-email: support@odoo-community.org
Classifier: Programming Language :: Python
Classifier: Framework :: Odoo
Classifier: Framework :: Odoo :: 18.0
Classifier: License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)
Classifier: Development Status :: 4 - Beta
Description-Content-Type: text/x-rst

================================
Paraguay - Sifende EDI Connector
================================

.. 
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
   !! This file is generated by oca-gen-addon-readme !!
   !! changes will be overwritten.                   !!
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
   !! source digest: sha256:d88c052d15dc18660a604d5488eca4b5ab9a73c2b0efb1451b73170c50b81589
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
    :target: https://odoo-community.org/page/development-status
    :alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png
    :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
    :alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fl10n--paraguay-lightgray.png?logo=github
    :target: https://github.com/OCA/l10n-paraguay/tree/18.0/l10n_py_edi_sifende
    :alt: OCA/l10n-paraguay
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
    :target: https://translation.odoo-community.org/projects/l10n-paraguay-18-0/l10n-paraguay-18-0-l10n_py_edi_sifende
    :alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
    :target: https://runboat.odoo-community.org/builds?repo=OCA/l10n-paraguay&target_branch=18.0
    :alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

`Sifende <https://sifende.com.py>`__ connector for Paraguay electronic
invoicing.

It registers Sifende as a provider in ``l10n_py_edi_base``. Odoo still
numbers the invoices and builds the document data; Sifende signs the
XML, sends it to SIFEN and returns the result and the KuDE. Odoo needs
no certificate, CSC or ``sifen`` library.

Supported documents: invoice (FE), credit note (NCE), debit note (NDE),
delivery note (NRE) and self-invoice (AFE).

Sending is asynchronous. After sending, the document is *Processing*
with its CDC and QR. Sifende notifies Odoo through a webhook when SIFEN
answers, and a cron that polls every 5 minutes acts as a fallback. When
SIFEN approves, the document becomes *Accepted* with the signed XML and
the KuDE attached.

Every hour the cron also polls the accepted documents that are still
within their cancellation window, in case they were cancelled in Sifende
and the notification was lost. Each run polls up to 200 documents per
connector. Documents still waiting for SIFEN or for their files go
first; the accepted documents under watch take the room that is left.
Within each group the ones polled longest ago go first across all
companies, so no company is left without its turn. A poll that does not
change the document's state is not written to the EDI log; failed polls
and state changes are.

**Table of contents**

.. contents::
   :local:

Configuration
=============

1. In Sifende, create an API key for the right environment (Sandbox,
   Test or Production).
2. In *Facturación electrónica > Conectores*, create a connector with
   provider **Sifende**. Only one connector per company is allowed.
3. Choose the connector environment (*Pruebas* or *Producción*), paste
   the API key and, if you use your own Sifende deployment, change the
   base URL (HTTPS; HTTP is only accepted for ``localhost``). Only
   administrators (*Ajustes*) can see and edit the API key and the base
   URL, because the URL decides where the key is sent.
4. Click **Probar Conexión**. It fails if the connector environment does
   not match the API key (``sk_live_`` is *Producción*; ``sk_sandbox_``
   and ``sk_test_`` are *Pruebas*; the match is also checked when saving
   the connector and before sending, cancelling or voiding), and it
   warns when the timbrado, establishment or expedition point used in
   Odoo do not exist in Sifende.
5. Load the same timbrado in Sifende. An expedition point used only by
   Odoo is recommended: Sifende accepts the document number Odoo sends
   and rejects numbers already in use.
6. Optional: in *Inventario > Configuración > Unidades de medida*, set
   the *Código de unidad de medida SIFEN* of each unit (77, unit, by
   default).
7. Optional but recommended: click **Registrar webhook** so that Sifende
   notifies Odoo as soon as SIFEN answers, without waiting for the cron.
   Odoo must be reachable from the Internet over HTTPS, and its base URL
   (``web.base.url``, in *Ajustes > Técnico > Parámetros del sistema*)
   must be the public one: Sifende rejects ``http`` and local addresses.
   The button registers
   ``<web.base.url>/l10n_py_edi_sifende/webhook/<connector id>`` for the
   ``documento.aprobado``, ``documento.rechazado`` and
   ``documento.cancelado`` events and stores the signing secret, visible
   only to administrators. If the URL was already registered in Sifende,
   the button says so and **Rotar secreto** gets a new secret. If the
   webhook no longer exists in Sifende, **Rotar secreto** forgets it and
   warns you: click **Registrar webhook** again. **Quitar webhook**
   deletes it in Sifende. Each notification only triggers a poll of the
   current state in Sifende, so a late notification never overwrites the
   real state. The cron stays active as a fallback.
8. With several databases on the same server, the public URL must
   resolve to the right database (``dbfilter`` or the subdomain),
   because Sifende does not send the database name.
9. Access rights. Each connector is only used from its own company.
   Sending, retrying and cancelling a document require *Contabilidad >
   Facturación* and write access to the document; checking its status
   also works for read-only users. *Inutilizar números* and **Test
   Connection** require *Contabilidad > Administrador*. The API key, the
   base URL and the webhook require *Ajustes*. Delivery note transports,
   with their vehicles and deliveries, belong to the company of their
   document: other companies can neither see nor edit them, and a
   transport without a document yet can only be edited by its creator.

Usage
=====

Labels are quoted as they appear on screen, in Spanish like the rest of
the localization.

1.  Post the invoice and click **Enviar a EDI** (only posted documents
    are sent). The document becomes *Procesando*. Once sent, the payment
    data (payment type, cheque, card, payment condition and due dates)
    and the fiscal data of the *Facturación Electrónica* tab (issuance,
    transaction, presence, receipt ID, contingency, delivery note,
    self-invoice, transport with its vehicles and deliveries, and
    associated documents) can no longer be changed. The same applies
    while a send is waiting for confirmation (see item 3).
2.  The state updates by itself: *Aceptado* with the XML and the KuDE
    attached, or *Rechazado* with the SIFEN messages in *Mensaje EDI*.
    With the webhook registered, Sifende notifies Odoo as soon as SIFEN
    answers; otherwise, or if a notification is lost, the cron «Sifende:
    verificar estado de documentos» does it every 5 minutes.
3.  If the document is *Rechazado* before reaching SIFEN (for example, a
    missing required field), fix the data and click **Reintentar**: it
    uses a new idempotency key. If it ends in *Error* because of a
    connection or Sifende failure before the document was registered
    (the message says so), **Reintentar** reuses the same key and
    nothing is duplicated; meanwhile the document cannot go back to
    draft and its data cannot change, so the retry sends exactly the
    same request. If the *Error* is a final failure sending to SIFEN,
    the document already has its CDC and number: **Reintentar** does not
    reissue it and shows the procedure instead. Retry the batch from the
    Sifende panel or ask support; Odoo polls the document every hour and
    updates it (*Procesando*, then *Aceptado*) when it is processed
    again with the same CDC.
4.  In a credit or debit note, choose the *Motivo de emisión* in the
    *Facturación Electrónica* tab. The associated document is filled
    with the CDC of the original invoice when it has one. In a delivery
    note, also set who is responsible for the issuance and the route
    kilometres.
5.  When a cash invoice or self-invoice is paid by *Cheque* (*Tipo de
    Pago* in the *Facturación Electrónica* tab), fill in the cheque
    number (digits only, up to 8) and the bank (4 to 20 characters):
    Sifende requires them. With a card, the *Marca de la tarjeta* is
    required (*Otra* if it is not listed).
6.  If SIFEN rejects a document that was already sent (*Rechazado* with
    a CDC), Sifende does not accept that number again, not even with the
    same data, and **Reintentar** shows the procedure instead of
    sending. With *Contabilidad > Administrador*, open *Facturación
    Electrónica > Inutilización de números*, create a voiding with the
    timbrado and the number of the rejected document and click **Enviar
    al SIFEN**. Then click **Restablecer a borrador** and **Cancelar**
    on the rejected document and issue a new one, which takes the next
    number. Odoo only allows voiding numbers without a document or of
    rejected documents. If Sifende did not answer, **Enviar al SIFEN**
    reuses the same request: meanwhile the timbrado, the range and the
    reason cannot change. To void a different range, delete the voiding
    and create a new one.
7.  To cancel an accepted document, click **Cancelar EDI**. The
    «Cancelar documento electrónico» wizard asks for the reason (sent to
    SIFEN) and confirms with **Cancelar Documento**. It requires
    *Contabilidad > Facturación* and the window Odoo checks (48 hours
    for invoices and self-invoices, 7 days for notes). Sifende does not
    accept cancellations in SANDBOX: the button is hidden and Odoo warns
    if it is attempted another way.
8.  Once the document is *Aceptado*, **Imprimir** (the button and the
    reports menu) delivers the KuDE generated by Sifende, with the CDC
    and the QR, instead of the standard Odoo PDF. **Enviar** emails the
    KuDE as Sifende delivered it, plus the signed XML (Odoo downloads
    them from Sifende if needed; if Sifende does not have them yet, it
    warns and you can retry). While the document is not *Aceptado*
    (draft, processing, rejected or error), **Enviar** warns that there
    is no fiscal document yet, and **Imprimir** still prints the Odoo
    PDF with a «Sin validez fiscal» notice. If the document was
    *Cancelado*, **Enviar** does not send the KuDE and **Imprimir**
    shows the cancelled notice; the customer portal and the *Imprimir >
    PDF* menu deliver the same, and the original KuDE and XML stay
    stored for archiving. Automatic or batch sending does not email a
    pro-forma of a document that is not *Aceptado* either: it is left
    unsent with the reason in the chatter. Vendor bills and documents of
    other EDI providers keep the standard Odoo behaviour.
9.  In guaraníes, Sifende rounds the total down to a multiple of 50 and
    requires payments and instalments to cover it (the self-invoice
    payment too): the connector spreads the Odoo amounts proportionally
    and the last instalment absorbs the difference.
10. If Sifende answers that the number is already in use, the document
    ends in *Error*. Raise the timbrado *Número Desde* to the next free
    number of the expedition point (see *Numeración* in the Sifende
    panel) and click **Renumerar**: the document takes the next free
    number, never one Sifende already reported, and is sent again with
    **Enviar a EDI**.
11. In a self-invoice, the type and number of the certificate in the
    *Autofactura* section are added as an associated document when
    posting or sending; there is no need to enter them again in
    *Documentos asociados*. Sifende receives only the type; the number
    and the control code stay in Odoo.
12. Every line needs a product: Sifende takes the code and the NCM from
    it. In a delivery note, *Datos de transporte* only offers transports
    without a document or of the same document.
13. The document title, the email subject and the PDF name show the
    fiscal type and number (for example, *Nota de Débito
    001-001-0000101*). Odoo's internal number (*FE 00000027*) is the
    journal's accounting sequence and is not changed.
14. If Sifende answers that some configuration is missing (taxpayer
    data, timbrado or an expired certificate), the document ends in
    *Error*, not *Rechazado*: the message says what to fix in the
    Sifende panel; then click **Reintentar**.
15. If Sifende does not answer when cancelling a document or sending a
    voiding, try again: Odoo reuses the same request and the event is
    not duplicated. *Probar Conexión* warns about inactive expedition
    points, and *Registrar webhook* about a webhook disabled in Sifende.
16. If the partner has no department or no city Sifende recognises,
    invoices and notes are issued without the receiver address, because
    SIFEN rejects an address without a city. The delivery note requires
    it: choose the *Ciudad SIFEN* on the partner.
17. For air transport, each vehicle needs its *Número de vuelo* (6
    characters), shown in the vehicle list when the *Aéreo* mode is
    chosen.

The XML and QR preview is not available: Sifende does not generate
documents without issuing them.

Known issues / Roadmap
======================

This module works around some issues of the localization. Each
workaround can be removed once the issue is fixed upstream:

- The asynchronous provider contract: this module overrides
  ``_process_edi_response`` and runs its own status cron
  (`#97 <https://github.com/OCA/l10n-paraguay/issues/97>`__, see also
  `#33 <https://github.com/OCA/l10n-paraguay/pull/33>`__).
- Receiver ID type and delivery note motive are translated to the SIFEN
  codes here (`#89 <https://github.com/OCA/l10n-paraguay/issues/89>`__,
  `#92 <https://github.com/OCA/l10n-paraguay/issues/92>`__). When those
  are fixed upstream, the translation tables must go in the same
  release.
- Department and city are resolved by name against the SIFEN catalog
  shipped with this module
  (`#85 <https://github.com/OCA/l10n-paraguay/issues/85>`__,
  `#86 <https://github.com/OCA/l10n-paraguay/issues/86>`__).
- The partner form shows the identity document fields
  (`#87 <https://github.com/OCA/l10n-paraguay/issues/87>`__).
- Transport: carrier fields, freight responsibility 5 and creation from
  the invoice (`#93 <https://github.com/OCA/l10n-paraguay/issues/93>`__,
  `#94 <https://github.com/OCA/l10n-paraguay/issues/94>`__).
- Payment terms, item prices with VAT and discount, unit of measure
  code, and number voiding
  (`#95 <https://github.com/OCA/l10n-paraguay/issues/95>`__,
  `#96 <https://github.com/OCA/l10n-paraguay/issues/96>`__,
  `#98 <https://github.com/OCA/l10n-paraguay/issues/98>`__).
- The extra keys this module adds to the document dict under ``sifende``
  (issuance motive, unit of measure, discounts, email and customer code)
  should become part of the ``l10n_py_edi_base`` contract, so every
  provider shares them.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/l10n-paraguay/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/l10n-paraguay/issues/new?body=module:%20l10n_py_edi_sifende%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
-------

* ITH

Contributors
------------

- `ITH <https://sifende.com.py>`__:

  - Mijhael Samaniego

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
   :alt: Odoo Community Association
   :target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

.. |maintainer-mijhaels| image:: https://github.com/mijhaels.png?size=40px
    :target: https://github.com/mijhaels
    :alt: mijhaels

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-mijhaels| 

This module is part of the `OCA/l10n-paraguay <https://github.com/OCA/l10n-paraguay/tree/18.0/l10n_py_edi_sifende>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
