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

[FIX] Precisione decimale non usata durante l'importazione della fattura elettronica #4446

Conversation

SirAionTech
Copy link
Contributor

@SirAionTech SirAionTech commented Nov 20, 2024

Risolve #4445 per 16.0.

Sostituisce #3843 per risolvere #3843 (review).
Non ho incluso un test perché il codice che imposta la precisione decimale quando eseguito nei test solleva l'errore:

Stack
  File "/path/to/l10n-italy/l10n_it_fatturapa_in/tests/fatturapa_common.py", line 305, in run_wizard
    return wizard.importFatturaPA()
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/l10n-italy/l10n_it_fatturapa_in/wizard/wizard_import_fatturapa.py", line 1830, in importFatturaPA
    ) = self._set_decimal_precision("Product Price", "price_decimal_digits")
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/l10n-italy/l10n_it_fatturapa_in/wizard/wizard_import_fatturapa.py", line 1808, in _set_decimal_precision
    new_cr.commit()
  File "/path/to/odoo/odoo/sql_db.py", line 461, in commit
    self.flush()
  File "/path/to/odoo/odoo/sql_db.py", line 134, in flush
    self.transaction.flush()
  File "/path/to/odoo/odoo/api.py", line 883, in flush
    env_to_flush.flush_all()
  File "/path/to/odoo/odoo/api.py", line 747, in flush_all
    self[model_name].flush_model()
  File "/path/to/odoo/odoo/models.py", line 5630, in flush_model
    self._flush(fnames)
  File "/path/to/odoo/odoo/models.py", line 5731, in _flush
    model.browse(ids)._write(vals)
  File "/path/to/odoo/odoo/models.py", line 3882, in _write
    cr.execute(query, params + [sub_ids])
  File "/path/to/odoo/odoo/sql_db.py", line 321, in execute
    res = self._obj.execute(query, params)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
psycopg2.errors.ForeignKeyViolation: insert or update on table "decimal_precision" violates foreign key constraint "decimal_precision_write_uid_fkey"
DETAIL:  Key (write_uid)=(80) is not present in table "res_users".

Ho aggiunto un commit per correggere l'errore nei test https://github.com/OCA/l10n-italy/actions/runs/12313495777/job/34367636978#step:8:1717:

Stack
2024-12-13 10:22:13,191 528 ERROR odoo odoo.addons.l10n_it_fatturapa_pec.tests.test_e_invoice_response: ERROR: TestEInvoiceResponse.test_process_response_RC
Traceback (most recent call last):
  File "/__w/l10n-italy/l10n-italy/l10n_it_fatturapa_pec/tests/test_e_invoice_response.py", line 41, in test_process_response_RC
    ).message_process(False, incoming_mail)
  File "/opt/odoo/addons/mail/models/mail_thread.py", line 1298, in message_process
    routes = self.message_route(message, msg_dict, model, thread_id, custom_values)
  File "/__w/l10n-italy/l10n-italy/l10n_it_fatturapa_pec/models/mail_thread.py", line 77, in message_route
    return self.manage_pec_sdi_notification(message, message_dict)
  File "/__w/l10n-italy/l10n-italy/l10n_it_fatturapa_pec/models/mail_thread.py", line 138, in manage_pec_sdi_notification
    ).create(message_dict)
  File "", line 2, in create
  File "/opt/odoo/odoo/api.py", line 414, in _model_create_multi
    return create(self, [arg])
  File "/opt/odoo/addons/mail/models/mail_message.py", line 606, in create
    messages = super(Message, self).create(values_list)
  File "", line 2, in create
  File "/opt/odoo/odoo/api.py", line 415, in _model_create_multi
    return create(self, arg)
  File "/opt/odoo/odoo/addons/base/models/ir_fields.py", line 670, in create
    recs = super().create(vals_list)
  File "", line 2, in create
  File "/opt/odoo/odoo/api.py", line 415, in _model_create_multi
    return create(self, arg)
  File "/opt/odoo/odoo/models.py", line 3958, in create
    raise ValueError("Invalid field %r on model %r" % (key, self._name))
ValueError: Invalid field 'x_odoo_message_id' on model 'mail.message'

Dovuto al commit odoo/odoo@43041df che è solo in 16.0.

@SirAionTech
Copy link
Contributor Author

@eLBati il primo commit è un cherry-pick del tuo commit e7a60c9, mi sono aggiunto come co-autore perché l'ho modificato, fammi sapere se per te è ok

@SirAionTech SirAionTech marked this pull request as ready for review November 20, 2024 15:45
Copy link

@MaurizioPellegrinet MaurizioPellegrinet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test funzionale: OK

Copy link

@MaurizioPellegrinet MaurizioPellegrinet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bug
STEPS

  1. importo xml con 3 decimali
  2. la fattura viene importata correttamente
  3. modifica data di registrazione (o conto contropartita)

ATTESO
gli importi dovrebbero rimanere corretti

RISULTATO
alla modifica di data registrazione (o conto contropartita) vengono ricalcolati gli importi
Allego video

Screencast.2024-11-21.14.43.38.mp4

@SirAionTech
Copy link
Contributor Author

bug STEPS

  1. importo xml con 3 decimali
  2. la fattura viene importata correttamente
  3. modifica data di registrazione (o conto contropartita)

ATTESO gli importi dovrebbero rimanere corretti

RISULTATO alla modifica di data registrazione (o conto contropartita) vengono ricalcolati gli importi Allego video

Screencast.2024-11-21.14.43.38.mp4

Giusto: quando gli importi vengono ricalcolati, si usa la precisione globale non quella temporanea impostata durante l'importazione.

Secondo me è un problema dovuto a queste precisioni temporanee in sé, non alla PR specifica.
Il fatto è che prima non venivano proprio applicate quindi il ricalcolo non cambiava gli importi: aggiustare questa feature in pratica ha fatto scoprire che esiste questo problema.

Comunque ci sta segnalarlo qui, grazie 😄 magari ne parliamo domattina

@eLBati
Copy link
Member

eLBati commented Nov 22, 2024

A questo punto vedo 2 strade:

  • quella semplice è togliere del tutto la funzionalità per non confondere l'utente
  • quella completa sarebbe impostare la precisione desiderata a livello di fattura e usarla per tutti i ricalcoli che coinvolgono prezzo, quantità e sconto

Un approccio per il ricalcolo: #2874

@SirAionTech
Copy link
Contributor Author

A questo punto vedo 2 strade:

  • quella semplice è togliere del tutto la funzionalità per non confondere l'utente
  • quella completa sarebbe impostare la precisione desiderata a livello di fattura e usarla per tutti i ricalcoli che coinvolgono prezzo, quantità e sconto

Un approccio per il ricalcolo: #2874

Ok grazie, vedo come fare

@SirAionTech SirAionTech marked this pull request as draft November 22, 2024 09:03
@SirAionTech SirAionTech force-pushed the 16.0-fix-l10n_it_fatturapa_in-wizard_precision branch 2 times, most recently from 89c5ed6 to 6ba5e5b Compare November 26, 2024 13:39
@SirAionTech SirAionTech marked this pull request as ready for review November 26, 2024 14:07
@SirAionTech

This comment was marked as resolved.

@SirAionTech
Copy link
Contributor Author

/ocabot rebase

@OCA-git-bot
Copy link
Contributor

Congratulations, PR rebased to 16.0.

@OCA-git-bot OCA-git-bot force-pushed the 16.0-fix-l10n_it_fatturapa_in-wizard_precision branch from 6ba5e5b to 83528df Compare December 10, 2024 17:02
Copy link

@MaurizioPellegrinet MaurizioPellegrinet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test funzionale: OK

@TheMule71
Copy link
Contributor

/ocabot merge minor

@OCA-git-bot
Copy link
Contributor

What a great day to merge this nice PR. Let's do it!
Prepared branch 16.0-ocabot-merge-pr-4446-by-TheMule71-bump-minor, awaiting test results.

OCA-git-bot added a commit that referenced this pull request Dec 13, 2024
Signed-off-by TheMule71
Copy link
Contributor

@TheMule71 TheMule71 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@OCA-git-bot
Copy link
Contributor

This PR has the approved label and has been created more than 5 days ago. It should therefore be ready to merge by a maintainer (or a PSC member if the concerned addon has no declared maintainer). 🤖

@OCA-git-bot
Copy link
Contributor

@TheMule71 your merge command was aborted due to failed check(s), which you can inspect on this commit of 16.0-ocabot-merge-pr-4446-by-TheMule71-bump-minor.

After fixing the problem, you can re-issue a merge command. Please refrain from merging manually as it will most probably make the target branch red.

@SirAionTech
Copy link
Contributor Author

@TheMule71 your merge command was aborted due to failed check(s), which you can inspect on this commit of 16.0-ocabot-merge-pr-4446-by-TheMule71-bump-minor.

After fixing the problem, you can re-issue a merge command. Please refrain from merging manually as it will most probably make the target branch red.

3 giorni fa era tutto 🟢
🤔 vediamo come va con un rebase
/ocabot rebase

eLBati and others added 2 commits December 13, 2024 11:58
Otherwise, if another precision is used during import and an exception is raised, the system precision becomes the precision set during import.

Co-authored-by: Simone Rubino <[email protected]>
When price precision is increased during import, the price of the created lines should have been computed using the new precision
@OCA-git-bot
Copy link
Contributor

Congratulations, PR rebased to 16.0.

@OCA-git-bot OCA-git-bot force-pushed the 16.0-fix-l10n_it_fatturapa_in-wizard_precision branch from 83528df to 7b3db28 Compare December 13, 2024 11:58
`message_dict` contains values used to track the message, but we use it to create a `mail.message` so the extra values have to be removed because they are not fields of `mail.message`.
@TheMule71
Copy link
Contributor

/ocabot merge minor

@OCA-git-bot
Copy link
Contributor

On my way to merge this fine PR!
Prepared branch 16.0-ocabot-merge-pr-4446-by-TheMule71-bump-minor, awaiting test results.

@OCA-git-bot OCA-git-bot merged commit dd2c99d into OCA:16.0 Dec 13, 2024
7 checks passed
@OCA-git-bot
Copy link
Contributor

Congratulations, your PR was merged at f0fa0e2. Thanks a lot for contributing to OCA. ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Precisione decimale non usata durante l'importazione della fattura elettronica
5 participants