[9.0][IMP] stock_inventory_exclude_sublocaton: track visibility and only editable in draft state

This commit is contained in:
lreficent
2017-07-04 10:31:31 +02:00
committed by joan
parent 21a30e4ff7
commit c89870e9de
4 changed files with 21 additions and 16 deletions

View File

@@ -6,12 +6,12 @@
"name": "Stock Inventory Exclude Sublocation", "name": "Stock Inventory Exclude Sublocation",
"summary": "Allow to perform inventories of a location without including " "summary": "Allow to perform inventories of a location without including "
"its child locations.", "its child locations.",
"version": "9.0.1.0.0", "version": "9.0.1.0.1",
"author": "Eficent," "author": "Eficent,"
"Odoo Community Association (OCA)", "Odoo Community Association (OCA)",
"website": "https://github.com/OCA/stock-logistics-warehouse", "website": "https://github.com/OCA/stock-logistics-warehouse",
"category": "Warehouse Management", "category": "Warehouse Management",
"depends": ["stock"], "depends": ["stock", "stock_inventory_chatter"],
"data": [ "data": [
'views/stock_inventory_view.xml' 'views/stock_inventory_view.xml'
], ],

View File

@@ -3,21 +3,26 @@
# (http://www.eficent.com) # (http://www.eficent.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from openerp import fields, models, api from openerp import api, fields, models
class StockInventory(models.Model): class StockInventory(models.Model):
_inherit = 'stock.inventory' _inherit = 'stock.inventory'
exclude_sublocation = fields.Boolean(string='Exclude Sublocations', exclude_sublocation = fields.Boolean(
default=False) string='Exclude Sublocations', default=False,
track_visibility='onchange', readonly=True,
states={'draft': [('readonly', False)]})
@api.model @api.model
def _get_inventory_lines(self, inventory): def _get_inventory_lines(self, inventory):
if inventory.exclude_sublocation: if inventory.exclude_sublocation:
product_obj = self.env['product.product'] product_obj = self.env['product.product']
domain = ' location_id = %s' domain = ' location_id = %s'
args = (tuple(inventory.location_id.ids)) args = (tuple(inventory.location_id.ids),)
if inventory.company_id.id:
domain += ' and company_id = %s'
args += (inventory.company_id.id,)
if inventory.partner_id: if inventory.partner_id:
domain += ' and owner_id = %s' domain += ' and owner_id = %s'
args += (inventory.partner_id.id,) args += (inventory.partner_id.id,)

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

View File

@@ -3,10 +3,10 @@
# (http://www.eficent.com) # (http://www.eficent.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
import openerp.tests.common as common from openerp.tests.common import TransactionCase
class TestStockInventoryExcludeSublocation(common.TransactionCase): class TestStockInventoryExcludeSublocation(TransactionCase):
def setUp(self): def setUp(self):
super(TestStockInventoryExcludeSublocation, self).setUp() super(TestStockInventoryExcludeSublocation, self).setUp()
@@ -100,8 +100,8 @@ class TestStockInventoryExcludeSublocation(common.TransactionCase):
return inventory return inventory
def test_not_excluding_sublocations(self): def test_not_excluding_sublocations(self):
'''Check if products in sublocations are included into the inventory """Check if products in sublocations are included into the inventory
if the excluding sublocations option is disabled.''' if the excluding sublocations option is disabled."""
inventory_location = self._create_inventory_all_products( inventory_location = self._create_inventory_all_products(
'location inventory', self.location, False) 'location inventory', self.location, False)
inventory_location.prepare_inventory() inventory_location.prepare_inventory()
@@ -111,8 +111,8 @@ class TestStockInventoryExcludeSublocation(common.TransactionCase):
'included') 'included')
def test_excluding_sublocations(self): def test_excluding_sublocations(self):
'''Check if products in sublocations are not included if the exclude """Check if products in sublocations are not included if the exclude
sublocations is enabled.''' sublocations is enabled."""
inventory_location = self._create_inventory_all_products( inventory_location = self._create_inventory_all_products(
'location inventory', self.location, True) 'location inventory', self.location, True)
inventory_sublocation = self._create_inventory_all_products( inventory_sublocation = self._create_inventory_all_products(
@@ -129,7 +129,7 @@ class TestStockInventoryExcludeSublocation(common.TransactionCase):
'The products in the sublocations are not excluded') 'The products in the sublocations are not excluded')
def test_lot_excluding_sublocation(self): def test_lot_excluding_sublocation(self):
'''Check if the sublocations are excluded when using lots.''' """Check if the sublocations are excluded when using lots."""
inventory = self.inventory_model.sudo(self.user.id).create({ inventory = self.inventory_model.sudo(self.user.id).create({
'name': 'Inventory lot', 'name': 'Inventory lot',
'filter': 'lot', 'filter': 'lot',
@@ -144,8 +144,8 @@ class TestStockInventoryExcludeSublocation(common.TransactionCase):
'not excluded with lots.') 'not excluded with lots.')
def test_product_and_owner_excluding_sublocation(self): def test_product_and_owner_excluding_sublocation(self):
'''Check if sublocations are excluded when filtering by owner and """Check if sublocations are excluded when filtering by owner and
product.''' product."""
self.quant_model.create({ self.quant_model.create({
'product_id': self.product1.id, 'product_id': self.product1.id,
'location_id': self.location.id, 'location_id': self.location.id,
@@ -167,7 +167,7 @@ class TestStockInventoryExcludeSublocation(common.TransactionCase):
'not excluded with product and owner filter.') 'not excluded with product and owner filter.')
def test_pack_excluding_sublocation(self): def test_pack_excluding_sublocation(self):
'''Check if sublocations are excluded when filtering by package.''' """Check if sublocations are excluded when filtering by package."""
self.quant_model.create({ self.quant_model.create({
'product_id': self.product1.id, 'product_id': self.product1.id,
'location_id': self.location.id, 'location_id': self.location.id,