mirror of
https://gitlab.com/hibou-io/hibou-odoo/suite.git
synced 2025-01-20 12:37:31 +02:00
Initial commit of stock_delivery_route fro 11.0
This commit is contained in:
18
stock_delivery_route/README.rst
Normal file
18
stock_delivery_route/README.rst
Normal file
@@ -0,0 +1,18 @@
|
||||
********************************
|
||||
Hibou - Warehouse Delivery Route
|
||||
********************************
|
||||
|
||||
Define delivery routes per warehouse. Pick the delivery route on the sale order or delivery order.
|
||||
|
||||
Optionally define warehouse routes on the Customer or Customer's Delivery address to pre-select
|
||||
the delivery route.
|
||||
|
||||
For more information and add-ons, visit `Hibou.io <https://hibou.io/>`_.
|
||||
|
||||
|
||||
=======
|
||||
License
|
||||
=======
|
||||
|
||||
Please see `LICENSE <https://github.com/hibou-io/hibou-odoo-suite/blob/master/LICENSE>`_.
|
||||
Copyright Hibou Corp. 2018
|
||||
1
stock_delivery_route/__init__.py
Normal file
1
stock_delivery_route/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import models
|
||||
32
stock_delivery_route/__manifest__.py
Normal file
32
stock_delivery_route/__manifest__.py
Normal file
@@ -0,0 +1,32 @@
|
||||
{
|
||||
'name': 'Warehouse Delivery Routes',
|
||||
'summary': 'Assign a delivery route to a sale order or picking.',
|
||||
'version': '11.0.1.0.0',
|
||||
'author': "Hibou Corp. <hello@hibou.io>",
|
||||
'category': 'Warehouse',
|
||||
'license': 'AGPL-3',
|
||||
'complexity': 'expert',
|
||||
'images': [],
|
||||
'website': "https://hibou.io",
|
||||
'description': """
|
||||
Warehouse Delivery Routes
|
||||
=========================
|
||||
|
||||
Assign a delivery route at the time of sale order.
|
||||
Additionally, set a default route on the customer level.
|
||||
|
||||
""",
|
||||
'depends': [
|
||||
'sale_stock',
|
||||
'stock_picking_batch',
|
||||
],
|
||||
'demo': [],
|
||||
'data': [
|
||||
'views/partner_views.xml',
|
||||
'views/sale_views.xml',
|
||||
'views/stock_views.xml',
|
||||
'security/ir.model.access.csv',
|
||||
],
|
||||
'auto_install': False,
|
||||
'installable': True,
|
||||
}
|
||||
3
stock_delivery_route/models/__init__.py
Normal file
3
stock_delivery_route/models/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from . import stock
|
||||
from . import partner
|
||||
from . import sale
|
||||
7
stock_delivery_route/models/partner.py
Normal file
7
stock_delivery_route/models/partner.py
Normal file
@@ -0,0 +1,7 @@
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class Partner(models.Model):
|
||||
_inherit = 'res.partner'
|
||||
|
||||
delivery_route_ids = fields.Many2many('stock.warehouse.delivery.route', string="Delivery Routes")
|
||||
32
stock_delivery_route/models/sale.py
Normal file
32
stock_delivery_route/models/sale.py
Normal file
@@ -0,0 +1,32 @@
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class SaleOrder(models.Model):
|
||||
_inherit = 'sale.order'
|
||||
|
||||
delivery_route_id = fields.Many2one('stock.warehouse.delivery.route', string='Delivery Route')
|
||||
|
||||
@api.onchange('partner_id', 'partner_shipping_id', 'warehouse_id')
|
||||
@api.multi
|
||||
def _prefill_delivery_route(self):
|
||||
for so in self:
|
||||
if so.warehouse_id:
|
||||
for route in so.partner_shipping_id.delivery_route_ids.filtered(lambda d: d.warehouse_id == so.warehouse_id):
|
||||
so.delivery_route_id = route
|
||||
break
|
||||
else:
|
||||
for route in so.partner_id.delivery_route_ids.filtered(lambda d: d.warehouse_id == so.warehouse_id):
|
||||
so.delivery_route_id = route
|
||||
break
|
||||
else:
|
||||
so.delivery_route_id = False
|
||||
else:
|
||||
so.delivery_route_id = False
|
||||
|
||||
@api.multi
|
||||
def action_confirm(self):
|
||||
val = super(SaleOrder, self).action_confirm()
|
||||
for so in self:
|
||||
if so.delivery_route_id and so.picking_ids:
|
||||
so.picking_ids.write({'delivery_route_id': so.delivery_route_id.id})
|
||||
return val
|
||||
43
stock_delivery_route/models/stock.py
Normal file
43
stock_delivery_route/models/stock.py
Normal file
@@ -0,0 +1,43 @@
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class Warehouse(models.Model):
|
||||
_inherit = 'stock.warehouse'
|
||||
|
||||
delivery_route_ids = fields.One2many('stock.warehouse.delivery.route', 'warehouse_id', string='Delivery Routes')
|
||||
|
||||
|
||||
class Picking(models.Model):
|
||||
_inherit = 'stock.picking'
|
||||
_order = 'sequence asc, priority desc, date asc, id desc'
|
||||
|
||||
sequence = fields.Integer(string='Sequence')
|
||||
warehouse_id = fields.Many2one('stock.warehouse', related='picking_type_id.warehouse_id')
|
||||
delivery_route_id = fields.Many2one('stock.warehouse.delivery.route', string='Delivery Route')
|
||||
partner_address = fields.Char(string='Address', compute='_compute_partner_address')
|
||||
|
||||
@api.multi
|
||||
def _compute_partner_address(self):
|
||||
for pick in self:
|
||||
if pick.partner_id:
|
||||
pick.partner_address = '%s: %s, %s' % (pick.partner_id.name or '', pick.partner_id.street or '', pick.partner_id.city or '')
|
||||
else:
|
||||
pick.partner_address = ''
|
||||
|
||||
|
||||
class WarehouseDeliveryRoute(models.Model):
|
||||
_name = 'stock.warehouse.delivery.route'
|
||||
|
||||
name = fields.Char(string='Name')
|
||||
warehouse_id = fields.Many2one('stock.warehouse', string='Warehouse')
|
||||
note = fields.Text(string='Note')
|
||||
|
||||
@api.multi
|
||||
def name_get(self):
|
||||
res = []
|
||||
for route in self:
|
||||
res.append((route.id, '[%s] %s' % (route.warehouse_id.code, route.name)))
|
||||
return res
|
||||
|
||||
|
||||
|
||||
2
stock_delivery_route/security/ir.model.access.csv
Normal file
2
stock_delivery_route/security/ir.model.access.csv
Normal file
@@ -0,0 +1,2 @@
|
||||
"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink"
|
||||
"user_stock_warehouse_delivery_route","user stock_warehouse_delivery_route","model_stock_warehouse_delivery_route","base.group_user",1,1,1,1
|
||||
|
1
stock_delivery_route/tests/__init__.py
Normal file
1
stock_delivery_route/tests/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import test_sale_routes
|
||||
22
stock_delivery_route/tests/test_sale_routes.py
Normal file
22
stock_delivery_route/tests/test_sale_routes.py
Normal file
@@ -0,0 +1,22 @@
|
||||
from odoo.tests import common
|
||||
|
||||
|
||||
class TestSaleRoutes(common.TransactionCase):
|
||||
|
||||
def test_plan_two_warehouses(self):
|
||||
partner = self.env.ref('base.res_partner_2')
|
||||
product_1 = self.env.ref('product.product_product_24_product_template')
|
||||
wh_1 = self.env.ref('stock.stock_warehouse_shop0')
|
||||
delivery_route = self.env['stock.warehouse.delivery.route'].create({
|
||||
'name': 'Test',
|
||||
'warehouse_id': wh_1.id,
|
||||
})
|
||||
so = self.env['sale.order'].create({
|
||||
'warehouse_id': wh_1.id,
|
||||
'partner_id': partner.id,
|
||||
'order_line': [(0, 0, {'product_id': product_1.product_variant_id.id})],
|
||||
'delivery_route_id': delivery_route.id,
|
||||
})
|
||||
so.action_confirm()
|
||||
self.assertTrue(so.state in ('sale', 'done'))
|
||||
self.assertEqual(so.picking_ids[0].delivery_route_id, delivery_route)
|
||||
17
stock_delivery_route/views/partner_views.xml
Normal file
17
stock_delivery_route/views/partner_views.xml
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<odoo>
|
||||
<record id="view_partner_form_inherit" model="ir.ui.view">
|
||||
<field name="name">res.partner.form.inherit</field>
|
||||
<field name="model">res.partner</field>
|
||||
<field name="inherit_id" ref="base.view_partner_form" />
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//group[@name='container_row_2']" position="after">
|
||||
<group name="container_row_delivery_routes">
|
||||
<group string="Delivery Routes" name="delivery_routes">
|
||||
<field name="delivery_route_ids" widget="many2many_tags" nolabel="1" options="{'no_create': True}"/>
|
||||
</group>
|
||||
</group>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
13
stock_delivery_route/views/sale_views.xml
Normal file
13
stock_delivery_route/views/sale_views.xml
Normal file
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<odoo>
|
||||
<record id="view_order_form_inherit_sale_stock_inherit" model="ir.ui.view">
|
||||
<field name="name">sale.order.form.sale.stock.inherit</field>
|
||||
<field name="model">sale.order</field>
|
||||
<field name="inherit_id" ref="sale_stock.view_order_form_inherit_sale_stock" />
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='warehouse_id']" position="after">
|
||||
<field name="delivery_route_id" context="{'default_warehouse_id': warehouse_id}" domain="[('warehouse_id', '=', warehouse_id)]" options="{'no_create': True}"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
86
stock_delivery_route/views/stock_views.xml
Normal file
86
stock_delivery_route/views/stock_views.xml
Normal file
@@ -0,0 +1,86 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<odoo>
|
||||
<!-- Warehouse -->
|
||||
<record id="view_warehouse_inherit" model="ir.ui.view">
|
||||
<field name="name">stock.warehouse.inherit</field>
|
||||
<field name="model">stock.warehouse</field>
|
||||
<field name="inherit_id" ref="stock.view_warehouse" />
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//page[1]" position="after">
|
||||
<page string="Delivery Routes" colspan="4">
|
||||
<group colspan="4">
|
||||
<field name="id" invisible="1"/>
|
||||
<field name="delivery_route_ids" context="{'default_warehouse_id': id}" nolabel="1">
|
||||
<tree>
|
||||
<field name="name"/>
|
||||
</tree>
|
||||
<form>
|
||||
<group>
|
||||
<group>
|
||||
<field name="name" required="1"/>
|
||||
<field name="warehouse_id"/>
|
||||
</group>
|
||||
<group>
|
||||
<field name="note"/>
|
||||
</group>
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
</group>
|
||||
</page>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- Picking -->
|
||||
<record id="view_picking_internal_search_inherit" model="ir.ui.view">
|
||||
<field name="name">stock.picking.internal.search.inherit</field>
|
||||
<field name="model">stock.picking</field>
|
||||
<field name="inherit_id" ref="stock.view_picking_internal_search"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='name']" position="after">
|
||||
<field name="delivery_route_id"/>
|
||||
</xpath>
|
||||
<xpath expr="//filter[@name='picking_type']" position="after">
|
||||
<filter name="delivery_route_id" string="Delivery Route" context="{'group_by':'delivery_route_id'}"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
<record id="vpicktree_inherit" model="ir.ui.view">
|
||||
<field name="name">stock.picking.tree.search.inherit</field>
|
||||
<field name="model">stock.picking</field>
|
||||
<field name="inherit_id" ref="stock.vpicktree"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='name']" position="before">
|
||||
<field name="sequence" widget="handle"/>
|
||||
</xpath>
|
||||
<xpath expr="//field[@name='partner_id']" position="after">
|
||||
<field name="delivery_route_id"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
<record id="view_picking_form_inherit" model="ir.ui.view">
|
||||
<field name="name">stock.picking.form.inherit</field>
|
||||
<field name="model">stock.picking</field>
|
||||
<field name="inherit_id" ref="stock.view_picking_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='partner_id']" position="after">
|
||||
<field name="warehouse_id" invisible="1"/>
|
||||
<field name="delivery_route_id" context="{'default_warehouse_id': warehouse_id}" domain="[('warehouse_id', '=', warehouse_id)]" options="{'no_create': True}"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- Picking Batch -->
|
||||
<record id="stock_picking_batch_form_inherit" model="ir.ui.view">
|
||||
<field name="name">stock.picking.batch.form.inherit</field>
|
||||
<field name="model">stock.picking.batch</field>
|
||||
<field name="inherit_id" ref="stock_picking_batch.stock_picking_batch_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='picking_ids']/tree/field[@name='name']" position="before">
|
||||
<field name="sequence" widget="handle"/>
|
||||
<field name="partner_address" />
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
Reference in New Issue
Block a user