mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
[MIG] stock_warehouse_orderpoint_stock_info: Migration to Odoo 11
This commit is contained in:
@@ -14,7 +14,7 @@ Usage
|
||||
|
||||
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
|
||||
:alt: Try me on Runbot
|
||||
:target: https://runbot.odoo-community.org/runbot/153/10.0
|
||||
:target: https://runbot.odoo-community.org/runbot/153/11.0
|
||||
|
||||
Bug Tracker
|
||||
===========
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2016 OdooMRP Team
|
||||
# Copyright 2016 AvanzOSC
|
||||
# Copyright 2016 Pedro M. Baeza <pedro.baeza@tecnativa.com>
|
||||
# Copyright 2016 Serpent Consulting Services Pvt. Ltd.
|
||||
# Copyright 2016 Eficent Business and IT Consulting Services, S.L.
|
||||
# Copyright 2018 Camptocamp SA
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from . import models
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2016 OdooMRP Team
|
||||
# Copyright 2016 AvanzOSC
|
||||
# Copyright 2016 Pedro M. Baeza <pedro.baeza@tecnativa.com>
|
||||
# Copyright 2016 Serpent Consulting Services Pvt. Ltd.
|
||||
# Copyright 2017 Eficent Business and IT Consulting Services, S.L.
|
||||
# Copyright 2018 Camptocamp SA
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
{
|
||||
"name": "Stock Warehouse Orderpoint Stock Info",
|
||||
"version": "10.0.1.0.0",
|
||||
"version": "11.0.1.0.0",
|
||||
"depends": [
|
||||
"stock",
|
||||
],
|
||||
@@ -16,12 +16,10 @@
|
||||
"AvanzOSC, "
|
||||
"Tecnativa, "
|
||||
"Odoo Community Association (OCA)",
|
||||
"website": "http://www.odoomrp.com",
|
||||
"website": "https://github.com/OCA/stock-logistics-warehouse",
|
||||
"category": "Warehouse",
|
||||
"license": "AGPL-3",
|
||||
"data": [
|
||||
"views/stock_warehouse_orderpoint_view.xml",
|
||||
],
|
||||
"installable": True,
|
||||
"application": False,
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2016 OdooMRP Team
|
||||
# Copyright 2016 AvanzOSC
|
||||
# Copyright 2016 Pedro M. Baeza <pedro.baeza@tecnativa.com>
|
||||
# Copyright 2016 Serpent Consulting Services Pvt. Ltd.
|
||||
# Copyright 2016 Eficent Business and IT Consulting Services, S.L.
|
||||
# Copyright 2018 Camptocamp SA
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from . import stock_warehouse_orderpoint
|
||||
|
||||
@@ -1,48 +1,62 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2016 OdooMRP Team
|
||||
# Copyright 2016 AvanzOSC
|
||||
# Copyright 2016 Pedro M. Baeza <pedro.baeza@tecnativa.com>
|
||||
# Copyright 2016 Serpent Consulting Services Pvt. Ltd.
|
||||
# Copyright 2016-17 Eficent Business and IT Consulting Services, S.L.
|
||||
# Copyright 2018 Camptocamp SA
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import api, fields, models
|
||||
from collections import defaultdict
|
||||
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class StockWarehouseOrderpoint(models.Model):
|
||||
_inherit = 'stock.warehouse.orderpoint'
|
||||
|
||||
@api.multi
|
||||
def _compute_product_available_qty(self):
|
||||
op_by_loc = defaultdict(lambda: self.env['stock.warehouse.orderpoint'])
|
||||
for order in self:
|
||||
op_by_loc[order.location_id] |= order
|
||||
for location_id, order_in_loc in op_by_loc.items():
|
||||
products = order_in_loc.mapped('product_id').with_context(
|
||||
location=location_id.id)._compute_quantities_dict(
|
||||
lot_id=self.env.context.get('lot_id'),
|
||||
owner_id=self.env.context.get('owner_id'),
|
||||
package_id=self.env.context.get('package_id'))
|
||||
for order in order_in_loc:
|
||||
product = products[order.product_id.id]
|
||||
order.product_location_qty = product['qty_available']
|
||||
order.incoming_location_qty = product['incoming_qty']
|
||||
order.outgoing_location_qty = product['outgoing_qty']
|
||||
order.virtual_location_qty = product['virtual_available']
|
||||
|
||||
product_location_qty = fields.Float(
|
||||
string='Quantity On Location',
|
||||
compute='_compute_product_available_qty')
|
||||
compute='_compute_product_available_qty'
|
||||
)
|
||||
incoming_location_qty = fields.Float(
|
||||
string='Incoming On Location',
|
||||
compute='_compute_product_available_qty')
|
||||
compute='_compute_product_available_qty'
|
||||
)
|
||||
outgoing_location_qty = fields.Float(
|
||||
string='Outgoing On Location',
|
||||
compute='_compute_product_available_qty')
|
||||
compute='_compute_product_available_qty'
|
||||
)
|
||||
virtual_location_qty = fields.Float(
|
||||
string='Forecast On Location',
|
||||
compute='_compute_product_available_qty')
|
||||
product_category = fields.Many2one(string='Product Category',
|
||||
related='product_id.categ_id',
|
||||
store=True, readonly=True)
|
||||
compute='_compute_product_available_qty'
|
||||
)
|
||||
product_category = fields.Many2one(
|
||||
string='Product Category',
|
||||
related='product_id.categ_id',
|
||||
store=True,
|
||||
readonly=True
|
||||
)
|
||||
|
||||
@api.multi
|
||||
def _compute_product_available_qty(self):
|
||||
operation_by_locaion = defaultdict(
|
||||
lambda: self.env['stock.warehouse.orderpoint']
|
||||
)
|
||||
for order in self:
|
||||
operation_by_locaion[order.location_id] |= order
|
||||
for location_id, order_in_locaion in operation_by_locaion.items():
|
||||
products = order_in_locaion.mapped('product_id').with_context(
|
||||
location=location_id.id
|
||||
)._compute_quantities_dict(
|
||||
lot_id=self.env.context.get('lot_id'),
|
||||
owner_id=self.env.context.get('owner_id'),
|
||||
package_id=self.env.context.get('package_id')
|
||||
)
|
||||
for order in order_in_locaion:
|
||||
product = products[order.product_id.id]
|
||||
order.update({
|
||||
'product_location_qty': product['qty_available'],
|
||||
'incoming_location_qty': product['incoming_qty'],
|
||||
'outgoing_location_qty': product['outgoing_qty'],
|
||||
'virtual_location_qty': product['virtual_available'],
|
||||
})
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2016 OdooMRP Team
|
||||
# Copyright 2016 AvanzOSC
|
||||
# Copyright 2016 Pedro M. Baeza <pedro.baeza@tecnativa.com>
|
||||
# Copyright 2016 Serpent Consulting Services Pvt. Ltd.
|
||||
# Copyright 2016 Eficent Business and IT Consulting Services, S.L.
|
||||
# Copyright 2018 Camptocamp SA
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from . import test_stock_warehouse_orderpoint
|
||||
|
||||
@@ -1,66 +1,52 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2016 OdooMRP Team
|
||||
# Copyright 2016 AvanzOSC
|
||||
# Copyright 2016 Pedro M. Baeza <pedro.baeza@tecnativa.com>
|
||||
# Copyright 2016 Serpent Consulting Services Pvt. Ltd.
|
||||
# Copyright 2016-17 Eficent Business and IT Consulting Services, S.L.
|
||||
# Copyright 2018 Camptocamp SA
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo.tests import common
|
||||
from odoo.tests.common import SavepointCase
|
||||
|
||||
|
||||
class TestStockWarehouseOrderpoint(common.TransactionCase):
|
||||
class TestStockWarehouseOrderpoint(SavepointCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestStockWarehouseOrderpoint, self).setUp()
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
# Get required Model
|
||||
self.reordering_rule_model = self.env['stock.warehouse.orderpoint']
|
||||
self.stock_move_model = self.env['stock.move']
|
||||
self.product_model = self.env['product.product']
|
||||
self.product_ctg_model = self.env['product.category']
|
||||
cls.reordering_rule_model = cls.env['stock.warehouse.orderpoint']
|
||||
cls.stock_move_model = cls.env['stock.move']
|
||||
cls.product_model = cls.env['product.product']
|
||||
cls.product_ctg_model = cls.env['product.category']
|
||||
|
||||
# Get required Model data
|
||||
self.product_uom = self.env.ref('product.product_uom_unit')
|
||||
self.dest_location = self.env.ref('stock.stock_location_stock')
|
||||
self.location = self.env.ref('stock.stock_location_locations_partner')
|
||||
self.picking = self.env.ref('stock.picking_type_in')
|
||||
cls.product_uom = cls.env.ref('product.product_uom_unit')
|
||||
cls.dest_location = cls.env.ref('stock.stock_location_stock')
|
||||
cls.location = cls.env.ref('stock.stock_location_locations_partner')
|
||||
cls.picking = cls.env.ref('stock.picking_type_in')
|
||||
|
||||
# Create product category and product
|
||||
self.product_ctg = self._create_product_category()
|
||||
self.product = self._create_product()
|
||||
|
||||
# Create Reordering Rule
|
||||
self.reordering_record = self.create_orderpoint()
|
||||
|
||||
def _create_product_category(self):
|
||||
"""Create a Product Category."""
|
||||
product_ctg = self.product_ctg_model.create({
|
||||
cls.product_ctg = cls.product_ctg_model.create({
|
||||
'name': 'test_product_ctg',
|
||||
'type': 'normal',
|
||||
})
|
||||
return product_ctg
|
||||
|
||||
def _create_product(self):
|
||||
"""Create a Stockable Product."""
|
||||
product = self.product_model.create({
|
||||
cls.product = cls.product_model.create({
|
||||
'name': 'Test Product',
|
||||
'categ_id': self.product_ctg.id,
|
||||
'categ_id': cls.product_ctg.id,
|
||||
'type': 'product',
|
||||
'uom_id': self.product_uom.id,
|
||||
'uom_id': cls.product_uom.id,
|
||||
})
|
||||
return product
|
||||
|
||||
def create_orderpoint(self):
|
||||
"""Create a Reordering rule for the product."""
|
||||
record = self.reordering_rule_model.create({
|
||||
# Create Reordering Rule
|
||||
cls.reordering_record = cls.reordering_rule_model.create({
|
||||
'name': 'Reordering Rule',
|
||||
'product_id': self.product.id,
|
||||
'product_id': cls.product.id,
|
||||
'product_min_qty': '1',
|
||||
'product_max_qty': '5',
|
||||
'qty_multiple': '1',
|
||||
'location_id': self.dest_location.id,
|
||||
'location_id': cls.dest_location.id,
|
||||
})
|
||||
return record
|
||||
|
||||
def create_stock_move(self):
|
||||
"""Create a Stock Move."""
|
||||
@@ -73,7 +59,7 @@ class TestStockWarehouseOrderpoint(common.TransactionCase):
|
||||
'location_id': self.location.id,
|
||||
'location_dest_id': self.dest_location.id
|
||||
})
|
||||
move.action_confirm()
|
||||
move._action_confirm()
|
||||
return move
|
||||
|
||||
def test_product_qty(self):
|
||||
@@ -87,7 +73,7 @@ class TestStockWarehouseOrderpoint(common.TransactionCase):
|
||||
self.assertEqual(self.reordering_record.virtual_location_qty,
|
||||
self.product.virtual_available,
|
||||
'Virtual Qty does not match')
|
||||
move.action_done()
|
||||
move._action_done()
|
||||
self.reordering_record.refresh()
|
||||
self.assertEqual(self.reordering_record.product_location_qty,
|
||||
self.product.qty_available,
|
||||
|
||||
Reference in New Issue
Block a user