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][ADD] mrp_bom_product_price_margin #1227

Open
wants to merge 1 commit into
base: 16.0
Choose a base branch
from
Open
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 mrp_bom_product_price_margin/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
============================
MRP BoM Product Price Margin
============================

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

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |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%2Fmanufacture-lightgray.png?logo=github
:target: https://github.com/OCA/manufacture/tree/16.0/mrp_bom_product_price_margin
:alt: OCA/manufacture
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/manufacture-16-0/manufacture-16-0-mrp_bom_product_price_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/manufacture&target_branch=16.0
:alt: Try me on Runboat

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

Help handling cost and sale price of product variant linked to bill of material.

**Table of contents**

.. contents::
:local:

Usage
=====

Set Product Variant in your Bill of Material.
Change BoM quantity or BoM lines quantity or price in one component.
See new panel to change Product Variant Standard Price.

.. figure:: https://raw.githubusercontent.com/OCA/manufacture/16.0/mrp_bom_product_price_margin/static/mrp_bom_product_price_margin_diff.png

.. figure:: https://raw.githubusercontent.com/OCA/manufacture/16.0/mrp_bom_product_price_margin/static/mrp_bom_product_price_margin_no_diff.png

In tree view, quickly see difference between Product standard price and BoM cost.
You can also change Product standard price here
Lines are red when Sale margin in negative.

.. figure:: https://raw.githubusercontent.com/OCA/manufacture/16.0/mrp_bom_product_price_margin/static/mrp_bom_product_price_margin_tree.png

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

Bugs are tracked on `GitHub Issues <https://github.com/OCA/manufacture/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/manufacture/issues/new?body=module:%20mrp_bom_product_price_margin%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
~~~~~~~

* GRAP

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

* Quentin Dupont ([email protected])

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/manufacture <https://github.com/OCA/manufacture/tree/16.0/mrp_bom_product_price_margin>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions mrp_bom_product_price_margin/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
22 changes: 22 additions & 0 deletions mrp_bom_product_price_margin/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright (C) 2022 - Today: GRAP (http://www.grap.coop)
# @author: Quentin Dupont ([email protected])
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

{
"name": "MRP BoM Product Price Margin",
"summary": "Handle Product Standard, Sale Price and Margin with its BoM cost",
"version": "16.0.1.0.0",
"category": "GRAP - Custom",
"author": "GRAP, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/manufacture",
"license": "AGPL-3",
"depends": [
"mrp",
# OCA modules
"product_standard_margin",
],
"data": [
"views/view_mrp_bom.xml",
],
"installable": True,
}
206 changes: 206 additions & 0 deletions mrp_bom_product_price_margin/i18n/fr.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * mrp_bom_product_price_margin
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-03-11 15:59+0000\n"
"PO-Revision-Date: 2024-03-11 15:59+0000\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: mrp_bom_product_price_margin
#: model_terms:ir.ui.view,arch_db:mrp_bom_product_price_margin.view_mrp_bom_sale_product_margin_form
msgid " (for 1x"
msgstr " (pour 1x"

#. module: mrp_bom_product_price_margin
#: model_terms:ir.ui.view,arch_db:mrp_bom_product_price_margin.view_mrp_bom_sale_product_margin_form
msgid "(margin"
msgstr "(marge"

#. module: mrp_bom_product_price_margin
#: model_terms:ir.ui.view,arch_db:mrp_bom_product_price_margin.view_mrp_bom_sale_product_margin_form
msgid "(margin:"
msgstr "(marge :"

#. module: mrp_bom_product_price_margin
#: model_terms:ir.ui.view,arch_db:mrp_bom_product_price_margin.view_mrp_bom_sale_product_margin_form
msgid ""
"<br/>\n"
" Product variant cost :"
msgstr ""
"<br/>\n"
" Coût du produit :"

#. module: mrp_bom_product_price_margin
#: model_terms:ir.ui.view,arch_db:mrp_bom_product_price_margin.view_mrp_bom_sale_product_margin_form
msgid ""
"<br/>\n"
" Product variant sale price:"
msgstr ""
"<br/>\n"
" Prix de vente du produit :"

#. module: mrp_bom_product_price_margin
#: model:ir.model,name:mrp_bom_product_price_margin.model_mrp_bom
msgid "Bill of Material"
msgstr "Nomenclature"

#. module: mrp_bom_product_price_margin
#: model:ir.model,name:mrp_bom_product_price_margin.model_mrp_bom_line
msgid "Bill of Material Line"
msgstr "Ligne de nomenclature"

#. module: mrp_bom_product_price_margin
#: model_terms:ir.ui.view,arch_db:mrp_bom_product_price_margin.view_mrp_bom_sale_product_margin_form
msgid "Bill of Material cost:"
msgstr "Coût de la nomenclature :"

#. module: mrp_bom_product_price_margin
#: model:ir.model.fields,field_description:mrp_bom_product_price_margin.field_mrp_bom__standard_price
#: model_terms:ir.ui.view,arch_db:mrp_bom_product_price_margin.view_mrp_bom_sale_product_margin_form
msgid "BoM Unit Cost"
msgstr "Coût unitaire"

#. module: mrp_bom_product_price_margin
#: model:ir.model.fields,help:mrp_bom_product_price_margin.field_mrp_bom__standard_price
msgid "Calculated with raw components cost divided by the BoM quantity."
msgstr ""
"Calculé à partir du coût des composants divisé par la quantité de la "
"nomenclature."

#. module: mrp_bom_product_price_margin
#: model:ir.model.fields,field_description:mrp_bom_product_price_margin.field_product_product__standard_price
msgid "Cost"
msgstr "Coût"

#. module: mrp_bom_product_price_margin
#: model:ir.model.fields,field_description:mrp_bom_product_price_margin.field_mrp_bom__currency_id
#: model:ir.model.fields,field_description:mrp_bom_product_price_margin.field_mrp_bom_line__currency_id
msgid "Currency"
msgstr ""

#. module: mrp_bom_product_price_margin
#: model_terms:ir.ui.view,arch_db:mrp_bom_product_price_margin.view_mrp_bom_tree
msgid "Diff BoM and Product"
msgstr ""

#. module: mrp_bom_product_price_margin
#: model:ir.model.fields,field_description:mrp_bom_product_price_margin.field_mrp_bom__diff_product_bom_standard_price
msgid "Diff Product Bom Standard Price"
msgstr ""

#. module: mrp_bom_product_price_margin
#: model:ir.model.fields,help:mrp_bom_product_price_margin.field_product_product__standard_price
msgid ""
"In Standard Price & AVCO: value of the product (automatically computed in AVCO).\n"
" In FIFO: value of the next unit that will leave the stock (automatically computed).\n"
" Used to value the product when the purchase cost is not known (e.g. inventory adjustment).\n"
" Used to compute margins on sale orders."
msgstr ""
"En prix standard en en coût moyen : valeur du produit (calculée automatiquement en coût moyen).\n"
" En FIFO : valeur de l'unité suivante qui quittera le stock (calculée automatiquement).\n"
" Utilisé pour évaluer le produit lorsque le coût d'achat n'est pas connu (par ex. ajustement de stock).\n"
" Utilisé pour calculer les marges sur les commandes."

#. module: mrp_bom_product_price_margin
#: model_terms:ir.ui.view,arch_db:mrp_bom_product_price_margin.view_mrp_bom_sale_product_margin_form
#: model_terms:ir.ui.view,arch_db:mrp_bom_product_price_margin.view_mrp_bom_tree
msgid "It will set product variant's standard price with this price"
msgstr "Cela définira le coût du Produit avec ce total."

#. module: mrp_bom_product_price_margin
#: model:ir.model.fields,help:mrp_bom_product_price_margin.field_mrp_bom__product_margin_rate
msgid ""
"Margin rate is [ Theorical Margin / sale price (Wo Tax) ] of the product "
"form (not based on historical values).Take care of tax include and exclude.."
" If no sale price set, will display 999.0"
msgstr ""

#. module: mrp_bom_product_price_margin
#: model:ir.model.fields,field_description:mrp_bom_product_price_margin.field_mrp_bom__product_margin_rate_percentage
msgid "Product Margin"
msgstr "Produit - Marge"

#. module: mrp_bom_product_price_margin
#: model:ir.model.fields,field_description:mrp_bom_product_price_margin.field_mrp_bom__product_sale_price
msgid "Product Sale Price"
msgstr "Produit - Prix de vente"

#. module: mrp_bom_product_price_margin
#: model:ir.model.fields,field_description:mrp_bom_product_price_margin.field_mrp_bom__product_standard_price
msgid "Product Standard Price"
msgstr "Produit - Coût"

#. module: mrp_bom_product_price_margin
#: model:ir.model,name:mrp_bom_product_price_margin.model_product_product
msgid "Product Variant"
msgstr "Variante de produit"

#. module: mrp_bom_product_price_margin
#: model_terms:ir.ui.view,arch_db:mrp_bom_product_price_margin.view_mrp_bom_sale_product_margin_form
msgid ""
"Product cost is based on this Bill of Material.<br/>\n"
" Product variant sale price:"
msgstr ""
"Le coût du Produit est basé sur cette Nomenclature.<br/>\n"
" Prix de vente du produit :"

#. module: mrp_bom_product_price_margin
#: model_terms:ir.ui.view,arch_db:mrp_bom_product_price_margin.view_mrp_bom_sale_product_margin_form
msgid "ST %"
msgstr ""

#. module: mrp_bom_product_price_margin
#: model:ir.model.fields,field_description:mrp_bom_product_price_margin.field_mrp_bom_line__standard_price_unit
msgid "Standard Price Unit"
msgstr "Prix unitaire"

#. module: mrp_bom_product_price_margin
#: model:ir.model.fields,field_description:mrp_bom_product_price_margin.field_mrp_bom_line__standard_price_subtotal
msgid "Subtotal price"
msgstr "Sous-total"

#. module: mrp_bom_product_price_margin
#: model:ir.model.fields,field_description:mrp_bom_product_price_margin.field_mrp_bom_line__standard_price_subtotal_percentage
msgid "Subtotal price %"
msgstr "Sous-total %"

#. module: mrp_bom_product_price_margin
#: model:ir.model.fields,help:mrp_bom_product_price_margin.field_mrp_bom__product_sale_price
msgid ""
"The sale price is managed from the product template. Click on the 'Configure"
" Variants' button to set the extra attribute prices."
msgstr ""

#. module: mrp_bom_product_price_margin
#: model:ir.model.fields,field_description:mrp_bom_product_price_margin.field_mrp_bom__product_margin_rate
msgid "Theorical Margin (%)"
msgstr "Marge théorique (%)"

#. module: mrp_bom_product_price_margin
#: model_terms:ir.ui.view,arch_db:mrp_bom_product_price_margin.view_mrp_bom_sale_product_margin_form
msgid "Total"
msgstr ""

#. module: mrp_bom_product_price_margin
#: model_terms:ir.ui.view,arch_db:mrp_bom_product_price_margin.view_mrp_bom_tree
msgid "Update Product standard price"
msgstr "Mettre à jour le coût du Produit"

#. module: mrp_bom_product_price_margin
#: model_terms:ir.ui.view,arch_db:mrp_bom_product_price_margin.view_mrp_bom_sale_product_margin_form
msgid "for 1x"
msgstr "pour 1x"

#. module: mrp_bom_product_price_margin
#: model_terms:ir.ui.view,arch_db:mrp_bom_product_price_margin.view_mrp_bom_sale_product_margin_form
msgid "⇙ Apply this cost to Product variant standard price"
msgstr "⇙ Définir le coût du Produit avec ce prix."
3 changes: 3 additions & 0 deletions mrp_bom_product_price_margin/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import mrp_bom
from . import mrp_bom_line
from . import product_product
69 changes: 69 additions & 0 deletions mrp_bom_product_price_margin/models/mrp_bom.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Copyright (C) 2022 - Today: GRAP (http://www.grap.coop)
# @author: Quentin DUPONT ([email protected])
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import api, fields, models
from odoo.tools.float_utils import float_round


class MrpBom(models.Model):
_inherit = "mrp.bom"

currency_id = fields.Many2one(related="product_tmpl_id.currency_id")

# Fields related to standard price
product_standard_price = fields.Float(compute="_compute_product_standard_price")
standard_price = fields.Float(
string="BoM Unit Cost",
tracking=True,
digits="Product Price",
compute="_compute_standard_price",
help="Calculated with raw components cost divided by the BoM quantity.",
)
diff_product_bom_standard_price = fields.Boolean(
default=False,
compute="_compute_diff_product_bom_standard_price",
)

# Fields related to sale price
product_sale_price = fields.Float(
string="Product Sale Price", related="product_id.lst_price"
)
product_margin_rate = fields.Float(related="product_id.standard_margin_rate")
product_margin_rate_percentage = fields.Float(
string="Product Margin", compute="_compute_product_margin_rate_percentage"
)

# Compute functions
@api.depends("product_id", "product_id.standard_price")
def _compute_product_standard_price(self):
for bom in self:
bom.product_standard_price = bom.product_id.standard_price

@api.depends("product_id", "bom_line_ids", "product_qty")
def _compute_standard_price(self):
for bom in self:
qty_to_divide = bom.product_qty if bom.product_qty != 0 else 1
bom.standard_price = (
sum(x.standard_price_subtotal for x in bom.bom_line_ids) / qty_to_divide
)

@api.depends("product_id.standard_price", "standard_price")
def _compute_diff_product_bom_standard_price(self):
price_dp = self.env["decimal.precision"].precision_get("Product Price")
for bom in self:
if bom.product_id:
diff = bom.product_id.standard_price - bom.standard_price
bom.diff_product_bom_standard_price = float_round(diff, price_dp)
else:
bom.diff_product_bom_standard_price = False

@api.depends("product_margin_rate")
def _compute_product_margin_rate_percentage(self):
for bom in self:
bom.product_margin_rate_percentage = bom.product_margin_rate / 100

Check warning on line 64 in mrp_bom_product_price_margin/models/mrp_bom.py

View check run for this annotation

Codecov / codecov/patch

mrp_bom_product_price_margin/models/mrp_bom.py#L64

Added line #L64 was not covered by tests

# Functions to change product fields
def set_product_standard_price(self):
for bom in self.filtered(lambda x: x.product_id):
bom.product_id.standard_price = bom.standard_price
Loading
Loading