Skip to content

Commit

Permalink
crm_rma_stock_location: Migration V9
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyril Gaudin committed May 19, 2016
1 parent 8b35cee commit 2cca386
Show file tree
Hide file tree
Showing 18 changed files with 434 additions and 474 deletions.
19 changes: 12 additions & 7 deletions crm_rma_stock_location/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Usage

.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/8.0/145
:target: https://runbot.odoo-community.org/runbot/145/9.0

For further information, please visit:

Expand All @@ -64,21 +64,26 @@ Known issues / Roadmap
Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/rma/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed feedback
`here <https://github.com/OCA/rma/issues/new?body=module:%20crm_rma_stock_location%0Aversion:%208.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Bugs are tracked on `GitHub Issues
<https://github.com/OCA/rma/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smashing it by providing a detailed and welcomed feedback.

Credits
=======

Images
------

* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.

Contributors
------------

* Guewen Baconnier <guewen.baconnier@camptocamp.com>
* Yanina Aular <yanina.aular@vauxoo.com>
* Osval Reyes <osval@vauxoo.com>
* Cyril Gaudin <cyril.gaudin@camptocamp.com>

Maintainer
----------
Expand All @@ -93,4 +98,4 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

To contribute to this module, please visit http://odoo-community.org.
To contribute to this module, please visit https://odoo-community.org.
21 changes: 0 additions & 21 deletions crm_rma_stock_location/__init__.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,4 @@
# -*- 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 <http://www.gnu.org/licenses/>.
#
##############################################################################

from . import models
from . import wizards
Expand Down
34 changes: 10 additions & 24 deletions crm_rma_stock_location/__openerp__.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,18 @@
# -*- coding: utf-8 -*-
##############################################################################
# Author: Guewen Baconnier,
# Emmanuel Samyn, Raphaël Valyi, Sébastien Beau,
# Joel Grand-Guillaume,
# Yanina Aular, Osval Reyes
#
# Copyright 2015 Vauxoo
# Copyright 2013-2014 Camptocamp SA
# Copyright 2009-2013 Akretion,
# Author: Guewen Baconnier,
# Emmanuel Samyn, Raphaël Valyi, Sébastien Beau,
# Joel Grand-Guillaume,
# Yanina Aular, 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
# © 2009-2013 Akretion
# © 2014-2016 Camptocamp SA
# © 2015 Vauxoo
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).


{
'name': 'RMA Stock Location',
'version': '8.0.1.0.0',
'version': '9.0.1.0.0',
'author': "Akretion,Vauxoo,Camptocamp,Odoo Community Association (OCA)",
'maintainer': 'Camptocamp',
'website': 'http://www.camptocamp.com,http://www.vauxoo.com',
Expand Down
38 changes: 12 additions & 26 deletions crm_rma_stock_location/init_hooks.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,17 @@
# -*- 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
# © 2015 Vauxoo
# © 2014-2016 Camptocamp SA
# Author: Guewen Baconnier,
# Osval Reyes
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from openerp import SUPERUSER_ID
from openerp.api import Environment


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)
with Environment.manage():
env = Environment(cr, SUPERUSER_ID, {})

warehouses = env['stock.warehouse'].search([])
warehouses.create_locations_rma()
24 changes: 0 additions & 24 deletions crm_rma_stock_location/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,4 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright 2015 Vauxoo
# Copyright 2013-2014 Camptocamp SA
# Copyright 2009-2013 Akretion,
# Author: Guewen Baconnier,
# Emmanuel Samyn, Raphaël Valyi, Sébastien Beau,
# Joel Grand-Guillaume,
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################

from . import product_product
from . import product_template
Expand Down
141 changes: 52 additions & 89 deletions crm_rma_stock_location/models/product_product.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,9 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Author: Guewen Baconnier
# Copyright 2014 Camptocamp SA
#
# 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 openerp import _, api, fields, models
# © 2014-2016 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

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


Expand All @@ -30,16 +12,18 @@ class ProductProduct(models.Model):
_inherit = 'product.product'

rma_qty_available = fields.Float(
compute='_rma_product_available',
compute='_compute_rma_product_quantities',
digits_compute=dp.get_precision('Product Unit of Measure'),
search='_search_rma_product_quantity',
string=_('RMA Quantity On Hand'))
string='RMA Quantity On Hand'
)

rma_virtual_available = fields.Float(
compute='_rma_product_available',
compute='_compute_rma_product_quantities',
digits_compute=dp.get_precision('Product Unit of Measure'),
search='_search_rma_product_quantity',
string=_('RMA Forecasted Quantity'))
string='RMA Forecasted Quantity'
)

def _search_rma_product_quantity(self, operator, value):
res = []
Expand All @@ -64,69 +48,48 @@ def _search_rma_product_quantity(self, operator, value):
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
locations.
@api.depends()
def _compute_rma_product_quantities(self):
""" Compute both rma_qty_available and rma_virtual_available values
by calling product_product._product_available with RMA locations
in context.
"""
context = self.env.context
warehouse_id = context.get('warehouse_id')
ctx = context.copy()
location_ids = set()
warehouse_model = self.env['stock.warehouse']

locations = self.env['stock.location']

warehouse_id = self.env.context.get('warehouse_id')
if warehouse_id:
warehouse = warehouse_model.browse(warehouse_id)
if warehouse.lot_rma_id:
locations |= warehouse.lot_rma_id

else:
warehouses = warehouse_model.search([('lot_rma_id', '!=', False)])
locations |= warehouses.mapped('lot_rma_id')

if locations:
result = self.with_context(
# Sorted by parent_left to avoid a little Odoo bug
# in tests environnement
# see https://github.com/odoo/odoo/pull/11996
location=locations.sorted(
lambda l: l.parent_left
).mapped('id'),
)._product_available()

else:
result = {}

for product in self:
if warehouse_id and warehouse_id.lot_rma_id:
location_ids.add(warehouse_id.lot_rma_id.id)
else:
warehouse_ids = self.env['stock.warehouse'].search([])
if not warehouse_ids:
return
for warehouse_id in warehouse_ids:
if warehouse_id.lot_rma_id:
location_ids.add(warehouse_id.lot_rma_id.id)

if not location_ids:
return
ctx['location'] = list(location_ids)

domain_products = [('product_id', 'in', [product.id])]
domain_quant, domain_move_in, domain_move_out = \
product.with_context(ctx)._get_domain_locations()
domain_move_in += product.with_context(ctx)._get_domain_dates() + \
[('state', 'not in', ('done', 'cancel', 'draft'))] + \
domain_products
domain_move_out += product.with_context(ctx).\
_get_domain_dates() + \
[('state', 'not in', ('done', 'cancel', 'draft'))] + \
domain_products
domain_quant += domain_products
moves_in = []
moves_out = []
lot_id = context.get('lot_id')
if lot_id:
domain_quant.append(('lot_id', '=', lot_id))
try:
product_qties = result[product.id]
except KeyError:
product.rma_qty_available = 0
product.rma_virtual_available = 0

else:
moves_in = self.env['stock.move'].\
with_context(ctx).read_group(domain_move_in,
['product_id', 'product_qty'],
['product_id'])
moves_out = self.env['stock.move'].\
with_context(ctx).read_group(domain_move_out,
['product_id', 'product_qty'],
['product_id'])
quants = self.env['stock.quant'].with_context(ctx).read_group(
domain_quant, ['product_id', 'qty'], ['product_id'])
quants = dict([(item.get('product_id')[0],
item.get('qty')) for item in quants])
moves_in = dict([(item.get('product_id')[0],
item.get('product_qty')) for item in moves_in])
moves_out = dict([(item.get('product_id')[0],
item.get('product_qty')) for item in moves_out])
product.rma_qty_available = \
float_round(quants.get(product.id, 0.0),
precision_rounding=product.uom_id.rounding)
product.rma_virtual_available = \
float_round(quants.get(product.id, 0.0) +
moves_in.get(product.id, 0.0) -
moves_out.get(product.id, 0.0),
precision_rounding=product.uom_id.rounding)
product.rma_qty_available = product_qties['qty_available']
product.rma_virtual_available = product_qties[
'virtual_available'
]
Loading

0 comments on commit 2cca386

Please sign in to comment.