mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
[IMP] Add domain filter
This commit is contained in:
committed by
Ivàn Todorovich
parent
e013825249
commit
c6ddad4872
@@ -28,6 +28,7 @@ Extended Inventory Preparation Filters
|
||||
Includes more options for making an inventory out of:
|
||||
|
||||
* Multiple products.
|
||||
* Products filtered by a domain.
|
||||
* Products of a category.
|
||||
* Multiple lots
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
from odoo import _, api, fields, models
|
||||
from odoo.addons import decimal_precision as dp
|
||||
from odoo.tools.safe_eval import safe_eval
|
||||
|
||||
|
||||
class StockInventoryEmptyLines(models.Model):
|
||||
@@ -41,6 +42,7 @@ class StockInventory(models.Model):
|
||||
res_filters = super(StockInventory, self)._selection_filter()
|
||||
res_filters.append(('categories', _('Selected Categories')))
|
||||
res_filters.append(('products', _('Selected Products')))
|
||||
res_filters.append(('domain', _('Filtered Products')))
|
||||
for res_filter in res_filters:
|
||||
if res_filter[0] == 'lot':
|
||||
res_filters.append(('lots', _('Selected Lots')))
|
||||
@@ -60,6 +62,7 @@ class StockInventory(models.Model):
|
||||
empty_line_ids = fields.One2many(
|
||||
comodel_name='stock.inventory.line.empty', inverse_name='inventory_id',
|
||||
string='Capture Lines')
|
||||
product_domain = fields.Char('Domain', default=[('name', 'ilike', '')])
|
||||
|
||||
@api.model
|
||||
def _get_inventory_lines_values(self):
|
||||
@@ -85,6 +88,14 @@ class StockInventory(models.Model):
|
||||
inventory.lot_id = lot
|
||||
vals += super(StockInventory,
|
||||
inventory)._get_inventory_lines_values()
|
||||
elif self.filter == 'domain':
|
||||
domain = safe_eval(self.product_domain)
|
||||
products = self.env['product.product'].search(domain)
|
||||
inventory.filter = 'product'
|
||||
for product in products:
|
||||
inventory.product_id = product
|
||||
vals += super(
|
||||
StockInventory, inventory)._get_inventory_lines_values()
|
||||
elif self.filter == 'empty':
|
||||
tmp_lines = {}
|
||||
for line in self.empty_line_ids:
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
Includes more options for making an inventory out of:
|
||||
|
||||
* Multiple products.
|
||||
* Products filtered by a domain.
|
||||
* Products of a category.
|
||||
* Multiple lots
|
||||
|
||||
|
||||
@@ -371,6 +371,7 @@ ul.auto-toc {
|
||||
<p>Includes more options for making an inventory out of:</p>
|
||||
<ul class="simple">
|
||||
<li>Multiple products.</li>
|
||||
<li>Products filtered by a domain.</li>
|
||||
<li>Products of a category.</li>
|
||||
<li>Multiple lots</li>
|
||||
</ul>
|
||||
|
||||
@@ -121,6 +121,20 @@ class TestStockInventoryPreparationFilterCategories(common.TransactionCase):
|
||||
self.assertEqual(line2.theoretical_qty, 4.0)
|
||||
self.assertEqual(line2.location_id, self.location)
|
||||
|
||||
def test_inventory_domain_filter(self):
|
||||
inventory = self.inventory_model.create({
|
||||
'name': 'Domain inventory',
|
||||
'filter': 'domain',
|
||||
'location_id': self.location.id,
|
||||
'product_domain': [('id', '=', self.product1.id)],
|
||||
})
|
||||
inventory.action_start()
|
||||
self.assertEqual(len(inventory.line_ids), 1)
|
||||
line1 = inventory.line_ids[0]
|
||||
self.assertEqual(line1.product_id, self.product1)
|
||||
self.assertEqual(line1.theoretical_qty, 2.0)
|
||||
self.assertEqual(line1.location_id, self.location)
|
||||
|
||||
def test_inventory_lots_filter(self):
|
||||
inventory = self.inventory_model.create(
|
||||
{
|
||||
|
||||
@@ -27,6 +27,9 @@
|
||||
<field name="lot_ids"
|
||||
attrs="{'invisible':[('filter','!=','lots')]}" />
|
||||
</field>
|
||||
<notebook position="before">
|
||||
<field name="product_domain" widget="domain" attrs="{'invisible': [('filter', '!=', 'domain')]}" options="{'model': 'product.product'}"/>
|
||||
</notebook>
|
||||
<notebook position="inside">
|
||||
<page string="Capture Lines"
|
||||
attrs="{'invisible':[('filter','!=','empty')]}">
|
||||
|
||||
Reference in New Issue
Block a user