Skip to content

Commit

Permalink
[IMP] display quant button even if there wasn't any to allow creating…
Browse files Browse the repository at this point in the history
… new quants during the inventory
  • Loading branch information
benwillig committed Jul 17, 2024
1 parent 9e22ce7 commit 037988e
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 18 deletions.
5 changes: 5 additions & 0 deletions stock_inventory/i18n/fr.po
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ msgstr "Société"
msgid "Config Settings"
msgstr ""

#. module: stock_inventory
#: model:ir.model.fields,field_description:stock_inventory.field_stock_inventory__auto_create_missing_quants
msgid "Create missing quants"
msgstr "Créer les quants manquants"

#. module: stock_inventory
#: model:ir.model.fields,field_description:stock_inventory.field_stock_inventory__create_uid
msgid "Created by"
Expand Down
5 changes: 5 additions & 0 deletions stock_inventory/i18n/stock_inventory.pot
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ msgstr ""
msgid "Config Settings"
msgstr ""

#. module: stock_inventory
#: model:ir.model.fields,field_description:stock_inventory.field_stock_inventory__auto_create_missing_quants
msgid "Create missing quants"
msgstr ""

#. module: stock_inventory
#: model:ir.model.fields,field_description:stock_inventory.field_stock_inventory__create_uid
msgid "Created by"
Expand Down
2 changes: 0 additions & 2 deletions stock_inventory/models/res_company.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ class ResCompany(models.Model):
stock_inventory_auto_complete = fields.Boolean(
help="If enabled, when all the quants prepared for the adjustment "
"are done, the adjustment is automatically set to done.",
default=False,
)
stock_inventory_auto_create_missing_quants = fields.Boolean(
help="If enabled, missing quants will be created on the inventory confirmation",
default=False,
)
4 changes: 2 additions & 2 deletions stock_inventory/models/stock_inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ class InventoryAdjustmentsGroup(models.Model):
string="Create missing quants",
readonly=True,
states=READONLY_STATES,
default=False,
)

@api.depends("stock_quant_ids")
Expand Down Expand Up @@ -413,6 +412,7 @@ def action_view_inventory_adjustment(self):
{
"search_default_to_do": 1,
"inventory_id": self.id,
"default_stock_inventory_ids": [(4, self.id)],
"default_to_do": True,
"default_user_id": self.env.user.id,
}
Expand Down Expand Up @@ -567,7 +567,7 @@ def _get_new_quant_base_values(self, product, **kwargs):
self.ensure_one()
values = {
"product_id": product.id,
"user_id": self.env.user.id,
"user_id": self.responsible_id.id or self.env.user.id,
"stock_inventory_ids": [(4, self.id)],
}
values.update(kwargs)
Expand Down
39 changes: 25 additions & 14 deletions stock_inventory/models/stock_quant.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from odoo import fields, models
from odoo import api, fields, models


class StockQuant(models.Model):
_inherit = "stock.quant"

to_do = fields.Boolean(default=False)
virtual_in_progress_inventory_id = fields.Many2one(
comodel_name="stock.inventory",
compute="_compute_virtual_in_progress_inventory_id",
Expand All @@ -15,20 +16,17 @@ class StockQuant(models.Model):
)

def _compute_virtual_in_progress_inventory_id(self):
Inventory = self.env["stock.inventory"]
locations = self.mapped("location_id")
inventories = self.env["stock.inventory"].search(
self._get_virtual_in_progress_inventory_domain(locations),
limit=1,
)
for rec in self:
rec.virtual_in_progress_inventory_id = Inventory.search(
[
("state", "=", "in_progress"),
"|",
"&",
("exclude_sublocation", "=", False),
("location_ids", "parent_of", rec.location_id.ids),
"&",
("exclude_sublocation", "=", True),
("location_ids", "in", rec.location_id.ids),
],
limit=1,
filtered_inventories = inventories.filtered_domain(
self._get_virtual_in_progress_inventory_domain(rec.location_id)
)
rec.virtual_in_progress_inventory_id = (
filtered_inventories[0] if filtered_inventories else False
)

def _apply_inventory(self):
Expand Down Expand Up @@ -87,3 +85,16 @@ def _get_inventory_move_values(self, qty, location_id, location_dest_id, out=Fal

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

@api.model
def _get_virtual_in_progress_inventory_domain(self, locations):
return [
("state", "=", "in_progress"),
"|",
"&",
("exclude_sublocation", "=", False),
("location_ids", "parent_of", locations.ids),
"&",
("exclude_sublocation", "=", True),
("location_ids", "in", locations.ids),
]
11 changes: 11 additions & 0 deletions stock_inventory/views/stock_quant.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
<odoo>
<record model="ir.ui.view" id="view_stock_quant_tree_inventory_editable">
<field name="name">stock.quant.tree stock inventory</field>
<field name="model">stock.quant</field>
<field name="inherit_id" ref="stock.view_stock_quant_tree_inventory_editable" />
<field name="arch" type="xml">
<xpath expr="//field[@name='company_id']" position="after">
<field name="to_do" invisible="1" />
<field name="stock_inventory_ids" invisible="1" />
</xpath>
</field>
</record>
<record id="view_stock_quant_search_not_done" model="ir.ui.view">
<field name="name">stock.quant.search.not.done</field>
<field name="model">stock.quant</field>
Expand Down

0 comments on commit 037988e

Please sign in to comment.