Skip to content

Commit

Permalink
# This is a combination of 7 commits.
Browse files Browse the repository at this point in the history
# This is the 1st commit message:

[IMP] Stock Request Order Bypass Submitted

[IMP] stock_request: Add group to bypass submission (OCA#595)

[IMP] Flake8

[IMP] Migration Script

[IMP] Add Direction Functionality

[IMP] stock_request: Add group to bypass submission (OCA#595)

# This is the commit message #2:

[IMP] Fix Indent

# This is the commit message #3:

[IMP] Expected Date

# This is the commit message #4:

[IMP] Remove Warning Depricated Method Name

# This is the commit message #5:

[IMP] Add Test Location_id Outbound

# This is the commit message #6:

[IMP] Flake8 Line Too Long

# This is the commit message #7:

[IMP] Indent, Expected Date
  • Loading branch information
osi-scampbell committed Jul 12, 2019
1 parent 91052f5 commit 1295667
Show file tree
Hide file tree
Showing 15 changed files with 105 additions and 45 deletions.
2 changes: 1 addition & 1 deletion stock_request/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
"name": "Stock Request",
"summary": "Internal request for stock",
"version": "12.0.1.1.0",
"version": "12.0.2.0.0",
"license": "LGPL-3",
"website": "https://github.com/stock-logistics-warehouse",
"author": "Eficent, "
Expand Down
2 changes: 1 addition & 1 deletion stock_request/data/default.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<odoo>
<data noupdate="1">
<function model="res.config.settings" name="set_default_parameters"/>
<function model="res.config.settings" name="default_parameters"/>
</data>
</odoo>
3 changes: 1 addition & 2 deletions stock_request/migrations/12.0.1.1.0/post-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@ def migrate(cr, version):
search([('group_bypass_submit_request', '=', True)])
if not settings:
settings = env['res.config.settings'].create({
'group_bypass_submit_request': True,
})
'group_bypass_submit_request': True})
settings.execute()
18 changes: 18 additions & 0 deletions stock_request/migrations/12.0.2.0.0/post-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright (C) 2019 - TODAY, Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api
from odoo import SUPERUSER_ID


def migrate(cr, version):
if not version:
return

env = api.Environment(cr, SUPERUSER_ID, {})
settings = env['res.config.settings'].\
search([('group_bypass_submit_request', '=', True)])
if not settings:
settings = env['res.config.settings'].create({
'group_bypass_submit_request': True,
})
settings.execute()
2 changes: 1 addition & 1 deletion stock_request/models/res_config_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ResConfigSettings(models.TransientModel):
string='Stock Requests Analytic integration')

@api.model
def set_default_parameters(self):
def default_parameters(self):
settings = self.env['res.config.settings'].\
search([('group_bypass_submit_request', '=', True)])
if not settings:
Expand Down
11 changes: 5 additions & 6 deletions stock_request/models/stock_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ def _get_default_requested_by(self):
states={'draft': [('readonly', False)]}, readonly=True
)
location_id = fields.Many2one(
states={'draft': [('readonly', False)]}, readonly=True
states={'draft': [('readonly', False)]}, readonly=True,
domain=[('usage', 'in', ['internal', 'transit', 'customer'])],
)
product_id = fields.Many2one(
states={'draft': [('readonly', False)]}, readonly=True
Expand Down Expand Up @@ -115,13 +116,11 @@ def _get_default_requested_by(self):
@api.onchange('direction')
def _onchange_location_id(self):
if self.direction == 'outbound':
# Stock Location set to Partner Locations/Customers
self.location_id = \
self.company_id.partner_id.property_stock_customer.id
# Partner Locations/Customers
self.location_id = self.env.ref('stock.stock_location_customers')
else:
# Otherwise the Stock Location of the Warehouse
self.location_id = \
self.warehouse_id.lot_stock_id.id
self.location_id = self.warehouse_id.lot_stock_id.id

@api.depends('allocation_ids')
def _compute_move_ids(self):
Expand Down
29 changes: 15 additions & 14 deletions stock_request/models/stock_request_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def _get_default_requested_by(self):
states={'draft': [('readonly', False)]})
location_id = fields.Many2one(
'stock.location', 'Location', readonly=True,
domain=[('usage', 'in', ['internal', 'transit'])],
domain=[('usage', 'in', ['internal', 'transit', 'customer'])],
ondelete="cascade", required=True,
states={'draft': [('readonly', False)]},
)
Expand Down Expand Up @@ -117,16 +117,6 @@ def _get_default_requested_by(self):
string='Direction',
states={'draft': [('readonly', False)]},
readonly=True)
@api.onchange('direction')
def _onchange_location_id(self):
if self.direction == 'outbound':
# Stock Location set to Partner Locations/Customers
self.location_id = \
self.company_id.partner_id.property_stock_customer.id
else:
# Otherwise the Stock Location of the Warehouse
self.location_id = \
self.warehouse_id.lot_stock_id.id

@api.depends('stock_request_ids.allocation_ids')
def _compute_picking_ids(self):
Expand Down Expand Up @@ -156,6 +146,16 @@ def onchange_expected_date(self):
def onchange_picking_policy(self):
self.change_childs()

@api.onchange('direction')
def _onchange_location_id(self):
if self.direction == 'outbound':
# Partner Locations/Customers
self.location_id = self.env.ref('stock.stock_location_customers')
else:
# Otherwise the Stock Location of the Warehouse
self.location_id = self.warehouse_id.lot_stock_id.id
self.change_childs()

@api.onchange('location_id')
def onchange_location_id(self):
if self.location_id:
Expand Down Expand Up @@ -206,6 +206,7 @@ def change_childs(self):
if not self._context.get('no_change_childs', False):
for line in self.stock_request_ids:
line.warehouse_id = self.warehouse_id
line.direction = self.direction
line.location_id = self.location_id
line.company_id = self.company_id
line.picking_policy = self.picking_policy
Expand All @@ -223,12 +224,12 @@ def action_confirm(self):
self.state = 'open'
else:
# Move one state
for line in self.stock_request_ids:
line.action_confirm()
if self.state == 'draft':
self.state = 'submitted'
else:
for line in self.stock_request_ids:
line.action_confirm()
self.state == 'open'
self.state = 'open'
return True

def action_draft(self):
Expand Down
1 change: 1 addition & 0 deletions stock_request/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
* Raul Martin <raul.martin@braintec-group.com>
* Serpent Consulting Services Pvt. Ltd. <support@serpentcs.com>
* Maxime Chambreuil <mchambreuil@opensourceintegrators.com>
* Steve Campbell <scampbell@opensourceintegrators.com>
1 change: 1 addition & 0 deletions stock_request/readme/CREDITS.rst
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
* Eficent <https://www.eficent.com>
* Open Source Integrators <https://www.opensourceintegrators.com>
10 changes: 5 additions & 5 deletions stock_request/security/stock_request_security.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<field name="global" eval="True"/>
<field name="domain_force">['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])]</field>
</record>

<record id="stock_request_followers_rule" model="ir.rule">
<field name="name">Follow Stock Request</field>
<field name="model_id" ref="model_stock_request"/>
Expand All @@ -54,9 +54,9 @@
<field name="perm_create" eval="False"/>
<field name="perm_unlink" eval="False"/>
<field name="domain_force">['|',('requested_by','=',user.id),
('message_partner_ids', 'in', [user.partner_id.id])]</field>
('message_partner_ids', 'in', [user.partner_id.id])]</field>
</record>

<record id="stock_request_rule" model="ir.rule">
<field name="name">Stock Request User</field>
<field name="model_id" ref="model_stock_request"/>
Expand All @@ -67,7 +67,7 @@
<field name="perm_unlink" eval="True"/>
<field name="domain_force">[('requested_by','=',user.id)]</field>
</record>

<record id="stock_request_manager_rule" model="ir.rule">
<field name="name">Stock Request Manager</field>
<field name="model_id" ref="model_stock_request"/>
Expand All @@ -94,7 +94,7 @@
<field name="perm_create" eval="False"/>
<field name="perm_unlink" eval="False"/>
<field name="domain_force">['|',('requested_by','=',user.id),
('message_partner_ids', 'in', [user.partner_id.id])]</field>
('message_partner_ids', 'in', [user.partner_id.id])]</field>
</record>

<record id="stock_request_order_rule" model="ir.rule">
Expand Down
45 changes: 39 additions & 6 deletions stock_request/tests/test_stock_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,8 @@ def test_create_request_01(self):
stock_request = order.stock_request_ids

self.product.route_ids = [(6, 0, self.route.ids)]
order.action_confirm()
order.action_confirm() # To submit
order.action_confirm() # To confirm
self.assertEqual(order.state, 'open')
self.assertEqual(stock_request.state, 'open')

Expand Down Expand Up @@ -559,7 +560,8 @@ def test_create_request_02(self):
self.stock_request_user).create(vals)

self.product.route_ids = [(6, 0, self.route.ids)]
stock_request.action_confirm()
stock_request.action_confirm() # To submit
stock_request.action_confirm() # To confirm
self.assertEqual(stock_request.state, 'open')
self.assertEqual(len(stock_request.sudo().picking_ids), 1)
self.assertEqual(len(stock_request.sudo().move_ids), 1)
Expand Down Expand Up @@ -601,8 +603,10 @@ def test_create_request_03(self):
self.stock_request_manager).create(vals)
stock_request_2.product_uom_qty = 6.0
self.product.route_ids = [(6, 0, self.route.ids)]
stock_request_1.action_confirm()
stock_request_2.action_confirm()
stock_request_1.action_confirm() # To submit
stock_request_1.action_confirm() # To confirm
stock_request_2.action_confirm() # To submit
stock_request_2.action_confirm() # To confirm
self.assertEqual(len(stock_request_1.sudo().picking_ids), 1)
self.assertEqual(stock_request_1.sudo().picking_ids,
stock_request_2.sudo().picking_ids)
Expand Down Expand Up @@ -641,7 +645,8 @@ def test_cancel_request(self):
self.stock_request_user).create(vals)

self.product.route_ids = [(6, 0, self.route.ids)]
order.action_confirm()
order.action_confirm() # To submit
order.action_confirm() # To confirm
stock_request = order.stock_request_ids
self.assertEqual(len(order.sudo().picking_ids), 1)
self.assertEqual(len(order.sudo().move_ids), 1)
Expand Down Expand Up @@ -698,7 +703,8 @@ def test_view_actions(self):
self.stock_request_manager).create(vals)
self.product.route_ids = [(6, 0, self.route.ids)]

order.action_confirm()
order.action_confirm() # To submit
order.action_confirm() # To confirm
stock_request = order.stock_request_ids
self.assertTrue(stock_request.picking_ids)
self.assertTrue(order.picking_ids)
Expand Down Expand Up @@ -863,15 +869,18 @@ def test_allow_virtual_location(self):
self.assertTrue(order.allow_virtual_location)

def test_onchange_wh_no_effect_from_order(self):
expected_date = datetime.now()
vals = {
'company_id': self.main_company.id,
'expected_date': expected_date,
'warehouse_id': self.warehouse.id,
'location_id': self.virtual_loc.id,
'stock_request_ids': [(0, 0, {
'product_id': self.product.id,
'product_uom_id': self.product.uom_id.id,
'product_uom_qty': 5.0,
'company_id': self.main_company.id,
'expected_date': expected_date,
'warehouse_id': self.warehouse.id,
'location_id': self.virtual_loc.id,
})]
Expand All @@ -881,3 +890,27 @@ def test_onchange_wh_no_effect_from_order(self):
order.stock_request_ids.onchange_warehouse_id()
self.assertEqual(
order.stock_request_ids[0].location_id, self.virtual_loc)

def test_onchange_location_id_outbound(self):
expected_date = datetime.now()
vals = {
'company_id': self.main_company.id,
'expected_date': expected_date,
'warehouse_id': self.warehouse.id,
'location_id': self.virtual_loc.id,
'stock_request_ids': [(0, 0, {
'product_id': self.product.id,
'product_uom_id': self.product.uom_id.id,
'product_uom_qty': 5.0,
'company_id': self.main_company.id,
'expected_date': expected_date,
'warehouse_id': self.warehouse.id,
'direction': 'outbound',
'location_id': self.virtual_loc.id,
})]
}
order = self.request_order.sudo(
self.stock_request_user).create(vals)
order.stock_request_ids._onchange_location_id()
self.assertEqual(order.stock_request_ids.location_id,
self.env.ref('stock.stock_location_customers'))
3 changes: 1 addition & 2 deletions stock_request/views/stock_picking_views.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>

<record id="view_picking_form" model="ir.ui.view">
<field name="name">stock.picking.form</field>
<field name="model">stock.picking</field>
<field name="inherit_id" ref="stock.view_picking_form"/>
<field eval="12" name="priority"/>
<field name="priority" eval="12"/>
<field name="arch" type="xml">
<div name="button_box" position="inside">
<button type="object"
Expand Down
20 changes: 13 additions & 7 deletions stock_request/views/stock_request_order_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@
<header>
<button name="action_confirm"
string="Confirm" type="object"
attrs="{'invisible': [('state', 'not in', ['draft'])]}"/>
<button name="action_cancel" states="draft,open"
type="object" string="Cancel"/>
<button name="action_draft" states="cancel" type="object"
class="oe_highlight"
attrs="{'invisible': [('state', 'not in', ['draft', 'submitted'])]}"/>
<button name="action_draft" states="submitted,cancel"
class="oe_highlight"
type="object"
string="Set to Draft"/>
<button name="action_cancel" states="draft,submitted,open"
type="object" string="Cancel"/>
<field name="state" widget="statusbar"/>
</header>
<sheet>
Expand Down Expand Up @@ -81,14 +84,15 @@
<notebook>
<page name="items" string="Items">
<field name="stock_request_ids" context="{
'default_expected_date':expected_date,
'default_expected_date': expected_date,
'default_picking_policy': picking_policy,
'default_warehouse_id': warehouse_id,
'default_direction': direction,
'default_location_id': location_id,
'default_procurement_group_id': procurement_group_id,
'default_company_id': company_id,
'default_state': state,
}" attrs="{'readonly': [('state', '!=', 'draft')]}">
}" attrs="{'readonly': [('state', 'not in', ['draft', 'submitted'])]}">
<tree editable="bottom">
<field name="name" readonly="1"/>
<field name="product_id"/>
Expand All @@ -97,12 +101,14 @@
groups="uom.group_uom"/>
<field name="route_id"
options="{'no_create': True}"
groups="stock.group_stock_multi_locations"/>
groups="stock.group_stock_multi_locations"
attrs="{'readonly': [('state', 'not in', ['draft', 'submitted'])]}"/>
<field name="route_ids" invisible="1"/>
<field name="product_uom_qty"/>
<field name="qty_in_progress"/>
<field name="qty_done"/>
<field name="expected_date" invisible="1"/>
<field name="direction" invisible="1"/>
<field name="picking_policy"
invisible="1"/>
<field name="warehouse_id" invisible="1"/>
Expand Down
1 change: 1 addition & 0 deletions stock_request/views/stock_request_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
</group>
<group>
<field name="warehouse_id" widget="selection" groups="stock.group_stock_multi_locations"/>
<field name="direction"/>
<field name="location_id" groups="stock.group_stock_multi_locations"
domain="['|', ('company_id', '=', company_id), ('company_id', '=', False)]"/>
<field name="direction"/>
Expand Down
2 changes: 2 additions & 0 deletions stock_request_purchase/tests/test_stock_request_purchase.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ def test_create_request_02(self):
stock_request_2.product_uom_qty)

def test_view_actions(self):
expected_date = datetime.now()
vals = {
'company_id': self.main_company.id,
'warehouse_id': self.warehouse.id,
Expand All @@ -196,6 +197,7 @@ def test_view_actions(self):
'product_uom_id': self.product.uom_id.id,
'product_uom_qty': 5.0,
'company_id': self.main_company.id,
'expected_date': expected_date,
'warehouse_id': self.warehouse.id,
'location_id': self.warehouse.lot_stock_id.id,
})]
Expand Down

0 comments on commit 1295667

Please sign in to comment.