diff --git a/stock_picking_type_default_partner/__manifest__.py b/stock_picking_type_default_partner/__manifest__.py index 8403faf..bc6e7f8 100644 --- a/stock_picking_type_default_partner/__manifest__.py +++ b/stock_picking_type_default_partner/__manifest__.py @@ -1,45 +1,26 @@ -# -*- encoding: utf-8 -*- -############################################################################## -# -# Stock Picking Type Default Partner module for Odoo -# Copyright (C) 2014 Akretion (http://www.akretion.com) -# @author Alexis de Lattre -# -# 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 . -# -############################################################################## +# -*- coding: utf-8 -*- +# Copyright (C) 2014-2018 Akretion (http://www.akretion.com) +# @author Alexis de Lattre +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { 'name': 'Stock Picking Type Default Partner', - 'version': '0.1', - 'category': 'Inventory, Logistic, Storage', + 'version': '10.0.1.0.0', + 'category': 'Inventory, Logistics, Warehousing', 'license': 'AGPL-3', 'summary': 'Adds a default partner on types of operation', 'description': """ Stock Picking Type Default Partner ================================== -This module adds a new field on the Types of Operation (stock.picking.type) : *Default Partner*. +This module adds a new field on the Types of Operation (stock.picking.type) : *Default Partner*. This is useful for multi-site companies that create inter-site Type of Operations: all the operations that use this Type of Operation should have the same destination partner. This module has been written by Alexis de Lattre from Akretion . """, 'author': 'Akretion', 'website': 'http://www.akretion.com', 'depends': ['stock'], - 'data': [ - 'stock_view.xml' - ], - 'installable': False, + 'data': ['stock_view.xml'], + 'installable': True, } diff --git a/stock_picking_type_default_partner/stock.py b/stock_picking_type_default_partner/stock.py index 6a79763..fcce416 100644 --- a/stock_picking_type_default_partner/stock.py +++ b/stock_picking_type_default_partner/stock.py @@ -1,57 +1,31 @@ -# -*- encoding: utf-8 -*- -############################################################################## -# -# Stock Picking Type Default Partner module for Odoo -# Copyright (C) 2014 Akretion (http://www.akretion.com) -# @author Alexis de Lattre -# -# 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 . -# -############################################################################## - -# For an unknown reasons, it doesn't work when using the new API -# with this module it breaks in an SQL query trying to select the -# "picking_type_code" on stock.picking although it is a related field -# store=False So I keep it with the old API for the moment -from openerp.osv import orm, fields +# -*- coding: utf-8 -*- +# Copyright 2014-2018 Akretion (http://www.akretion.com) +# @author Alexis de Lattre +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -class StockPickingType(orm.Model): +from odoo import models, fields, api + + +class StockPickingType(models.Model): _inherit = 'stock.picking.type' - _columns = { - 'default_partner_id': fields.many2one( - 'res.partner', 'Default Partner', ondelete='restrict', - help="If set, it will be the default partner on this type " - "of pickings."), - } + default_partner_id = fields.Many2one( + 'res.partner', string='Default Partner', ondelete='restrict', + help="If set, it will be the default partner on this type of " + "pickings.") -class StockPicking(orm.Model): +class StockPicking(models.Model): _inherit = 'stock.picking' - def _default_partner_id(self, cr, uid, context=None): - if context is None: - context = {} - if context.get('default_picking_type_id'): - picktype = self.pool['stock.picking.type'].browse( - cr, uid, context.get('default_picking_type_id'), - context=context) + @api.model + def _default_partner_id(self): + if self._context.get('default_picking_type_id'): + picktype = self.env['stock.picking.type'].browse( + self._context.get('default_picking_type_id')) if picktype.default_partner_id: - return picktype.default_partner_id.id + return picktype.default_partner_id return False - _defaults = { - 'partner_id': _default_partner_id, - } + partner_id = fields.Many2one(default=_default_partner_id) diff --git a/stock_picking_type_default_partner/stock_view.xml b/stock_picking_type_default_partner/stock_view.xml index bef01d5..f58e139 100644 --- a/stock_picking_type_default_partner/stock_view.xml +++ b/stock_picking_type_default_partner/stock_view.xml @@ -1,13 +1,12 @@ - - - + + default.partner.stock.picking.type.form @@ -20,5 +19,5 @@ - - + +