stock_usability: inventory: set default location via filter on location
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
# @author Alexis de Lattre <alexis.delattre@akretion.com>
|
# @author Alexis de Lattre <alexis.delattre@akretion.com>
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
from odoo import fields, models
|
from odoo import api, fields, models
|
||||||
|
|
||||||
|
|
||||||
class StockQuant(models.Model):
|
class StockQuant(models.Model):
|
||||||
@@ -27,3 +27,14 @@ class StockQuant(models.Model):
|
|||||||
]
|
]
|
||||||
action['context'] = {'create': 0}
|
action['context'] = {'create': 0}
|
||||||
return action
|
return action
|
||||||
|
|
||||||
|
@api.model
|
||||||
|
def default_get(self, fields_list):
|
||||||
|
res = super().default_get(fields_list)
|
||||||
|
if (
|
||||||
|
not res.get('location_id') and
|
||||||
|
self._context.get('search_location') and
|
||||||
|
isinstance(self._context['search_location'], list) and
|
||||||
|
len(self._context['search_location']) == 1):
|
||||||
|
res['location_id'] = self._context['search_location'][0]
|
||||||
|
return res
|
||||||
|
|||||||
@@ -51,6 +51,20 @@
|
|||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
|
<record id="quant_search_view" model="ir.ui.view">
|
||||||
|
<field name="model">stock.quant</field>
|
||||||
|
<field name="inherit_id" ref="stock.quant_search_view"/>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<!-- With the context set via the field location_id
|
||||||
|
odoo will set default_location_id to [self]
|
||||||
|
So, to make it work, we also inherit default_get
|
||||||
|
to convert from list of 1 ID to an ID -->
|
||||||
|
<field name="location_id" position="attributes">
|
||||||
|
<attribute name="context">{'search_location': self}</attribute>
|
||||||
|
</field>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
<record id="view_stock_quant_tree_editable" model="ir.ui.view">
|
<record id="view_stock_quant_tree_editable" model="ir.ui.view">
|
||||||
<field name="model">stock.quant</field>
|
<field name="model">stock.quant</field>
|
||||||
|
|||||||
Reference in New Issue
Block a user