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] account: quick edit analytic distribution posted line #144562

Conversation

guva-odoo
Copy link
Contributor

With this commit we allow to change/add analytic distribution
on a posted line in quick edit mode.

opw-3561831

@robodoo
Copy link
Contributor

robodoo commented Dec 1, 2023

@C3POdoo C3POdoo requested a review from a team December 1, 2023 13:50
@C3POdoo C3POdoo added the OE the report is linked to a support ticket (opw-...) label Dec 1, 2023
With this commit we allow to change/add analytic distribution
on a posted line in quick edit mode.

opw-3561831
@guva-odoo guva-odoo force-pushed the 16.0-opw-3561831-quick_edit_analytic_distribution_posted_line-guva branch from ef44176 to e1d8548 Compare December 19, 2023 15:32
Copy link
Contributor

@gawa-odoo gawa-odoo left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@Levizar Levizar left a comment

Choose a reason for hiding this comment

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

1 similar comment
@@ -210,3 +210,55 @@ def test_mandatory_plan_validation(self):
invoice.invoice_line_ids.analytic_distribution = {self.analytic_account_b.id: 0.9}
invoice.action_post()
self.assertEqual(invoice.state, 'posted')

def test_set_anaylytic_distribution_posted_line(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

anaylytic I just see it now 🤣

5 similar comments
@fw-bot fw-bot deleted the 16.0-opw-3561831-quick_edit_analytic_distribution_posted_line-guva branch January 4, 2024 16:46
luanjubica pushed a commit to luanjubica/odoo-code that referenced this pull request Feb 14, 2024
With this commit we allow to change/add analytic distribution
on a posted line in quick edit mode.

opw-3561831

closes odoo#144562

Signed-off-by: Brice Bartoletti (bib) <bib@odoo.com>
@ivantodorovich
Copy link
Contributor

Hello @guva-odoo

The PR description suggests the user would be allowed to add or change analytic distribution.
However, in our case, we see users are only allowed to add, but not change.

e.g.: this adapted unit test fails:

     def test_set_analytic_distribution_posted_line(self):
         """
         Test that we can set the analytic distribution on the product line of a move, when the line has tax with
         repartition lines used in tax closing. Although the change can not be applied on the tax line, we should
         not raise any error.
         """
         tax = self.tax_purchase_a.copy({
             'name': 'taXXX',
             'invoice_repartition_line_ids': [
                 Command.create({
                     'repartition_type': 'base',
                     'use_in_tax_closing': False,
                 }),
                 Command.create({
                     'repartition_type': 'tax',
                     'factor_percent': 50,
                     'use_in_tax_closing': False,
                 }),
                 Command.create({
                     'repartition_type': 'tax',
                     'factor_percent': 50,
                     'account_id': self.company_data['default_account_tax_purchase'].id,
                     'use_in_tax_closing': True,
                 }),
             ],
             'refund_repartition_line_ids': [
                 Command.create({
                     'repartition_type': 'base',
                     'use_in_tax_closing': False,
                 }),
                 Command.create({
                     'repartition_type': 'tax',
                     'factor_percent': 50,
                     'use_in_tax_closing': False,
                 }),
                 Command.create({
                     'repartition_type': 'tax',
                     'factor_percent': 50,
                     'account_id': self.company_data['default_account_tax_purchase'].id,
                     'use_in_tax_closing': True,
                 }),
             ],
         })

         bill = self.create_invoice(self.partner_a, self.product_a, move_type='in_invoice')
         bill.invoice_line_ids.tax_ids = [Command.set(tax.ids)]
+        line = bill.line_ids.filtered(lambda l: l.display_type == 'product')
+
+        # set distribution before posting
+        line.write({'analytic_distribution': {self.analytic_account_a.id: 50}})
+
+        # post the bill
         bill.action_post()

+        # modify distribution
-        line = bill.line_ids.filtered(lambda l: l.display_type == 'product')
         line.write({'analytic_distribution': {self.analytic_account_a.id: 100}})
         self.assertEqual(line.analytic_distribution, {str(self.analytic_account_a.id): 100})
Traceback (most recent call last):
  File "/odoo/src/addons/account/tests/test_account_analytic.py", line 269, in test_set_analytic_distribution_posted_line
    line.write({'analytic_distribution': {self.analytic_account_a.id: 100}})
  File "/odoo/src/addons/account/models/account_move_line.py", line 1530, in write
    line.move_id._message_log(
  File "/usr/lib/python3.9/contextlib.py", line 124, in __exit__
    next(self.gen)
  File "/odoo/src/addons/account/models/account_move.py", line 2211, in _sync_dynamic_lines
    update_containers()
  File "/usr/lib/python3.9/contextlib.py", line 513, in __exit__
    raise exc_details[1]
  File "/usr/lib/python3.9/contextlib.py", line 135, in __exit__
    self.gen.throw(type, value, traceback)
  File "/odoo/src/addons/account/models/account_move.py", line 2079, in _sync_dynamic_line
    yield
  File "/usr/lib/python3.9/contextlib.py", line 498, in __exit__
    if cb(*exc_details):
  File "/usr/lib/python3.9/contextlib.py", line 124, in __exit__
    next(self.gen)
  File "/odoo/src/addons/account/models/account_move.py", line 2133, in _sync_dynamic_line
    self.env['account.move.line'].browse(line_id).write(
  File "/odoo/src/addons/account/models/account_move_line.py", line 1473, in write
    raise UserError(_('You cannot modify the taxes related to a posted journal item, you should reset the journal entry to draft to do so.'))
odoo.exceptions.UserError: You cannot modify the taxes related to a posted journal item, you should reset the journal entry to draft to do so.

I would love to have more context on that opw, in order to know if this is a design decision or a bug 😓
Is it possible for external contributors like me to peek inside opw's?

@gawa-odoo
Copy link
Contributor

@ivantodorovich Hello!
Indeed, the fix is not working if you already have a distribution. The ticket was about a simple case where they wanted to add a distribution, so it wasn't noticed.
It's definitely a bug. We noticed recently that we have other issues with it (you can't change the account_d, or the vehicle_id with this kind of tax).
We've created a task to tackle it

@ivantodorovich
Copy link
Contributor

Thanks for the reply, @gawa-odoo ❤️

@Levizar
Copy link
Contributor

Levizar commented May 1, 2024

@guva-odoo what do we do about those fw port?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OE the report is linked to a support ticket (opw-...)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants