Initial commit of sale_sourced_by_line for 11.0

This commit is contained in:
Jared Kipe
2018-05-09 09:17:09 -07:00
parent f692dc2df1
commit 3b04ff23d5
8 changed files with 129 additions and 0 deletions

View File

@@ -0,0 +1,17 @@
============================
Hibou - Sale Sourced by Line
============================
Adds warehouse and planned date fields to sale order lines. Will split the delivery orders
to every distinct warehouse.
Additionally, adds fields per line and to the sale order to set the planned date on generated
delivery orders.
=======
License
=======
Please see `LICENSE <https://github.com/hibou-io/hibou-odoo-suite/blob/master/LICENSE>`_.
Copyright Hibou Corp. 2018

View File

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

View File

@@ -0,0 +1,29 @@
{
'name': 'Sale Sourced by Line',
'summary': 'Multiple warehouse source locations for Sale order',
'version': '11.0.1.0.0',
'author': "Hibou Corp.,Odoo Community Association (OCA)",
'category': 'Warehouse',
'license': 'AGPL-3',
'complexity': 'expert',
'images': [],
'website': "https://hibou.io",
'description': """
Sale Sourced by Line
====================
Adds the possibility to source a line of sale order from a specific
warehouse instead of using the warehouse of the sale order.
""",
'depends': [
'sale_stock',
'sale_order_dates',
],
'demo': [],
'data': [
'views/sale_views.xml',
],
'auto_install': False,
'installable': True,
}

View File

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

View File

@@ -0,0 +1,25 @@
from odoo import api, fields, models
class SaleOrder(models.Model):
_inherit = 'sale.order'
date_planned = fields.Datetime('Planned Date')
class SaleOrderLine(models.Model):
_inherit = 'sale.order.line'
warehouse_id = fields.Many2one('stock.warehouse', string='Warehouse')
date_planned = fields.Datetime('Planned Date')
@api.multi
def _prepare_procurement_values(self, group_id=False):
vals = super(SaleOrderLine, self)._prepare_procurement_values(group_id=group_id)
if self.warehouse_id:
vals.update({'warehouse_id': self.warehouse_id})
if self.date_planned:
vals.update({'date_planned': self.date_planned})
elif self.order_id.date_planned:
vals.update({'date_planned': self.order_id.date_planned})
return vals

View File

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

View File

@@ -0,0 +1,23 @@
from odoo.tests import common
class TestSaleSources(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')
product_2 = self.env.ref('product.product_product_16_product_template')
wh_1 = self.env.ref('stock.stock_warehouse_shop0')
wh_2 = self.env.ref('stock.warehouse0')
so = self.env['sale.order'].create({
'warehouse_id': wh_1.id,
'partner_id': partner.id,
'date_planned': '2018-01-01',
'order_line': [(0, 0, {'product_id': product_1.product_variant_id.id}),
(0, 0, {'product_id': product_2.product_variant_id.id, 'date_planned': '2018-02-01', 'warehouse_id': wh_2.id})]
})
so.action_confirm()
self.assertTrue(so.state in ('sale', 'done'))
self.assertEqual(len(so.picking_ids), 2)
self.assertEqual(len(so.picking_ids.filtered(lambda p: p.picking_type_id.warehouse_id == wh_1)), 1)
self.assertEqual(len(so.picking_ids.filtered(lambda p: p.picking_type_id.warehouse_id == wh_2)), 1)

View File

@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="view_order_form" model="ir.ui.view">
<field name="name">sale.order.form.warehouse</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='order_line']/form/group/group/field[@name='route_id']" position="before">
<field name="date_planned"/>
<field name="warehouse_id"/>
</xpath>
<xpath expr="//field[@name='order_line']/tree/field[@name='route_id']" position="before">
<field name="date_planned"/>
<field name="warehouse_id"/>
</xpath>
<xpath expr="//field[@name='requested_date']" position="before">
<field name="date_planned" />
</xpath>
</field>
</record>
<record id="view_order_line_tree" model="ir.ui.view">
<field name="name">sale.order.line.tree.warehouse</field>
<field name="model">sale.order.line</field>
<field name="inherit_id" ref="sale.view_order_line_tree"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='route_id']" position="before">
<field name="date_planned"/>
<field name="warehouse_id"/>
</xpath>
</field>
</record>
</odoo>