Skip to content

Commit de30627

Browse files
committed
[ADD] add module product_cost_from_supplier_price
1 parent 4b77b0b commit de30627

File tree

15 files changed

+821
-0
lines changed

15 files changed

+821
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
================================
2+
Product Cost From Supplier Price
3+
================================
4+
5+
..
6+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
7+
!! This file is generated by oca-gen-addon-readme !!
8+
!! changes will be overwritten. !!
9+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10+
!! source digest: sha256:225b2cc7851a250ab17863722bc2c4454179a3cf09b9177e542f2e54ab053e44
11+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
12+
13+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
14+
:target: https://odoo-community.org/page/development-status
15+
:alt: Beta
16+
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
17+
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
18+
:alt: License: AGPL-3
19+
.. |badge3| image:: https://img.shields.io/badge/github-beescoop%2FObeesdoo-lightgray.png?logo=github
20+
:target: https://github.com/beescoop/Obeesdoo/tree/16.0/product_cost_from_supplier_price
21+
:alt: beescoop/Obeesdoo
22+
23+
|badge1| |badge2| |badge3|
24+
25+
Compute the product cost from the main supplier's price.
26+
27+
This module sets de cost (``standard_price``) field of products to the value of the main supplier's price.
28+
The main supplier is defined by the ``product_main_supplier`` module.
29+
30+
**Table of contents**
31+
32+
.. contents::
33+
:local:
34+
35+
Usage
36+
=====
37+
38+
To enable this feature, the costing method (``property_cost_method``) of the product's category should be set to "Standard Price (From Main Supplier's Price)" (``standard_from_main_supplier_price``).
39+
40+
As the supplier's price is defined per product (``product.template``) and not per variant (``product.product``), if a product has multiple variants, the cost is not updated.
41+
42+
Bug Tracker
43+
===========
44+
45+
Bugs are tracked on `GitHub Issues <https://github.com/beescoop/Obeesdoo/issues>`_.
46+
In case of trouble, please check there if your issue has already been reported.
47+
If you spotted it first, help us to smash it by providing a detailed and welcomed
48+
`feedback <https://github.com/beescoop/Obeesdoo/issues/new?body=module:%20product_cost_from_supplier_price%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
49+
50+
Do not contact contributors directly about support or help with technical issues.
51+
52+
Credits
53+
=======
54+
55+
Authors
56+
~~~~~~~
57+
58+
* Coop IT Easy SC
59+
60+
Contributors
61+
~~~~~~~~~~~~
62+
63+
* `Coop IT Easy SC <https://coopiteasy.be>`_:
64+
65+
* hugues de keyzer
66+
67+
Maintainers
68+
~~~~~~~~~~~
69+
70+
This module is part of the `beescoop/Obeesdoo <https://github.com/beescoop/Obeesdoo/tree/16.0/product_cost_from_supplier_price>`_ project on GitHub.
71+
72+
You are welcome to contribute.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# SPDX-FileCopyrightText: 2025 Coop IT Easy SC
2+
#
3+
# SPDX-License-Identifier: AGPL-3.0-or-later
4+
5+
from . import models
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# SPDX-FileCopyrightText: 2025 Coop IT Easy SC
2+
#
3+
# SPDX-License-Identifier: AGPL-3.0-or-later
4+
5+
{
6+
"name": "Product Cost From Supplier Price",
7+
"summary": "Compute the product cost from the main supplier's price",
8+
"version": "16.0.1.0.0",
9+
"category": "Sales/Sales",
10+
"website": "https://github.com/beescoop/Obeesdoo",
11+
"author": "Coop IT Easy SC",
12+
"maintainers": [],
13+
"license": "AGPL-3",
14+
"depends": [
15+
"product_main_supplier",
16+
"sale_stock",
17+
],
18+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# SPDX-FileCopyrightText: 2025 Coop IT Easy SC
2+
#
3+
# SPDX-License-Identifier: AGPL-3.0-or-later
4+
5+
from . import product_category
6+
from . import product_supplierinfo
7+
from . import product_template
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# SPDX-FileCopyrightText: 2025 Coop IT Easy SC
2+
#
3+
# SPDX-License-Identifier: AGPL-3.0-or-later
4+
5+
from odoo import fields, models
6+
7+
8+
class ProductCategory(models.Model):
9+
_inherit = "product.category"
10+
11+
property_cost_method = fields.Selection(
12+
selection_add=[
13+
(
14+
"standard_from_main_supplier_price",
15+
"Standard Price (From Main Supplier's Price)",
16+
),
17+
("fifo",),
18+
],
19+
ondelete={"standard_from_main_supplier_price": "set standard"},
20+
)
21+
22+
def write(self, vals):
23+
# same remark as in product.supplierinfo.write()
24+
need_compute_cost = (
25+
vals.get("property_cost_method") == "standard_from_main_supplier_price"
26+
)
27+
res = super().write(vals)
28+
if need_compute_cost:
29+
self.env["product.template"].search(
30+
[("categ_id", "=", self.id)]
31+
)._compute_cost_from_main_supplier_price()
32+
return res
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# SPDX-FileCopyrightText: 2025 Coop IT Easy SC
2+
#
3+
# SPDX-License-Identifier: AGPL-3.0-or-later
4+
5+
from odoo import models
6+
7+
8+
class ProductSupplierInfo(models.Model):
9+
_inherit = "product.supplierinfo"
10+
11+
def write(self, vals):
12+
# this has to be done here instead of setting a compute method on
13+
# product.product.standard_price because it is a company_dependent
14+
# field, which forces it to be computed by
15+
# Field._compute_company_dependent().
16+
price_in_vals = "price" in vals
17+
previous_main_supplier = self.product_tmpl_id.main_supplierinfo_id
18+
res = super().write(vals)
19+
product_template = self.product_tmpl_id
20+
current_main_supplier = product_template.main_supplierinfo_id
21+
if (
22+
current_main_supplier == self and price_in_vals
23+
) or previous_main_supplier != current_main_supplier:
24+
product_template._compute_cost_from_main_supplier_price()
25+
return res
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# SPDX-FileCopyrightText: 2025 Coop IT Easy SC
2+
#
3+
# SPDX-License-Identifier: AGPL-3.0-or-later
4+
5+
from odoo import models
6+
7+
8+
class ProductTemplate(models.Model):
9+
_inherit = "product.template"
10+
11+
def _compute_cost_from_main_supplier_price(self):
12+
for rec in self:
13+
if (
14+
rec.categ_id.property_cost_method != "standard_from_main_supplier_price"
15+
or rec.product_variant_count != 1
16+
):
17+
continue
18+
uom_factor = rec.uom_po_id.factor / rec.uom_id.factor
19+
rec.product_variant_id.standard_price = (
20+
rec.main_supplierinfo_id.price * uom_factor
21+
)
22+
23+
def write(self, vals):
24+
# same remark as in product.supplierinfo.write()
25+
need_compute_cost = "uom_po_id" in vals or "uom_id" in vals
26+
res = super().write(vals)
27+
if need_compute_cost:
28+
self._compute_cost_from_main_supplier_price()
29+
return res
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
* `Coop IT Easy SC <https://coopiteasy.be>`_:
2+
3+
* hugues de keyzer
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Compute the product cost from the main supplier's price.
2+
3+
This module sets de cost (``standard_price``) field of products to the value of the main supplier's price.
4+
The main supplier is defined by the ``product_main_supplier`` module.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
To enable this feature, the costing method (``property_cost_method``) of the product's category should be set to "Standard Price (From Main Supplier's Price)" (``standard_from_main_supplier_price``).
2+
3+
As the supplier's price is defined per product (``product.template``) and not per variant (``product.product``), if a product has multiple variants, the cost is not updated.

0 commit comments

Comments
 (0)