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
7 changes: 2 additions & 5 deletions product_multi_company_stock/README.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
.. image:: https://odoo-community.org/readme-banner-image
:target: https://odoo-community.org/get-involved?utm_source=readme
:alt: Odoo Community Association

===========================
Product multi-company Stock
===========================
Expand All @@ -17,7 +13,7 @@ Product multi-company Stock
.. |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/license-AGPL--3-blue.png
.. |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%2Fmulti--company-lightgray.png?logo=github
Expand Down Expand Up @@ -62,6 +58,7 @@ Contributors
------------

- Joan Sisquella <joan.sisquella@forgeflow.com>
- Lois Rilo <lois.rilo@forgeflow.com>

Maintainers
-----------
Expand Down
1 change: 1 addition & 0 deletions product_multi_company_stock/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import product_template
from . import stock_lot
23 changes: 23 additions & 0 deletions product_multi_company_stock/models/stock_lot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2026 ForgeFlow S.L. (http://www.forgeflow.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from odoo import api, models


class StockLot(models.Model):
_inherit = "stock.lot"

@api.depends("product_id.company_id", "product_id.company_ids")
def _compute_company_id(self):
# For lots belonging to single-company products, defer to standard logic.
# For multi-company products, preserve the stored company_id so that a
# change to product.company_ids (e.g. adding a third company) never
# overwrites the lot's original company — which would cause _check_unique_lot
# to fire when two lots share the same name across different companies.
single_company_lots = self.filtered(
lambda rec: len(rec.product_id.sudo().company_ids) == 1
)
res = super(StockLot, single_company_lots)._compute_company_id()
for lot in self - single_company_lots:
lot.company_id = lot._origin.company_id or lot.product_id.company_id
return res
1 change: 1 addition & 0 deletions product_multi_company_stock/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
- Joan Sisquella \<joan.sisquella@forgeflow.com\>
- Lois Rilo \<lois.rilo@forgeflow.com\>
25 changes: 10 additions & 15 deletions product_multi_company_stock/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils: https://docutils.sourceforge.io/" />
<title>README.rst</title>
<title>Product multi-company Stock</title>
<style type="text/css">

/*
Expand Down Expand Up @@ -360,21 +360,16 @@
</style>
</head>
<body>
<div class="document">
<div class="document" id="product-multi-company-stock">
<h1 class="title">Product multi-company Stock</h1>


<a class="reference external image-reference" href="https://odoo-community.org/get-involved?utm_source=readme">
<img alt="Odoo Community Association" src="https://odoo-community.org/readme-banner-image" />
</a>
<div class="section" id="product-multi-company-stock">
<h1>Product multi-company Stock</h1>
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:c2890e80eee5fd642560a3ae22c4f14c520e904ef34406ceb5e2f3c938d111d8
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/license-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/multi-company/tree/18.0/product_multi_company_stock"><img alt="OCA/multi-company" src="https://img.shields.io/badge/github-OCA%2Fmulti--company-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/multi-company-18-0/multi-company-18-0-product_multi_company_stock"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/multi-company&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/multi-company/tree/18.0/product_multi_company_stock"><img alt="OCA/multi-company" src="https://img.shields.io/badge/github-OCA%2Fmulti--company-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/multi-company-18-0/multi-company-18-0-product_multi_company_stock"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/multi-company&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This modules does not allow to remove a company from company_ids if
there is stock or moves in that company</p>
<p><strong>Table of contents</strong></p>
Expand All @@ -390,29 +385,30 @@ <h1>Product multi-company Stock</h1>
</ul>
</div>
<div class="section" id="bug-tracker">
<h2><a class="toc-backref" href="#toc-entry-1">Bug Tracker</a></h2>
<h1><a class="toc-backref" href="#toc-entry-1">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/multi-company/issues">GitHub Issues</a>.
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
<a class="reference external" href="https://github.com/OCA/multi-company/issues/new?body=module:%20product_multi_company_stock%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
<h2><a class="toc-backref" href="#toc-entry-2">Credits</a></h2>
<h1><a class="toc-backref" href="#toc-entry-2">Credits</a></h1>
<div class="section" id="authors">
<h3><a class="toc-backref" href="#toc-entry-3">Authors</a></h3>
<h2><a class="toc-backref" href="#toc-entry-3">Authors</a></h2>
<ul class="simple">
<li>ForgeFlow</li>
</ul>
</div>
<div class="section" id="contributors">
<h3><a class="toc-backref" href="#toc-entry-4">Contributors</a></h3>
<h2><a class="toc-backref" href="#toc-entry-4">Contributors</a></h2>
<ul class="simple">
<li>Joan Sisquella &lt;<a class="reference external" href="mailto:joan.sisquella&#64;forgeflow.com">joan.sisquella&#64;forgeflow.com</a>&gt;</li>
<li>Lois Rilo &lt;<a class="reference external" href="mailto:lois.rilo&#64;forgeflow.com">lois.rilo&#64;forgeflow.com</a>&gt;</li>
</ul>
</div>
<div class="section" id="maintainers">
<h3><a class="toc-backref" href="#toc-entry-5">Maintainers</a></h3>
<h2><a class="toc-backref" href="#toc-entry-5">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
Expand All @@ -425,6 +421,5 @@ <h3><a class="toc-backref" href="#toc-entry-5">Maintainers</a></h3>
</div>
</div>
</div>
</div>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Copyright 2025 ForgeFlow S.L.
# (http://www.forgeflow.com)
# Copyright 2025-26 ForgeFlow S.L. (http://www.forgeflow.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from odoo.exceptions import UserError
Expand Down Expand Up @@ -116,3 +115,46 @@ def test_remove_company_with_quants_or_moves_archived_product(self):
with self.assertRaises(UserError) as error_move:
product.write({"company_ids": [(6, 0, [self.company_2.id])]})
self.assertIn("stock moves", str(error_move.exception))

def test_add_company_does_not_break_same_name_lots(self):
"""Adding a company to a product must not affect existing lots.

Adding a new company to a product's company_ids triggers a
recompute of stock.lot.company_id (which depends on product_id.company_id).
should not change lots company.
"""
product = self.env["product.product"].create(
{
"name": "Test Tracked Product",
"is_storable": True,
"tracking": "lot",
"company_ids": [(6, 0, [self.company_1.id, self.company_2.id])],
}
)
company_3 = self.company_obj.create({"name": "Test company 3"})
lot_1 = (
self.env["stock.lot"]
.with_company(self.company_1)
.create(
{
"name": "LOT001",
"product_id": product.id,
"company_id": self.company_1.id,
}
)
)
lot_2 = (
self.env["stock.lot"]
.with_company(self.company_2)
.create(
{
"name": "LOT001",
"product_id": product.id,
"company_id": self.company_2.id,
}
)
)
# Adding a third company should neither raise nor alter the lot companies.
product.write({"company_ids": [(4, company_3.id)]})
self.assertEqual(lot_1.company_id, self.company_1)
self.assertEqual(lot_2.company_id, self.company_2)
Loading