# Compute margins

**URL:** https://discuss.tryton.org/t/compute-margins/3278
**Category:** Ideas
**Tags:** stock, sales
**Created:** [September 25, 2020, 12:20pm UTC](https://discuss.tryton.org/t/compute-margins/3278 "2020-09-25T12:20:45Z")
**Posts on this page:** 16
**Page:** 1

<div class="post-metadata">

### Author: ![pokoli](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/pokoli/32/22_2.png) [@pokoli](https://discuss.tryton.org/u/pokoli)
#### Post date: [September 25, 2020, 12:20pm UTC](https://discuss.tryton.org/t/compute-margins/3278/1 "2020-09-25T12:20:45Z")

</div>

One of the objectives of implementing and ERP system is to know how much money the company is earning. This can be computed in several costs levels:

- Globaly on the company (using Profit and Lost)
- Per cost center or similar (using Analytic account)

But one may be interested on [computing the profit at document/line level](https://help.sap.com/saphelp_sbo882/helpdata/en/44/fd8a17a7100484e10000000a155369/frameset.htm). Normally this is computed using the following formulas:

- Profit = Sale Price - Cost Price
- Profit % = Profit / Sale Price = (Sale Price - Cost Price) / Sale Price

We could develop a new module that computes both formulas at sale line.  
It will also be interesting to have this information available on document level.

I’m wondering how we should use to compute the Cost Price:

- Saving the current product cost\_price on the sale line
- Using the product\_cost\_history to retieve the product cost\_price at the date of the move
- Using the cost\_price of the move sale price (only for goods).

To make the feature complete, I think we should also include the profit amount in the Sale Reporting, so one will be able to easly search which customers/products/categories are more profitable.

---

<div class="post-metadata">

### Author: ![tbruyere](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/tbruyere/32/37_2.png) [@tbruyere](https://discuss.tryton.org/u/tbruyere)
#### Post date: [September 25, 2020, 12:24pm UTC](https://discuss.tryton.org/t/compute-margins/3278/2 "2020-09-25T12:24:45Z")

</div>

Hello,  
We are also thinking about the possibility of a profit calculation module at the sales and reporting level.  
I find the proposal interesting and we would be interested in participating.  
I will prepare a summary of our needs / ideas early next week to complete this discussion.

---

<div class="post-metadata">

### Author: ![pokoli](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/pokoli/32/22_2.png) [@pokoli](https://discuss.tryton.org/u/pokoli)
#### Post date: [September 25, 2020, 12:28pm UTC](https://discuss.tryton.org/t/compute-margins/3278/3 "2020-09-25T12:28:08Z")

</div>

> [@tbruyere](#):
>
> We are also thinking about the possibility of a profit calculation module at the sales and reporting level.  
> I find the proposal interesting and we would be interested in participating.

Great to read this!

> [@tbruyere](#):
>
> I will prepare a summary of our needs / ideas early next week to complete this discussion.

We will wait for your comments.

Thanks!

---

<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: [September 25, 2020, 12:33pm UTC](https://discuss.tryton.org/t/compute-margins/3278/4 "2020-09-25T12:33:30Z")

</div>

> [@pokoli](#):
>
> We could develop a new module that computes both formulas at sale line.  
> It will also be interesting to have this information available on document level.

What are the goals? Who is ready this information?  
Why does it have to be on the sale? All the information are already available on the stock moves.

> [@pokoli](#):
>
> Saving the current product cost\_price on the sale line

The cost price change over time so it is not a good idea.

> [@pokoli](#):
>
> Using the product\_cost\_history to retieve the product cost\_price at the date of the move

So why not use the cost price on the move?

> [@pokoli](#):
>
> I think we should also include the profit amount in the Sale Reporting

I do not think the reports should be mixed because it is not the same person that consults them.

---

<div class="post-metadata">

### Author: ![pokoli](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/pokoli/32/22_2.png) [@pokoli](https://discuss.tryton.org/u/pokoli)
#### Post date: [September 25, 2020, 12:53pm UTC](https://discuss.tryton.org/t/compute-margins/3278/5 "2020-09-25T12:53:33Z")

</div>

> [@ced](#):
>
> > [@pokoli](#):
> >
> > We could develop a new module that computes both formulas at sale line.
> > 
> > > It will also be interesting to have this information available on document level.
> 
> What are the goals? Who is ready this information?  
> Why does it have to be on the sale? All the information are already available on the stock moves.

Because this is not usefull just for reporting but also to create rules contrains. For example:

- Require the authorization of the sale manager if the estimated profit it’s lower that a threhold.
- Add a warning when confirming sale where it is expected to have a negative profit.

Which makes me think that aybe it should be interesting to compute the estimated profit vs the real one.

> [@ced](#):
>
> So why not use the cost price on the move?

Because I thought we should support also profit calculation for services.

> [@ced](#):
>
> > [@pokoli](#):
> >
> > I think we should also include the profit amount in the Sale Reporting
> 
> I do not think the reports should be mixed because it is not the same person that consults them.

I think is relevant to have profit in SaleReporting because it give full details about how the customer/product impacts the profits of the company and the objective of the company is to increase the profits 🤑.

For example having a product that has a big number of sales (or revenue) may not produce a big impact on the profits of the company. With this information in hand the company manager may decide the price of the product to increase it’s impact on the profit. Same applies other way arround, you have a product with a big percentage of margin but not so much sales. The company may decide to invest on marketing to increase the number of sales of this product which will produce a big impact on the sales

---

<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: [September 25, 2020, 2:10pm UTC](https://discuss.tryton.org/t/compute-margins/3278/6 "2020-09-25T14:10:19Z")

</div>

> [@pokoli](#):
>
> Because this is not usefull just for reporting but also to create rules contrains. For example:
> 
> - Require the authorization of the sale manager if the estimated profit it’s lower that a threhold.
> - Add a warning when confirming sale where it is expected to have a negative profit.

You do not need to store the value for such usage. It should be managed with a similar design of `sale_credit_limit`.  
And you will not base such constraint on the always changing cost price but instead put a lower limit on the sale price.

> [@pokoli](#):
>
> Because I thought we should support also profit calculation for services.

Not before having [New invoicing method when selling both goods and services - #6 by ced](https://discuss.tryton.org/t/new-invoicing-method-when-selling-both-goods-and-services/345/6)

> [@pokoli](#):
>
> I think is relevant to have profit in SaleReporting because it give full details about how the customer/product impacts the profits of the company and the objective of the company is to increase the profits 🤑.

But this is not the targets of the sale group that’s why for me it has nothing to do with sales.

---

<div class="post-metadata">

### Author: ![pokoli](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/pokoli/32/22_2.png) [@pokoli](https://discuss.tryton.org/u/pokoli)
#### Post date: [September 25, 2020, 2:22pm UTC](https://discuss.tryton.org/t/compute-margins/3278/7 "2020-09-25T14:22:24Z")

</div>

> [@ced](#):
>
> You do not need to store the value for such usage. It should be managed with a similar design of `sale_credit_limit` .  
> And you will not base such constraint on the always changing cost price but instead put a lower limit on the sale price.

So in this case you think we should use the product\_cost price at the moment of computing the sale to compute the expected profit of a sale?

> [@ced](#):
>
> > [@pokoli](#):
> >
> > I think is relevant to have profit in SaleReporting because it give full details about how the customer/product impacts the profits of the company and the objective of the company is to increase the profits 🤑.
> 
> But this is not the targets of the sale group that’s why for me it has nothing to do with sales.

I’m specially interested in this part. So if it does not have nothing with sales how do you propose to show such information to the company manager in Tryton?

---

<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: [September 25, 2020, 2:30pm UTC](https://discuss.tryton.org/t/compute-margins/3278/8 "2020-09-25T14:30:01Z")

</div>

> [@pokoli](#):
>
> So in this case you think we should use the product\_cost price at the moment of computing the sale to compute the expected profit of a sale?

No I think you do not need to compute the profit of the sale to have such control.

> [@pokoli](#):
>
> I’m specially interested in this part. So if it does not have nothing with sales how do you propose to show such information to the company manager in Tryton?

For me, this report is useful to the product administration group because they are those we setup the sale price (on the product or the price lists).  
The report should be based on the stock moves to provide an accurate and updated cost price and unit price. (_by the way a similar report could be on incoming move could be useful_).

---

<div class="post-metadata">

### Author: ![pokoli](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/pokoli/32/22_2.png) [@pokoli](https://discuss.tryton.org/u/pokoli)
#### Post date: [September 25, 2020, 2:41pm UTC](https://discuss.tryton.org/t/compute-margins/3278/9 "2020-09-25T14:41:02Z")

</div>

> [@ced](#):
>
> For me, this report is useful to the product administration group because they are those we setup the sale price (on the product or the price lists).

Sounds good to me.

> [@ced](#):
>
> _by the way a similar report could be on incoming move could be useful_

I do not understand why you say it could be usefull. Isn’t the unit\_price and the cost\_price of an incoming move aren’t the same?

---

<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: [September 25, 2020, 2:44pm UTC](https://discuss.tryton.org/t/compute-margins/3278/10 "2020-09-25T14:44:17Z")

</div>

> [@pokoli](#):
>
> I do not understand why you say it could be usefull. Isn’t the unit\_price and the cost\_price of an incoming move aren’t the same?

No the cost price is usually the average cost price so you can point which move deviate a lot from the average.

---

<div class="post-metadata">

### Author: ![pokoli](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/pokoli/32/22_2.png) [@pokoli](https://discuss.tryton.org/u/pokoli)
#### Post date: [September 25, 2020, 3:02pm UTC](https://discuss.tryton.org/t/compute-margins/3278/11 "2020-09-25T15:02:55Z")

</div>

> [@ced](#):
>
> No the cost price is usually the average cost price so you can point which move deviate a lot from the average.

I see but this is a report that should focus on the move detail. For product profit I think we should not dig into the detail by default but show a grouped report:

- Profit per Category
- Profit per Product

And follow the sale reporting pattern:

- Use a range of dates to filter moves
- Have an line to show the evolution of profit
- Allow to have subtotals of different periods (using time-series model)
- Include the number of moves
- Include the total amount (using quantity \* unit\_price)

I’m not sure if it will be good to have a filter by warehouse, is it too complex? Does it makes sense to allow to compare the profits of the different warehouses?

---

<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: [September 25, 2020, 3:07pm UTC](https://discuss.tryton.org/t/compute-margins/3278/12 "2020-09-25T15:07:30Z")

</div>

> [@pokoli](#):
>
> I’m not sure if it will be good to have a filter by warehouse, is it too complex?

Using `parent_of` on location should not be a performance problem thanks to the MPTT.

> [@pokoli](#):
>
> Does it makes sense to allow to compare the profits of the different warehouses?

Probably especially if we have [Add module to compute product cost per warehouse (#9312) · Issues · Tryton / Tryton · GitLab](https://bugs.tryton.org/issue9312)

---

<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 1, 2020, 4:58pm UTC](https://discuss.tryton.org/t/compute-margins/3278/13 "2020-10-01T16:58:35Z")

</div>

I started to work on an implementation based on stock move: [Add cost, revenue and margin reporting (#9665) · Issues · Tryton / Tryton · GitLab](https://bugs.tryton.org/issue9665)

---

<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 2, 2020, 9:49pm UTC](https://discuss.tryton.org/t/compute-margins/3278/14 "2020-10-02T21:49:38Z")

</div>

I have uploaded a first version to get early feedback.

---

<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 14, 2020, 2:31pm UTC](https://discuss.tryton.org/t/compute-margins/3278/15 "2020-10-14T14:31:26Z")

</div>

I’m thinking about including a contextual switch to include or not the cost of the product sent to lost&found over the period. This should be useful for product kind that expire (or who are damageable).

---

<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 1, 2021, 5:00pm UTC](https://discuss.tryton.org/t/compute-margins/3278/16 "2021-02-01T17:00:06Z")

</div>

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