Files
odoo_source/addons/purchase_stock/__init__.py
T
Tiffany Chang (tic) d25d320e0e [IMP] mrp,(purchase_)stock: allow replenishment with only stock module
This commit makes it so products can be replenished without any other
module. This is achieved by adding a "pull" rule to the default receipt
route generated when a warehouse is created. "Pull" rule is added to 1-,
2-, and 3-step receipt routes. Previous to this commit, an additional
module (e.g. purchase, mrp, etc.) was needed for a pull rule to trigger
with the existing receipt route rules. Replenishments can be triggered
via "Replenish" button in product form, recording rules (auto trigger),
and replenishment (manual trigger).

Additionally, this commit makes it so when other modules (mrp, purchase)
that handle replenishment are installed, this additional "pull" rule is
removed from the default receipt route to prevent undesired behavior
(e.g. MTO manufacturing components magically being received from no
where). Unfortunately this means 2 undesirable situations:

1. If a user adds adds/changes rules to the receipt route and then installs
   mrp or purchase then their additions/changes will be removed.
2. If a user removes either (when only 1 installed) or both of these
   modules then stock module will again not be able to replenish as the
   pull rule will not be re-added to the receipt route.

It is expected that these 2 cases do not need to be handled in most
cases or can be handled by advanced users.

Stock tests have also been updated to accomodate this new pull rule.

Specification 4 of overall inventory onboarding improvement task.
Task: 2220129
Related Enterprise PR: odoo/enterprise#10719
2020-06-18 08:33:22 +00:00

18 lines
590 B
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import models
from . import report
from odoo import api, SUPERUSER_ID
def _create_buy_rules(cr, registry):
""" This hook is used to add a default buy_pull_id on every warehouse. It is
necessary if the purchase_stock module is installed after some warehouses
were already created.
"""
env = api.Environment(cr, SUPERUSER_ID, {})
warehouse_ids = env['stock.warehouse'].search([('buy_pull_id', '=', False)])
warehouse_ids.write({'buy_to_resupply': True})