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 Aug 31, 2022
1 parent 2d69fa5 commit ccdd566
Show file tree
Hide file tree
Showing 13 changed files with 222 additions and 7 deletions.
21 changes: 14 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ exclude: |
# Files and folders generated by bots, to avoid loops
^setup/|/static/description/index\.html$|
# We don't want to mess with tool-generated files
.svg$|.copier-answers.yml|/tests/([^/]+/)?cassettes/|^.github/|
.svg$|/tests/([^/]+/)?cassettes/|^.copier-answers.yml$|^.github/|
# Maybe reactivate this when all README files include prettier ignore tags?
^README\.md$|
# Library files can have extraneous formatting (even minimized)
Expand Down Expand Up @@ -38,22 +38,28 @@ repos:
rev: v1.4
hooks:
- id: autoflake
args: ["-i", "--ignore-init-module-imports"]
args:
- --expand-star-imports
- --ignore-init-module-imports
- --in-place
- --remove-all-unused-imports
- --remove-duplicate-keys
- --remove-unused-variables
- repo: https://github.com/psf/black
rev: "22.3.0"
rev: 22.3.0
hooks:
- id: black
args: [--line-length=88]
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.1.2
hooks:
- id: prettier
name: prettier + plugin-xml
name: prettier (with plugin-xml)
additional_dependencies:
- "prettier@2.1.2"
- "@prettier/plugin-xml@0.12.0"
args:
- --plugin=@prettier/plugin-xml
files: \.(css|htm|html|js|json|jsx|less|md|scss|toml|ts|xml|yaml|yml)$
- repo: https://github.com/pre-commit/mirrors-eslint
rev: v7.8.1
hooks:
Expand Down Expand Up @@ -88,6 +94,7 @@ repos:
rev: v2.7.2
hooks:
- id: pyupgrade
args: ["--keep-percent-format"]
- repo: https://github.com/PyCQA/isort
rev: 5.5.1
hooks:
Expand All @@ -113,7 +120,7 @@ repos:
name: flake8
additional_dependencies: ["flake8-bugbear==20.1.4"]
- repo: https://github.com/PyCQA/pylint
rev: pylint-2.5.3
rev: v2.11.1
hooks:
- id: pylint
name: pylint with optional checks
Expand All @@ -122,7 +129,7 @@ repos:
- --exit-zero
verbose: true
additional_dependencies: &pylint_deps
- pylint-odoo==3.5.0
- pylint-odoo==5.0.5
- id: pylint
name: pylint with mandatory checks
args:
Expand Down
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 ccdd566

Please sign in to comment.