Parcourir la source

commit inicial

Rodney Elpidio Enciso Arias il y a 6 ans
commit
353240132c
8 fichiers modifiés avec 210 ajouts et 0 suppressions
  1. 22 0
      __init__.py
  2. BIN
      __init__.pyc
  3. 40 0
      __openerp__.py
  4. 22 0
      models/__init__.py
  5. BIN
      models/__init__.pyc
  6. 107 0
      models/stock_inventory.py
  7. BIN
      models/stock_inventory.pyc
  8. 19 0
      views/stock_inventory.xml

+ 22 - 0
__init__.py

@@ -0,0 +1,22 @@
+# -*- encoding: utf-8 -*-
+##############################################################################
+#
+#    Copyright (C) 2016 ICTSTUDIO (<http://www.ictstudio.eu>).
+#
+#    This program is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU Affero General Public License as
+#    published by the Free Software Foundation, either version 3 of the
+#    License, or (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU Affero General Public License for more details.
+#
+#    You should have received a copy of the GNU Affero General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+
+from . import models
+

BIN
__init__.pyc


+ 40 - 0
__openerp__.py

@@ -0,0 +1,40 @@
+# -*- encoding: utf-8 -*-
+##############################################################################
+#
+#    Copyright (C) 2016 ICTSTUDIO (<http://www.ictstudio.eu>).
+#
+#    This program is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU Affero General Public License as
+#    published by the Free Software Foundation, either version 3 of the
+#    License, or (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU Affero General Public License for more details.
+#
+#    You should have received a copy of the GNU Affero General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+
+{
+    'name': 'Stock Inventory for specific Product Categorie',
+    'version': '8.0.1.0.0',
+    'website': 'http://www.ictstudio.eu',
+    'category': 'Product',
+    'summary': 'Provide Stock inventory for one specific Product Categorie',
+    'description': """
+Stock Inventory Product Categorie
+=================================
+- On the stock inventory form make the product categorie selectable
+""",
+    'author': 'ICTSTUDIO, André Schenkels',
+    'depends': [
+        'stock',
+    ],
+    'data': [
+        'views/stock_inventory.xml',
+    ],
+}
+

+ 22 - 0
models/__init__.py

@@ -0,0 +1,22 @@
+# -*- encoding: utf-8 -*-
+##############################################################################
+#
+#    Copyright (C) 2016 ICTSTUDIO (<http://www.ictstudio.eu>).
+#
+#    This program is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU Affero General Public License as
+#    published by the Free Software Foundation, either version 3 of the
+#    License, or (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU Affero General Public License for more details.
+#
+#    You should have received a copy of the GNU Affero General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+
+from . import stock_inventory
+

BIN
models/__init__.pyc


+ 107 - 0
models/stock_inventory.py

@@ -0,0 +1,107 @@
+# -*- encoding: utf-8 -*-
+##############################################################################
+#
+#    Copyright (C) 2016 ICTSTUDIO (<http://www.ictstudio.eu>).
+#
+#    This program is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU Affero General Public License as
+#    published by the Free Software Foundation, either version 3 of the
+#    License, or (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU Affero General Public License for more details.
+#
+#    You should have received a copy of the GNU Affero General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+
+import logging
+
+from openerp import models, fields, api, _
+
+_logger = logging.getLogger(__name__)
+
+class StockInventory(models.Model):
+    _inherit = "stock.inventory"
+
+    categ_id = fields.Many2one(
+            comodel_name='product.category',
+            string='Inventoried Product Category',
+            readonly=True,
+            states={'draft': [('readonly', False)]},
+            help="Specify Product Category to focus your inventory on a particular Product Category."
+    )
+
+    filter = fields.Selection(
+            selection='_get_available_filters'
+    )
+
+    @api.model
+    def _get_available_filters(self):
+        res_filter = super(StockInventory, self)._get_available_filters()
+        res_filter.append(('category', _('Only Products from Product Category')))
+        return res_filter
+
+    @api.model
+    def _get_inventory_lines(self, inventory):
+        if inventory.categ_id:
+            location_obj = self.env['stock.location']
+            product_obj = self.env['product.product']
+            categ_obj = self.env['product.category']
+            locations = location_obj.search(
+                    [
+                        ('id', 'child_of', [inventory.location_id.id])
+                    ]
+            )
+            categories = categ_obj.search(
+                    [
+                        ('id', 'child_of', [inventory.categ_id.id])
+                    ]
+            )
+
+            domain = ' sq.location_id in %s'
+            args = (tuple(locations.ids),)
+
+            domain += ' and pc.id in %s'
+            args += (tuple(categories.ids),)
+            if inventory.partner_id:
+                domain += ' and sq.owner_id = %s'
+                args += (inventory.partner_id.id,)
+            if inventory.lot_id:
+                domain += ' and sq.lot_id = %s'
+                args += (inventory.lot_id.id,)
+            if inventory.product_id:
+                domain += ' and sq.product_id = %s'
+                args += (inventory.product_id.id,)
+            if inventory.package_id:
+                domain += ' and sq.package_id = %s'
+                args += (inventory.package_id.id,)
+
+            self.env.cr.execute('''
+                   SELECT sq.product_id as product_id, sum(sq.qty) as product_qty, sq.location_id as location_id,
+                   sq.lot_id as prod_lot_id, sq.package_id as package_id, sq.owner_id as partner_id, pc.id as categ_id
+                   FROM stock_quant as sq
+                   INNER JOIN product_product as pp on pp.id =  sq.product_id
+                   INNER JOIN product_template as pt on pp.product_tmpl_id = pt.id
+                   INNER JOIN product_category as pc on pt.categ_id = pc.id
+                   WHERE''' + domain + '''
+                   GROUP BY sq.product_id, sq.location_id, sq.lot_id, sq.package_id, sq.owner_id, pc.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)
+        else:
+            vals = super(StockInventory, self)._get_inventory_lines(inventory)
+        return vals

BIN
models/stock_inventory.pyc


+ 19 - 0
views/stock_inventory.xml

@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+	<data>
+
+        <record id="view_inventory_form" model="ir.ui.view">
+            <field name="name">stock.inventory.form</field>
+            <field name="model">stock.inventory</field>
+            <field name="inherit_id" ref="stock.view_inventory_form"/>
+            <field name="arch" type="xml">
+                <xpath expr="//field[@name='lot_id']" position="after">
+                    <field name="categ_id"
+                           attrs="{'invisible': [('filter', '!=', 'category')],'required': [('filter', '=', 'category')]}"
+                           />
+                </xpath>
+            </field>
+        </record>
+
+    </data>
+</openerp>