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 -*-
##############################################################################
#
# Stock Picking Type Default Partner module for Odoo
# 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/>.
#
##############################################################################
# -*- coding: utf-8 -*-
# Copyright (C) 2014-2018 Akretion (http://www.akretion.com)
# @author Alexis de Lattre <alexis.delattre@akretion.com>
# 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 <alexis.delattre@akretion.com>.
""",
'author': 'Akretion',
'website': 'http://www.akretion.com',
'depends': ['stock'],
'data': [
'stock_view.xml'
],
'installable': False,
'data': ['stock_view.xml'],
'installable': True,
}

View File

@@ -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 <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
# -*- coding: utf-8 -*-
# Copyright 2014-2018 Akretion (http://www.akretion.com)
# @author Alexis de Lattre <alexis.delattre@akretion.com>
# 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)

View File

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