mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
ADD stock_dynamic_mto
This commit is contained in:
1
stock_dynamic_mto/__init__.py
Normal file
1
stock_dynamic_mto/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import procurement
|
||||
42
stock_dynamic_mto/__openerp__.py
Normal file
42
stock_dynamic_mto/__openerp__.py
Normal file
@@ -0,0 +1,42 @@
|
||||
# -*- 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/>.
|
||||
#
|
||||
###############################################################################
|
||||
{
|
||||
"name": "Stock Dynamic MTO",
|
||||
"version": "1.0",
|
||||
"category": "Stock",
|
||||
"description": """
|
||||
Stock Dynamic MTO
|
||||
======================
|
||||
The purpose of the module is to give the possibility to a pull rule
|
||||
make to order or make to stock depending of the virtual stock of a product.
|
||||
""",
|
||||
"license": "AGPL-3",
|
||||
"author": "Akretion,Odoo Community Association (OCA)",
|
||||
"website": "http://www.akretion.com/",
|
||||
"depends": [
|
||||
"stock",
|
||||
],
|
||||
"data": [
|
||||
"pull_rule_view.xml",
|
||||
],
|
||||
"installable": True,
|
||||
}
|
||||
80
stock_dynamic_mto/procurement.py
Normal file
80
stock_dynamic_mto/procurement.py
Normal file
@@ -0,0 +1,80 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
###############################################################################
|
||||
#
|
||||
# Module for OpenERP
|
||||
# Copyright (C) 2015 Akretion (http://www.akretion.com). All Rights Reserved
|
||||
# @author Benoît GUILLOT <benoit.guillot@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, fields, api
|
||||
|
||||
|
||||
class ProcurementRule(models.Model):
|
||||
_inherit = 'procurement.rule'
|
||||
|
||||
mts_pull_rule_id = fields.Many2one('procurement.rule',
|
||||
string="MTS Rule")
|
||||
|
||||
|
||||
class ProcurementOrder(models.Model):
|
||||
_inherit = 'procurement.order'
|
||||
|
||||
@api.multi
|
||||
def get_mto_qty_to_order(self):
|
||||
self.ensure_one()
|
||||
uom_obj = self.env['product.uom']
|
||||
proc_warehouse = self.with_context(warehouse=self.warehouse_id.id)
|
||||
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)
|
||||
if qty_available > 0:
|
||||
if qty_available >= self.product_qty:
|
||||
return 0.0
|
||||
else:
|
||||
return self.product_qty - qty_available
|
||||
return self.product_qty
|
||||
|
||||
@api.model
|
||||
def _run(self, procurement):
|
||||
uom_obj = self.env['product.uom']
|
||||
rule_id = procurement.rule_id
|
||||
rule_mts = rule_id and rule_id.mts_pull_rule_id or False
|
||||
if rule_mts:
|
||||
needed_qty = procurement.get_mto_qty_to_order()
|
||||
if needed_qty == 0.0:
|
||||
procurement.write({'rule_id': rule_mts.id})
|
||||
return super(ProcurementOrder, self)._run(procurement)
|
||||
else:
|
||||
if needed_qty != procurement.product_qty:
|
||||
mts_qty = procurement.product_qty - needed_qty
|
||||
mts_uos_qty = uom_obj._compute_qty(
|
||||
procurement.product_uom.id,
|
||||
mts_qty,
|
||||
procurement.product_uos.id)
|
||||
default_vals = {
|
||||
'product_qty': mts_qty,
|
||||
'product_uos_qty': mts_uos_qty,
|
||||
}
|
||||
uos_qty = procurement.product_uos_qty
|
||||
update_vals = {
|
||||
'product_qty': needed_qty,
|
||||
'product_uos_qty': uos_qty - mts_uos_qty,
|
||||
}
|
||||
mts_proc = procurement.copy(default=default_vals)
|
||||
mts_proc.run()
|
||||
procurement.write(update_vals)
|
||||
return super(ProcurementOrder, self)._run(procurement)
|
||||
18
stock_dynamic_mto/pull_rule_view.xml
Normal file
18
stock_dynamic_mto/pull_rule_view.xml
Normal file
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
<record id="view_procurement_rule_form_dynamic_mto" model="ir.ui.view">
|
||||
<field name="name">procurement.rule.dynamic.mto</field>
|
||||
<field name="model">procurement.rule</field>
|
||||
<field name="inherit_id" ref="stock.view_procurement_rule_form_stock_inherit" />
|
||||
<field name="arch" type="xml">
|
||||
<field name="procure_method" position="after">
|
||||
<field name="mts_pull_rule_id"
|
||||
groups="stock.group_adv_location"
|
||||
attrs="{'invisible': [('procure_method', '!=', 'make_to_order')]}"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
Reference in New Issue
Block a user