Skip to content

Commit

Permalink
Merge PR #183 into 16.0
Browse files Browse the repository at this point in the history
Signed-off-by pedrobaeza
  • Loading branch information
OCA-git-bot committed Sep 15, 2023
2 parents 9d79abc + febd948 commit 1c1083f
Show file tree
Hide file tree
Showing 29 changed files with 1,077 additions and 0 deletions.
115 changes: 115 additions & 0 deletions sale_margin_delivered/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
=====================
Sale Margin Delivered
=====================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Production%2FStable-green.png
:target: https://odoo-community.org/page/development-status
:alt: Production/Stable
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fmargin--analysis-lightgray.png?logo=github
:target: https://github.com/OCA/margin-analysis/tree/16.0/sale_margin_delivered
:alt: OCA/margin-analysis
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/margin-analysis-16-0/margin-analysis-16-0-sale_margin_delivered
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/webui/builds.html?repo=OCA/margin-analysis&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

Computes sale order lines margins for the delivered items.

**Table of contents**

.. contents::
:local:

Configuration
=============

To grant Sales Margin view privileges to a user, go to *Settings > Users &
Companies > Users*, select the user and set *Show Sale Margin* on.

Usage
=====

#. Go to *Sales > Orders > Quotations*.
#. Create a new *Sales Order* and add a line with an stockable product. Set a
quantity higher than one.
#. Confirm the *Sales Order* and deliver just a partial amount of product in
the picking.
#. Go to *Sales > Reporting > Sales* and unfold the *Order Reference* dimension
and the *Margin* and *Margin Delivered* to compare them.

For example:

In an order line with a product at a cost of 10 and a sell price of 25 we
deliver 2 of 3 units. Then, the reported margins would be:

`margin`: 45 (3 * 15)
`margin_delivered`: 30 (2 * 15)

Additionally, you can check the margin and the margin percent in the sales
order line.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/margin-analysis/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/margin-analysis/issues/new?body=module:%20sale_margin_delivered%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
~~~~~~~

* Tecnativa

Contributors
~~~~~~~~~~~~


* `Tecnativa <https://www.tecnativa.com>`_:

* Sergio Teruel
* David Vidal
* Carlos Roca
* Pilar Vargas

Maintainers
~~~~~~~~~~~

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

.. |maintainer-sergio-teruel| image:: https://github.com/sergio-teruel.png?size=40px
:target: https://github.com/sergio-teruel
:alt: sergio-teruel

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-sergio-teruel|

This module is part of the `OCA/margin-analysis <https://github.com/OCA/margin-analysis/tree/16.0/sale_margin_delivered>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 2 additions & 0 deletions sale_margin_delivered/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import models
from . import reports
15 changes: 15 additions & 0 deletions sale_margin_delivered/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2018 Tecnativa - Sergio Teruel
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Sale Margin Delivered",
"version": "16.0.1.0.0",
"author": "Tecnativa, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/margin-analysis",
"category": "Sales",
"license": "AGPL-3",
"depends": ["sale_stock", "sale_margin"],
"data": ["views/sale_margin_delivered_view.xml"],
"installable": True,
"development_status": "Production/Stable",
"maintainers": ["sergio-teruel"],
}
65 changes: 65 additions & 0 deletions sale_margin_delivered/i18n/es.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * sale_margin_delivered
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 11.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-12-09 08:52+0000\n"
"PO-Revision-Date: 2019-12-09 09:55+0100\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"Language: es\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: \n"
"X-Generator: Poedit 2.0.6\n"

#. module: sale_margin_delivered
#: model_terms:ir.ui.view,arch_db:sale_margin_delivered.view_order_form
msgid "% Margin"
msgstr "% Margen"

#. module: sale_margin_delivered
#: model_terms:ir.ui.view,arch_db:sale_margin_delivered.view_order_form
msgid "Cost Price dlvd."
msgstr "Coste de lo entregado."

#. module: sale_margin_delivered
#: model_terms:ir.ui.view,arch_db:sale_margin_delivered.view_order_form
msgid "Margin"
msgstr "Margen"

#. module: sale_margin_delivered
#: model:ir.model.fields,field_description:sale_margin_delivered.field_sale_order_line__margin_delivered
#: model:ir.model.fields,field_description:sale_margin_delivered.field_sale_report__margin_delivered
msgid "Margin Delivered"
msgstr "Margen de lo entregado"

#. module: sale_margin_delivered
#: model:ir.model.fields,field_description:sale_margin_delivered.field_sale_order_line__margin_delivered_percent
msgid "Margin Delivered Percent"
msgstr "Porcentage de margen de lo entregado"

#. module: sale_margin_delivered
#: model_terms:ir.ui.view,arch_db:sale_margin_delivered.view_order_form
msgid "Margin dlvd."
msgstr "Margen entr."

#. module: sale_margin_delivered
#: model:ir.model.fields,field_description:sale_margin_delivered.field_sale_order_line__purchase_price_delivery
msgid "Purchase Price Delivered"
msgstr "Precio de compra de lo entregado"

#. module: sale_margin_delivered
#: model:ir.model,name:sale_margin_delivered.model_sale_report
msgid "Sales Analysis Report"
msgstr "Análisis de ventas"

#. module: sale_margin_delivered
#: model:ir.model,name:sale_margin_delivered.model_sale_order_line
msgid "Sales Order Line"
msgstr "Línea de pedido de ventas"

55 changes: 55 additions & 0 deletions sale_margin_delivered/i18n/sale_margin_delivered.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * sale_margin_delivered
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 15.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: sale_margin_delivered
#: model_terms:ir.ui.view,arch_db:sale_margin_delivered.view_order_form
msgid "% Margin"
msgstr ""

#. module: sale_margin_delivered
#: model_terms:ir.ui.view,arch_db:sale_margin_delivered.view_order_form
msgid "Cost Price dlvd."
msgstr ""

#. module: sale_margin_delivered
#: model:ir.model.fields,field_description:sale_margin_delivered.field_sale_order_line__margin_delivered
#: model:ir.model.fields,field_description:sale_margin_delivered.field_sale_report__margin_delivered
msgid "Margin Delivered"
msgstr ""

#. module: sale_margin_delivered
#: model:ir.model.fields,field_description:sale_margin_delivered.field_sale_order_line__margin_delivered_percent
msgid "Margin Delivered Percent"
msgstr ""

#. module: sale_margin_delivered
#: model_terms:ir.ui.view,arch_db:sale_margin_delivered.view_order_form
msgid "Margin dlvd."
msgstr ""

#. module: sale_margin_delivered
#: model:ir.model.fields,field_description:sale_margin_delivered.field_sale_order_line__purchase_price_delivery
msgid "Purchase Price Delivery"
msgstr ""

#. module: sale_margin_delivered
#: model:ir.model,name:sale_margin_delivered.model_sale_report
msgid "Sales Analysis Report"
msgstr ""

#. module: sale_margin_delivered
#: model:ir.model,name:sale_margin_delivered.model_sale_order_line
msgid "Sales Order Line"
msgstr ""
16 changes: 16 additions & 0 deletions sale_margin_delivered/migrations/16.0.1.0.0/post-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2023 Tecnativa - Pilar Vargas
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from openupgradelib import openupgrade


@openupgrade.migrate()
def migrate(env, version):
sale_margin_delivered_security = env["ir.module.module"].search(
[
("name", "=", "sale_margin_delivered_security"),
("state", "=", "uninstalled"),
]
)
if sale_margin_delivered_security:
sale_margin_delivered_security.state = "to install"
1 change: 1 addition & 0 deletions sale_margin_delivered/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import sale_margin
75 changes: 75 additions & 0 deletions sale_margin_delivered/models/sale_margin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Copyright 2018 Tecnativa - Sergio Teruel
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, fields, models, tools


class SaleOrderLine(models.Model):
_inherit = "sale.order.line"

margin_delivered = fields.Float(compute="_compute_margin_delivered", store=True)
margin_delivered_percent = fields.Float(
compute="_compute_margin_delivered",
store=True,
readonly=True,
)
purchase_price_delivery = fields.Float(
compute="_compute_margin_delivered",
store=True,
)

@api.depends(
"margin",
"qty_delivered",
"product_uom_qty",
"move_ids.stock_valuation_layer_ids.unit_cost",
)
def _compute_margin_delivered(self):
digits = self.env["decimal.precision"].precision_get("Product Price")
self.margin_delivered = 0.0
self.margin_delivered_percent = 0.0
self.purchase_price_delivery = 0.0
for line in self.filtered("qty_delivered"):
if line.product_id.type != "product":
currency = line.order_id.pricelist_id.currency_id
price = line.purchase_price
line.margin_delivered = currency.round(
line.price_subtotal - (price * line.qty_delivered)
)
line.purchase_price_delivery = price
continue
else:
cost_price = 0.0
moves = line.move_ids.filtered(
lambda x: (
x.state == "done"
and (
x.picking_code == "outgoing"
or (x.picking_code == "incoming" and x.to_refund)
)
)
)
for move in moves:
# In v12.0 price unit was negative for incomming moves, in
# v13.0 price unit is positive in stock valuation layer model
cost = move.stock_valuation_layer_ids[:1].unit_cost
if move.to_refund:
cost = -cost
cost_price += move.product_qty * cost
average_price = (
abs(cost_price) / line.qty_delivered
) or line.purchase_price
line.purchase_price_delivery = tools.float_round(
average_price, precision_digits=digits
)
line.margin_delivered = line.qty_delivered * (
line.price_reduce - line.purchase_price_delivery
)
# compute percent margin based on delivered quantities or ordered
# quantities
if line.price_reduce:
line.margin_delivered_percent = (
(line.price_reduce - line.purchase_price_delivery)
/ line.price_reduce
* 100.0
)
2 changes: 2 additions & 0 deletions sale_margin_delivered/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
To grant Sales Margin view privileges to a user, go to *Settings > Users &
Companies > Users*, select the user and set *Show Sale Margin* on.
7 changes: 7 additions & 0 deletions sale_margin_delivered/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

* `Tecnativa <https://www.tecnativa.com>`_:

* Sergio Teruel
* David Vidal
* Carlos Roca
* Pilar Vargas
1 change: 1 addition & 0 deletions sale_margin_delivered/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Computes sale order lines margins for the delivered items.
18 changes: 18 additions & 0 deletions sale_margin_delivered/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#. Go to *Sales > Orders > Quotations*.
#. Create a new *Sales Order* and add a line with an stockable product. Set a
quantity higher than one.
#. Confirm the *Sales Order* and deliver just a partial amount of product in
the picking.
#. Go to *Sales > Reporting > Sales* and unfold the *Order Reference* dimension
and the *Margin* and *Margin Delivered* to compare them.

For example:

In an order line with a product at a cost of 10 and a sell price of 25 we
deliver 2 of 3 units. Then, the reported margins would be:

`margin`: 45 (3 * 15)
`margin_delivered`: 30 (2 * 15)

Additionally, you can check the margin and the margin percent in the sales
order line.
1 change: 1 addition & 0 deletions sale_margin_delivered/reports/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import sale_report
Loading

0 comments on commit 1c1083f

Please sign in to comment.