From bdc11ae77a847a4a680e2d869fd13f36057fad4c Mon Sep 17 00:00:00 2001 From: Osval Reyes Date: Fri, 27 Nov 2015 18:58:54 -0430 Subject: [PATCH] [REF] crm_rma_stock_location: add init_hooks file for post_init_hook, correct typos in readme, change usage for created locations loss and refurbished, rename compute method _rma_product_available -> _rma_template_available and get defined with @api.multi decorator --- crm_rma_stock_location/README.rst | 14 ++++----- crm_rma_stock_location/__init__.py | 10 +----- crm_rma_stock_location/init_hooks.py | 31 +++++++++++++++++++ .../models/product_product.py | 3 +- .../models/product_template.py | 9 +++--- .../models/stock_warehouse.py | 11 +++++-- 6 files changed, 54 insertions(+), 24 deletions(-) create mode 100644 crm_rma_stock_location/init_hooks.py diff --git a/crm_rma_stock_location/README.rst b/crm_rma_stock_location/README.rst index db575389..d4e8a113 100644 --- a/crm_rma_stock_location/README.rst +++ b/crm_rma_stock_location/README.rst @@ -10,16 +10,16 @@ Allow the user to know how much for a product is available 'On Hand' and how muc is virtually (expected to be) available for RMA locations. Adding for the different product views (Tree, Form and Kanban) information about it. -Both quantities are computed and includes its children locations. +Both quantities are computed and include its children locations. -It is useful use it as a quick snapshot for RMA from product perspective. +It is useful to use it as a quick snapshot for RMA from product perspective. It also adds the following location on warehouses : * Loss - * Refurbish + * Refurbished -Various wizards on incoming deliveries that allow you to move your +Several wizards on incoming deliveries that allow you to move your goods easily in those new locations from a done reception. Using this module make the logistic flow of return a bit more complex: @@ -41,11 +41,11 @@ Usage ===== * Go to Sales > After-sale Services and note that 'RMA Quantity On Hand' and - 'RMA Forecasted Quantity' had been included and it'll be shown when at least - a product has either a on hand or forecasted quantities available. + 'RMA Forecasted Quantity' has been included and they'll be shown when at least + when a product has either on hand or forecasted quantities available. * In the other hand, it provides three wizards to make stock moves (transfers) - allowing to do product returns (incoming), send a product to loss or, to a refurbish + allowing to do product returns (incoming), send a product to loss or, to a refurbished location. .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas diff --git a/crm_rma_stock_location/__init__.py b/crm_rma_stock_location/__init__.py index 9f9433ff..d59c3ae6 100644 --- a/crm_rma_stock_location/__init__.py +++ b/crm_rma_stock_location/__init__.py @@ -23,12 +23,4 @@ from . import models from . import wizards -from openerp import SUPERUSER_ID - - -def post_init_hook(cr, registry): - stock_wh = registry['stock.warehouse'] - for wh_id in stock_wh.browse(cr, SUPERUSER_ID, - stock_wh.search(cr, SUPERUSER_ID, [])): - vals = stock_wh.create_locations_rma(cr, SUPERUSER_ID, wh_id) - stock_wh.write(cr, SUPERUSER_ID, wh_id.id, vals) +from .init_hooks import post_init_hook diff --git a/crm_rma_stock_location/init_hooks.py b/crm_rma_stock_location/init_hooks.py new file mode 100644 index 00000000..9b97870c --- /dev/null +++ b/crm_rma_stock_location/init_hooks.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Copyright 2015 Vauxoo +# Copyright 2014 Camptocamp SA +# Author: Guewen Baconnier, +# Osval Reyes +# +# 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 . +# +############################################################################## +from openerp import SUPERUSER_ID + + +def post_init_hook(cr, registry): + stock_wh = registry['stock.warehouse'] + for wh_id in stock_wh.browse(cr, SUPERUSER_ID, + stock_wh.search(cr, SUPERUSER_ID, [])): + vals = stock_wh.create_locations_rma(cr, SUPERUSER_ID, wh_id) + stock_wh.write(cr, SUPERUSER_ID, wh_id.id, vals) diff --git a/crm_rma_stock_location/models/product_product.py b/crm_rma_stock_location/models/product_product.py index 8e950ddb..719606cf 100644 --- a/crm_rma_stock_location/models/product_product.py +++ b/crm_rma_stock_location/models/product_product.py @@ -19,7 +19,7 @@ # ############################################################################## -from openerp import _, models, fields +from openerp import _, api, fields, models import openerp.addons.decimal_precision as dp from openerp.tools.float_utils import float_round from openerp.tools.safe_eval import safe_eval as eval @@ -64,6 +64,7 @@ class ProductProduct(models.Model): res.append(('id', 'in', ids)) return res + @api.multi def _rma_product_available(self): """ Finds the incoming and outgoing quantity of product for the RMA diff --git a/crm_rma_stock_location/models/product_template.py b/crm_rma_stock_location/models/product_template.py index 7bf733c4..8059e33b 100644 --- a/crm_rma_stock_location/models/product_template.py +++ b/crm_rma_stock_location/models/product_template.py @@ -21,7 +21,7 @@ # ############################################################################## -from openerp import _, models, fields +from openerp import _, api, fields, models import openerp.addons.decimal_precision as dp @@ -29,19 +29,20 @@ class ProductTemplate(models.Model): _inherit = 'product.template' - rma_qty_available = fields.Float(compute='_rma_product_available', + rma_qty_available = fields.Float(compute='_rma_template_available', digits_compute=dp. get_precision('Product Unit ' 'of Measure'), string=_('RMA Quantity On Hand')) - rma_virtual_available = fields.Float(compute='_rma_product_available', + rma_virtual_available = fields.Float(compute='_rma_template_available', digits_compute=dp. get_precision('Product Unit' ' of Measure'), string=_('RMA Forecasted Quantity')) - def _rma_product_available(self): + @api.multi + def _rma_template_available(self): for product in self: product.rma_qty_available = sum( [p.rma_qty_available for p in product.product_variant_ids]) diff --git a/crm_rma_stock_location/models/stock_warehouse.py b/crm_rma_stock_location/models/stock_warehouse.py index 88a63625..ab919f57 100644 --- a/crm_rma_stock_location/models/stock_warehouse.py +++ b/crm_rma_stock_location/models/stock_warehouse.py @@ -44,7 +44,6 @@ class StockWarehouse(models.Model): vals_new = super(StockWarehouse, self).create_locations_rma(wh_id) loc_vals = { - 'usage': 'internal', 'location_id': wh_loc_id, 'active': True, } @@ -53,13 +52,19 @@ class StockWarehouse(models.Model): loc_vals['company_id'] = vals.get('company_id') if not wh_id.lot_refurbish_id: - loc_vals.update({'name': _('Refurbish')}) + loc_vals.update({ + 'name': _('Refurbish'), + 'usage': 'production' + }) location_id = location_obj.with_context(context_with_inactive).\ create(loc_vals) vals['lot_refurbish_id'] = location_id.id if not wh_id.loss_loc_id: - loc_vals.update({'name': _('Loss')}) + loc_vals.update({ + 'name': _('Loss'), + 'usage': 'inventory' + }) location_id = location_obj.with_context(context_with_inactive).\ create(loc_vals) vals['loss_loc_id'] = location_id.id