Skip to content

Commit

Permalink
[FIX] stock_inventory
Browse files Browse the repository at this point in the history
Allow to create stock.quants making the quants smart button not invisible when quantity is equal to 0. (Removing one of the invisible conditions).
  • Loading branch information
DavidJForgeFlow committed Apr 12, 2024
1 parent c135d9b commit ee2ee48
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
9 changes: 6 additions & 3 deletions stock_inventory/models/stock_inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ def _get_domain_category_quants(self, base_domain):
]
)

def refresh_stock_quant_ids(self):
for rec in self:
rec.stock_quant_ids = rec._get_quants(rec.location_ids)

def action_state_to_in_progress(self):
active_rec = self.env["stock.inventory"].search(
[
Expand All @@ -164,7 +168,7 @@ def action_state_to_in_progress(self):
% active_rec.name
)
self.state = "in_progress"
self.stock_quant_ids = self._get_quants(self.location_ids)
self.refresh_stock_quant_ids()
self.stock_quant_ids.update({"to_do": True})
return

Expand All @@ -181,8 +185,7 @@ def action_state_to_draft(self):

def action_view_inventory_adjustment(self):
result = self.env["stock.quant"].action_view_inventory()
ia_ids = self.mapped("stock_quant_ids").ids
result["domain"] = [("id", "in", ia_ids)]
result["domain"] = [("id", "in", self.stock_quant_ids.ids)]
result["search_view_id"] = self.env.ref("stock.quant_search_view").id
result["context"]["search_default_to_do"] = 1
return result
Expand Down
13 changes: 12 additions & 1 deletion stock_inventory/models/stock_quant.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from odoo import _, fields, models
from odoo import _, api, fields, models


class StockQuant(models.Model):
Expand Down Expand Up @@ -42,3 +42,14 @@ def _apply_inventory(self):

def _get_inventory_fields_write(self):
return super()._get_inventory_fields_write() + ["to_do"]

@api.model
def create(self, vals):
res = super().create(vals)
if self.env.context.get(
"active_model", False
) == "stock.inventory" and self.env.context.get("active_id", False):
self.env["stock.inventory"].browse(
self.env.context.get("active_id")
).refresh_stock_quant_ids()
return res
2 changes: 1 addition & 1 deletion stock_inventory/views/stock_inventory.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
name="action_view_inventory_adjustment"
class="oe_stat_button"
icon="fa-pencil-square-o"
attrs="{'invisible':['|', ('state', 'in', ['draft', 'done']), ('count_stock_quants', '=', 0)]}"
attrs="{'invisible':[('state', 'in', ['draft', 'done'])]}"
>
<field
name="count_stock_quants_string"
Expand Down

0 comments on commit ee2ee48

Please sign in to comment.