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

[14.0][l10n_br_account][IMP] composite account.move #2761

Merged
merged 4 commits into from
Apr 19, 2024

Conversation

rvalyi
Copy link
Member

@rvalyi rvalyi commented Oct 28, 2023

A single account.move can now eventually have different l10n_br_fiscal.document from its invoice_line_ids. This can be useful to import several CTe's or several NFSe's under the same account.move as these fiscal document allow only 1 item line and as this is usually done in other ERP's. At least we are reusing the _onchange_fiscal_document_line_id from this feature to properly complete the account.move.line with their proper onchanges.

This PR is used in the NFe importation PR #2781

@rvalyi rvalyi marked this pull request as draft October 28, 2023 21:51
@OCA-git-bot
Copy link
Contributor

Hi @renatonlima,
some modules you are maintaining are being modified, check this out!

@felipemotter
Copy link
Contributor

felipemotter commented Mar 17, 2024

Como ta a situação dessa proposta @rvalyi ? Já da pra testar de forma concreta?

@rvalyi
Copy link
Member Author

rvalyi commented Mar 17, 2024

Como ta a situação dessa proposta @rvalyi ? Já da pra testar de forma concreta?

vou subir uns testes em breve...

@rvalyi rvalyi force-pushed the 14.0-composite-move branch 4 times, most recently from 337ecd8 to 74f9560 Compare March 21, 2024 10:31
@rvalyi
Copy link
Member Author

rvalyi commented Mar 21, 2024

@felipemotter @antoniospneto @marcelsavegnago @renatonlima @mbcosta @mileo

The PR is ready now for review now. I made e few changes and added a complete test suite (it's inside the test_account_move_lc.py file to avoid loading a fake chart of account another time, which would make the tests much slower).

As you can see, I added the fiscal_document_ids computed field with proper comments. Some extra checks are added in the case the user tries to perform an action on a move with several different fiscal documents.

Especially the fiscal view button now open the list of the related fiscal documents in the case there are more than 1.
For this, I changed the menu so there is now an "all low level Fiscal Documents" menu and action that will open the l10n_br_fiscal.document even when the l10n_br_account module is installed. This will also be useful to better track the webservice communication as pointed by @renatonlima and @antoniospneto.

Also now, in the UI, you can either:

  1. create a new invoice line and select an existing fiscal document line to import it (the line will be populated with the onchange event):
    2024-03-21_07-35

  2. or you can also import all the lines and other fiscal information from an existing l10n_br_fiscal.document right from the account.move form:
    2024-03-21_07-33

@felipemotter @antoniospneto you could probably use that to merge several CTe's into the same bill for instance. cc @douglascstd . Mileo you were also concerned with the need for such a feature for the NFSe's a few years ago...

Just to be clear: I could have made the NFe importation (#2781) work without this, but it would give me almost 2x more work as these two PRs share many concerns.

@rvalyi
Copy link
Member Author

rvalyi commented Mar 21, 2024

Eu atualizei o PR de importação da NFe com esses 4 commits #2781 (comment)

Comment on lines +154 to +158
if values.get("fiscal_document_line_id"):
fiscal_line_data = (
self.env["l10n_br_fiscal.document.line"]
.browse(values["fiscal_document_line_id"])
.read(self._shadowed_fields())[0]
)
for k, v in fiscal_line_data.items():
if isinstance(v, tuple): # m2o
values[k] = v[0]
else:
values[k] = v
continue
Copy link
Contributor

Choose a reason for hiding this comment

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

@rvalyi eu não certerza se compreendi bem aqui, aqui você faz o inverso do que é feito _inject_shadowed_fields() ?
ao invés de sincronizar o fiscal_line com o move_line, vc tá sincronizando o move_line com o fiscal_line isso ?

Copy link
Member Author

@rvalyi rvalyi Mar 21, 2024

Choose a reason for hiding this comment

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

eh isso sim. Nos testes desse PR eu testo isso de forma um pouco superficial, mas se vc testa de importar uma NFe em #2781 vai testar isso de forma bem funda. Inclusive eu penso botar outros testes depois em #2781 antes do merge...

Ai pelo sistema do _inherits a sincronização acontece de forma natural pelo framework (ou seja o account.move.line vai puxar os valoras fiscais da linha de documento fiscal pelo _inherits).
Os únicos campos que a gente tem que lidar são aqueles que são "shadowed" ou seja que não vão ser herdado mas que precisam ser duplicados no account.move.line. Esse código lida com essa copia desses 4 ou 5 campos.

@felipemotter
Copy link
Contributor

Irei revisar logo.

@rvalyi
Copy link
Member Author

rvalyi commented Mar 25, 2024

@mileo não era isso que vc precisava aqui na sua RFC #894 ?
ai que tal testar...

@mileo
Copy link
Member

mileo commented Mar 25, 2024

@mileo não era isso que vc precisava aqui na sua RFC #894 ? ai que tal testar...

Sim, sobrando um tempo essa semana eu vou testar. Isso tem que fazer com bastante calma, mas é uma ótima contribuição, vai ajudar na questão do CT-e e outros documentos.

@rvalyi rvalyi force-pushed the 14.0-composite-move branch from 74f9560 to 9638520 Compare March 28, 2024 17:45
@mileo
Copy link
Member

mileo commented Mar 29, 2024

@rvalyi pode fazer um rebase?

@rvalyi rvalyi force-pushed the 14.0-composite-move branch from 9638520 to b216bd2 Compare March 29, 2024 16:53
@rvalyi
Copy link
Member Author

rvalyi commented Mar 29, 2024

@rvalyi pode fazer um rebase?

feito.
CUIDADO se for fazer merge depois tem que ser com nobump.

Copy link
Member

@mileo mileo left a comment

Choose a reason for hiding this comment

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

LGTM, do ponto de vista financeiro depois será necessário pensar em algumas melhorias, caso somente umas das linhas tenha sido cancelada.

  • Seja removendo a linha ou dividindo o documento em dois, só com a parte não cancelada.
  • Ou inserindo uma linha negativa para abater o valor.
  • Ou até um reembolso da parte cancelada.

@rvalyi
Copy link
Member Author

rvalyi commented Mar 29, 2024

a ideia é meio que definir uma "topologia" que funciona e que não conflita com a importação dos documentos fiscais (a NFe no caso). Depois da sim para melhorar muitas coisas em volta disso. Inclusive, vale a pena vc pensar bem se quer continuar fazer a NFSe como vc fez hoje somando todas linhas na mesma NFSe, pois poderia fazer uma NFSe por linha tb.

@marcelsavegnago
Copy link
Member

@rvalyi pode dar um rebase por favor ?

@rvalyi rvalyi force-pushed the 14.0-composite-move branch from b216bd2 to e8bc9bd Compare April 17, 2024 17:56
@rvalyi
Copy link
Member Author

rvalyi commented Apr 17, 2024

@rvalyi pode dar um rebase por favor ?

feito

@rvalyi rvalyi force-pushed the 14.0-composite-move branch from e8bc9bd to 09893ef Compare April 18, 2024 18:37
Copy link
Member

@marcelsavegnago marcelsavegnago 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). 🤖

@rvalyi
Copy link
Member Author

rvalyi commented Apr 19, 2024

/ocabot merge nobump

@OCA-git-bot
Copy link
Contributor

What a great day to merge this nice PR. Let's do it!
Prepared branch 14.0-ocabot-merge-pr-2761-by-rvalyi-bump-nobump, awaiting test results.

@OCA-git-bot OCA-git-bot merged commit 99b780e into OCA:14.0 Apr 19, 2024
5 checks passed
@OCA-git-bot
Copy link
Contributor

Congratulations, your PR was merged at ee37297. 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.

6 participants