Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][MIG] sale_margin_delivered: Migration to 16.0 #183

Merged
merged 19 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
f9dda20
[ADD] sale_margin_delivered: New Module
chienandalu Jul 9, 2018
ea49bde
[IMP] sale_margin_delivered: Add new computed field for better contro…
sergio-teruel Nov 13, 2018
8d367a3
[11.0][FIX] sale_margin_delivered: Set % delivered percent to 0.0 if …
sergio-teruel Jan 14, 2019
d5a82cb
[11.0][FIX] sale_margin_delivered: Fix cost price unit from stock mov…
sergio-teruel Apr 15, 2019
6e2fa18
[11.0][IMP] sale_margin_delivered: take an account returned moves
sergio-teruel Apr 16, 2019
6a19b0a
[11.0][IMP] sale_margin_delivered: Compute avoid use product_uom_qty …
sergio-teruel Apr 17, 2019
eefdbc2
[IMP] stock_picking_comment_template: Change field label to fix travi…
sergio-teruel Dec 3, 2019
ce8d756
[IMP] sale_margin_delivered: black, isort
sergio-teruel Feb 24, 2020
50dad73
[MIG] sale_margin_delivered: Migration to v13.0
sergio-teruel Feb 24, 2020
c8614d4
[FIX] sale_margin_delivered: Fix compute avco from stock valuation la…
sergio-teruel Sep 18, 2020
dc13a79
[FIX] sale_margin_delivered: Fix cache miss error.
sergio-teruel Sep 22, 2020
cd27202
[FIX] sale_margin_delivered: Fix division by zero if no price_reduce
sergio-teruel Sep 22, 2020
6091a1a
[FIX] sale_margin_delivered: Delivered values not zero when sale line…
carlosdauden Oct 8, 2020
036585b
[FIX] sale_margin_delivered: Use Form in tests to avoid crash test du…
sergio-teruel Sep 6, 2021
2e56707
[MIG] sale_margin_delivered: Migration to 15.0
CarlosRoca13 Nov 7, 2022
3f31d53
[FIX] sale_margin_delivered: non storable
chienandalu Jan 3, 2022
ce6e408
[MIG] sale_margin_delivered: Migration to 16.0
pilarvargas-tecnativa Sep 12, 2023
2fecd69
[REF] split sale_margin_delivered into sale_margin_delivered and sale…
legalsylvain Sep 13, 2023
febd948
[OU-ADD] sale_margin_delivered: Script to install sale_margin_deliver…
pilarvargas-tecnativa Sep 14, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(

Check warning on line 36 in sale_margin_delivered/models/sale_margin.py

View check run for this annotation

Codecov / codecov/patch

sale_margin_delivered/models/sale_margin.py#L34-L36

Added lines #L34 - L36 were not covered by tests
line.price_subtotal - (price * line.qty_delivered)
)
line.purchase_price_delivery = price
continue

Check warning on line 40 in sale_margin_delivered/models/sale_margin.py

View check run for this annotation

Codecov / codecov/patch

sale_margin_delivered/models/sale_margin.py#L39-L40

Added lines #L39 - L40 were not covered by tests
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
Loading