[IMP] stock_cycle_count: Enable edit and cascade updates for responsible_id

This commit is contained in:
Joan Sisquella
2024-07-31 11:32:47 +02:00
committed by ArnauCForgeFlow
parent c5fd916a69
commit 2e7a818aa3
4 changed files with 96 additions and 8 deletions

View File

@@ -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:

View File

@@ -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:

View File

@@ -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
<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>

View File

@@ -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.",
)