Skip to content

Commit

Permalink
[IMP] stock_cycle_count: Enable edit and cascade updates for responsi…
Browse files Browse the repository at this point in the history
…ble_id
  • Loading branch information
JoanSForgeFlow committed Jul 31, 2024
1 parent ed30876 commit d04fe77
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 8 deletions.
13 changes: 12 additions & 1 deletion stock_cycle_count/models/stock_cycle_count.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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:
Expand Down
20 changes: 20 additions & 0 deletions stock_cycle_count/models/stock_inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]})

Check warning on line 55 in stock_cycle_count/models/stock_inventory.py

View check run for this annotation

Codecov / codecov/patch

stock_cycle_count/models/stock_inventory.py#L55

Added line #L55 was not covered by tests
return result

def _update_cycle_state(self):
for inv in self:
Expand Down
11 changes: 4 additions & 7 deletions stock_cycle_count/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@

/*
:Author: David Goodger ([email protected])
: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.
Expand Down Expand Up @@ -275,7 +274,7 @@
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 }
Expand All @@ -301,7 +300,7 @@
span.pre {
white-space: pre }

span.problematic, pre.problematic {
span.problematic {
color: red }

span.section-subtitle {
Expand Down Expand Up @@ -514,9 +513,7 @@ <h2><a class="toc-backref" href="#toc-entry-13">Contributors</a></h2>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-14">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" />
</a>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<p>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.</p>
Expand Down
60 changes: 60 additions & 0 deletions stock_cycle_count/tests/test_stock_cycle_count.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,3 +570,63 @@ def test_prefill_counted_quantity(self):
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(

Check warning on line 602 in stock_cycle_count/tests/test_stock_cycle_count.py

View check run for this annotation

Codecov / codecov/patch

stock_cycle_count/tests/test_stock_cycle_count.py#L602

Added line #L602 was not covered by tests
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(

Check warning on line 616 in stock_cycle_count/tests/test_stock_cycle_count.py

View check run for this annotation

Codecov / codecov/patch

stock_cycle_count/tests/test_stock_cycle_count.py#L616

Added line #L616 was not covered by tests
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(

Check warning on line 628 in stock_cycle_count/tests/test_stock_cycle_count.py

View check run for this annotation

Codecov / codecov/patch

stock_cycle_count/tests/test_stock_cycle_count.py#L628

Added line #L628 was not covered by tests
quant.user_id.id,
additional_user_2.id,
"Quant user not updated after inventory responsible change.",
)

0 comments on commit d04fe77

Please sign in to comment.