mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
[MIG] Migrate stock_mts_mto_rule to v10.0
This commit is contained in:
committed by
Pierrick Brun
parent
cd38204fc3
commit
8e43487ba4
@@ -42,7 +42,7 @@ 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/8.0
|
||||
:target: https://runbot.odoo-community.org/runbot/153/10.0
|
||||
|
||||
Configuration
|
||||
=============
|
||||
@@ -64,11 +64,7 @@ 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
|
||||
<https://github.com/OCA/
|
||||
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**>`_.
|
||||
help us smashing it by providing a detailed and welcomed feedback.
|
||||
|
||||
Credits
|
||||
=======
|
||||
|
||||
@@ -1,27 +1,8 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2015 Akretion (<http://www.akretion.com>).
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# 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/>.
|
||||
#
|
||||
##############################################################################
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
{'name': 'Stock MTS+MTO Rule',
|
||||
'version': '9.0.1.0.0',
|
||||
'version': '10.0.1.0.0',
|
||||
'author': 'Akretion,Odoo Community Association (OCA)',
|
||||
'website': 'http://www.akretion.com',
|
||||
'license': 'AGPL-3',
|
||||
|
||||
@@ -1,17 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
<odoo>
|
||||
|
||||
<!--
|
||||
Procurement rules
|
||||
-->
|
||||
|
||||
<record id="route_mto_mts" model='stock.location.route'>
|
||||
<field name="name">Make To Order + Make To Stock</field>
|
||||
<field name="sequence">5</field>
|
||||
<field name="product_selectable" eval="True"/>
|
||||
</record>
|
||||
<!--
|
||||
Procurement rules
|
||||
-->
|
||||
|
||||
<record id="route_mto_mts" model='stock.location.route'>
|
||||
<field name="name">Make To Order + Make To Stock</field>
|
||||
<field name="sequence">5</field>
|
||||
<field name="product_selectable" eval="True"/>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
</odoo>
|
||||
|
||||
@@ -1,25 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
###############################################################################
|
||||
#
|
||||
# Module for OpenERP
|
||||
# Copyright (C) 2015 Akretion (http://www.akretion.com). All Rights Reserved
|
||||
# @author Florian DA COSTA <florian.dacosta@akretion.com>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# 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 api, fields, models
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class ProcurementOrder(models.Model):
|
||||
@@ -37,13 +19,12 @@ class ProcurementOrder(models.Model):
|
||||
@api.multi
|
||||
def get_mto_qty_to_order(self):
|
||||
self.ensure_one()
|
||||
uom_obj = self.env['product.uom']
|
||||
stock_location = self.warehouse_id.lot_stock_id.id
|
||||
proc_warehouse = self.with_context(location=stock_location)
|
||||
virtual_available = proc_warehouse.product_id.virtual_available
|
||||
qty_available = uom_obj._compute_qty(self.product_id.uom_id.id,
|
||||
virtual_available,
|
||||
self.product_uom.id)
|
||||
qty_available = self.product_id.uom_id._compute_quantity(
|
||||
virtual_available, self.product_uom)
|
||||
|
||||
if qty_available > 0:
|
||||
if qty_available >= self.product_qty:
|
||||
return 0.0
|
||||
@@ -51,16 +32,17 @@ class ProcurementOrder(models.Model):
|
||||
return self.product_qty - qty_available
|
||||
return self.product_qty
|
||||
|
||||
@api.model
|
||||
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 "/")
|
||||
@api.multi
|
||||
def _get_mts_mto_procurement(self, rule, qty):
|
||||
self.ensure_one()
|
||||
origin = (self.group_id and (self.group_id.name + ":") or "") + \
|
||||
(self.rule_id and self.rule_id.name or self.origin or "/")
|
||||
return {
|
||||
'name': proc.name,
|
||||
'name': self.name,
|
||||
'origin': origin,
|
||||
'product_qty': qty,
|
||||
'rule_id': rule.id,
|
||||
'mts_mto_procurement_id': proc.id,
|
||||
'mts_mto_procurement_id': self.id,
|
||||
}
|
||||
|
||||
@api.model
|
||||
@@ -87,34 +69,34 @@ class ProcurementOrder(models.Model):
|
||||
autocommit=autocommit)
|
||||
return res
|
||||
|
||||
@api.model
|
||||
def _run(self, procurement):
|
||||
if procurement.rule_id and \
|
||||
procurement.rule_id.action == 'split_procurement':
|
||||
if procurement.mts_mto_procurement_ids:
|
||||
return super(ProcurementOrder, self)._run(procurement)
|
||||
needed_qty = procurement.get_mto_qty_to_order()
|
||||
rule = procurement.rule_id
|
||||
@api.multi
|
||||
def _run(self):
|
||||
self.ensure_one()
|
||||
if self.rule_id and self.rule_id.action == 'split_procurement':
|
||||
if self.mts_mto_procurement_ids:
|
||||
return super(ProcurementOrder, self)._run()
|
||||
needed_qty = self.get_mto_qty_to_order()
|
||||
rule = self.rule_id
|
||||
if needed_qty == 0.0:
|
||||
mts_vals = self._get_mts_mto_procurement(
|
||||
procurement, rule.mts_rule_id, procurement.product_qty)
|
||||
mts_proc = procurement.copy(mts_vals)
|
||||
rule.mts_rule_id, self.product_qty)
|
||||
mts_proc = self.copy(mts_vals)
|
||||
mts_proc.run()
|
||||
elif needed_qty == procurement.product_qty:
|
||||
elif needed_qty == self.product_qty:
|
||||
mto_vals = self._get_mts_mto_procurement(
|
||||
procurement, rule.mto_rule_id, procurement.product_qty)
|
||||
mto_proc = procurement.copy(mto_vals)
|
||||
rule.mto_rule_id, self.product_qty)
|
||||
mto_proc = self.copy(mto_vals)
|
||||
mto_proc.run()
|
||||
else:
|
||||
mts_qty = procurement.product_qty - needed_qty
|
||||
mts_qty = self.product_qty - needed_qty
|
||||
mts_vals = self._get_mts_mto_procurement(
|
||||
procurement, rule.mts_rule_id, mts_qty)
|
||||
mts_proc = procurement.copy(mts_vals)
|
||||
rule.mts_rule_id, mts_qty)
|
||||
mts_proc = self.copy(mts_vals)
|
||||
mts_proc.run()
|
||||
|
||||
mto_vals = self._get_mts_mto_procurement(
|
||||
procurement, rule.mto_rule_id, needed_qty)
|
||||
mto_proc = procurement.copy(mto_vals)
|
||||
rule.mto_rule_id, needed_qty)
|
||||
mto_proc = self.copy(mto_vals)
|
||||
mto_proc.run()
|
||||
|
||||
return super(ProcurementOrder, self)._run(procurement)
|
||||
return super(ProcurementOrder, self)._run()
|
||||
|
||||
@@ -1,26 +1,8 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
###############################################################################
|
||||
#
|
||||
# Module for OpenERP
|
||||
# Copyright (C) 2015 Akretion (http://www.akretion.com). All Rights Reserved
|
||||
# @author Florian DA COSTA <florian.dacosta@akretion.com>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# 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 models, api, fields
|
||||
from openerp.tools.translate import _
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import models, api, fields
|
||||
from odoo.tools.translate import _
|
||||
|
||||
|
||||
class ProcurementRule(models.Model):
|
||||
|
||||
@@ -1,26 +1,8 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
###############################################################################
|
||||
#
|
||||
# Module for OpenERP
|
||||
# Copyright (C) 2015 Akretion (http://www.akretion.com). All Rights Reserved
|
||||
# @author Florian DA COSTA <florian.dacosta@akretion.com>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# 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 models, api, fields, exceptions
|
||||
from openerp.tools.translate import _
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import models, api, fields, exceptions
|
||||
from odoo.tools.translate import _
|
||||
|
||||
|
||||
class Warehouse(models.Model):
|
||||
@@ -60,7 +42,7 @@ class Warehouse(models.Model):
|
||||
raise exceptions.Warning(_(
|
||||
'Can\'t find MTS Rule on the warehouse'))
|
||||
return {
|
||||
'name': self._format_routename(warehouse, _('MTS+MTO')),
|
||||
'name': warehouse._format_routename(route_type='mts_mto'),
|
||||
'route_id': mts_mto_route.id,
|
||||
'action': 'split_procurement',
|
||||
'mto_rule_id': warehouse.mto_pull_id.id,
|
||||
@@ -116,8 +98,7 @@ class Warehouse(models.Model):
|
||||
warehouse.mts_mto_rule_id.unlink()
|
||||
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)
|
||||
self.with_context({'active_test': False})._update_routes()
|
||||
return res
|
||||
|
||||
@api.model
|
||||
@@ -141,21 +122,24 @@ class Warehouse(models.Model):
|
||||
)
|
||||
return res
|
||||
|
||||
@api.multi
|
||||
def change_route(self, warehouse, new_reception_step=False,
|
||||
new_delivery_step=False):
|
||||
res = super(Warehouse, self).change_route(
|
||||
warehouse,
|
||||
new_reception_step=new_reception_step,
|
||||
new_delivery_step=new_delivery_step)
|
||||
def _get_route_name(self, route_type):
|
||||
names = {'mts_mto': _('MTS+MTO')}
|
||||
if route_type in names:
|
||||
return names[route_type]
|
||||
|
||||
mts_mto_rule_id = warehouse.mts_mto_rule_id
|
||||
if new_delivery_step and mts_mto_rule_id:
|
||||
return super(Warehouse, self)._get_route_name(route_type)
|
||||
|
||||
@api.multi
|
||||
def _update_routes(self):
|
||||
res = super(Warehouse, self)._update_routes()
|
||||
|
||||
mts_mto_rule_id = self.mts_mto_rule_id
|
||||
if self.delivery_steps and mts_mto_rule_id:
|
||||
pull_model = self.env['procurement.rule']
|
||||
warehouse.mts_mto_rule_id.location_id = (
|
||||
warehouse.mto_pull_id.location_id)
|
||||
mts_rules = pull_model.search(
|
||||
[('location_src_id', '=', warehouse.lot_stock_id.id),
|
||||
('route_id', '=', warehouse.delivery_route_id.id)])
|
||||
warehouse.mts_mto_rule_id.mts_rule_id = mts_rules[0].id
|
||||
self.mts_mto_rule_id.location_id = self.mto_pull_id.location_id
|
||||
mts_rules = pull_model.search([
|
||||
('location_src_id', '=', self.lot_stock_id.id),
|
||||
('route_id', '=', self.delivery_route_id.id),
|
||||
])
|
||||
self.mts_mto_rule_id.mts_rule_id = mts_rules[0].id
|
||||
return res
|
||||
|
||||
@@ -1,19 +1,7 @@
|
||||
# Author: Florian da Costa
|
||||
# Copyright 2015 Akretion
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# 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.tests.common import TransactionCase
|
||||
# -*- coding: utf-8 -*-
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo.tests.common import TransactionCase
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
|
||||
@@ -1,21 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
<record id="view_procurement_rule_form_mto_mto" model="ir.ui.view">
|
||||
<field name="name">procurement.rule.mts.mto</field>
|
||||
<field name="model">procurement.rule</field>
|
||||
<field name="inherit_id" ref="procurement.view_procurement_rule_form" />
|
||||
<field name="arch" type="xml">
|
||||
<field name="action" position="after">
|
||||
<field name="mts_rule_id"
|
||||
groups="stock.group_adv_location"
|
||||
attrs="{'invisible': [('action', '!=', 'split_procurement')]}"/>
|
||||
<field name="mto_rule_id"
|
||||
groups="stock.group_adv_location"
|
||||
attrs="{'invisible': [('action', '!=', 'split_procurement')]}"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
<odoo>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
<record id="view_procurement_rule_form_mto_mto" model="ir.ui.view">
|
||||
<field name="name">procurement.rule.mts.mto</field>
|
||||
<field name="model">procurement.rule</field>
|
||||
<field name="inherit_id" ref="procurement.view_procurement_rule_form" />
|
||||
<field name="arch" type="xml">
|
||||
<field name="action" position="after">
|
||||
<field name="mts_rule_id"
|
||||
groups="stock.group_adv_location"
|
||||
attrs="{'invisible': [('action', '!=', 'split_procurement')]}"/>
|
||||
<field name="mto_rule_id"
|
||||
groups="stock.group_adv_location"
|
||||
attrs="{'invisible': [('action', '!=', 'split_procurement')]}"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
|
||||
@@ -1,17 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
<odoo>
|
||||
|
||||
<record id="view_warehouse_inherited" model="ir.ui.view">
|
||||
<field name="name">view_warehouse_inherited</field>
|
||||
<field name="model">stock.warehouse</field>
|
||||
<field name="inherit_id" ref="stock.view_warehouse"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='delivery_steps']" position="after">
|
||||
<field name="mto_mts_management" />
|
||||
</xpath>
|
||||
</field>
|
||||
<field name="name">view_warehouse_inherited</field>
|
||||
<field name="model">stock.warehouse</field>
|
||||
<field name="inherit_id" ref="stock.view_warehouse"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='delivery_steps']" position="after">
|
||||
<field name="mto_mts_management" />
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
</odoo>
|
||||
|
||||
Reference in New Issue
Block a user