Skip to content

[12.0][FIX] account_invoice_triple_discount: subtotal computation - #876

Closed
SimoRubi wants to merge 5 commits into
OCA:12.0from
SimoRubi:12.0-fix-account_invoice_triple_discount-subtotal_computation
Closed

[12.0][FIX] account_invoice_triple_discount: subtotal computation#876
SimoRubi wants to merge 5 commits into
OCA:12.0from
SimoRubi:12.0-fix-account_invoice_triple_discount-subtotal_computation

Conversation

@SimoRubi

@SimoRubi SimoRubi commented Mar 3, 2021

Copy link
Copy Markdown
Member

Steps (see also added test case)

  1. In Sales > Configuration > Settings, enable 'discounts'
  2. Create a sale order with one line having:
    • price unit = 25
    • quantity = 65
    • discount = 50
    • discount = 13

Before this PR
The line's subtotal is 707

After this PR
The line's subtotal is 706.88

This modification borrows the triple discount computation from https://github.com/OCA/sale-workflow/blob/361d4b039f281fe9293e4dcde30f5a8ce9c805bb/sale_triple_discount/models/sale_order_line.py and puts everything in abstract model, in order to be reused from sale order line (PR coming soon) and purchase order line.

todo

Comment thread account_invoice_triple_discount/models/line_triple_discount.py Outdated
'Discount 3 (%)',
digits=dp.get_precision('Discount'),
)
discounting_type = fields.Selection(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't understand where this field can be changed ? Should not be a setting on the related res.partner ? I mean some suppliers are using additive method and other multiplicative method.

Don't you think ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This can be changed directly on the account invoice line's form, but it can be interesting to inherit that from the partner.
I'm currently investigating why Travis is still 🔴 (that's why this is still a Draft), after that I can try to add this new behavior.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

While implementing this feature I noticed that it is not as trivial as it seems because default value for invoice line cannot rely on the line's fields (default methods are api.model), so I'd need to save it in the context etc..
I think that deserves its own PR, and here let's focus on the described issue, is that ok for you?

BTW Now that Travis is 🟢, I'll mark this PR as ready for reviews

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

well, I was more thinking on storing the discounting_type only on the res.partner or at least on the order/invoice method.
it will be a lighter implementation.
Do you think there are real cases when there are some line with additive method, and other with multiplicative ?

I mean, setting this value 50 times, if you have 50 lines will be a mess, in a UX point of view.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

That is why I was talking about a default value for new lines: each of the 50 lines would have the default value inherited from the partner; and switching partner in the invoice would trigger the edit of all the invoice's lines.

I don't know about real cases of lines having different kinds of discounts but this is how sale orders + triple_discount currently work and it would be nice to have it in invoices too.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I added the logic explained above, can you update your review?

@legalsylvain legalsylvain Jul 18, 2022

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't know about real cases of lines having different kinds of discounts but this is how sale orders + triple_discount currently work and it would be nice to have it in invoices too.

  1. Well if it's not a use case, it should be changed I think. Don't you ?

  2. the problem with the current implementation is that it will create inconsistencies. I mean, it's possible to have "multiplicative" and invoice level and "additive" on line level.

  3. you are adding new field on invoice / invoice.line. don't you think you should add a pre-migration script to populate correctly the database. I fear that an update of the current module on a production database will be slow. Don't you think ?

@HaraldPanten

Copy link
Copy Markdown
Contributor

Might it be related to OCA/purchase-workflow#834 and my comment in #733 ?

@SimoRubi

SimoRubi commented Mar 3, 2021

Copy link
Copy Markdown
Member Author

Might it be related to OCA/purchase-workflow#834 and my comment in #733 ?

It might be, I didn't know purchase's version of triple discount but looks like every module is re-implementing that logic in its own way.
This PR aims to centralize the logic in the new mixin class that will then be inherited from lines of account.invoice, sale.order and purchase.order.

@HaraldPanten

Copy link
Copy Markdown
Contributor

Might it be related to OCA/purchase-workflow#834 and my comment in #733 ?

It might be, I didn't know purchase's version of triple discount but looks like every module is re-implementing that logic in its own way.
This PR aims to centralize the logic in the new mixin class that will then be inherited from lines of account.invoice, sale.order and purchase.order.

OK!

@SimoRubi
SimoRubi marked this pull request as ready for review March 3, 2021 12:10
When `super` method is `api.one`, each line has to be processed separately in order to have cache consistency.
@SimoRubi

Copy link
Copy Markdown
Member Author

@OCA/accounting-maintainers can this be merged?
@legalsylvain can you update your review?

Thanks!

@SimoRubi
SimoRubi marked this pull request as draft June 16, 2021 14:13
@SimoRubi
SimoRubi marked this pull request as ready for review June 16, 2021 14:50
@SimoRubi

Copy link
Copy Markdown
Member Author

Last commit solves the same issue as OCA/sale-workflow#1618

@SimoRubi
SimoRubi force-pushed the 12.0-fix-account_invoice_triple_discount-subtotal_computation branch from a847827 to 83c27b1 Compare June 17, 2021 13:15
@SimoRubi

Copy link
Copy Markdown
Member Author

@OCA/accounting-maintainers can this be merged or do I have to fix anything?
Thanks!

@tafaRU

tafaRU commented Sep 1, 2021

Copy link
Copy Markdown
Member

@SimoRubi could you please have a look at SimoRubi#1 ?

@SimoRubi

Copy link
Copy Markdown
Member Author

@OCA/accounting-maintainers can this be merged or do I have to fix anything?
Thanks!

@SimoRubi

Copy link
Copy Markdown
Member Author

@SimoRubi could you please have a look at SimoRubi#1 ?

I had a look and I think that cannot be merged as explained in SimoRubi#1 (review)

@SimoRubi

SimoRubi commented Mar 8, 2022

Copy link
Copy Markdown
Member Author

@OCA/accounting-maintainers can this be merged or do I have to fix anything?
Thanks!

@sergioeix

Copy link
Copy Markdown

So this is happening on v13 #733 and i guess it happens on v14 too??

@francesco-ooops

Copy link
Copy Markdown
Contributor

@legalsylvain could you review this one again? thanks

@legalsylvain legalsylvain left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Regarding Point 1, I think it can be changed later, but could you write a bullet in the ROADMAP.rst file to mention that topic ?
Also write a bullet to say that sale_triple_discount should be refactored to use new mixin introduced in that module.

https://github.com/OCA/sale-workflow/blob/14.0/sale_triple_discount/__manifest__.py

Regarding point 2 & 3, let me know your point of view.

@francesco-ooops

Copy link
Copy Markdown
Contributor

@SirTakobi can you take a look at the recent review?

@SirTakobi

Copy link
Copy Markdown
Contributor

@SirTakobi can you take a look at the recent review?

Thanks for letting me know of #876 (review).

I can't edit this PR because it is based on @SimoRubi's branch.
I'm currently not working on this topic so I won't be looking into this in the near future, if you want to make improvements or go on with the PR you can simply create another PR starting from https://github.com/SimoRubi/account-invoicing/tree/12.0-fix-account_invoice_triple_discount-subtotal_computation

@github-actions

Copy link
Copy Markdown

There hasn't been any activity on this pull request in the past 4 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 30 days.
If you want this PR to never become stale, please ask a PSC member to apply the "no stale" label.

@github-actions github-actions Bot added the stale PR/Issue without recent activity, it'll be soon closed automatically. label Jun 25, 2023
@github-actions github-actions Bot closed this Jul 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale PR/Issue without recent activity, it'll be soon closed automatically.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants