From cb5c370271453d28501f9ca335bb138a482088d8 Mon Sep 17 00:00:00 2001 From: oihane Date: Tue, 29 Jul 2014 18:28:56 +0200 Subject: [PATCH] [ADD] Nuevo modulo --- .../__init__.py | 21 +++ .../__openerp__.py | 43 ++++++ .../models/__init__.py | 21 +++ .../models/stock_inventory.py | 123 ++++++++++++++++++ .../views/stock_inventory_view.xml | 42 ++++++ 5 files changed, 250 insertions(+) create mode 100644 stock_inventory_preparation_filters/__init__.py create mode 100644 stock_inventory_preparation_filters/__openerp__.py create mode 100644 stock_inventory_preparation_filters/models/__init__.py create mode 100644 stock_inventory_preparation_filters/models/stock_inventory.py create mode 100644 stock_inventory_preparation_filters/views/stock_inventory_view.xml diff --git a/stock_inventory_preparation_filters/__init__.py b/stock_inventory_preparation_filters/__init__.py new file mode 100644 index 000000000..e16a7559a --- /dev/null +++ b/stock_inventory_preparation_filters/__init__.py @@ -0,0 +1,21 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# +# 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 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 diff --git a/stock_inventory_preparation_filters/__openerp__.py b/stock_inventory_preparation_filters/__openerp__.py new file mode 100644 index 000000000..9372f613a --- /dev/null +++ b/stock_inventory_preparation_filters/__openerp__.py @@ -0,0 +1,43 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# +# 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 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": "Extended Inventory Preparation Filters", + "version": "1.0", + "depends": [ + "stock", + ], + "author": "OdooMRP team", + "contributors": [ + "Oihane Crucelaegui ", + ], + "category": "Custom Module", + "website": "http://www.odoomrp.com", + "complexity": "normal", + "summary": "More filters for inventory adjustments", + "description": """ + This module adds more filters to the inventory adjustments + """, + "data": [ + "views/stock_inventory_view.xml", + ], + "installable": True, + "auto_install": False, +} diff --git a/stock_inventory_preparation_filters/models/__init__.py b/stock_inventory_preparation_filters/models/__init__.py new file mode 100644 index 000000000..b537890cf --- /dev/null +++ b/stock_inventory_preparation_filters/models/__init__.py @@ -0,0 +1,21 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# +# 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 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 \ No newline at end of file diff --git a/stock_inventory_preparation_filters/models/stock_inventory.py b/stock_inventory_preparation_filters/models/stock_inventory.py new file mode 100644 index 000000000..a21199ba0 --- /dev/null +++ b/stock_inventory_preparation_filters/models/stock_inventory.py @@ -0,0 +1,123 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# +# 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 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 openerp.osv import orm, fields +from openerp.tools.translate import _ + + +class StockInventoryEmptyLines(orm.Model): + _name = 'stock.inventory.line.empty' + + _columns = { + 'product_code': fields.char('Product Code', size=64, required=True), + 'product_qty': fields.float('Quantity', required=True), + 'inventory_id': fields.many2one('stock.inventory', 'Inventory', + required=True, ondelete="cascade"), + } + + _defaults = { + 'product_qty': 1.0, + } + + +class StockInventoryFake(object): + def __init__(self, inventory, product=None, lot=None): + self.id = inventory.id + self.location_id = inventory.location_id + self.product_id = product + self.lot_id = lot + self.partner_id = inventory.partner_id + self.package_id = inventory.package_id + + +class StockInventory(orm.Model): + _inherit = 'stock.inventory' + + def _get_available_filters(self, cr, uid, context=None): + """ + This function will return the list of filter allowed according to + the options checked in 'Settings\Warehouse'. + + :rtype: list of tuple + """ + res_filter = super(StockInventory, + self)._get_available_filters(cr, uid, + context=context) + res_filter.append(('categories', _('Selected Categories'))) + res_filter.append(('products', _('Selected Products'))) + res_filter.append(('lots', _('Selected Lots'))) + res_filter.append(('empty', _('Empty list'))) + return res_filter + + _columns = { + 'filter': fields.selection(_get_available_filters, 'Selection Filter', + required=True), + 'categ_ids': fields.many2many('product.category', + 'rel_inventories_categories', + 'inventory_id', 'category_id', + 'Categories'), + 'product_ids': fields.many2many('product.product', + 'rel_inventories_products', + 'inventory_id', 'product_id', + 'Products'), + 'lot_ids': fields.many2many('stock.production.lot', + 'rel_inventories_lots', 'inventory_id', + 'lot_id', 'Lots'), + 'empty_line_ids': fields.one2many('stock.inventory.line.empty', + 'inventory_id', 'Capture Lines'), + } + + def _get_inventory_lines(self, cr, uid, inventory, context=None): + vals = [] + if not inventory.filter in ('categories', 'products', 'lots', 'empty'): + vals = super(StockInventory, self)._get_inventory_lines( + cr, uid, inventory, context=context) + elif inventory.filter in ('categories', 'products'): + product_tmpl_obj = self.pool['product.template'] + product_obj = self.pool['product.product'] + product_ids = [] + + if inventory.filter == 'categories': + product_tmpl_ids = product_tmpl_obj.search( + cr, uid, [('categ_id', 'in', inventory.categ_ids.ids)], + context=context) + product_ids = product_obj.search( + cr, uid, [('product_tmpl_id', 'in', product_tmpl_ids)], + context=context) + + elif inventory.filter == 'products': + product_ids = inventory.product_ids.ids + for product in product_obj.browse(cr, uid, product_ids, + context=context): + fake_inventory = StockInventoryFake(inventory, product=product) + vals += super(StockInventory, self)._get_inventory_lines( + cr, uid, fake_inventory, context=context) + + elif inventory.filter == 'lots': + for lot in inventory.lot_ids: + fake_inventory = StockInventoryFake(inventory, lot=lot) + vals += super(StockInventory, self)._get_inventory_lines( + cr, uid, fake_inventory, context=context) + elif inventory.filter == 'empty': + print "EMPTY LIST" + # TODO: además de calcular por linea y por producto actualizar + # la cantidad real + + return vals diff --git a/stock_inventory_preparation_filters/views/stock_inventory_view.xml b/stock_inventory_preparation_filters/views/stock_inventory_view.xml new file mode 100644 index 000000000..169b7b02b --- /dev/null +++ b/stock_inventory_preparation_filters/views/stock_inventory_view.xml @@ -0,0 +1,42 @@ + + + + + stock.inventory.form + stock.inventory + + + + + + + + {'invisible':[('state','=','draft')]} + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file