Merge pull request #204 from syleam/9.0-migrate-stock_mts_mto_rule

[MIG][9.0] Migrate stock_mts_mto_rule
This commit is contained in:
Pedro M. Baeza
2016-10-21 08:27:01 +02:00
committed by GitHub
8 changed files with 561 additions and 101 deletions

View File

@@ -1,6 +1,8 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:alt: License: AGPL-3
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
==================
Stock MTS+MTO Rule
==================
@@ -35,15 +37,34 @@ After validation, a purchase order with 2 products will be created.
Usage
=====
You have to choose the mts+mto route on the product form.
You should not choose both mts+mto route and mto route.
You have to select the mts+mto route on the product form.
You should not select both the mts+mto route and the mto route.
.. 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/9.0
Configuration
=============
You have to choose 'Use MTO+MTS rules' on the company's warehouse form.
You have to select 'Use MTO+MTS rules' on the company's warehouse form.
Note: In order to see this option, you must enable "Manage advanced routes for your warehouse" under Settings -> Configuration -> Warehouse.
Known issues
============
If you cancel a delivery order and then recreate it from Recreate
Delivery Order button in sale order form, then the stock level at the time of
the Re-Creation won't be taken into account. So if a purchase order was created
when the sale order was first validated, a similar purchase order will be created
during the Re-creation of the delivery order, even if not needed regarding the actual stock.
Bug Tracker
===========
Bugs are tracked on `GitHub Issues
<https://github.com/OCA/stock-logistics-warehouse/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smashing it by providing a detailed and welcomed feedback.
Credits
=======
@@ -56,9 +77,9 @@ Contributors
Maintainer
----------
.. image:: http://odoo-community.org/logo.png
.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: http://odoo-community.org
:target: https://odoo-community.org
This module is maintained by the OCA.
@@ -66,4 +87,4 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.
To contribute to this module, please visit http://odoo-community.org.
To contribute to this module, please visit https://odoo-community.org.

View File

@@ -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,
}

View File

@@ -0,0 +1,107 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * stock_mts_mto_rule
#
# Translators:
# Rudolf Schnapka <rs@techno-flex.de>, 2016
msgid ""
msgstr ""
"Project-Id-Version: stock-logistics-warehouse (8.0)\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-01-14 01:38+0000\n"
"PO-Revision-Date: 2016-01-14 09:50+0000\n"
"Last-Translator: Rudolf Schnapka <rs@techno-flex.de>\n"
"Language-Team: German (http://www.transifex.com/oca/OCA-stock-logistics-warehouse-8-0/language/de/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Language: de\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
#. module: stock_mts_mto_rule
#: code:addons/stock_mts_mto_rule/model/warehouse.py:53
#, python-format
msgid "Can't find MTO Rule on the warehouse"
msgstr "Kann MTO-Regel zum Lager nicht finden"
#. module: stock_mts_mto_rule
#: code:addons/stock_mts_mto_rule/model/warehouse.py:60
#, python-format
msgid "Can't find MTS Rule on the warehouse"
msgstr "Kann MTS-Regel zum Lager nicht finden"
#. module: stock_mts_mto_rule
#: code:addons/stock_mts_mto_rule/model/warehouse.py:49
#, python-format
msgid "Can't find any generic MTS+MTO route."
msgstr "Kann keine allg. MTO- oder MTS-Route finden"
#. module: stock_mts_mto_rule
#: code:addons/stock_mts_mto_rule/model/rule.py:36
#, python-format
msgid "Choose between MTS and MTO"
msgstr "Wähle aus MTO und MTS"
#. module: stock_mts_mto_rule
#: help:stock.warehouse,mto_mts_management:0
msgid ""
"If this new route is selected on product form view, a purchase order will be"
" created only if the virtual stock is less than 0 else, the product will be "
"taken from stocks"
msgstr "Wird diese neue Route in der Produktdetailsicht gewählt, wird eine Beschaffung nur dann bewirkt, wenn der Planbestand unter 0 fällt, anderenfalls wird das Produkt aus dem Bestand genommen."
#. module: stock_mts_mto_rule
#: field:procurement.rule,mto_rule_id:0
msgid "MTO Rule"
msgstr "MTO-Regel"
#. module: stock_mts_mto_rule
#: field:stock.warehouse,mts_mto_rule_id:0
msgid "MTO+MTS rule"
msgstr "MTO+MTS-Regel"
#. module: stock_mts_mto_rule
#: field:procurement.rule,mts_rule_id:0
msgid "MTS Rule"
msgstr "MTS-Regel"
#. module: stock_mts_mto_rule
#: code:addons/stock_mts_mto_rule/model/warehouse.py:63
#, python-format
msgid "MTS+MTO"
msgstr "MTS+MTO"
#. module: stock_mts_mto_rule
#: model:stock.location.route,name:stock_mts_mto_rule.route_mto_mts
msgid "Make To Order + Make To Stock"
msgstr "MTO Auftragsfertigung + MTS Lagerfertigung"
#. module: stock_mts_mto_rule
#: field:procurement.order,mts_mto_procurement_id:0
msgid "Mto+Mts Procurement"
msgstr "MTO+MTS-Beschaffung"
#. module: stock_mts_mto_rule
#: model:ir.model,name:stock_mts_mto_rule.model_procurement_order
msgid "Procurement"
msgstr "Beschaffung"
#. module: stock_mts_mto_rule
#: model:ir.model,name:stock_mts_mto_rule.model_procurement_rule
msgid "Procurement Rule"
msgstr "Beschaffungsregel"
#. module: stock_mts_mto_rule
#: field:procurement.order,mts_mto_procurement_ids:0
msgid "Procurements"
msgstr "Beschaffungen"
#. module: stock_mts_mto_rule
#: field:stock.warehouse,mto_mts_management:0
msgid "Use MTO+MTS rules"
msgstr "Verwende MTO+MTS-Regeln"
#. module: stock_mts_mto_rule
#: model:ir.model,name:stock_mts_mto_rule.model_stock_warehouse
msgid "Warehouse"
msgstr "Warenlager"

View File

@@ -0,0 +1,107 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * stock_mts_mto_rule
#
# Translators:
# Antonio Trueba, 2016
msgid ""
msgstr ""
"Project-Id-Version: stock-logistics-warehouse (8.0)\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-01-14 01:38+0000\n"
"PO-Revision-Date: 2016-02-10 16:39+0000\n"
"Last-Translator: Antonio Trueba\n"
"Language-Team: Spanish (http://www.transifex.com/oca/OCA-stock-logistics-warehouse-8-0/language/es/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Language: es\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
#. module: stock_mts_mto_rule
#: code:addons/stock_mts_mto_rule/model/warehouse.py:53
#, python-format
msgid "Can't find MTO Rule on the warehouse"
msgstr ""
#. module: stock_mts_mto_rule
#: code:addons/stock_mts_mto_rule/model/warehouse.py:60
#, python-format
msgid "Can't find MTS Rule on the warehouse"
msgstr ""
#. module: stock_mts_mto_rule
#: code:addons/stock_mts_mto_rule/model/warehouse.py:49
#, python-format
msgid "Can't find any generic MTS+MTO route."
msgstr ""
#. module: stock_mts_mto_rule
#: code:addons/stock_mts_mto_rule/model/rule.py:36
#, python-format
msgid "Choose between MTS and MTO"
msgstr ""
#. module: stock_mts_mto_rule
#: help:stock.warehouse,mto_mts_management:0
msgid ""
"If this new route is selected on product form view, a purchase order will be"
" created only if the virtual stock is less than 0 else, the product will be "
"taken from stocks"
msgstr ""
#. module: stock_mts_mto_rule
#: field:procurement.rule,mto_rule_id:0
msgid "MTO Rule"
msgstr ""
#. module: stock_mts_mto_rule
#: field:stock.warehouse,mts_mto_rule_id:0
msgid "MTO+MTS rule"
msgstr ""
#. module: stock_mts_mto_rule
#: field:procurement.rule,mts_rule_id:0
msgid "MTS Rule"
msgstr ""
#. module: stock_mts_mto_rule
#: code:addons/stock_mts_mto_rule/model/warehouse.py:63
#, python-format
msgid "MTS+MTO"
msgstr ""
#. module: stock_mts_mto_rule
#: model:stock.location.route,name:stock_mts_mto_rule.route_mto_mts
msgid "Make To Order + Make To Stock"
msgstr ""
#. module: stock_mts_mto_rule
#: field:procurement.order,mts_mto_procurement_id:0
msgid "Mto+Mts Procurement"
msgstr ""
#. module: stock_mts_mto_rule
#: model:ir.model,name:stock_mts_mto_rule.model_procurement_order
msgid "Procurement"
msgstr "Abastecimiento"
#. module: stock_mts_mto_rule
#: model:ir.model,name:stock_mts_mto_rule.model_procurement_rule
msgid "Procurement Rule"
msgstr "Regla de abastecimiento"
#. module: stock_mts_mto_rule
#: field:procurement.order,mts_mto_procurement_ids:0
msgid "Procurements"
msgstr "Abastecimientos"
#. module: stock_mts_mto_rule
#: field:stock.warehouse,mto_mts_management:0
msgid "Use MTO+MTS rules"
msgstr ""
#. module: stock_mts_mto_rule
#: model:ir.model,name:stock_mts_mto_rule.model_stock_warehouse
msgid "Warehouse"
msgstr "Almacén"

View File

@@ -0,0 +1,107 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * stock_mts_mto_rule
#
# Translators:
# Matjaž Mozetič <m.mozetic@matmoz.si>, 2015
msgid ""
msgstr ""
"Project-Id-Version: stock-logistics-warehouse (8.0)\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2015-10-24 09:07+0000\n"
"PO-Revision-Date: 2015-10-23 12:22+0000\n"
"Last-Translator: Matjaž Mozetič <m.mozetic@matmoz.si>\n"
"Language-Team: Slovenian (http://www.transifex.com/oca/OCA-stock-logistics-warehouse-8-0/language/sl/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Language: sl\n"
"Plural-Forms: nplurals=4; plural=(n%100==1 ? 0 : n%100==2 ? 1 : n%100==3 || n%100==4 ? 2 : 3);\n"
#. module: stock_mts_mto_rule
#: code:addons/stock_mts_mto_rule/model/warehouse.py:53
#, python-format
msgid "Can't find MTO Rule on the warehouse"
msgstr "Za skladišče ni pravila 'po naročilu'"
#. module: stock_mts_mto_rule
#: code:addons/stock_mts_mto_rule/model/warehouse.py:60
#, python-format
msgid "Can't find MTS Rule on the warehouse"
msgstr "Za skladišče ni pravila 'na zalogo'"
#. module: stock_mts_mto_rule
#: code:addons/stock_mts_mto_rule/model/warehouse.py:49
#, python-format
msgid "Can't find any generic MTS+MTO route."
msgstr "Ni generične proge 'na zalogo' + 'po naročilu'"
#. module: stock_mts_mto_rule
#: code:addons/stock_mts_mto_rule/model/rule.py:36
#, python-format
msgid "Choose between MTS and MTO"
msgstr "Izbira med 'Na zalogo' in 'Po naročilu'"
#. module: stock_mts_mto_rule
#: help:stock.warehouse,mto_mts_management:0
msgid ""
"If this new route is selected on product form view, a purchase order will be"
" created only if the virtual stock is less than 0 else, the product will be "
"taken from stocks"
msgstr "Če je na prikazu obrazca proizvoda izbrana ta proga, se nabavni nalog ustvari le, če je navidezna zaloga manj od 0. V nasprotnem primeru se proizvod vzame iz zaloge."
#. module: stock_mts_mto_rule
#: field:procurement.rule,mto_rule_id:0
msgid "MTO Rule"
msgstr "Pravilo 'Po naročilu'"
#. module: stock_mts_mto_rule
#: field:stock.warehouse,mts_mto_rule_id:0
msgid "MTO+MTS rule"
msgstr "Pravilo 'Po naročilu' + 'Na zalogo'"
#. module: stock_mts_mto_rule
#: field:procurement.rule,mts_rule_id:0
msgid "MTS Rule"
msgstr "Pravilo 'Na zalogo'"
#. module: stock_mts_mto_rule
#: code:addons/stock_mts_mto_rule/model/warehouse.py:63
#, python-format
msgid "MTS+MTO"
msgstr "Na zalogo + Po naročilu"
#. module: stock_mts_mto_rule
#: model:stock.location.route,name:stock_mts_mto_rule.route_mto_mts
msgid "Make To Order + Make To Stock"
msgstr "Naredi po naročilu + Naredi na zalogo"
#. module: stock_mts_mto_rule
#: field:procurement.order,mts_mto_procurement_id:0
msgid "Mto+Mts Procurement"
msgstr "Oskrbovanja 'po naročilu'+'na zalogo'"
#. module: stock_mts_mto_rule
#: model:ir.model,name:stock_mts_mto_rule.model_procurement_order
msgid "Procurement"
msgstr "Oskrbovanje"
#. module: stock_mts_mto_rule
#: model:ir.model,name:stock_mts_mto_rule.model_procurement_rule
msgid "Procurement Rule"
msgstr "Oskrbovalno pravilo"
#. module: stock_mts_mto_rule
#: field:procurement.order,mts_mto_procurement_ids:0
msgid "Procurements"
msgstr "Oskrbovanja"
#. module: stock_mts_mto_rule
#: field:stock.warehouse,mto_mts_management:0
msgid "Use MTO+MTS rules"
msgstr "Uporabi pravila Po naročilu + Na zalogo"
#. module: stock_mts_mto_rule
#: model:ir.model,name:stock_mts_mto_rule.model_stock_warehouse
msgid "Warehouse"
msgstr "Skladišče"

View File

@@ -19,12 +19,21 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
###############################################################################
from openerp import models, api
from openerp import api, fields, models
class ProcurementOrder(models.Model):
_inherit = 'procurement.order'
mts_mto_procurement_id = fields.Many2one(
'procurement.order',
string="Mto+Mts Procurement",
copy=False)
mts_mto_procurement_ids = fields.One2many(
'procurement.order',
'mts_mto_procurement_id',
string="Procurements")
@api.multi
def get_mto_qty_to_order(self):
self.ensure_one()
@@ -43,69 +52,69 @@ 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': rule.name,
'name': proc.name,
'origin': origin,
'product_qty': qty,
'product_uos_qty': uos_qty,
'rule_id': rule.id,
'mts_mto_procurement_id': proc.id,
}
@api.model
def _check(self, procurement):
if procurement.rule_id and \
procurement.rule_id.action == 'split_procurement':
if procurement.state == 'running':
cancel_proc_list = [x.state == 'cancel'
for x in procurement.mts_mto_procurement_ids]
done_cancel_test_list = [
x.state in ('done', 'cancel')
for x in procurement.mts_mto_procurement_ids]
if all(cancel_proc_list):
procurement.write({'state': 'cancel'})
elif all(done_cancel_test_list):
return True
return super(ProcurementOrder, self)._check(procurement)
@api.multi
def run(self, autocommit=False):
res = super(ProcurementOrder, self).run(autocommit=autocommit)
for proc in self:
if proc.rule_id and \
proc.rule_id.action == 'split_procurement':
proc.check()
def check(self, autocommit=False):
res = super(ProcurementOrder, self).check(autocommit=autocommit)
for procurement in self:
if procurement.mts_mto_procurement_id:
procurement.mts_mto_procurement_id.check(
autocommit=autocommit)
return res
@api.model
def _run(self, procurement):
if procurement.rule_id and \
procurement.rule_id.action == 'split_procurement':
uom_obj = self.env['product.uom']
if procurement.mts_mto_procurement_ids:
return super(ProcurementOrder, self)._run(procurement)
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)

View File

@@ -70,6 +70,26 @@ class Warehouse(models.Model):
'picking_type_id': warehouse.mto_pull_id.picking_type_id.id,
}
@api.model
def _get_push_pull_rules(self, warehouse, active, values, new_route_id):
pull_obj = self.env['procurement.rule']
res = super(Warehouse, self)._get_push_pull_rules(
warehouse, active, values, new_route_id)
customer_location = warehouse._get_partner_locations()
location_id = customer_location[0].id
if warehouse.mto_mts_management:
for pull in res[1]:
if pull['location_id'] == location_id:
pull_mto_mts = pull.copy()
pull_mto_mts_id = pull_obj.create(pull_mto_mts)
pull.update({
'action': 'split_procurement',
'mto_rule_id': pull_mto_mts_id.id,
'mts_rule_id': pull_mto_mts_id.id,
'sequence': 10
})
return res
@api.multi
def create_routes(self, warehouse):
pull_model = self.env['procurement.rule']
@@ -94,7 +114,11 @@ class Warehouse(models.Model):
for warehouse in self:
if warehouse.mts_mto_rule_id:
warehouse.mts_mto_rule_id.unlink()
return super(Warehouse, self).write(vals)
res = super(Warehouse, self).write(vals)
if 'mto_mts_management' in vals:
self.with_context({'active_test': False}).change_route(
warehouse, new_delivery_step=warehouse.delivery_steps)
return res
@api.model
def get_all_routes_for_wh(self, warehouse):

View File

@@ -13,77 +13,15 @@
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from openerp import exceptions
from openerp.tests.common import TransactionCase
from datetime import datetime
class TestMtoMtsRoute(TransactionCase):
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.assertEqual(self.warehouse.mto_pull_id,
self.procurement.rule_id)
self.assertEqual('make_to_order',
self.procurement.move_ids[0].procure_method)
self.assertEqual(self.procurement.product_qty,
self.procurement.move_ids[0].product_uom_qty)
self.assertEqual('waiting',
self.procurement.move_ids[0].state)
def test_standard_mts_route(self):
self.procurement.run()
self.assertEqual('make_to_stock',
self.procurement.move_ids[0].procure_method)
self.assertEqual(self.procurement.product_qty,
self.procurement.move_ids[0].product_uom_qty)
self.assertEqual('confirmed',
self.procurement.move_ids[0].state)
def test_mts_mto_route_split(self):
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()
moves = self.env['stock.move'].search(
[('group_id', '=', self.group.id)])
self.assertEqual(2, len(moves))
self.assertEqual(1.0, moves[0].product_uom_qty)
def test_mts_mto_route_mts_only(self):
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()
moves = self.env['stock.move'].search(
[('group_id', '=', self.group.id)])
self.assertEqual(1, len(moves))
self.assertEqual(2.0, moves[0].product_uom_qty)
self.assertEqual('make_to_order',
moves[0].procure_method)
def test_mts_mto_route_mto_only(self):
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()
moves = self.env['stock.move'].search(
[('group_id', '=', self.group.id)])
self.assertEqual(1, len(moves))
self.assertEqual(2.0, moves[0].product_uom_qty)
self.assertEqual('make_to_stock',
moves[0].procure_method)
def setUp(self):
super(TestMtoMtsRoute, self).setUp()
self.warehouse = self.env.ref('stock.warehouse0')
self.warehouse.mto_mts_management = True
self.product = self.env.ref('product.product_product_4')
self.company_partner = self.env.ref('base.main_partner')
self.group = self.env['procurement.group'].create({
'name': 'test',
})
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,
@@ -96,6 +34,153 @@ class TestMtoMtsRoute(TransactionCase):
'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_create()
self.assertEqual(self.warehouse.mto_pull_id,
self.procurement.rule_id)
self.assertEqual('make_to_order',
self.procurement.move_ids[0].procure_method)
self.assertEqual(self.procurement.product_qty,
self.procurement.move_ids[0].product_uom_qty)
self.assertEqual('waiting',
self.procurement.move_ids[0].state)
def test_standard_mts_route(self):
self._procurement_create()
procurement_id = self.procurement_obj.search([
('group_id', '=', self.procurement.group_id.id),
('move_ids', '!=', False)], limit=1)
self.assertEqual('make_to_stock',
procurement_id.move_ids[0].procure_method)
self.assertEqual(self.procurement.product_qty,
procurement_id.move_ids[0].product_uom_qty)
self.assertEqual('confirmed',
procurement_id.move_ids[0].state)
def test_mts_mto_route_split(self):
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_create()
moves = self.env['stock.move'].search(
[('group_id', '=', self.group.id)])
self.assertEqual(2, len(moves))
self.assertEqual(1.0, moves[0].product_uom_qty)
def test_mts_mto_route_split_done(self):
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_create()
self.assertEqual(self.procurement.state, 'running')
self.procurement.mts_mto_procurement_ids.mapped(
'move_ids').action_done()
self.assertEqual(self.procurement.state, 'done')
def test_mts_mto_route_split_cancel(self):
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_create()
self.procurement.mts_mto_procurement_ids.cancel()
self.assertEqual(self.procurement.state, 'running')
self.procurement.check()
self.assertEqual(self.procurement.state, 'cancel')
def test_mts_mto_route_mts_only(self):
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_create()
moves = self.env['stock.move'].search(
[('group_id', '=', self.group.id)])
self.assertEqual(1, len(moves))
self.assertEqual(2.0, moves[0].product_uom_qty)
self.assertEqual('make_to_order',
moves[0].procure_method)
def test_mts_mto_route_mto_only(self):
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_create()
moves = self.env['stock.move'].search(
[('group_id', '=', self.group.id)])
self.assertEqual(1, len(moves))
self.assertEqual(2.0, moves[0].product_uom_qty)
self.assertEqual('make_to_stock',
moves[0].procure_method)
def test_mts_mto_route_mto_removed(self):
self.env.ref('stock_mts_mto_rule.route_mto_mts').unlink()
self.warehouse.mts_mto_rule_id = False
with self.assertRaises(exceptions.Warning):
self.warehouse.mto_mts_management = True
def test_mts_mto_route_mts_removed(self):
self.warehouse.mto_mts_management = True
self.env['procurement.rule'].search([
('location_src_id', '=', self.warehouse.lot_stock_id.id),
('route_id', '=', self.warehouse.delivery_route_id.id),
]).unlink()
self.warehouse.mts_mto_rule_id = False
with self.assertRaises(exceptions.Warning):
self.warehouse.mto_mts_management = True
def test_mts_mto_route_mto_no_mts_rule(self):
self.warehouse.mts_mto_rule_id = False
self.warehouse.mto_pull_id = False
with self.assertRaises(exceptions.Warning):
self.warehouse.mto_mts_management = True
def test_create_routes(self):
rule_obj = self.env['procurement.rule']
created_routes = self.warehouse.create_routes(self.warehouse)
mts_mto_route = rule_obj.browse(created_routes['mts_mto_rule_id'])
self.assertEqual(mts_mto_route.warehouse_id, self.warehouse)
self.assertEqual(
mts_mto_route.location_id, self.warehouse.mto_pull_id.location_id)
self.assertEqual(
mts_mto_route.picking_type_id,
self.warehouse.mto_pull_id.picking_type_id)
self.assertEqual(
mts_mto_route.route_id,
self.env.ref('stock_mts_mto_rule.route_mto_mts'))
def test_remove_mts_mto_management(self):
warehouse_rule = self.warehouse.mts_mto_rule_id
self.assertTrue(self.warehouse.mts_mto_rule_id)
self.warehouse.mto_mts_management = False
self.assertFalse(warehouse_rule.exists())
self.assertFalse(self.warehouse.mts_mto_rule_id)
def test_get_all_routes_for_wh(self):
routes = self.warehouse.get_all_routes_for_wh(self.warehouse)
self.assertTrue(self.warehouse.mts_mto_rule_id)
self.assertTrue(self.warehouse.mts_mto_rule_id.route_id.id in routes)
def test_rename_warehouse(self):
rule_name = self.warehouse.mts_mto_rule_id.name
new_warehouse_name = 'NewName'
new_rule_name = rule_name.replace(
self.warehouse.name, new_warehouse_name, 1)
self.warehouse.name = new_warehouse_name
self.assertEqual(new_rule_name, self.warehouse.mts_mto_rule_id.name)
def setUp(self):
super(TestMtoMtsRoute, self).setUp()
self.warehouse = self.env.ref('stock.warehouse0')
self.warehouse.mto_mts_management = True
self.product = self.env.ref('product.product_product_4')
self.company_partner = self.env.ref('base.main_partner')
self.procurement_obj = self.env['procurement.order']
self.group = self.env['procurement.group'].create({
'name': 'test',
})
self.quant = self.env['stock.quant'].create({
'owner_id': self.company_partner.id,
'location_id': self.env.ref('stock.stock_location_stock').id,