[ADD] Nuevo modulo <stock_inventory_preparation_filters>

This commit is contained in:
oihane
2014-07-29 18:28:56 +02:00
committed by Pedro M. Baeza
parent 5060d2f010
commit cb5c370271
5 changed files with 250 additions and 0 deletions

View File

@@ -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

View File

@@ -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 <oihanecrucelaegi@avanzosc.es>",
],
"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,
}

View File

@@ -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

View File

@@ -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

View File

@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<record model="ir.ui.view" id="stock_inventory_form">
<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">
<data>
<notebook position="attributes">
<attribute name="attrs" />
</notebook>
<page string="Inventory Details" position="attributes">
<attribute name="attrs">{'invisible':[('state','=','draft')]}</attribute>
</page>
<notebook position="before">
<group>
<field name="categ_ids" nolabel="1"
attrs="{'invisible':[('filter','!=','categories')]}" />
<field name="product_ids" nolabel="1"
attrs="{'invisible':[('filter','!=','products')]}" />
<field name="lot_ids" nolabel="1"
attrs="{'invisible':[('filter','!=','lots')]}" />
</group>
</notebook>
<notebook position="inside">
<page string="Capture Lines"
attrs="{'invisible':[('filter','!=','empty')]}">
<field name="empty_line_ids" nolabel="1">
<tree editable="bottom">
<field name="product_code"/>
<field name="product_qty"/>
</tree>
</field>
</page>
</notebook>
</data>
</field>
</record>
</data>
</openerp>