[MIG] purchase_stock_partner_default_picking_type from v14 to v16

This commit is contained in:
Alexis de Lattre
2025-05-20 15:37:20 +02:00
parent 8cc20fa84f
commit dd915b906b
7 changed files with 86 additions and 0 deletions

View File

@@ -0,0 +1 @@
from . import models

View File

@@ -0,0 +1,24 @@
# Copyright (C) 2025 Akretion (https://www.akretion.com)
# @author Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
'name': 'Purchase Stock Default Picking Type on Partner',
'version': '16.0.1.0.0',
'category': 'Purchases',
'license': 'AGPL-3',
'summary': 'Configure the default picking type for purchase orders on partners',
'description': """
Purchase Stock Default Picking Type on Partner
==============================================
Allow to configure on partners the default picking type for purchase orders.
Please contact Alexis de Lattre from Akretion <alexis.delattre@akretion.com> for any help or question about this module.
""",
'author': 'Akretion',
'website': 'https://github.com/akretion/odoo-usability',
'depends': ['purchase_stock'],
'data': ['views/res_partner.xml'],
'installable': True,
}

View File

@@ -0,0 +1,2 @@
from . import res_partner
from . import purchase_order

View File

@@ -0,0 +1,23 @@
# Copyright 2025 Akretion France (https://www.akretion.com/)
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import api, fields, models
class PurchaseOrder(models.Model):
_inherit = "purchase.order"
# If I set picking_type_id as computed field with store=True and readonly=False
# it doesn't work when creating a PO from the smartbutton of the partner form view
# in v14 and v16... and I don't understand why :-(
# So, until I find the cause of this, I use a good old onchange !
@api.onchange("partner_id", "company_id")
def onchange_partner_id(self):
super().onchange_partner_id()
if self.partner_id and self.company_id:
partner = self.partner_id.commercial_partner_id.with_company(self.company_id.id)
if partner.purchase_picking_type_id:
self.picking_type_id = partner.purchase_picking_type_id
else:
self.picking_type_id = self._get_picking_type(self.company_id.id)

View File

@@ -0,0 +1,15 @@
# Copyright 2025 Akretion France (https://www.akretion.com/)
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import fields, models
class ResPartner(models.Model):
_inherit = 'res.partner'
# Used only for manual POs
purchase_picking_type_id = fields.Many2one(
'stock.picking.type', string="Purchase Picking Type",
company_dependent=True,
domain="[('code', '=', 'incoming'), ('company_id', '=', current_company_id)]")

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

View File

@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2025 Akretion France (https://www.akretion.com/)
@author: Alexis de Lattre <alexis.delattre@akretion.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
<odoo>
<record id="view_partner_property_form" model="ir.ui.view">
<field name="model">res.partner</field>
<field name="inherit_id" ref="purchase.view_partner_property_form"/>
<field name="arch" type="xml">
<field name="property_purchase_currency_id" position="before">
<field name="purchase_picking_type_id" attrs="{'invisible': [('parent_id', '!=', False)]}"/>
</field>
</field>
</record>
</odoo>