deisy 5 роки тому
коміт
70c3006130

+ 3 - 0
__init__.py

@@ -0,0 +1,3 @@
+# -*- coding : utf-8 -*-
+
+import models


+ 18 - 0
__openerp__.py

@@ -0,0 +1,18 @@
+# -*- encoding: utf-8 -*-
+
+{
+    'name': 'Inventario Inicial',
+    'version': '8.0.1.0.0',
+    'category': 'Product',
+    'summary': 'Inventario Inicial',
+    'description': """
+Inventario Inicial
+""",
+    'author': 'Eiru',
+    'depends': [
+        'stock',
+    ],
+    'data': [
+        'views/initial_inventory.xml',
+    ],
+}

+ 3 - 0
models/__init__.py

@@ -0,0 +1,3 @@
+# -*- coding : utf-8 -*-
+
+import initial_inventory

BIN
models/__init__.pyc


+ 64 - 0
models/initial_inventory.py

@@ -0,0 +1,64 @@
+# -*- encoding: utf-8 -*-
+
+import logging
+
+from openerp import models, fields, api, _
+from openerp.exceptions import Warning
+
+_logger = logging.getLogger(__name__)
+
+class StockInventory(models.Model):
+    _inherit = "stock.inventory"
+
+    category_id = fields.Many2one(
+            comodel_name='product.category',
+            string='Categoría de Producto',
+            readonly=True,
+            states={'draft': [('readonly', False)]},
+    )
+
+    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(('category2', _('Inventario inicial por categoría')))
+        return res_filter
+
+    @api.model
+    def _get_inventory_lines(self, inventory):
+        if inventory.category_id:
+            product_obj = self.env['product.product']
+            categ_obj = self.env['product.category']
+            categories = categ_obj.search([('id', 'child_of', [inventory.category_id.id])])
+            sql =  "SELECT pp.id as product_id, pc.id as category_id FROM product_product as pp 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 pt.type = 'product' and pc.id IN %s"
+
+            self.env.cr.execute(sql, (tuple(categories.ids),))
+            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['theoretical_qty'] = 0
+                product_line['product_id'] = product_line['product_id']
+                product_line['location_id'] = inventory.location_id.id
+                product_line['prod_lot_id'] = False
+                product_line['category_id'] = product_line['category_id']
+                product_line['inventory_id'] = inventory.id
+                product_line['package_id'] = False
+                product_line['product_qty'] = 0
+                product_line['partner_id'] = False
+                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/initial_inventory.pyc


BIN
static/description/icon.png


+ 19 - 0
views/initial_inventory.xml

@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+	<data>
+
+        <record id="view_inventory_form2" model="ir.ui.view">
+            <field name="name">stock.inventory.form2</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="category_id"
+                           attrs="{'invisible': [('filter', '!=', 'category2')],'required': [('filter', '=', 'category2')]}"
+                           />
+                </xpath>
+            </field>
+        </record>
+
+    </data>
+</openerp>