[IMP] stock: merge two wizards into one

This commit merge the wizards asking for a inventory name and the one
warning the user not all quant have been set.

Task : 2555118

Part-of: odoo/odoo#74715
This commit is contained in:
William Henrotin
2021-09-02 12:57:32 +00:00
parent 79ee1ae3d2
commit 8f12dbc00f
6 changed files with 27 additions and 37 deletions
-13
View File
@@ -307,19 +307,6 @@ class StockQuant(models.Model):
# for some reason if multi-record, env.context doesn't pass to wizards...
ctx = dict(self.env.context or {})
ctx['default_quant_ids'] = self.ids
quants_not_entered = self.filtered(lambda quant: not quant.inventory_quantity_set)
if quants_not_entered:
view = self.env.ref('stock.inventory_warning_apply_view', False)
return {
'name': _('Quantities Not Entered'),
'type': 'ir.actions.act_window',
'view_mode': 'form',
'views': [(view.id, 'form')],
'view_id': view.id,
'res_model': 'stock.inventory.warning',
'target': 'new',
'context': ctx,
}
quants_outdated = self.filtered(lambda quant: quant.is_outdated)
if quants_outdated:
ctx['default_quant_to_fix_ids'] = quants_outdated.ids
+12 -1
View File
@@ -343,7 +343,6 @@
<tree default_order="location_id, inventory_date, product_id, package_id, lot_id, owner_id" decoration-warning='is_outdated' editable="bottom" create="1" edit="1" import="1" js_class="singleton_list" sample="1">
<header>
<button name="stock.action_stock_inventory_adjustement_name" groups="stock.group_stock_manager" type="action" string="Apply"/>
<button name="action_set_inventory_quantity" type="object" string="Set"/>
<button name="action_reset" type="object" string="Clear"/>
<button name="stock.action_stock_request_count" groups="stock.group_stock_manager" type="action" string="Request a Count"/>
</header>
@@ -376,6 +375,18 @@
</field>
</record>
<record model="ir.actions.server" id="action_view_set_quants_tree">
<field name="name">Set</field>
<field name="model_id" ref="model_stock_quant"/>
<field name="binding_model_id" ref="stock.model_stock_quant"/>
<field name="binding_view_types">list</field>
<field name="state">code</field>
<field name="groups_id" eval="[(4, ref('stock.group_stock_user'))]"/>
<field name="code">
action = records.action_set_inventory_quantity()
</field>
</record>
<record model="ir.actions.server" id="action_view_inventory_tree"> <!-- Menu + python -->
<field name="name">Inventory</field>
<field name="model_id" ref="model_stock_quant"/>
@@ -6,13 +6,21 @@ from odoo import fields, models, _
class StockInventoryAdjustmentName(models.TransientModel):
_name = 'stock.inventory.adjustment.name'
_description = 'Inventory Adjustment Name'
_description = 'Inventory Adjustment Reference / Reason'
def default_get(self, fields_list):
res = super().default_get(fields_list)
if self.env.context.get('default_quant_ids'):
quants = self.env['stock.quant'].browse(self.env.context['default_quant_ids'])
res['show_info'] = any(not quant.inventory_quantity_set for quant in quants)
return res
def _default_inventory_adjustment_name(self):
return _("Inventory Adjustment") + " - " + fields.Date.to_string(fields.Date.today())
quant_ids = fields.Many2many('stock.quant')
inventory_adjustment_name = fields.Char(default=_default_inventory_adjustment_name)
show_info = fields.Boolean('Show warning')
def action_apply(self):
return self.quant_ids.with_context(
@@ -7,8 +7,12 @@
<field name="arch" type="xml">
<form>
<div>
<div attrs="{'invisible': [('show_info', '=', False)]}">
Some selected lines don't have any quantities set, they will be ignored.
</div>
<group>
<field name="inventory_adjustment_name" string="Inventory Reference"/>
<field name="inventory_adjustment_name" string="Inventory Reference / Reason"/>
<field name="show_info" invisible="1"/>
</group>
</div>
<footer>
@@ -19,7 +23,7 @@
</field>
</record>
<record id="action_stock_inventory_adjustement_name" model="ir.actions.act_window">
<field name="name">Name Inventory Adjustement</field>
<field name="name">Inventory Adjustment Reference / Reason</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">stock.inventory.adjustment.name</field>
<field name="view_mode">form</field>
@@ -10,9 +10,6 @@ class StockInventoryWarning(models.TransientModel):
quant_ids = fields.Many2many('stock.quant')
def action_apply(self):
return self.quant_ids.filtered(lambda q: q.inventory_quantity_set).action_apply_inventory()
def action_reset(self):
return self.quant_ids.action_set_inventory_quantity_to_zero()
@@ -33,21 +33,4 @@
</form>
</field>
</record>
<record id="inventory_warning_apply_view" model="ir.ui.view">
<field name="name">inventory.apply.warning.view</field>
<field name="model">stock.inventory.warning</field>
<field name="mode">primary</field>
<field name="arch" type="xml">
<form>
<div>
Some selected lines don't have any quantities set, they will be ignored.
</div>
<footer>
<button name="action_apply" string="Continue" type="object" class="btn-primary" data-hotkey="q"/>
<button name="cancel_button" string="Discard" class="btn-secondary" special="cancel" data-hotkey="z"/>
</footer>
</form>
</field>
</record>
</odoo>