margin-analysis icon indicating copy to clipboard operation
margin-analysis copied to clipboard

account_invoice_margin: does not populate purchase_price on install

Open dreispt opened this issue 2 years ago • 5 comments

Module

account_invoice_margin

Describe the bug

When installing account_invoice_margin, the purchase_price field is expected to be populated with the product's standard_price, but it stays as zero. Manually running _compute_purchase_price fixes it, but I can't see why this is not already being done on install - I could be missing something.

To Reproduce

Affected versions: 14.0

Steps to reproduce the behavior:

  1. Install account_invoice_margin
  2. Find an Invoice using a product that has a non zero cost
  3. Check the cost invoice line column: is is zero while it should be the product cost

Expected behavior the cost invoice line column: is is zero while it should be the product cost

dreispt avatar Sep 08 '23 06:09 dreispt

Hi @dreispt. Thanks for your comment.

I've already thought about this, and I haven't found a better solution yet. Here's my train of thought:

  • Idea 1 : Let's populate purchase_price with standard_price when installing module, for existing invoices.

  • BUT : that logic is right for current invoices, but not for past invoices. So you'll have bad margin on past invoices.

  • Idea 2 : Let's populate purchase_price, with values present in product.price.history tables, for past invoices.

  • BUT : product.price.history was not present before version 10.0. That means that for databases that have been migrated from older version. (my current database comes from 5.0 version), the purchase_price will be wrong.

-> my current conclusion on that topic : let's put 0 for existing invoices. it's better to have no margin than to have a false margin and base bad decisions on it.

What do you think ?

legalsylvain avatar Sep 08 '23 07:09 legalsylvain

Help me understand why purchase_price it is not populated in the first place: The field is added by this module, and it is computed. Why isn't it populated with the computed value? Because of readonly=False ?

dreispt avatar Sep 08 '23 07:09 dreispt

Why isn't it populated with the computed value? Because of readonly=False ?

no. because of this hook :

https://github.com/OCA/margin-analysis/blob/12.0/account_invoice_margin/hooks.py

  • see comment in this commit : https://github.com/OCA/margin-analysis/commit/9fe0f39cbcfb37e0424acb96507368ab24dae3b1

legalsylvain avatar Sep 08 '23 07:09 legalsylvain

There hasn't been any activity on this issue in the past 6 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 issue to never become stale, please ask a PSC member to apply the "no stale" label.

github-actions[bot] avatar Mar 10 '24 12:03 github-actions[bot]

@legalsylvain Hello, can you please have a look at #202?

dreispt avatar Aug 20 '24 14:08 dreispt

There hasn't been any activity on this issue in the past 6 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 issue to never become stale, please ask a PSC member to apply the "no stale" label.

github-actions[bot] avatar Feb 23 '25 12:02 github-actions[bot]

#202 was merged

dreispt avatar Feb 24 '25 16:02 dreispt