diff --git a/stock_cycle_count/models/stock_cycle_count.py b/stock_cycle_count/models/stock_cycle_count.py
index 843a41b97..d1b4b243e 100644
--- a/stock_cycle_count/models/stock_cycle_count.py
+++ b/stock_cycle_count/models/stock_cycle_count.py
@@ -27,7 +27,7 @@ class StockCycleCount(models.Model):
comodel_name="res.users",
string="Assigned to",
readonly=True,
- states={"draft": [("readonly", False)]},
+ states={"draft": [("readonly", False)], "open": [("readonly", False)]},
tracking=True,
)
date_deadline = fields.Date(
@@ -84,6 +84,17 @@ class StockCycleCount(models.Model):
readonly=True,
)
+ def write(self, vals):
+ result = super().write(vals)
+ if "responsible_id" in vals and not self.env.context.get("no_propagate"):
+ stock_inventory_records = self.mapped("stock_adjustment_ids")
+ for record in stock_inventory_records:
+ if record.responsible_id.id != vals["responsible_id"]:
+ record.with_context(no_propagate=True).write(
+ {"responsible_id": vals["responsible_id"]}
+ )
+ return result
+
@api.depends("stock_adjustment_ids")
def _compute_inventory_adj_count(self):
for rec in self:
diff --git a/stock_cycle_count/models/stock_inventory.py b/stock_cycle_count/models/stock_inventory.py
index 7a6026776..74fabd2d0 100644
--- a/stock_cycle_count/models/stock_inventory.py
+++ b/stock_cycle_count/models/stock_inventory.py
@@ -34,6 +34,26 @@ class StockInventory(models.Model):
group_operator="avg",
default=False,
)
+ responsible_id = fields.Many2one(
+ states={"draft": [("readonly", False)], "in_progress": [("readonly", False)]},
+ tracking=True,
+ )
+
+ def write(self, vals):
+ result = super().write(vals)
+ if "responsible_id" in vals:
+ if not self.env.context.get("no_propagate"):
+ if (
+ self.cycle_count_id
+ and self.cycle_count_id.responsible_id.id != vals["responsible_id"]
+ ):
+ self.cycle_count_id.with_context(no_propagate=True).write(
+ {"responsible_id": vals["responsible_id"]}
+ )
+ for quant in self.mapped("stock_quant_ids"):
+ if quant.user_id.id != vals["responsible_id"]:
+ quant.write({"user_id": vals["responsible_id"]})
+ return result
def _update_cycle_state(self):
for inv in self:
diff --git a/stock_cycle_count/static/description/index.html b/stock_cycle_count/static/description/index.html
index 17edd7396..7cf0ee64c 100644
--- a/stock_cycle_count/static/description/index.html
+++ b/stock_cycle_count/static/description/index.html
@@ -8,11 +8,10 @@
/*
:Author: David Goodger (goodger@python.org)
-:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
+:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
:Copyright: This stylesheet has been placed in the public domain.
Default cascading style sheet for the HTML output of Docutils.
-Despite the name, some widely supported CSS2 features are used.
See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
customize this style sheet.
@@ -275,7 +274,7 @@ pre.literal-block, pre.doctest-block, pre.math, pre.code {
margin-left: 2em ;
margin-right: 2em }
-pre.code .ln { color: gray; } /* line numbers */
+pre.code .ln { color: grey; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
@@ -301,7 +300,7 @@ span.option {
span.pre {
white-space: pre }
-span.problematic, pre.problematic {
+span.problematic {
color: red }
span.section-subtitle {
@@ -514,9 +513,7 @@ If you spotted it first, help us to smash it by providing a detailed and welcome
This module is maintained by the OCA.
-
-
-
+
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.
diff --git a/stock_cycle_count/tests/test_stock_cycle_count.py b/stock_cycle_count/tests/test_stock_cycle_count.py
index 575465842..b671ae31a 100644
--- a/stock_cycle_count/tests/test_stock_cycle_count.py
+++ b/stock_cycle_count/tests/test_stock_cycle_count.py
@@ -570,3 +570,63 @@ class TestStockCycleCount(common.TransactionCase):
adjustment_2.action_state_to_in_progress()
# Check that the inventory_quantity is 0
self.assertEqual(quant_2.inventory_quantity, 0.0)
+
+ def test_responsible_id_propagation_with_inventory_adjustment(self):
+ additional_user = self._create_user(
+ "user_3", [self.g_stock_manager], self.company
+ )
+ additional_user_2 = self._create_user(
+ "user_4", [self.g_stock_manager], self.company
+ )
+ self.cycle_count_1.responsible_id = self.manager
+ self.assertEqual(
+ self.cycle_count_1.responsible_id.id,
+ self.manager,
+ "Initial responsible not correctly assigned.",
+ )
+ self.quant_model.create(
+ {
+ "product_id": self.product1.id,
+ "location_id": self.count_loc.id,
+ "quantity": 100,
+ }
+ )
+ self.cycle_count_1.action_create_inventory_adjustment()
+ inventory = self.cycle_count_1.stock_adjustment_ids[0]
+ self.assertEqual(
+ inventory.responsible_id.id,
+ self.cycle_count_1.responsible_id.id,
+ "Inventory responsible does not match cycle count responsible.",
+ )
+ for quant in inventory.stock_quant_ids:
+ self.assertEqual(
+ quant.user_id.id,
+ inventory.responsible_id.id,
+ "Quant user does not match inventory responsible.",
+ )
+ self.cycle_count_1.responsible_id = additional_user.id
+ inventory.invalidate_cache()
+ self.cycle_count_1.stock_adjustment_ids[0].stock_quant_ids.invalidate_cache()
+ self.assertEqual(
+ inventory.responsible_id.id,
+ additional_user.id,
+ "Inventory responsible not updated after cycle count responsible change.",
+ )
+ for quant in inventory.stock_quant_ids:
+ self.assertEqual(
+ quant.user_id.id,
+ additional_user.id,
+ "Quant user not updated after inventory responsible change.",
+ )
+ inventory.responsible_id = additional_user_2
+ self.assertEqual(
+ self.cycle_count_1.responsible_id.id,
+ additional_user_2.id,
+ "Cycle Count not updated after inventory responsible change.",
+ )
+ for quant in inventory.stock_quant_ids:
+ self.assertEqual(
+ quant.user_id.id,
+ additional_user_2.id,
+ "Quant user not updated after inventory responsible change.",
+ )