Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[9.0][ADD] stock_inventory_exclude_sublocation #240

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions stock_inventory_exclude_sublocation/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3

===================================
Stock Inventory Exclude Sublocation
===================================

This module extends the functionality of Inventory Adjustment to allow you to
exclude all the sublocations when doing an inventory adjustment for a
given location.


Usage
=====

To use this module, you simply need to:

#. Create a new inventory adjustment.
#. Select the option inventory of all products.
#. Check the box "Exclude Sublocations".

.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/{repo_id}/{branch}


Known issues / Roadmap
======================

* Sometimes we just want to make an inventory adjustment of just one shelf, or
space and forget about extra subdivisions in the location.
* In other cases we do inventories of smaller locations contained in our stock,
so we don't want to count them again when doing an inventory adjustment of the
parent location. E.g. if we apply a cycle count strategy.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues
<https://github.com/OCA/{project_repo}/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smash it by providing detailed and welcomed feedback.

Credits
=======

Images
------

* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.

Contributors
------------

* Lois Rilo Antelo <[email protected]>


Maintainer
----------

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

This module is maintained by the OCA.

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

To contribute to this module, please visit https://odoo-community.org.
6 changes: 6 additions & 0 deletions stock_inventory_exclude_sublocation/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright 2016 Eficent Business and IT Consulting Services S.L.
# (http://www.eficent.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from . import models
21 changes: 21 additions & 0 deletions stock_inventory_exclude_sublocation/__openerp__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Eficent Business and IT Consulting Services S.L.
# (http://www.eficent.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
{
"name": "Stock Inventory Exclude Sublocation",
"summary": "Allow to perform inventories of a location without including "
"its child locations.",
"version": "9.0.1.0.0",
"author": "Eficent Business and IT Consulting Services S.L,"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace the long Eficent name with just Eficent

"Odoo Community Association (OCA)",
"website": "https://www.odoo-community.org",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"category": "Warehouse Management",
"depends": ["stock"],
"data": [
'views/stock_inventory_view.xml'
],
"license": "AGPL-3",
'installable': True,
'application': False,
}
6 changes: 6 additions & 0 deletions stock_inventory_exclude_sublocation/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright 2016 Eficent Business and IT Consulting Services S.L.
# (http://www.eficent.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from . import stock_inventory
60 changes: 60 additions & 0 deletions stock_inventory_exclude_sublocation/models/stock_inventory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# -*- coding: utf-8 -*-
# Copyright 2016 Eficent Business and IT Consulting Services S.L.
# (http://www.eficent.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from openerp import fields, models, api


class StockInventory(models.Model):
_inherit = 'stock.inventory'

exclude_sublocation = fields.Boolean(string='Exclude Sublocations',
default=False)

@api.model
def _get_location_ids(self, inventory):
location_obj = self.env['stock.location']
return location_obj.search([('id', '=',
[inventory.location_id.id])]).ids

@api.model
def _get_inventory_lines(self, inventory):
if inventory.exclude_sublocation:
product_obj = self.env['product.product']
location_ids = self._get_location_ids(inventory)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Omit this

domain = ' location_id in %s'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there's only one location, use:

domain = ' location_id = %s'
args = (inventory.location_id.id)

args = (tuple(location_ids),)
if inventory.partner_id:
domain += ' and owner_id = %s'
args += (inventory.partner_id.id,)
if inventory.lot_id:
domain += ' and lot_id = %s'
args += (inventory.lot_id.id,)
if inventory.product_id:
domain += ' and product_id = %s'
args += (inventory.product_id.id,)
if inventory.package_id:
domain += ' and package_id = %s'
args += (inventory.package_id.id,)

self.env.cr.execute('''
SELECT product_id, sum(qty) as product_qty, location_id, lot_id as prod_lot_id, package_id, owner_id as partner_id
FROM stock_quant WHERE''' + domain + '''
GROUP BY product_id, location_id, lot_id, package_id, partner_id
''', args)
vals = []
for product_line in self.env.cr.dictfetchall():
#replace the None the dictionary by False, because falsy values are tested later on
for key, value in product_line.items():
if not value:
product_line[key] = False
product_line['inventory_id'] = inventory.id
product_line['theoretical_qty'] = product_line['product_qty']
if product_line['product_id']:
product = product_obj.browse(product_line['product_id'])
product_line['product_uom_id'] = product.uom_id.id
vals.append(product_line)
return vals
else:
return super(StockInventory, self)._get_inventory_lines(inventory)
18 changes: 18 additions & 0 deletions stock_inventory_exclude_sublocation/views/stock_inventory_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!-- Copyright 2017 Eficent Business and IT Consulting Services S.L.
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->

<odoo>

<record id="view_inventory_form" model="ir.ui.view">
<field name="name">Inventory form view - cycle count extension </field>
<field name="model">stock.inventory</field>
<field name="inherit_id" ref="stock.view_inventory_form"/>
<field name="arch" type="xml">
<field name="filter" position="after">
<field name="exclude_sublocation"
attrs="{'invisible': [('filter', '!=', 'none')]}"/>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only hide if it's multiple

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The remaining option is to select only one product and the field to select the product is this (https://github.com/odoo/odoo/blob/9.0/addons/stock/stock_view.xml#L108). Since the domain is not affected by the location of the inventory adjustment I think that the "exclude sublocation" option is still not applicable.

</field>
</field>
</record>

</odoo>