Skip to content

Commit

Permalink
[14.0][ADD] product_inventoriable module
Browse files Browse the repository at this point in the history
  • Loading branch information
chafique-delli committed Nov 2, 2023
1 parent 6fb5e3d commit c64ad28
Show file tree
Hide file tree
Showing 12 changed files with 208 additions and 0 deletions.
57 changes: 57 additions & 0 deletions product_inventoriable/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
=====================
Product Inventoriable
=====================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-akretion%2Fak--odoo--incubator-lightgray.png?logo=github
:target: https://github.com/akretion/ak-odoo-incubator/tree/14.0/product_inventoriable
:alt: akretion/ak-odoo-incubator

|badge1| |badge2| |badge3|

This module allows to define if a product can be inventoried or not.

**Table of contents**

.. contents::
:local:

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

Bugs are tracked on `GitHub Issues <https://github.com/akretion/ak-odoo-incubator/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/akretion/ak-odoo-incubator/issues/new?body=module:%20product_inventoriable%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
~~~~~~~

* Akretion

Contributors
~~~~~~~~~~~~

* Chafique Delli <chafique.delli@akretion.com>

Maintainers
~~~~~~~~~~~

This module is part of the `akretion/ak-odoo-incubator <https://github.com/akretion/ak-odoo-incubator/tree/14.0/product_inventoriable>`_ project on GitHub.

You are welcome to contribute.
3 changes: 3 additions & 0 deletions product_inventoriable/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from . import models
14 changes: 14 additions & 0 deletions product_inventoriable/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

{
"name": "Product Inventoriable",
"author": "Akretion,Odoo Community Association (OCA)",
"website": "https://github.com/akretion/ak-odoo-incubator",
"license": "AGPL-3",
"category": "Product",
"version": "14.0.1.0.0",
"depends": ["stock"],
"data": [
"views/product_view.xml",
],
}
4 changes: 4 additions & 0 deletions product_inventoriable/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import product_template
from . import stock_inventory
from . import stock_quant
9 changes: 9 additions & 0 deletions product_inventoriable/models/product_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import fields, models


class ProductTemplate(models.Model):
_inherit = "product.template"

to_inventory = fields.Boolean("To inventory", default=True)
22 changes: 22 additions & 0 deletions product_inventoriable/models/stock_inventory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import fields, models


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

product_ids = fields.Many2many(
domain="[('type', '=', 'product'), ('to_inventory', '=', True),"
" '|', ('company_id', '=', False), ('company_id', '=', company_id)]"
)

def action_open_inventory_lines(self):
action = super().action_open_inventory_lines()
action["domain"].append(("product_id.to_inventory", "=", True))
return action

def _get_quantities(self):
return super(
StockInventory, self.with_context(stock_inventory=True)
)._get_quantities()
23 changes: 23 additions & 0 deletions product_inventoriable/models/stock_quant.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import api, models


class StockQuant(models.Model):
_inherit = "stock.quant"

@api.model
def read_group(
self, domain, fields, groupby, offset=0, limit=None, orderby=False, lazy=True
):
if self.env.context.get("stock_inventory", False):
domain.append(("product_id.to_inventory", "=", True))
return super().read_group(
domain=domain,
fields=fields,
groupby=groupby,
offset=offset,
limit=limit,
orderby=orderby,
lazy=lazy,
)
1 change: 1 addition & 0 deletions product_inventoriable/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_product_inventoriable
32 changes: 32 additions & 0 deletions product_inventoriable/tests/test_product_inventoriable.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo.tests.common import SavepointCase


class TestProductProduct(SavepointCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.product_product_4 = cls.env.ref("product.product_product_4")

def _create_inventory_lines(self):
inventory = self.env["stock.inventory"].create(
{
"name": "test inventory",
}
)
inventory.action_start()
inventory_lines = inventory.line_ids.filtered(
lambda l: l.product_id == self.product_product_4
)
return inventory_lines

def test_product_to_inventory(self):
self.product_product_4.write({"to_inventory": True})
inventory_lines = self._create_inventory_lines()
self.assertEqual(len(inventory_lines), 1)

def test_product_not_to_inventory(self):
self.product_product_4.write({"to_inventory": False})
inventory_lines = self._create_inventory_lines()
self.assertEqual(len(inventory_lines), 0)
36 changes: 36 additions & 0 deletions product_inventoriable/views/product_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<odoo>

<record id="product_template_form_view" model="ir.ui.view">
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_form_view" />
<field name="arch" type="xml">
<xpath expr="//div[@name='options']" position="inside">
<div>
<field name="to_inventory" />
<label for="to_inventory" />
</div>
</xpath>
</field>
</record>

<record id="view_stock_product_template_tree" model="ir.ui.view">
<field name="model">product.template</field>
<field name="inherit_id" ref="stock.view_stock_product_template_tree" />
<field name="arch" type="xml">
<xpath expr="//field[@name='virtual_available']" position="after">
<field name="to_inventory" optional="show" />
</xpath>
</field>
</record>

<record id="view_stock_product_tree" model="ir.ui.view">
<field name="model">product.product</field>
<field name="inherit_id" ref="stock.view_stock_product_tree" />
<field name="arch" type="xml">
<xpath expr="//field[@name='virtual_available']" position="after">
<field name="to_inventory" optional="show" />
</xpath>
</field>
</record>

</odoo>
6 changes: 6 additions & 0 deletions setup/product_inventoriable/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

0 comments on commit c64ad28

Please sign in to comment.