[MIG] stock_removal_location_by_priority: Migration to 10.0

This commit is contained in:
mreficent
2017-06-21 14:47:43 +02:00
committed by SergiCForgeFlow
parent a937cfc0a9
commit ee096b3654
10 changed files with 140 additions and 23 deletions

View File

@@ -15,13 +15,20 @@ Configuration
You can configure the removal priority as follows: You can configure the removal priority as follows:
#. Go to "Inventory > Configuration > Settings"
#. In 'Location & Warehouse' section, mark "Use 'Removal Priority' in Locations *"
Usage
=====
To use this module, you need to:
#. Go to "Inventory > Configuration > Warehouse Management > Locations" #. Go to "Inventory > Configuration > Warehouse Management > Locations"
#. In each Location form, put a Removal Priority. #. In each Location form, put a Removal Priority.
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot :alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/153/9.0 :target: https://runbot.odoo-community.org/runbot/153/10.0
Bug Tracker Bug Tracker

View File

@@ -5,13 +5,14 @@
{ {
"name": "Stock Removal Location by Priority", "name": "Stock Removal Location by Priority",
"summary": "Establish a removal priority on stock locations.", "summary": "Establish a removal priority on stock locations.",
"version": "9.0.1.0.0", "version": "10.0.1.0.0",
"author": "Eficent, " "author": "Eficent, "
"Odoo Community Association (OCA)", "Odoo Community Association (OCA)",
"website": "https://github.com/OCA/stock-logistics-warehouse", "website": "https://github.com/OCA/stock-logistics-warehouse",
"category": "Warehouse Management", "category": "Warehouse Management",
"depends": ["stock"], "depends": ["stock"],
"data": [ "data": [
'views/res_config_settings_views.xml',
'views/stock_location_view.xml'], 'views/stock_location_view.xml'],
"license": "AGPL-3", "license": "AGPL-3",
'installable': True, 'installable': True,

View File

@@ -3,5 +3,7 @@
# (http://www.eficent.com) # (http://www.eficent.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from . import res_company
from . import stock_config_settings
from . import stock_location from . import stock_location
from . import stock_quant from . import stock_quant

View File

@@ -0,0 +1,16 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Eficent Business and IT Consulting Services S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import fields, models
class ResCompany(models.Model):
_inherit = "res.company"
removal_priority_active = fields.Boolean(
string="Use 'Removal Priority' in Locations",
help="Adds an extra field in Locations named 'Removal Priority'."
"When removing stock from Locations, this priority will apply"
"whenever the incoming dates of the same stock in several "
"locations are the same.")

View File

@@ -0,0 +1,13 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import fields, models
class StockConfigSettings(models.TransientModel):
_inherit = 'stock.config.settings'
removal_priority_active = fields.Boolean(
related='company_id.removal_priority_active',
string="Use 'Removal Priority' in Locations (*)",
help="This configuration is related to the company you're logged into")

View File

@@ -3,7 +3,7 @@
# (http://www.eficent.com) # (http://www.eficent.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from openerp import fields, models from odoo import fields, models
class StockLocation(models.Model): class StockLocation(models.Model):

View File

@@ -3,32 +3,26 @@
# (http://www.eficent.com) # (http://www.eficent.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from openerp import api, fields, models from odoo import api, fields, models
from openerp.tools.translate import _ from odoo.tools.translate import _
from openerp.exceptions import UserError from odoo.exceptions import UserError
class StockQuant(models.Model): class Quant(models.Model):
_inherit = 'stock.quant' _inherit = 'stock.quant'
removal_priority = fields.Integer( removal_priority = fields.Integer(
related='location_id.removal_priority', readonly=True, store=True) related='location_id.removal_priority', readonly=True, store=True)
@api.model @api.model
def apply_removal_strategy(self, quantity, move, ops=False, def _quants_removal_get_order(self, removal_strategy=None):
domain=None, removal_strategy='fifo'): if self.env.user.company_id.removal_priority_active:
if any(move.mapped('location_id.removal_priority')):
if removal_strategy == 'fifo': if removal_strategy == 'fifo':
order = 'in_date, removal_priority, id' return 'in_date, removal_priority, id'
return self._quants_get_order(
quantity, move, ops=ops, domain=domain, orderby=order)
elif removal_strategy == 'lifo': elif removal_strategy == 'lifo':
order = 'in_date desc, removal_priority asc, id desc' return 'in_date desc, removal_priority asc, id desc'
return self._quants_get_order(
quantity, move, ops=ops, domain=domain, orderby=order)
raise UserError(_('Removal strategy %s not implemented.') % ( raise UserError(_('Removal strategy %s not implemented.') % (
removal_strategy,)) removal_strategy,))
else: else:
return super(StockQuant, self).apply_removal_strategy( return super(Quant, self)._quants_removal_get_order(
self, quantity, move, ops=ops, domain=domain,
removal_strategy=removal_strategy) removal_strategy=removal_strategy)

View File

@@ -2,7 +2,7 @@
# Copyright 2017 Eficent Business and IT Consulting Services S.L. # Copyright 2017 Eficent Business and IT Consulting Services S.L.
# (http://www.eficent.com) # (http://www.eficent.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from openerp.tests.common import TransactionCase from odoo.tests.common import TransactionCase
class TestStockRemovalLocationByPriority(TransactionCase): class TestStockRemovalLocationByPriority(TransactionCase):
@@ -22,7 +22,8 @@ class TestStockRemovalLocationByPriority(TransactionCase):
self.location_supplier = self.env.ref('stock.stock_location_suppliers') self.location_supplier = self.env.ref('stock.stock_location_suppliers')
self.company = self.env.ref('base.main_company') self.company = self.env.ref('base.main_company')
self.partner = self.env.ref('base.res_partner_1') self.company.removal_priority_active = True
self.g_stock_user = self.env.ref('stock.group_stock_user') self.g_stock_user = self.env.ref('stock.group_stock_user')
self.user = self._create_user( self.user = self._create_user(
@@ -89,7 +90,7 @@ class TestStockRemovalLocationByPriority(TransactionCase):
}) })
return picking return picking
def test_stock_removal_location_by_priority(self): def test_stock_removal_location_by_priority_fifo(self):
"""Tests removal priority.""" """Tests removal priority."""
wiz1 = self.stock_change_model.with_context( wiz1 = self.stock_change_model.with_context(
active_id=self.product_templ_1.id, active_id=self.product_templ_1.id,
@@ -138,3 +139,59 @@ class TestStockRemovalLocationByPriority(TransactionCase):
for record in records: for record in records:
self.assertEqual(record.qty, 5, self.assertEqual(record.qty, 5,
'Removal_priority did\'nt work properly.') 'Removal_priority did\'nt work properly.')
def test_stock_removal_location_by_priority_lifo(self):
"""Tests removal priority."""
removal_method_id = self.env['product.removal'].search(
[('name', '=', 'lifo')]).id
self.stock.removal_strategy_id = removal_method_id
self.shelf_A.removal_strategy_id = removal_method_id
self.shelf_B.removal_strategy_id = removal_method_id
self.location_supplier.removal_strategy_id = removal_method_id
wiz1 = self.stock_change_model.with_context(
active_id=self.product_templ_1.id,
active_model='product.template'
).create({'new_quantity': 20,
'location_id': self.stock.id,
'product_tmpl_id': self.product_templ_1.id,
})
wiz1.change_product_qty()
self.product1 = wiz1.product_id
picking_1 = self._create_picking(
self.picking_internal, self.stock, self.shelf_A, 5)
picking_1.action_confirm()
picking_1.action_assign()
picking_2 = self._create_picking(
self.picking_internal, self.stock, self.shelf_B, 10)
picking_2.action_confirm()
picking_2.action_assign()
self.assertEqual(picking_1.pack_operation_ids.
linked_move_operation_ids.reserved_quant_id.in_date,
picking_2.pack_operation_ids.
linked_move_operation_ids.reserved_quant_id.in_date,
'Testing data not generated properly.')
wiz_act = picking_1.do_new_transfer()
wiz2 = self.env[wiz_act['res_model']].browse(wiz_act['res_id'])
wiz2.process()
wiz_act = picking_2.do_new_transfer()
wiz3 = self.env[wiz_act['res_model']].browse(wiz_act['res_id'])
wiz3.process()
picking_3 = self._create_picking(
self.picking_out, self.stock, self.location_supplier, 5)
picking_3.action_confirm()
picking_3.action_assign()
wiz_act = picking_3.do_new_transfer()
wiz4 = self.env[wiz_act['res_model']].browse(wiz_act['res_id'])
wiz4.process()
records = self.quant_model.search(
[('product_id', '=', self.product1.id)])
for record in records:
self.assertEqual(record.qty, 5,
'Removal_priority did\'nt work properly.')

View File

@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2017 Eficent Business and IT Consulting Services S.L.
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo>
<record id="view_stock_config_settings" model="ir.ui.view">
<field name="name">stock.config.view - removal_priority</field>
<field name="model">stock.config.settings</field>
<field name="inherit_id" ref="stock.view_stock_config_settings"/>
<field name="arch" type="xml">
<field name="group_warning_stock" position="after">
<field name="removal_priority_active"/>
</field>
<header position="after">
<group>
<field name="company_id" invisible="1"/>
</group>
</header>
<form position="inside">
<div>
<span>(*) This configuration is related to the company you're logged into.</span>
</div>
</form>
</field>
</record>
</odoo>

View File

@@ -10,7 +10,7 @@
<field name="inherit_id" ref="stock.view_location_form"/> <field name="inherit_id" ref="stock.view_location_form"/>
<field name="arch" type="xml"> <field name="arch" type="xml">
<field name="active" position="after"> <field name="active" position="after">
<field name="removal_priority"/> <field name="removal_priority" group="removal_priority_active"/>
</field> </field>
</field> </field>
</record> </record>