Port stock_picking_type_default_partner to v10

This commit is contained in:
Alexis de Lattre
2018-06-07 16:56:48 +02:00
parent 6f3a468a7c
commit d3bddf5fda
3 changed files with 36 additions and 82 deletions

View File

@@ -1,45 +1,26 @@
# -*- encoding: utf-8 -*- # -*- coding: utf-8 -*-
############################################################################## # Copyright (C) 2014-2018 Akretion (http://www.akretion.com)
# # @author Alexis de Lattre <alexis.delattre@akretion.com>
# Stock Picking Type Default Partner module for Odoo # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
# Copyright (C) 2014 Akretion (http://www.akretion.com)
# @author Alexis de Lattre <alexis.delattre@akretion.com>
#
# 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/>.
#
##############################################################################
{ {
'name': 'Stock Picking Type Default Partner', 'name': 'Stock Picking Type Default Partner',
'version': '0.1', 'version': '10.0.1.0.0',
'category': 'Inventory, Logistic, Storage', 'category': 'Inventory, Logistics, Warehousing',
'license': 'AGPL-3', 'license': 'AGPL-3',
'summary': 'Adds a default partner on types of operation', 'summary': 'Adds a default partner on types of operation',
'description': """ 'description': """
Stock Picking Type Default Partner 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 <alexis.delattre@akretion.com>. This module has been written by Alexis de Lattre from Akretion <alexis.delattre@akretion.com>.
""", """,
'author': 'Akretion', 'author': 'Akretion',
'website': 'http://www.akretion.com', 'website': 'http://www.akretion.com',
'depends': ['stock'], 'depends': ['stock'],
'data': [ 'data': ['stock_view.xml'],
'stock_view.xml' 'installable': True,
],
'installable': False,
} }

View File

@@ -1,57 +1,31 @@
# -*- encoding: utf-8 -*- # -*- coding: utf-8 -*-
############################################################################## # Copyright 2014-2018 Akretion (http://www.akretion.com)
# # @author Alexis de Lattre <alexis.delattre@akretion.com>
# Stock Picking Type Default Partner module for Odoo # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
# Copyright (C) 2014 Akretion (http://www.akretion.com)
# @author Alexis de Lattre <alexis.delattre@akretion.com>
#
# 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/>.
#
##############################################################################
# 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
class StockPickingType(orm.Model): from odoo import models, fields, api
class StockPickingType(models.Model):
_inherit = 'stock.picking.type' _inherit = 'stock.picking.type'
_columns = { default_partner_id = fields.Many2one(
'default_partner_id': fields.many2one( 'res.partner', string='Default Partner', ondelete='restrict',
'res.partner', 'Default Partner', ondelete='restrict', help="If set, it will be the default partner on this type of "
help="If set, it will be the default partner on this type " "pickings.")
"of pickings."),
}
class StockPicking(orm.Model): class StockPicking(models.Model):
_inherit = 'stock.picking' _inherit = 'stock.picking'
def _default_partner_id(self, cr, uid, context=None): @api.model
if context is None: def _default_partner_id(self):
context = {} if self._context.get('default_picking_type_id'):
if context.get('default_picking_type_id'): picktype = self.env['stock.picking.type'].browse(
picktype = self.pool['stock.picking.type'].browse( self._context.get('default_picking_type_id'))
cr, uid, context.get('default_picking_type_id'),
context=context)
if picktype.default_partner_id: if picktype.default_partner_id:
return picktype.default_partner_id.id return picktype.default_partner_id
return False return False
_defaults = { partner_id = fields.Many2one(default=_default_partner_id)
'partner_id': _default_partner_id,
}

View File

@@ -1,13 +1,12 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!-- <!--
Copyright (C) 2015 Akretion (http://www.akretion.com/) Copyright (C) 2015-2018 Akretion (http://www.akretion.com/)
@author Alexis de Lattre <alexis.delattre@akretion.com> @author Alexis de Lattre <alexis.delattre@akretion.com>
The licence is in the file __openerp__.py License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
--> -->
<openerp> <odoo>
<data>
<record id="view_picking_type_form" model="ir.ui.view"> <record id="view_picking_type_form" model="ir.ui.view">
<field name="name">default.partner.stock.picking.type.form</field> <field name="name">default.partner.stock.picking.type.form</field>
@@ -20,5 +19,5 @@
</field> </field>
</record> </record>
</data>
</openerp> </odoo>