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

[IMP] accounting v16. Yeeeeaah #96134

Closed

Conversation

william-andre
Copy link
Contributor

@william-andre william-andre commented Jul 15, 2022

TLDR:

  • invoices are implemented using computed methods instead of onchange
  • the synchronization only happens when switching tabs in the Form view
    to improve perfs.

The whole engine of the synchronization of Invoices to the Journal
Entries has been refactored

  • by using computed fields instead of onchange functions
  • by synchronizing only from invoice to journal entry in create and
    write
  • by saving when switching tabs on the Invoice form, to synchronize
    before showing the values

This comes with numerous advantages:

  • no need to call the onchange methods manually
  • no need to use the Form emulator to build invoices (i.e. EDI, OCR,
    intercompany, ...)
  • the performance for invoices with many lines improves drastically, going
    from 2 minutes to 4 seconds to create an invoice with 500 lines
  • the model is more declarative, we can now see how the values are computed
    instead of having the values being copied from various places.
  • remove the hack in onchange that disabled the recursivity of it,
    which was unexpected and needed to be managed manually in all the
    onchange methods

This means that:

  • Some fields need to be exclusively computed on journal entries values
    or invoice values, more specifically the Tax Summary widget.
    It is now
    • computed from entry lines, when opening the view
    • computed from invoice lines when changing those, because the tax lines
      will need to be recomputed anyways, erasing previously set values
    • set with an inverse function when saving; after the sync has been done
  • Some possible operations previously possible have been dropped.
    (i.e. look at the removed test test_in_invoice_line_onchange_accounting_fields_1)
    This is because such a behavior was undefined (how is changing the balance going
    to affect the unit price? How is the amount currency going to affect it?)

Implementation Details

The "dynamic lines", meaning the payment terms and the tax lines are now
only created in the create and write functions.
In order to reduce code duplication, it has been implemented using
context managers used in both account.move and account.move.line
These context managers help comparing the values before/after, acting
like a local onchange, but getting benefit from the dirty flags from
the compute dependences.
This is relying on computed fields on the move (needed_terms) and on
the lines (compute_all_tax) which contain the values needed for the
related move.
Depending on the needed values and the existing values (term_key and
tax_key, respectively) the context manager will determine what needs
to be created/updated/deleted.

Some related changes are to produce a dict instead of a str for the
tax_totals (previously tax_totals_json) fields, by simplicity to
reduce the complexity of IO, and simplicity of debugging, because the
logic of the field needed to change (cannot be computed at the same time
anymore since it needed the lines to be synced)

By simplicity, and also because it makes more sense, some boolean fields
have been merged into display_type:

  • is_rounding_line
  • exclude_from_invoice_tab
  • is_anglo_saxon_line

The price_unit, quantity and other "invoice fields" are now not set
anymore on lines that are not product lines since it didn't make any
sense to have it.

Performances

You have to keep in mind that a simple create didn't compute a lot of
fields, for instance not taxes were set, no payment terms,...
Now it does.

import random
from timeit import timeit
from odoo import Command
domain = [('company_id', 'in', (False, self.env.company.id))]
products = self.env['product.product'].search(domain).ids
partners = self.env['res.partner'].search(domain).ids
taxes = self.env['account.tax'].search(domain).ids
def create(nmove, nline):
    self.env['account.move'].create([
        {
            'move_type': 'out_invoice',
            'partner_id': random.choice(partners),
            'invoice_line_ids': [
                Command.create({
                    'name': f'line{i}',
                    'product_id': random.choice(products),
                    'tax_ids': [Command.set([random.choice(taxes)])],
                })
                for i in range(nline)
            ]
        }
        for j in range(nmove)
    ])
                                                             # After  | Before
print(timeit("create(1, 1)", globals=globals(), number=1))   # 0.11   | 0.09
print(timeit("create(100, 1)", globals=globals(), number=1)) # 2.76   | 2.50
print(timeit("create(500, 1)", globals=globals(), number=1)) # 14.56  | 12.34
print(timeit("create(1, 100)", globals=globals(), number=1)) # 1.03   | 5.52
print(timeit("create(1, 500)", globals=globals(), number=1)) # 3.99   | 125.02
print(timeit("create(50, 50)", globals=globals(), number=1)) # 19.44  | 79.55

Another metric that can be used is running the test suite with
--test-tags=/account (only account installed)

  • before: 404s, 267127 queries (366 tests)
  • after: 318s, 232125 queries (362 tests)

Why this commit title?

Someone told me that this was the perfect way of naming your commits.
c04065a

@robodoo
Copy link
Contributor

robodoo commented Jul 15, 2022

Pull request status dashboard

@C3POdoo C3POdoo added the RD research & development, internal work label Jul 15, 2022
@william-andre william-andre force-pushed the master-account-onchange-fp-wan branch 13 times, most recently from 6684bb9 to 2c44bce Compare July 20, 2022 11:58
Copy link
Contributor

@qdp-odoo qdp-odoo left a comment

Choose a reason for hiding this comment

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

WIP

  • JS not reviewed
  • some unnecessary diff (like in tests), might be worth moving those in dedicated ref commit(s)

addons/account/models/account_journal.py Outdated Show resolved Hide resolved
addons/account/models/account_move.py Show resolved Hide resolved
addons/account/models/account_move.py Outdated Show resolved Hide resolved
addons/account/tests/test_account_payment.py Show resolved Hide resolved
addons/account/tests/test_invoice_taxes.py Show resolved Hide resolved
addons/account/tests/test_invoice_taxes.py Show resolved Hide resolved
vals['partner_bank_id'] = partner_banks[vals['payment_values']['payment_type']]
vals['lines'] = lines
batch_vals.append(vals)
return batch_vals
Copy link
Contributor

Choose a reason for hiding this comment

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

what's that diff? not related to the task?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My task uncovered a nasty bug. It isn't related to the task, but tests were failing.
I'll do a back port

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

@qdp-odoo qdp-odoo left a comment

Choose a reason for hiding this comment

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

WIP

addons/hr_expense/models/account_move.py Show resolved Hide resolved
addons/account/models/account_move.py Show resolved Hide resolved
addons/l10n_it_edi/data/invoice_it_template.xml Outdated Show resolved Hide resolved
addons/l10n_it_edi/models/account_edi_format.py Outdated Show resolved Hide resolved
addons/l10n_se/models/account_move.py Show resolved Hide resolved
@william-andre william-andre force-pushed the master-account-onchange-fp-wan branch 2 times, most recently from b9839c1 to c0a982a Compare July 20, 2022 16:01
Copy link
Contributor

@qdp-odoo qdp-odoo left a comment

Choose a reason for hiding this comment

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

  • changes in odoo/tests should not be here
  • next: enterprise branch

addons/sale/models/sale_order.py Show resolved Hide resolved
addons/sale/tests/test_accrued_sale_orders.py Show resolved Hide resolved
addons/stock_account/models/account_move.py Show resolved Hide resolved
@@ -782,6 +782,10 @@ tour.stepUtils.openBuggerMenu("li.breadcrumb-item.active:contains('OP/')"),
trigger:".o_field_widget[name=invoice_date] input",
content: _t('Set the invoice date'),
run: "text 01/01/2020",
}, {
trigger: ".modal-footer .btn-primary:contains('Ok')",
content: _t('Aknowledge warning'),
Copy link
Contributor

Choose a reason for hiding this comment

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

what warning?

odoo/tests/loader.py Outdated Show resolved Hide resolved
odoo/tests/runner.py Outdated Show resolved Hide resolved
addons/account/models/account_journal.py Show resolved Hide resolved
@@ -307,6 +299,7 @@ def test_in_invoice_line_onchange_product_2_with_fiscal_pos(self):
})

uom_dozen = self.env.ref('uom.product_uom_dozen')
self.env.user.groups_id += self.env.ref('uom.group_uom')
Copy link
Contributor

Choose a reason for hiding this comment

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

addons/account/models/account_move.py Outdated Show resolved Hide resolved
addons/account/models/account_move.py Outdated Show resolved Hide resolved
@william-andre william-andre force-pushed the master-account-onchange-fp-wan branch 2 times, most recently from a98af4d to 7e12acb Compare July 25, 2022 10:06
@william-andre
Copy link
Contributor Author

william-andre commented Jul 25, 2022

@odoo/rd-security
Hello, I am already asking for a review so that you will be ready when we want to merge as nothing should "change" security wise anymore.
There is only one warning

odoo/addons/account/models/account_move.py:2467

ref_function = getattr(self, f'_get_invoice_reference_{self.journal_id.invoice_reference_model}_{self.journal_id.invoice_reference_type}')

Line may contain security risk: getattr. Please contact security team for advanced review (you can ping @odoo/rd-security)

The code is only moved. It should also be safe because it is getting values that are built from fields.Selection values

@william-andre william-andre force-pushed the master-account-onchange-fp-wan branch 4 times, most recently from 574d7a3 to 207b9ca Compare July 25, 2022 18:37
yajo added a commit to moduon/account-financial-tools that referenced this pull request Apr 24, 2023
When renumbering the moves, a lot of recomputes were executed, specially after Yeeeeaah was merged (a.k.a. odoo/odoo#96134).

None of those recomputes is needed. The entry number we're adding here has no impact on taxes, invoices, or anything related. We can just skip all that stuff and make renumbering actually be able to finish in less than 100 years.

@moduon MT-2806
andreagidaltig added a commit to vauxoo-dev/odoo that referenced this pull request Oct 23, 2023
Using an attribute in the context to force the change of the state of the
accounting entries for CABA and Exchange Differential to "draft." This is
to allow the deletion of these entries to facilitate the accounting audit
process. As the number of lines in the accounting entries generated by
these transactions can grow significantly, this occurs each time a payment
that has generated CABA or Exchange Differential entries is canceled or
unreconciled, reverse lines are generated for these entries.
Setting the posted journal entries to "draft" when canceling by using the
button_cancel method was introduced in [1], this not allow to delete the
CABA or Exchange Differential entries generated in the unreconcile and
reconcile process.

[1] odoo@1de5c98
Related: odoo#96134
cormaza pushed a commit to cormaza/account-financial-reporting that referenced this pull request Jun 2, 2024
When renumbering the moves, a lot of recomputes were executed, specially after Yeeeeaah was merged (a.k.a. odoo/odoo#96134).

None of those recomputes is needed. The entry number we're adding here has no impact on taxes, invoices, or anything related. We can just skip all that stuff and make renumbering actually be able to finish in less than 100 years.

@moduon MT-2806
luistorresm added a commit to vauxoo-dev/odoo that referenced this pull request Jun 27, 2024
The restrictions on `button_draft` method on account move was moved to a
new method to allow inherit and mute the restrictions in necessary cases
for some customizations.

A user case is the next:
Allow the deletion of cash basis or Exchange Differential entries to
facilitate the accounting audit process.

As the number of lines in the accounting entries generated by these
transactions can grow significantly, this occurs each time a payment
that has generated CABA or Exchange Differential entries is canceled or
unreconciled, reverse lines are generated for these entries.
Setting the posted journal entries to "draft" when canceling by using
the `button_cancel` method was introduced in [1], this not allow to delete
the CABA or Exchange Differential entries generated in the unreconciled
and reconcile process.

[1] 1de5c98
Related: odoo#96134
robodoo pushed a commit that referenced this pull request Jul 9, 2024
The restrictions on `button_draft` method on account move was moved to a
new method to allow inherit and mute the restrictions in necessary cases
for some customizations.

A user case is the next:
Allow the deletion of cash basis or Exchange Differential entries to
facilitate the accounting audit process.

As the number of lines in the accounting entries generated by these
transactions can grow significantly, this occurs each time a payment
that has generated CABA or Exchange Differential entries is canceled or
unreconciled, reverse lines are generated for these entries.
Setting the posted journal entries to "draft" when canceling by using
the `button_cancel` method was introduced in [1], this not allow to delete
the CABA or Exchange Differential entries generated in the unreconciled
and reconcile process.

[1] 1de5c98

closes #170067

Related: #96134
Signed-off-by: Olivier Colson (oco) <oco@odoo.com>
fw-bot pushed a commit to odoo-dev/odoo that referenced this pull request Jul 9, 2024
The restrictions on `button_draft` method on account move was moved to a
new method to allow inherit and mute the restrictions in necessary cases
for some customizations.

A user case is the next:
Allow the deletion of cash basis or Exchange Differential entries to
facilitate the accounting audit process.

As the number of lines in the accounting entries generated by these
transactions can grow significantly, this occurs each time a payment
that has generated CABA or Exchange Differential entries is canceled or
unreconciled, reverse lines are generated for these entries.
Setting the posted journal entries to "draft" when canceling by using
the `button_cancel` method was introduced in [1], this not allow to delete
the CABA or Exchange Differential entries generated in the unreconciled
and reconcile process.

[1] 1de5c98

Related: odoo#96134
X-original-commit: 506786d
robodoo pushed a commit that referenced this pull request Jul 9, 2024
The restrictions on `button_draft` method on account move was moved to a
new method to allow inherit and mute the restrictions in necessary cases
for some customizations.

A user case is the next:
Allow the deletion of cash basis or Exchange Differential entries to
facilitate the accounting audit process.

As the number of lines in the accounting entries generated by these
transactions can grow significantly, this occurs each time a payment
that has generated CABA or Exchange Differential entries is canceled or
unreconciled, reverse lines are generated for these entries.
Setting the posted journal entries to "draft" when canceling by using
the `button_cancel` method was introduced in [1], this not allow to delete
the CABA or Exchange Differential entries generated in the unreconciled
and reconcile process.

[1] 1de5c98

closes #172432

Related: #96134
X-original-commit: 506786d
Signed-off-by: Olivier Colson (oco) <oco@odoo.com>
oco-odoo pushed a commit to odoo-dev/odoo that referenced this pull request Jul 16, 2024
The restrictions on `button_draft` method on account move was moved to a
new method to allow inherit and mute the restrictions in necessary cases
for some customizations.

A user case is the next:
Allow the deletion of cash basis or Exchange Differential entries to
facilitate the accounting audit process.

As the number of lines in the accounting entries generated by these
transactions can grow significantly, this occurs each time a payment
that has generated CABA or Exchange Differential entries is canceled or
unreconciled, reverse lines are generated for these entries.
Setting the posted journal entries to "draft" when canceling by using
the `button_cancel` method was introduced in [1], this not allow to delete
the CABA or Exchange Differential entries generated in the unreconciled
and reconcile process.

[1] 1de5c98

Related: odoo#96134
X-original-commit: 506786d
robodoo pushed a commit that referenced this pull request Jul 16, 2024
The restrictions on `button_draft` method on account move was moved to a
new method to allow inherit and mute the restrictions in necessary cases
for some customizations.

A user case is the next:
Allow the deletion of cash basis or Exchange Differential entries to
facilitate the accounting audit process.

As the number of lines in the accounting entries generated by these
transactions can grow significantly, this occurs each time a payment
that has generated CABA or Exchange Differential entries is canceled or
unreconciled, reverse lines are generated for these entries.
Setting the posted journal entries to "draft" when canceling by using
the `button_cancel` method was introduced in [1], this not allow to delete
the CABA or Exchange Differential entries generated in the unreconciled
and reconcile process.

[1] 1de5c98

closes #172456

Related: #96134
X-original-commit: 506786d
Signed-off-by: Olivier Colson (oco) <oco@odoo.com>
fw-bot pushed a commit to odoo-dev/odoo that referenced this pull request Jul 16, 2024
The restrictions on `button_draft` method on account move was moved to a
new method to allow inherit and mute the restrictions in necessary cases
for some customizations.

A user case is the next:
Allow the deletion of cash basis or Exchange Differential entries to
facilitate the accounting audit process.

As the number of lines in the accounting entries generated by these
transactions can grow significantly, this occurs each time a payment
that has generated CABA or Exchange Differential entries is canceled or
unreconciled, reverse lines are generated for these entries.
Setting the posted journal entries to "draft" when canceling by using
the `button_cancel` method was introduced in [1], this not allow to delete
the CABA or Exchange Differential entries generated in the unreconciled
and reconcile process.

[1] 1de5c98

Related: odoo#96134
X-original-commit: 9cf5a94
oco-odoo pushed a commit to odoo-dev/odoo that referenced this pull request Jul 19, 2024
The restrictions on `button_draft` method on account move was moved to a
new method to allow inherit and mute the restrictions in necessary cases
for some customizations.

A user case is the next:
Allow the deletion of cash basis or Exchange Differential entries to
facilitate the accounting audit process.

As the number of lines in the accounting entries generated by these
transactions can grow significantly, this occurs each time a payment
that has generated CABA or Exchange Differential entries is canceled or
unreconciled, reverse lines are generated for these entries.
Setting the posted journal entries to "draft" when canceling by using
the `button_cancel` method was introduced in [1], this not allow to delete
the CABA or Exchange Differential entries generated in the unreconciled
and reconcile process.

[1] 1de5c98

Related: odoo#96134
X-original-commit: 9cf5a94
robodoo pushed a commit that referenced this pull request Jul 19, 2024
The restrictions on `button_draft` method on account move was moved to a
new method to allow inherit and mute the restrictions in necessary cases
for some customizations.

A user case is the next:
Allow the deletion of cash basis or Exchange Differential entries to
facilitate the accounting audit process.

As the number of lines in the accounting entries generated by these
transactions can grow significantly, this occurs each time a payment
that has generated CABA or Exchange Differential entries is canceled or
unreconciled, reverse lines are generated for these entries.
Setting the posted journal entries to "draft" when canceling by using
the `button_cancel` method was introduced in [1], this not allow to delete
the CABA or Exchange Differential entries generated in the unreconciled
and reconcile process.

[1] 1de5c98

closes #173417

Related: #96134
X-original-commit: 9cf5a94
Signed-off-by: Olivier Colson (oco) <oco@odoo.com>
fw-bot pushed a commit to odoo-dev/odoo that referenced this pull request Jul 19, 2024
The restrictions on `button_draft` method on account move was moved to a
new method to allow inherit and mute the restrictions in necessary cases
for some customizations.

A user case is the next:
Allow the deletion of cash basis or Exchange Differential entries to
facilitate the accounting audit process.

As the number of lines in the accounting entries generated by these
transactions can grow significantly, this occurs each time a payment
that has generated CABA or Exchange Differential entries is canceled or
unreconciled, reverse lines are generated for these entries.
Setting the posted journal entries to "draft" when canceling by using
the `button_cancel` method was introduced in [1], this not allow to delete
the CABA or Exchange Differential entries generated in the unreconciled
and reconcile process.

[1] 1de5c98

Related: odoo#96134
X-original-commit: fe1d3ec
robodoo pushed a commit that referenced this pull request Jul 20, 2024
The restrictions on `button_draft` method on account move was moved to a
new method to allow inherit and mute the restrictions in necessary cases
for some customizations.

A user case is the next:
Allow the deletion of cash basis or Exchange Differential entries to
facilitate the accounting audit process.

As the number of lines in the accounting entries generated by these
transactions can grow significantly, this occurs each time a payment
that has generated CABA or Exchange Differential entries is canceled or
unreconciled, reverse lines are generated for these entries.
Setting the posted journal entries to "draft" when canceling by using
the `button_cancel` method was introduced in [1], this not allow to delete
the CABA or Exchange Differential entries generated in the unreconciled
and reconcile process.

[1] 1de5c98

closes #173943

Related: #96134
X-original-commit: fe1d3ec
Signed-off-by: Olivier Colson (oco) <oco@odoo.com>
Yoann-bary pushed a commit to odoo-dev/odoo that referenced this pull request Jul 30, 2024
The restrictions on `button_draft` method on account move was moved to a
new method to allow inherit and mute the restrictions in necessary cases
for some customizations.

A user case is the next:
Allow the deletion of cash basis or Exchange Differential entries to
facilitate the accounting audit process.

As the number of lines in the accounting entries generated by these
transactions can grow significantly, this occurs each time a payment
that has generated CABA or Exchange Differential entries is canceled or
unreconciled, reverse lines are generated for these entries.
Setting the posted journal entries to "draft" when canceling by using
the `button_cancel` method was introduced in [1], this not allow to delete
the CABA or Exchange Differential entries generated in the unreconciled
and reconcile process.

[1] 1de5c98

closes odoo#172456

Related: odoo#96134
X-original-commit: 506786d
Signed-off-by: Olivier Colson (oco) <oco@odoo.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
15.5 RD research & development, internal work
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet