From ecef773cb876760346c2cd108654f88e64ccad96 Mon Sep 17 00:00:00 2001 From: Cyril Gaudin Date: Mon, 9 May 2016 11:07:56 +0200 Subject: [PATCH] crm_rma_location: v9 migration --- crm_rma_location/README.rst | 4 +- crm_rma_location/__init__.py | 35 +-- crm_rma_location/__openerp__.py | 23 +- crm_rma_location/models/__init__.py | 23 +- crm_rma_location/models/stock_warehouse.py | 225 +++++++++----------- crm_rma_location/tests/__init__.py | 19 -- crm_rma_location/tests/test_location_rma.py | 21 +- crm_rma_location/views/stock_warehouse.xml | 36 ++-- 8 files changed, 136 insertions(+), 250 deletions(-) diff --git a/crm_rma_location/README.rst b/crm_rma_location/README.rst index 38d7eb5f..bb964b8a 100644 --- a/crm_rma_location/README.rst +++ b/crm_rma_location/README.rst @@ -27,7 +27,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/145/8.0 + :target: https://runbot.odoo-community.org/runbot/145/9.0 For further information, please visit: @@ -44,8 +44,6 @@ Bug Tracker Bugs are tracked on `GitHub 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 `_. - Credits ======= diff --git a/crm_rma_location/__init__.py b/crm_rma_location/__init__.py index 3cb92eb9..92b1a87d 100644 --- a/crm_rma_location/__init__.py +++ b/crm_rma_location/__init__.py @@ -1,33 +1,16 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# Copyright 2015 Vauxoo -# Author: Yanina Aular -# -# 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 . -# -############################################################################## +# © 2015 Yanina Aular, Vauxoo +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from . import models + 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) - vals = stock_wh.create_sequences_picking_types(cr, SUPERUSER_ID, wh_id) - stock_wh.write(cr, SUPERUSER_ID, wh_id.id, vals) + env = Environment(cr, SUPERUSER_ID, {}) + + warehouses = env['stock.warehouse'].search([]) + warehouses.create_locations_rma() + warehouses.create_sequences_picking_types() diff --git a/crm_rma_location/__openerp__.py b/crm_rma_location/__openerp__.py index 08527cf5..8eed2270 100644 --- a/crm_rma_location/__openerp__.py +++ b/crm_rma_location/__openerp__.py @@ -1,27 +1,10 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# Copyright 2015 Vauxoo -# Author: Yanina Aular -# -# 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 . -# -############################################################################## +# © Guewen Yanina Aular, Vauxoo +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). { 'name': 'RMA Location', - 'version': '8.0.1.0.0', + 'version': '9.0.1.0.0', 'author': "Vauxoo, Odoo Community Association (OCA)", 'license': 'AGPL-3', 'website': 'http://www.camptocamp.com,http://www.vauxoo.com', diff --git a/crm_rma_location/models/__init__.py b/crm_rma_location/models/__init__.py index 59059dd4..ebf0dc55 100644 --- a/crm_rma_location/models/__init__.py +++ b/crm_rma_location/models/__init__.py @@ -1,23 +1,6 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# Copyright 2013 Camptocamp -# Copyright 2015 Vauxoo -# Author: Yanina Aular -# -# 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 . -# -############################################################################## +# © 2013 Camptocamp +# © 2015 Yanina Aular, Vauxoo +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from . import stock_warehouse diff --git a/crm_rma_location/models/stock_warehouse.py b/crm_rma_location/models/stock_warehouse.py index 479bbc79..6a52109b 100644 --- a/crm_rma_location/models/stock_warehouse.py +++ b/crm_rma_location/models/stock_warehouse.py @@ -1,25 +1,7 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# Copyright 2013 Camptocamp -# Copyright 2015 Vauxoo -# Author: 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 . -# -############################################################################## +# © 2013 Camptocamp +# © 2015 Osval Reyes, Yanina Aular, Vauxoo +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from openerp import _, api, fields, models @@ -50,134 +32,129 @@ class StockWarehouse(models.Model): return available_colors[0] if available_colors else 0 - def create_sequence(self, warehouse_id, name, prefix, padding): + def create_sequence(self, name, prefix, padding): + self.ensure_one() return self.env['ir.sequence'].sudo().\ create(values={ - 'name': warehouse_id.name + name, - 'prefix': warehouse_id.code + prefix, + 'name': self.name + name, + 'prefix': self.code + prefix, 'padding': padding, - 'company_id': warehouse_id.company_id.id + 'company_id': self.company_id.id }) - @api.model - def create_sequences_picking_types(self, warehouse): + @api.multi + def create_sequences_picking_types(self): """ Takes care of create picking types for internal, incoming and outgoing RMA """ - picking_type = self.env['stock.picking.type'] + picking_type_model = self.env['stock.picking.type'] - # create new sequences - if not warehouse.rma_in_type_id: - in_seq_id = self.create_sequence( - warehouse, _(' Sequence in'), '/RMA/IN/', 5 + for warehouse in self: + # create new sequences + if not warehouse.rma_in_type_id: + in_seq_id = warehouse.create_sequence( + _(' Sequence in'), '/RMA/IN/', 5 + ) + + if not warehouse.rma_out_type_id: + out_seq_id = warehouse.create_sequence( + _(' Sequence out'), '/RMA/OUT/', 5 + ) + + if not warehouse.rma_int_type_id: + int_seq_id = warehouse.create_sequence( + _(' Sequence internal'), '/RMA/INT/', 5 + ) + + wh_stock_loc = warehouse.lot_rma_id + + # fetch customer and supplier locations, for references + customer_loc, supplier_loc = self._get_partner_locations() + + color = self.compute_next_color() + + # order the picking types with a sequence + # allowing to have the following suit for + # each warehouse: reception, internal, pick, pack, ship. + max_sequence = picking_type_model.search_read( + [], ['sequence'], order='sequence desc' ) + max_sequence = max_sequence and max_sequence[0]['sequence'] or 0 - if not warehouse.rma_out_type_id: - out_seq_id = self.create_sequence( - warehouse, _(' Sequence out'), '/RMA/OUT/', 5 - ) + in_type_id = warehouse.rma_in_type_id + if not in_type_id: + in_type_id = picking_type_model.create(vals={ + 'name': _('RMA Receipts'), + 'warehouse_id': warehouse.id, + 'code': 'incoming', + 'sequence_id': in_seq_id.id, + 'default_location_src_id': customer_loc.id, + 'default_location_dest_id': wh_stock_loc.id, + 'sequence': max_sequence + 4, + 'color': color}) - if not warehouse.rma_int_type_id: - int_seq_id = self.create_sequence( - warehouse, _(' Sequence internal'), '/RMA/INT/', 5 - ) + out_type_id = warehouse.rma_out_type_id + if not out_type_id: + out_type_id = picking_type_model.create(vals={ + 'name': _('RMA Delivery Orders'), + 'warehouse_id': warehouse.id, + 'code': 'outgoing', + 'sequence_id': out_seq_id.id, + 'return_picking_type_id': in_type_id.id, + 'default_location_src_id': wh_stock_loc.id, + 'default_location_dest_id': supplier_loc.id, + 'sequence': max_sequence + 1, + 'color': color}) + in_type_id.write({'return_picking_type_id': out_type_id.id}) - wh_stock_loc = warehouse.lot_rma_id + int_type_id = warehouse.rma_int_type_id + if not int_type_id: + int_type_id = picking_type_model.create(vals={ + 'name': _('RMA Internal Transfers'), + 'warehouse_id': warehouse.id, + 'code': 'internal', + 'sequence_id': int_seq_id.id, + 'default_location_src_id': wh_stock_loc.id, + 'default_location_dest_id': wh_stock_loc.id, + 'active': True, + 'sequence': max_sequence + 2, + 'color': color}) - # fetch customer and supplier locations, for references - customer_loc, supplier_loc = self._get_partner_locations() + # write picking types on WH + warehouse.write({ + 'rma_in_type_id': in_type_id.id, + 'rma_out_type_id': out_type_id.id, + 'rma_int_type_id': int_type_id.id, + }) - color = self.compute_next_color() - - # order the picking types with a sequence - # allowing to have the following suit for - # each warehouse: reception, internal, pick, pack, ship. - max_sequence = self.env['stock.picking.type'].\ - search_read([], ['sequence'], order='sequence desc') - max_sequence = max_sequence and max_sequence[0]['sequence'] or 0 - - in_type_id = warehouse.rma_in_type_id - if not in_type_id: - in_type_id = picking_type.create(vals={ - 'name': _('RMA Receipts'), - 'warehouse_id': warehouse.id, - 'code': 'incoming', - 'sequence_id': in_seq_id.id, - 'default_location_src_id': customer_loc.id, - 'default_location_dest_id': wh_stock_loc.id, - 'sequence': max_sequence + 4, - 'color': color}) - - out_type_id = warehouse.rma_out_type_id - if not out_type_id: - out_type_id = picking_type.create(vals={ - 'name': _('RMA Delivery Orders'), - 'warehouse_id': warehouse.id, - 'code': 'outgoing', - 'sequence_id': out_seq_id.id, - 'return_picking_type_id': in_type_id.id, - 'default_location_src_id': wh_stock_loc.id, - 'default_location_dest_id': supplier_loc.id, - 'sequence': max_sequence + 1, - 'color': color}) - in_type_id.write({'return_picking_type_id': out_type_id.id}) - - int_type_id = warehouse.rma_int_type_id - if not int_type_id: - int_type_id = picking_type.create(vals={ - 'name': _('RMA Internal Transfers'), - 'warehouse_id': warehouse.id, - 'code': 'internal', - 'sequence_id': int_seq_id.id, - 'default_location_src_id': wh_stock_loc.id, - 'default_location_dest_id': wh_stock_loc.id, - 'active': True, - 'sequence': max_sequence + 2, - 'color': color}) - - # write picking types on WH - vals = { - 'rma_in_type_id': in_type_id.id, - 'rma_out_type_id': out_type_id.id, - 'rma_int_type_id': int_type_id.id, - } - return vals - - @api.model - def create_locations_rma(self, warehouse_id): + @api.multi + def create_locations_rma(self): """ Create a RMA location for RMA movements that takes place when internal, outgoing or incoming pickings are made from/to this location """ - vals = {} - location_obj = self.env['stock.location'] - context_with_inactive = self.env.context.copy() - context_with_inactive['active_test'] = False - if not warehouse_id.lot_rma_id: - loc_vals = { - 'name': _('RMA'), - 'usage': 'internal', - 'location_id': warehouse_id.view_location_id.id, - 'company_id': warehouse_id.company_id.id, - 'active': True, - } - location_id = location_obj.with_context(context_with_inactive).\ - create(loc_vals) - vals['lot_rma_id'] = location_id.id - - return vals + for warehouse in self: + if not warehouse.lot_rma_id: + location_id = location_obj.with_context( + active_test=False + ).create({ + 'name': _('RMA'), + 'usage': 'internal', + 'location_id': warehouse.view_location_id.id, + 'company_id': warehouse.company_id.id, + 'active': True, + }) + warehouse.lot_rma_id = location_id @api.model def create(self, vals): """ Create Locations and picking types for warehouse """ - warehouse_id = super(StockWarehouse, self).create(vals=vals) - new_vals = self.create_locations_rma(warehouse_id) - warehouse_id.write(vals=new_vals) - new_vals = self.create_sequences_picking_types(warehouse_id) - warehouse_id.write(vals=new_vals) - return warehouse_id + warehouse = super(StockWarehouse, self).create(vals=vals) + warehouse.create_locations_rma() + warehouse.create_sequences_picking_types() + return warehouse diff --git a/crm_rma_location/tests/__init__.py b/crm_rma_location/tests/__init__.py index ed9b4717..342ce3b2 100644 --- a/crm_rma_location/tests/__init__.py +++ b/crm_rma_location/tests/__init__.py @@ -1,22 +1,3 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# Copyright 2015 Vauxoo -# Author: 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 . import test_location_rma diff --git a/crm_rma_location/tests/test_location_rma.py b/crm_rma_location/tests/test_location_rma.py index 77c3e64c..4c04bcc6 100644 --- a/crm_rma_location/tests/test_location_rma.py +++ b/crm_rma_location/tests/test_location_rma.py @@ -1,23 +1,6 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# Copyright 2015 Vauxoo -# Author: 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 . -# -############################################################################## +# © 2015 Osval Reyes, Vauxoo +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from openerp.tests.common import TransactionCase diff --git a/crm_rma_location/views/stock_warehouse.xml b/crm_rma_location/views/stock_warehouse.xml index cdaddeb9..e3716b20 100644 --- a/crm_rma_location/views/stock_warehouse.xml +++ b/crm_rma_location/views/stock_warehouse.xml @@ -1,21 +1,19 @@ - - - - view_warehouse_form - stock.warehouse - - - - - - - - - - - - - - + + + view_warehouse_form + stock.warehouse + + + + + + + + + + + + +