mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
stock_mts_mto_rule
This commit is contained in:
@@ -70,8 +70,6 @@ stock-logistics-warehouse/issues/new?body=module:%20
|
||||
stock_mts_mto_rule%0Aversion:%20
|
||||
8.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
|
||||
|
||||
Note: In order to see this option, you must enable "Manage advanced routes for your warehouse" under Settings -> Configuration -> Warehouse.
|
||||
|
||||
Credits
|
||||
=======
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
##############################################################################
|
||||
|
||||
{'name': 'Stock MTS+MTO Rule',
|
||||
'version': '8.0.1.0.0',
|
||||
'version': '9.0.1.0.0',
|
||||
'author': 'Akretion,Odoo Community Association (OCA)',
|
||||
'website': 'http://www.akretion.com',
|
||||
'license': 'AGPL-3',
|
||||
@@ -34,5 +34,5 @@
|
||||
'view/pull_rule.xml',
|
||||
'view/warehouse.xml',
|
||||
],
|
||||
'installable': False,
|
||||
'installable': True,
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
###############################################################################
|
||||
from openerp import models, api, fields
|
||||
from openerp import api, fields, models
|
||||
|
||||
|
||||
class ProcurementOrder(models.Model):
|
||||
@@ -52,14 +52,13 @@ class ProcurementOrder(models.Model):
|
||||
return self.product_qty
|
||||
|
||||
@api.model
|
||||
def _get_mts_mto_procurement(self, proc, rule, qty, uos_qty):
|
||||
def _get_mts_mto_procurement(self, proc, rule, qty):
|
||||
origin = (proc.group_id and (proc.group_id.name + ":") or "") + \
|
||||
(proc.rule_id and proc.rule_id.name or proc.origin or "/")
|
||||
return {
|
||||
'name': proc.name,
|
||||
'origin': origin,
|
||||
'product_qty': qty,
|
||||
'product_uos_qty': uos_qty,
|
||||
'rule_id': rule.id,
|
||||
'mts_mto_procurement_id': proc.id,
|
||||
}
|
||||
@@ -94,37 +93,28 @@ class ProcurementOrder(models.Model):
|
||||
procurement.rule_id.action == 'split_procurement':
|
||||
if procurement.mts_mto_procurement_ids:
|
||||
return super(ProcurementOrder, self)._run(procurement)
|
||||
uom_obj = self.env['product.uom']
|
||||
needed_qty = procurement.get_mto_qty_to_order()
|
||||
rule = procurement.rule_id
|
||||
if needed_qty == 0.0:
|
||||
mts_vals = self._get_mts_mto_procurement(
|
||||
procurement, rule.mts_rule_id, procurement.product_qty,
|
||||
procurement.product_uos_qty)
|
||||
procurement, rule.mts_rule_id, procurement.product_qty)
|
||||
mts_proc = procurement.copy(mts_vals)
|
||||
mts_proc.run()
|
||||
elif needed_qty == procurement.product_qty:
|
||||
mto_vals = self._get_mts_mto_procurement(
|
||||
procurement, rule.mto_rule_id, procurement.product_qty,
|
||||
procurement.product_uos_qty)
|
||||
procurement, rule.mto_rule_id, procurement.product_qty)
|
||||
mto_proc = procurement.copy(mto_vals)
|
||||
mto_proc.run()
|
||||
else:
|
||||
mts_qty = procurement.product_qty - needed_qty
|
||||
mts_uos_qty = uom_obj._compute_qty(
|
||||
procurement.product_uom.id,
|
||||
mts_qty,
|
||||
procurement.product_uos.id)
|
||||
mts_vals = self._get_mts_mto_procurement(
|
||||
procurement, rule.mts_rule_id, mts_qty, mts_uos_qty)
|
||||
procurement, rule.mts_rule_id, mts_qty)
|
||||
mts_proc = procurement.copy(mts_vals)
|
||||
mts_proc.run()
|
||||
|
||||
uos_qty = procurement.product_uos_qty
|
||||
mto_vals = self._get_mts_mto_procurement(
|
||||
procurement, rule.mto_rule_id, needed_qty,
|
||||
uos_qty - mts_uos_qty)
|
||||
|
||||
procurement, rule.mto_rule_id, needed_qty)
|
||||
mto_proc = procurement.copy(mto_vals)
|
||||
mto_proc.run()
|
||||
|
||||
return super(ProcurementOrder, self)._run(procurement)
|
||||
|
||||
@@ -19,10 +19,24 @@ from datetime import datetime
|
||||
|
||||
class TestMtoMtsRoute(TransactionCase):
|
||||
|
||||
def _procurement_create(self):
|
||||
self.procurement = self.env['procurement.order'].create({
|
||||
'location_id': self.env.ref('stock.stock_location_customers').id,
|
||||
'product_id': self.product.id,
|
||||
'product_qty': 2.0,
|
||||
'product_uom': 1,
|
||||
'warehouse_id': self.warehouse.id,
|
||||
'priority': '1',
|
||||
'date_planned': datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
|
||||
'name': self.product.name,
|
||||
'origin': 'test',
|
||||
'group_id': self.group.id,
|
||||
})
|
||||
|
||||
def test_standard_mto_route(self):
|
||||
mto_route = self.env.ref('stock.route_warehouse0_mto')
|
||||
self.product.route_ids = [(6, 0, [mto_route.id])]
|
||||
self.procurement.run()
|
||||
self._procurement_create()
|
||||
self.assertEqual(self.warehouse.mto_pull_id,
|
||||
self.procurement.rule_id)
|
||||
self.assertEqual('make_to_order',
|
||||
@@ -33,7 +47,7 @@ class TestMtoMtsRoute(TransactionCase):
|
||||
self.procurement.move_ids[0].state)
|
||||
|
||||
def test_standard_mts_route(self):
|
||||
self.procurement.run()
|
||||
self._procurement_create()
|
||||
procurement_id = self.procurement_obj.search([
|
||||
('group_id', '=', self.procurement.group_id.id),
|
||||
('move_ids', '!=', False)], limit=1)
|
||||
@@ -48,7 +62,7 @@ class TestMtoMtsRoute(TransactionCase):
|
||||
mto_mts_route = self.env.ref('stock_mts_mto_rule.route_mto_mts')
|
||||
self.product.route_ids = [(6, 0, [mto_mts_route.id])]
|
||||
self.quant.qty = 1.0
|
||||
self.procurement.run()
|
||||
self._procurement_create()
|
||||
moves = self.env['stock.move'].search(
|
||||
[('group_id', '=', self.group.id)])
|
||||
self.assertEqual(2, len(moves))
|
||||
@@ -58,7 +72,7 @@ class TestMtoMtsRoute(TransactionCase):
|
||||
mto_mts_route = self.env.ref('stock_mts_mto_rule.route_mto_mts')
|
||||
self.product.route_ids = [(6, 0, [mto_mts_route.id])]
|
||||
self.quant.qty = 0.0
|
||||
self.procurement.run()
|
||||
self._procurement_create()
|
||||
moves = self.env['stock.move'].search(
|
||||
[('group_id', '=', self.group.id)])
|
||||
self.assertEqual(1, len(moves))
|
||||
@@ -70,7 +84,7 @@ class TestMtoMtsRoute(TransactionCase):
|
||||
mto_mts_route = self.env.ref('stock_mts_mto_rule.route_mto_mts')
|
||||
self.product.route_ids = [(6, 0, [mto_mts_route.id])]
|
||||
self.quant.qty = 3.0
|
||||
self.procurement.run()
|
||||
self._procurement_create()
|
||||
moves = self.env['stock.move'].search(
|
||||
[('group_id', '=', self.group.id)])
|
||||
self.assertEqual(1, len(moves))
|
||||
@@ -88,18 +102,7 @@ class TestMtoMtsRoute(TransactionCase):
|
||||
self.group = self.env['procurement.group'].create({
|
||||
'name': 'test',
|
||||
})
|
||||
self.procurement = self.env['procurement.order'].create({
|
||||
'location_id': self.env.ref('stock.stock_location_customers').id,
|
||||
'product_id': self.product.id,
|
||||
'product_qty': 2.0,
|
||||
'product_uom': 1,
|
||||
'warehouse_id': self.warehouse.id,
|
||||
'priority': '1',
|
||||
'date_planned': datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
|
||||
'name': self.product.name,
|
||||
'origin': 'test',
|
||||
'group_id': self.group.id,
|
||||
})
|
||||
|
||||
self.quant = self.env['stock.quant'].create({
|
||||
'owner_id': self.company_partner.id,
|
||||
'location_id': self.env.ref('stock.stock_location_stock').id,
|
||||
|
||||
Reference in New Issue
Block a user