crm_rma_location: v9 migration

This commit is contained in:
Cyril Gaudin
2016-05-09 11:07:56 +02:00
parent 09805bf635
commit ecef773cb8
8 changed files with 136 additions and 250 deletions

View File

@@ -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 <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_location%0Aversion:%208.0.1.0.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Credits
=======

View File

@@ -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 <http://www.gnu.org/licenses/>.
#
##############################################################################
# © 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()

View File

@@ -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 <http://www.gnu.org/licenses/>.
#
##############################################################################
# © 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',

View File

@@ -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 <http://www.gnu.org/licenses/>.
#
##############################################################################
# © 2013 Camptocamp
# © 2015 Yanina Aular, Vauxoo
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import stock_warehouse

View File

@@ -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 <http://www.gnu.org/licenses/>.
#
##############################################################################
# © 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

View File

@@ -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 <http://www.gnu.org/licenses/>.
#
##############################################################################
from . import test_location_rma

View File

@@ -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 <http://www.gnu.org/licenses/>.
#
##############################################################################
# © 2015 Osval Reyes, Vauxoo
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp.tests.common import TransactionCase

View File

@@ -1,21 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="view_warehouse_form" model="ir.ui.view">
<field name="name">view_warehouse_form</field>
<field name="model">stock.warehouse</field>
<field name="inherit_id" ref="stock.view_warehouse" />
<field name="arch" type="xml">
<xpath expr="//field[@name='wh_output_stock_loc_id']" position="after">
<field name="lot_rma_id"/>
</xpath>
<xpath expr="//field[@name='out_type_id']" position="after">
<field name="rma_in_type_id"/>
<field name="rma_int_type_id"/>
<field name="rma_out_type_id"/>
</xpath>
</field>
</record>
</data>
</openerp>
<odoo>
<record id="view_warehouse_form" model="ir.ui.view">
<field name="name">view_warehouse_form</field>
<field name="model">stock.warehouse</field>
<field name="inherit_id" ref="stock.view_warehouse"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='wh_output_stock_loc_id']" position="after">
<field name="lot_rma_id"/>
</xpath>
<xpath expr="//field[@name='out_type_id']" position="after">
<field name="rma_in_type_id"/>
<field name="rma_int_type_id"/>
<field name="rma_out_type_id"/>
</xpath>
</field>
</record>
</odoo>