# Better cost price history

**URL:** <https://discuss.tryton.org/t/better-cost-price-history/1810>\
**Category:** Feature\
**Tags:** stock\
**Created:** [October 7, 2019, 10:49am UTC](https://discuss.tryton.org/t/better-cost-price-history/1810 "2019-10-07T10:49:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)\
**Post date:** [October 7, 2019, 10:49am UTC](https://discuss.tryton.org/t/better-cost-price-history/1810/1 "2019-10-07T10:49:31Z")

</div>

## Rational

The historization of the cost price is currently done using the [`_history` feature](http://docs.tryton.org/projects/server/en/latest/ref/models/models.html#trytond.model.ModelSQL._history). The problem is that it does not work well when the [cost price is recomputed](https://discuss.tryton.org/t/update-re-computed-cost-price-on-moves/1802) because the Tryton history is immutable.  
Indeed the cost price changes only when there is an incoming move done and we store the cost price on each move done. So this means that we already have the history of the cost price stored on the moves. And we can display it on a timeline (per day) if we group all incoming moves per date and cost price (usually the cost price will be the same for a day thanks to the cron re-computation).

## Proposal

- Add stock dependency to `product_cost_history` module.
- Change the query in `product_cost_history` to be based on stock moves
- Change getter of `cost_price` MultiValue field to read from history query the cost when `_datetime` is in the context.

## Implementation

> **[Use stock move as history source (#8858) · Issues · Tryton / Tryton · GitLab](https://foss.heptapod.net/tryton/tryton/-/issues/8858)**
>
> From https://discuss.tryton.org/t/better-cost-price-history/1810

---

<div class="post-metadata">

**Author:** ![risto3](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/r/a87d85/32.png) [@risto3](https://discuss.tryton.org/u/risto3)\
**Post date:** [November 23, 2019, 10:06am UTC](https://discuss.tryton.org/t/better-cost-price-history/1810/2 "2019-11-23T10:06:25Z")

</div>

Two things pop into my mind again:

1. for purchases, the cost price should be reserved for the actual invoiced purchased price…  
any adjustments (like transportation, non-VAT taxes, production costs or other arbitrary values) should be factored in and stored in a different field, such as calculated\_cost\_price, which can be recomputed ad nauseum based upon business rules/needs.

2. Why mix logistics moves directly with finance in the first place?

---

<div class="post-metadata">

**Author:** ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)\
**Post date:** [February 9, 2020, 5:00pm UTC](https://discuss.tryton.org/t/better-cost-price-history/1810/3 "2020-02-09T17:00:00Z")

</div>

This topic was automatically closed after 13 days. New replies are no longer allowed.
