Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
93 changes: 93 additions & 0 deletions sale_elaboration_margin/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
=======================
Sale Elaboration Margin
=======================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:d1ccb85319b0169184f5f38af878b21ccbd51523fcb38a3bf2a7a068bc26dc80
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |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/18.0/sale_elaboration_margin
: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-18-0/margin-analysis-18-0-sale_elaboration_margin
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/margin-analysis&target_branch=18.0
:alt: Try me on Runboat

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

This module extends the functionality of sale_elaboration module to
allow to display margin data from elaboration costs.

**Table of contents**

.. contents::
:local:

Usage
=====

1. Go to *Sale > Orders > Quotations*.
2. Create a sales order.
3. Add a new line.
4. Select an elaboration in the line.
5. Confirm the sales order.
6. Go to the picking created by this sales order and validate it.
7. Go back to the sales order. A new line is created with the product
linked to the elaboration.

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 to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/margin-analysis/issues/new?body=module:%20sale_elaboration_margin%0Aversion:%2018.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
- Pedro M. Baeza
- Carlos Roca

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.

This module is part of the `OCA/margin-analysis <https://github.com/OCA/margin-analysis/tree/18.0/sale_elaboration_margin>`_ 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_elaboration_margin/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from . import models
16 changes: 16 additions & 0 deletions sale_elaboration_margin/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2021 Tecnativa - Sergio Teruel
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Sale Elaboration Margin",
"summary": "Compute elaboration margins in sale orders lines",
"version": "18.0.1.0.0",
"development_status": "Production/Stable",
"category": "Sale",
"website": "https://github.com/OCA/margin-analysis",
"author": "Tecnativa, Odoo Community Association (OCA)",
"license": "AGPL-3",
"application": False,
"installable": True,
"depends": ["sale_elaboration"],
"data": ["views/sale_order_views.xml"],
}
38 changes: 38 additions & 0 deletions sale_elaboration_margin/i18n/es.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * sale_elaboration_margin
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 11.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-12-20 09:22+0000\n"
"PO-Revision-Date: 2019-12-20 10:23+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: nplurals=2; plural=(n != 1);\n"
"X-Generator: Poedit 2.0.6\n"

#. module: sale_elaboration_margin
#: model:ir.model.fields,field_description:sale_elaboration_margin.field_sale_order_line__elaboration_cost_price
msgid "Elaboration Cost"
msgstr "Coste elaboración"

#. module: sale_elaboration_margin
#: model:ir.model.fields,field_description:sale_elaboration_margin.field_sale_order_line__elaboration_margin
msgid "Elaboration Margin"
msgstr "Margen elaboración"

#. module: sale_elaboration_margin
#: model:ir.model.fields,field_description:sale_elaboration_margin.field_sale_order_line__elaboration_price
msgid "Elaboration Price"
msgstr "Precio elaboración"

#. module: sale_elaboration_margin
#: model:ir.model,name:sale_elaboration_margin.model_sale_order_line
msgid "Sales Order Line"
msgstr "Líneas de pedido"
34 changes: 34 additions & 0 deletions sale_elaboration_margin/i18n/sale_elaboration_margin.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * sale_elaboration_margin
#
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_elaboration_margin
#: model:ir.model.fields,field_description:sale_elaboration_margin.field_sale_order_line__elaboration_cost_price
msgid "Elaboration Cost"
msgstr ""

#. module: sale_elaboration_margin
#: model:ir.model.fields,field_description:sale_elaboration_margin.field_sale_order_line__elaboration_margin
msgid "Elaboration Margin"
msgstr ""

#. module: sale_elaboration_margin
#: model:ir.model.fields,field_description:sale_elaboration_margin.field_sale_order_line__elaboration_price
msgid "Elaboration Price"
msgstr ""

#. module: sale_elaboration_margin
#: model:ir.model,name:sale_elaboration_margin.model_sale_order_line
msgid "Sales Order Line"
msgstr ""
2 changes: 2 additions & 0 deletions sale_elaboration_margin/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from . import sale_order
71 changes: 71 additions & 0 deletions sale_elaboration_margin/models/sale_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Copyright 2021 Tecnativa - Sergio Teruel
# Copyright 2021 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import api, fields, models


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

elaboration_cost_price = fields.Float(
compute="_compute_elaboration_price",
store=True,
readonly=False,
string="Elaboration Cost",
digits="Product Price",
aggregator="avg",
)
elaboration_price = fields.Float(
compute="_compute_elaboration_price",
store=True,
readonly=False,
digits="Product Price",
aggregator="avg",
)
elaboration_margin = fields.Monetary(
compute="_compute_elaboration_margin",
currency_field="currency_id",
default=0.0,
)

@api.depends("elaboration_ids")
def _compute_elaboration_price(self):
for line in self:
if not line.elaboration_ids:
line.elaboration_cost_price = 0.0
line.elaboration_price = 0.0
elif line.order_id.pricelist_id and line.order_id.partner_id:
elaboration_price = 0
elaboration_cost_price = 0
for elaboration_product in line.elaboration_ids.product_id:
new_sol = self.env["sale.order.line"].new(
{
"order_id": line.order_id.id,
"product_id": elaboration_product.id,
"product_uom_qty": line.product_uom_qty,
"product_uom": line.product_uom.id,
"sequence": max(
line.order_id.order_line.mapped("sequence"), default=0
)
+ 1,
}
)
new_sol._compute_price_unit()
elaboration_price += self.env[
"account.tax"
]._fix_tax_included_price_company(
new_sol.price_unit,
elaboration_product.taxes_id,
line.tax_id,
line.company_id,
)
new_sol.order_id = False
elaboration_cost_price += elaboration_product.standard_price
line.elaboration_price = elaboration_price
line.elaboration_cost_price = elaboration_cost_price

def _compute_elaboration_margin(self):
for line in self:
line.elaboration_margin = (line.qty_delivered or line.product_uom_qty) * (
line.elaboration_price - line.elaboration_cost_price
)
3 changes: 3 additions & 0 deletions sale_elaboration_margin/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
4 changes: 4 additions & 0 deletions sale_elaboration_margin/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- [Tecnativa](https://www.tecnativa.com):
- Sergio Teruel
- Pedro M. Baeza
- Carlos Roca
2 changes: 2 additions & 0 deletions sale_elaboration_margin/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This module extends the functionality of sale_elaboration module to
allow to display margin data from elaboration costs.
8 changes: 8 additions & 0 deletions sale_elaboration_margin/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
1. Go to *Sale \> Orders \> Quotations*.
2. Create a sales order.
3. Add a new line.
4. Select an elaboration in the line.
5. Confirm the sales order.
6. Go to the picking created by this sales order and validate it.
7. Go back to the sales order. A new line is created with the product
linked to the elaboration.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading