fix for pneumac
This commit is contained in:
parent
2a1be1885e
commit
c2c4e632af
16 changed files with 314 additions and 0 deletions
1
picking_policy_per_customer/__init__.py
Normal file
1
picking_policy_per_customer/__init__.py
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
from . import models
|
||||||
23
picking_policy_per_customer/__manifest__.py
Normal file
23
picking_policy_per_customer/__manifest__.py
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
{
|
||||||
|
'name': 'Customer Specific Picking Policy',
|
||||||
|
'version': '18.0.1.0.0',
|
||||||
|
'category': 'Sales',
|
||||||
|
'summary': 'Configure picking policy (delivery orders) per customer',
|
||||||
|
'description': """
|
||||||
|
This module allows you to set specific picking policies per customer.
|
||||||
|
It extends the default global picking policy setting to be configurable at the customer level.
|
||||||
|
""",
|
||||||
|
'author': 'Bemade',
|
||||||
|
'website': 'https://bemade.org',
|
||||||
|
'depends': [
|
||||||
|
'sale',
|
||||||
|
'stock',
|
||||||
|
],
|
||||||
|
'data': [
|
||||||
|
'views/res_partner_views.xml',
|
||||||
|
],
|
||||||
|
'license': 'LGPL-3',
|
||||||
|
'installable': True,
|
||||||
|
'auto_install': False,
|
||||||
|
'application': False,
|
||||||
|
}
|
||||||
2
picking_policy_per_customer/models/__init__.py
Normal file
2
picking_policy_per_customer/models/__init__.py
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
from . import res_partner
|
||||||
|
from . import sale_order
|
||||||
19
picking_policy_per_customer/models/res_partner.py
Normal file
19
picking_policy_per_customer/models/res_partner.py
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
from odoo import fields, models
|
||||||
|
|
||||||
|
|
||||||
|
class ResPartner(models.Model):
|
||||||
|
"""
|
||||||
|
Extends the partner model to add customer-specific picking policy preferences.
|
||||||
|
|
||||||
|
This extension allows setting a default picking (shipping) policy at the customer level,
|
||||||
|
which will be used as the default value when creating sales orders for this customer.
|
||||||
|
"""
|
||||||
|
_inherit = 'res.partner'
|
||||||
|
|
||||||
|
picking_policy = fields.Selection([
|
||||||
|
('direct', 'Deliver each product when available'),
|
||||||
|
('one', 'Deliver all products at once')],
|
||||||
|
string='Shipping Policy',
|
||||||
|
help='Select how to handle multi-product deliveries:\n'
|
||||||
|
'- Deliver each product when available: products will be shipped as soon as they are available\n'
|
||||||
|
'- Deliver all products at once: products will be shipped altogether when all of them are available')
|
||||||
19
picking_policy_per_customer/models/sale_order.py
Normal file
19
picking_policy_per_customer/models/sale_order.py
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
from odoo import api, models
|
||||||
|
|
||||||
|
|
||||||
|
class SaleOrder(models.Model):
|
||||||
|
_inherit = 'sale.order'
|
||||||
|
|
||||||
|
@api.onchange('partner_id')
|
||||||
|
def _onchange_partner_id(self):
|
||||||
|
if self.partner_id and self.partner_id.picking_policy:
|
||||||
|
self.picking_policy = self.partner_id.picking_policy
|
||||||
|
|
||||||
|
@api.model_create_multi
|
||||||
|
def create(self, vals_list):
|
||||||
|
for vals in vals_list:
|
||||||
|
if vals.get('partner_id'):
|
||||||
|
partner = self.env['res.partner'].browse(vals['partner_id'])
|
||||||
|
if partner.picking_policy:
|
||||||
|
vals['picking_policy'] = partner.picking_policy
|
||||||
|
return super().create(vals_list)
|
||||||
13
picking_policy_per_customer/views/res_partner_views.xml
Normal file
13
picking_policy_per_customer/views/res_partner_views.xml
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<odoo>
|
||||||
|
<record id="view_partner_form_inherit_picking_policy" model="ir.ui.view">
|
||||||
|
<field name="name">res.partner.form.inherit.picking.policy</field>
|
||||||
|
<field name="model">res.partner</field>
|
||||||
|
<field name="inherit_id" ref="base.view_partner_form"/>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<xpath expr="//page[@name='sales_purchases']//group[@name='sale']" position="inside">
|
||||||
|
<field name="picking_policy"/>
|
||||||
|
</xpath>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
</odoo>
|
||||||
1
purchase_customer_requisition/__init__.py
Normal file
1
purchase_customer_requisition/__init__.py
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
from . import models
|
||||||
27
purchase_customer_requisition/__manifest__.py
Normal file
27
purchase_customer_requisition/__manifest__.py
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
{
|
||||||
|
'name': 'Purchase Customer Requisition',
|
||||||
|
'version': '1.0',
|
||||||
|
'category': 'Purchase',
|
||||||
|
'summary': 'Link customer requisition references to purchase orders',
|
||||||
|
'description': """
|
||||||
|
This module allows to:
|
||||||
|
* Store customer-specific requisition references for suppliers
|
||||||
|
* Automatically add these references to purchase order lines
|
||||||
|
* Track customer requisition numbers across purchase orders
|
||||||
|
""",
|
||||||
|
'license': 'LGPL-3',
|
||||||
|
'depends': [
|
||||||
|
'purchase',
|
||||||
|
'sale_purchase',
|
||||||
|
'purchase_requisition'
|
||||||
|
],
|
||||||
|
'data': [
|
||||||
|
'security/ir.model.access.csv',
|
||||||
|
'views/customer_supplier_requisition_views.xml',
|
||||||
|
'views/purchase_views.xml',
|
||||||
|
'views/purchase_requisition_views.xml',
|
||||||
|
],
|
||||||
|
'installable': True,
|
||||||
|
'application': False,
|
||||||
|
'auto_install': False,
|
||||||
|
}
|
||||||
3
purchase_customer_requisition/models/__init__.py
Normal file
3
purchase_customer_requisition/models/__init__.py
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
from . import customer_supplier_requisition
|
||||||
|
from . import purchase_order_line
|
||||||
|
from . import purchase_requisition
|
||||||
|
|
@ -0,0 +1,37 @@
|
||||||
|
from odoo import models, fields, api
|
||||||
|
|
||||||
|
class CustomerSupplierRequisition(models.Model):
|
||||||
|
_name = 'customer.supplier.requisition'
|
||||||
|
_description = 'Customer Supplier Requisition Reference'
|
||||||
|
|
||||||
|
customer_id = fields.Many2one(
|
||||||
|
comodel_name='res.partner',
|
||||||
|
string='Customer',
|
||||||
|
required=True,
|
||||||
|
domain=[
|
||||||
|
('customer_rank', '>', 0)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
supplier_id = fields.Many2one(
|
||||||
|
comodel_name='res.partner',
|
||||||
|
string='Supplier',
|
||||||
|
required=True,
|
||||||
|
domain=[
|
||||||
|
('supplier_rank', '>', 0)]
|
||||||
|
)
|
||||||
|
|
||||||
|
requisition_ref = fields.Char(
|
||||||
|
string='Requisition Reference',
|
||||||
|
required=True,
|
||||||
|
help='Reference number used by the supplier for this customer'
|
||||||
|
)
|
||||||
|
|
||||||
|
active = fields.Boolean(
|
||||||
|
default=True
|
||||||
|
)
|
||||||
|
|
||||||
|
_sql_constraints = [
|
||||||
|
('unique_customer_supplier', 'unique(customer_id, supplier_id)',
|
||||||
|
'A requisition reference already exists for this customer-supplier pair!')
|
||||||
|
]
|
||||||
32
purchase_customer_requisition/models/purchase_order_line.py
Normal file
32
purchase_customer_requisition/models/purchase_order_line.py
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
from odoo import models, fields, api
|
||||||
|
|
||||||
|
class PurchaseOrderLine(models.Model):
|
||||||
|
_inherit = 'purchase.order.line'
|
||||||
|
|
||||||
|
customer_requisition_ref = fields.Char(
|
||||||
|
string='Customer Requisition Ref',
|
||||||
|
compute='_compute_customer_requisition_ref',
|
||||||
|
store=True,
|
||||||
|
help='Customer requisition reference for this supplier'
|
||||||
|
)
|
||||||
|
|
||||||
|
@api.depends('sale_line_id.order_id.partner_id', 'order_id.partner_id')
|
||||||
|
def _compute_customer_requisition_ref(self):
|
||||||
|
for line in self:
|
||||||
|
if line.sale_line_id and line.sale_line_id.order_id.partner_id and line.order_id.partner_id:
|
||||||
|
requisition = self.env['customer.supplier.requisition'].search([
|
||||||
|
('customer_id', '=', line.sale_line_id.order_id.partner_id.id),
|
||||||
|
('supplier_id', '=', line.order_id.partner_id.id)
|
||||||
|
], limit=1)
|
||||||
|
line.customer_requisition_ref = requisition.requisition_ref if requisition else False
|
||||||
|
else:
|
||||||
|
line.customer_requisition_ref = False
|
||||||
|
|
||||||
|
@api.model_create_multi
|
||||||
|
def create(self, vals_list):
|
||||||
|
lines = super().create(vals_list)
|
||||||
|
for line in lines:
|
||||||
|
if line.customer_requisition_ref:
|
||||||
|
if line.name:
|
||||||
|
line.name = f"[{line.customer_requisition_ref}] {line.name}"
|
||||||
|
return lines
|
||||||
41
purchase_customer_requisition/models/purchase_requisition.py
Normal file
41
purchase_customer_requisition/models/purchase_requisition.py
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
from odoo import models, fields, api
|
||||||
|
|
||||||
|
class PurchaseRequisition(models.Model):
|
||||||
|
_inherit = 'purchase.requisition'
|
||||||
|
|
||||||
|
customer_id = fields.Many2one(
|
||||||
|
comodel_name='res.partner',
|
||||||
|
string='Customer',
|
||||||
|
domain=[('customer_rank', '>', 0)],
|
||||||
|
help='Customer for whom this requisition is created'
|
||||||
|
)
|
||||||
|
|
||||||
|
customer_requisition_ref = fields.Char(
|
||||||
|
string='Customer Requisition Ref',
|
||||||
|
compute='_compute_customer_requisition_ref',
|
||||||
|
store=True,
|
||||||
|
help='Customer requisition reference'
|
||||||
|
)
|
||||||
|
|
||||||
|
@api.depends('customer_id', 'vendor_id')
|
||||||
|
def _compute_customer_requisition_ref(self):
|
||||||
|
for requisition in self:
|
||||||
|
if requisition.customer_id and requisition.vendor_id:
|
||||||
|
ref = self.env['customer.supplier.requisition'].search([
|
||||||
|
('customer_id', '=', requisition.customer_id.id),
|
||||||
|
('supplier_id', '=', requisition.vendor_id.id)
|
||||||
|
], limit=1)
|
||||||
|
requisition.customer_requisition_ref = ref.requisition_ref if ref else False
|
||||||
|
else:
|
||||||
|
requisition.customer_requisition_ref = False
|
||||||
|
|
||||||
|
def action_in_progress(self):
|
||||||
|
res = super().action_in_progress()
|
||||||
|
for requisition in self:
|
||||||
|
if requisition.customer_requisition_ref:
|
||||||
|
# Update all related PO lines description
|
||||||
|
for po in requisition.purchase_ids:
|
||||||
|
for line in po.order_line:
|
||||||
|
if line.name and not line.name.startswith(f'[{requisition.customer_requisition_ref}]'):
|
||||||
|
line.name = f'[{requisition.customer_requisition_ref}] {line.name}'
|
||||||
|
return res
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
|
||||||
|
access_customer_supplier_requisition_user,customer.supplier.requisition.user,model_customer_supplier_requisition,purchase.group_purchase_user,1,0,0,0
|
||||||
|
access_customer_supplier_requisition_manager,customer.supplier.requisition.manager,model_customer_supplier_requisition,purchase.group_purchase_manager,1,1,1,1
|
||||||
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<odoo>
|
||||||
|
<record id="view_customer_supplier_requisition_tree" model="ir.ui.view">
|
||||||
|
<field name="name">customer.supplier.requisition.list</field>
|
||||||
|
<field name="model">customer.supplier.requisition</field>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<list>
|
||||||
|
<field name="customer_id"/>
|
||||||
|
<field name="supplier_id"/>
|
||||||
|
<field name="requisition_ref"/>
|
||||||
|
</list>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<record id="view_customer_supplier_requisition_form" model="ir.ui.view">
|
||||||
|
<field name="name">customer.supplier.requisition.form</field>
|
||||||
|
<field name="model">customer.supplier.requisition</field>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<form string="Customer Supplier Requisition">
|
||||||
|
<sheet>
|
||||||
|
<group>
|
||||||
|
<group>
|
||||||
|
<field name="customer_id"/>
|
||||||
|
<field name="supplier_id"/>
|
||||||
|
</group>
|
||||||
|
<group>
|
||||||
|
<field name="requisition_ref"/>
|
||||||
|
<field name="active"/>
|
||||||
|
</group>
|
||||||
|
</group>
|
||||||
|
</sheet>
|
||||||
|
</form>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<record id="action_customer_supplier_requisition" model="ir.actions.act_window">
|
||||||
|
<field name="name">Customer Supplier Requisitions</field>
|
||||||
|
<field name="res_model">customer.supplier.requisition</field>
|
||||||
|
<field name="view_mode">list,form</field>
|
||||||
|
<field name="help" type="html">
|
||||||
|
<p class="o_view_nocontent_smiling_face">
|
||||||
|
Create your first customer supplier requisition reference
|
||||||
|
</p>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<menuitem id="menu_customer_supplier_requisition"
|
||||||
|
name="Customer Requisitions"
|
||||||
|
action="action_customer_supplier_requisition"
|
||||||
|
parent="purchase.menu_purchase_config"
|
||||||
|
sequence="6"/>
|
||||||
|
</odoo>
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<odoo>
|
||||||
|
<record id="view_purchase_requisition_form_inherit" model="ir.ui.view">
|
||||||
|
<field name="name">purchase.requisition.form.inherit</field>
|
||||||
|
<field name="model">purchase.requisition</field>
|
||||||
|
<field name="inherit_id" ref="purchase_requisition.view_purchase_requisition_form"/>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<field name="vendor_id" position="after">
|
||||||
|
<field name="customer_id"/>
|
||||||
|
<field name="customer_requisition_ref" invisible="not customer_id"/>
|
||||||
|
</field>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<record id="view_purchase_requisition_list_inherit" model="ir.ui.view">
|
||||||
|
<field name="name">purchase.requisition.list.inherit</field>
|
||||||
|
<field name="model">purchase.requisition</field>
|
||||||
|
<field name="inherit_id" ref="purchase_requisition.view_purchase_requisition"/>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<xpath expr="//list" position="inside">
|
||||||
|
<field name="customer_id" optional="show"/>
|
||||||
|
</xpath>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
</odoo>
|
||||||
16
purchase_customer_requisition/views/purchase_views.xml
Normal file
16
purchase_customer_requisition/views/purchase_views.xml
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<odoo>
|
||||||
|
<record id="purchase_order_form_inherit" model="ir.ui.view">
|
||||||
|
<field name="name">purchase.order.form.inherit</field>
|
||||||
|
<field name="model">purchase.order</field>
|
||||||
|
<field name="inherit_id" ref="purchase.purchase_order_form"/>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<xpath expr="//field[@name='order_line']/list" position="inside">
|
||||||
|
<field name="customer_requisition_ref" optional="show"/>
|
||||||
|
</xpath>
|
||||||
|
<xpath expr="//field[@name='order_line']/form//field[@name='product_id']" position="before">
|
||||||
|
<field name="customer_requisition_ref"/>
|
||||||
|
</xpath>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
</odoo>
|
||||||
Loading…
Reference in a new issue