[IMP] stock: handle multi-warehouse with the same logic of multi-company

Activate the multi-warehouse automatically when there is more than 1 in
a company. Then remove the multi-warehouse setting in the config, and
allow to create warehouse. Because create a warehouse can change
groups of the user, we reload the page when there is any modification.
Update warehouse demo data accordingly (remove the second warehouse
of the second company).

task-2196687

closes odoo/odoo#49625

Related: odoo/upgrade#1253
Related: odoo/enterprise#9934
Signed-off-by: Simon Lejeune (sle) <sle@openerp.com>
This commit is contained in:
Rémy Voet (ryv)
2020-05-25 08:50:02 +00:00
parent 82ca6b92c8
commit 8414e6b9fd
8 changed files with 73 additions and 85 deletions
+33 -34
View File
@@ -185,20 +185,19 @@
<field name="name">My Company (San Francisco)</field>
</record>
<!-- Rename auto-created Chicago Warehouse -->
<function model="stock.warehouse" name="write">
<value model="stock.warehouse" search="[('company_id', '=', obj().env.ref('stock.res_company_1').id)]"/>
<value eval="{
'name': 'Chicago 1',
'code': 'CHIC1',
}"/>
<!-- Create a ir data with the autocreated warehouse -->
<function model="ir.model.data" name="_update_xmlids">
<value model="base" eval="[{
'xml_id': 'stock.stock_warehouse_shop0',
'record': obj().env['stock.warehouse'].search([('company_id', '=', obj().env.ref('stock.res_company_1').id)]),
'noupdate': True,
}]"/>
</function>
<record id="stock_warehouse_shop0" model="stock.warehouse">
<field name="name">Chicago 2</field>
<record id="stock.stock_warehouse_shop0" model="stock.warehouse">
<field name="name">Chicago 1</field>
<field name="code">CHIC1</field>
<field name="partner_id" ref="res_partner_address_41"/>
<field name="company_id" ref="res_company_1"/>
<field name="code">CHIC2</field>
</record>
<record id="product.consu_delivery_03" model="product.product">
@@ -215,31 +214,31 @@
</record>
<!-- Inventory for Chicago Warehouse -->
<record id="stock_inventory_chic_0" model="stock.inventory">
<field name="name">Starting Inventory</field>
<field name="company_id" ref="stock.res_company_1"/>
</record>
<record id="stock_inventory_chic_0" model="stock.inventory">
<field name="name">Starting Inventory</field>
<field name="company_id" ref="stock.res_company_1"/>
</record>
<record id="stock_inventory_line_1" model="stock.inventory.line">
<field name="product_id" ref="product.product_product_6"/>
<field name="product_uom_id" ref="uom.product_uom_unit"/>
<field name="inventory_id" ref="stock_inventory_chic_0"/>
<field name="product_qty">100.0</field>
<field name="location_id" model="stock.location"
eval="obj().env['stock.location'].search([
('company_id', '=', obj().env.ref('stock.res_company_1').id),
('location_id', '!=', False),
('child_ids', '=', False),
], limit=1)"
/>
</record>
<record id="stock_inventory_line_1" model="stock.inventory.line">
<field name="product_id" ref="product.product_product_6"/>
<field name="product_uom_id" ref="uom.product_uom_unit"/>
<field name="inventory_id" ref="stock_inventory_chic_0"/>
<field name="product_qty">200.0</field>
<field name="location_id" model="stock.location"
eval="obj().env['stock.location'].search([
('company_id', '=', obj().env.ref('stock.res_company_1').id),
('location_id', '!=', False),
('child_ids', '=', False),
], limit=1)"
/>
</record>
<function model="stock.inventory" name="_action_start">
<function eval="[[('state','=','draft'),('id', '=', ref('stock_inventory_chic_0'))]]" model="stock.inventory" name="search"/>
</function>
<function model="stock.inventory" name="action_validate">
<function eval="[[('state','=','confirm'),('id', '=', ref('stock_inventory_chic_0'))]]" model="stock.inventory" name="search"/>
</function>
<function model="stock.inventory" name="_action_start">
<function eval="[[('state','=','draft'),('id', '=', ref('stock_inventory_chic_0'))]]" model="stock.inventory" name="search"/>
</function>
<function model="stock.inventory" name="action_validate">
<function eval="[[('state','=','confirm'),('id', '=', ref('stock_inventory_chic_0'))]]" model="stock.inventory" name="search"/>
</function>
<!-- Activate Lots options as demo data depends on it -->
<record id="base.group_user" model="res.groups">
@@ -41,19 +41,12 @@ class ResConfigSettings(models.TransientModel):
module_delivery_easypost = fields.Boolean("Easypost Connector")
group_stock_multi_locations = fields.Boolean('Storage Locations', implied_group='stock.group_stock_multi_locations',
help="Store products in specific locations of your warehouse (e.g. bins, racks) and to track inventory accordingly.")
group_stock_multi_warehouses = fields.Boolean('Multi-Warehouses', implied_group='stock.group_stock_multi_warehouses')
@api.onchange('group_stock_multi_locations')
def _onchange_group_stock_multi_locations(self):
if not self.group_stock_multi_locations:
self.group_stock_multi_warehouses = False
self.group_stock_adv_location = False
@api.onchange('group_stock_multi_warehouses')
def _onchange_group_stock_multi_warehouses(self):
if self.group_stock_multi_warehouses:
self.group_stock_multi_locations = True
@api.onchange('group_stock_production_lot')
def _onchange_group_stock_production_lot(self):
if not self.group_stock_production_lot:
+20
View File
@@ -122,6 +122,9 @@ class Warehouse(models.Model):
# update partner data if partner assigned
if vals.get('partner_id'):
self._update_partner_data(vals['partner_id'], vals.get('company_id'))
self._check_multiwarehouse_group()
return warehouse
def write(self, vals):
@@ -246,6 +249,23 @@ class Warehouse(models.Model):
to_disable_route_ids.toggle_active()
return res
def unlink(self):
res = super().unlink()
self._check_multiwarehouse_group()
return res
def _check_multiwarehouse_group(self):
cnt_by_company = self.env['stock.warehouse'].sudo().read_group([('active', '=', True)], ['company_id'], groupby=['company_id'])
if cnt_by_company:
max_cnt = max(cnt_by_company, key=lambda k: k['company_id_count'])
group_user = self.env.ref('base.group_user')
group_stock_multi_warehouses = self.env.ref('stock.group_stock_multi_warehouses')
if max_cnt['company_id_count'] <= 1 and group_stock_multi_warehouses in group_user.implied_ids:
group_user.write({'implied_ids': [(3, group_stock_multi_warehouses.id)]})
group_stock_multi_warehouses.write({'users': [(3, user.id) for user in group_user.users]})
if max_cnt['company_id_count'] > 1 and group_stock_multi_warehouses not in group_user.implied_ids:
group_user.write({'implied_ids': [(4, group_stock_multi_warehouses.id), (4, self.env.ref('stock.group_stock_multi_locations').id)]})
@api.model
def _update_partner_data(self, partner_id, company_id):
if not partner_id:
+16
View File
@@ -0,0 +1,16 @@
odoo.define('stock.BasicModel', function (require) {
"use strict";
var BasicModel = require('web.BasicModel');
var localStorage = require('web.local_storage');
BasicModel.include({
_invalidateCache: function (dataPoint) {
this._super.apply(this, arguments);
if (dataPoint.model === 'stock.warehouse' && !localStorage.getItem('running_tour')) {
this.do_action('reload_context');
}
}
});
});
@@ -346,23 +346,6 @@
</div>
</div>
</div>
<div class="col-12 col-lg-6 o_setting_box" id="manage_several_warehouses">
<div class="o_setting_left_pane">
<field name="group_stock_multi_warehouses"/>
</div>
<div class="o_setting_right_pane">
<label for="group_stock_multi_warehouses"/>
<a href="https://www.odoo.com/documentation/user/13.0/inventory/management/warehouses/difference_warehouse_location.html" title="Documentation" class="o_doc_link" target="_blank"></a>
<div class="text-muted">
Manage several warehouses
</div>
<div class="content-group">
<div class="mt8" attrs="{'invisible': [('group_stock_multi_warehouses', '=', False)]}">
<button name="%(stock.action_warehouse_form)d" icon="fa-arrow-right" type="action" string="Warehouses" class="btn-link"/>
</div>
</div>
</div>
</div>
<div class="col-12 col-lg-6 o_setting_box"
id="use_own_routes"
title="Add and customize route operations to process product moves in your warehouse(s): e.g. unload &gt; quality control &gt; stock for incoming products, pick &gt; pack &gt; ship for outgoing products. You can also set putaway strategies on warehouse locations in order to send incoming products into specific child locations straight away (e.g. specific bins, racks).">
+1
View File
@@ -15,6 +15,7 @@
<script type="text/javascript" src="/stock/static/src/js/stock_traceability_report_backend.js"></script>
<script type="text/javascript" src="/stock/static/src/js/stock_traceability_report_widgets.js"></script>
<script type="text/javascript" src="/stock/static/src/js/popover_widget.js"></script>
<script type="text/javascript" src="/stock/static/src/js/basic_model.js"></script>
<script type="text/javascript" src="/stock/static/src/js/stock_rescheduling_popover.js"></script>
<link rel="stylesheet" type="text/scss" href="/stock/static/src/scss/stock_traceability_report.scss"/>
</xpath>
+2 -26
View File
@@ -5,7 +5,7 @@
<field name="name">stock.warehouse</field>
<field name="model">stock.warehouse</field>
<field name="arch" type="xml">
<form string="Warehouse" create="false">
<form string="Warehouse">
<sheet>
<div class="oe_button_box" name="button_box">
<button name="action_view_all_routes"
@@ -66,23 +66,11 @@
</field>
</record>
<record id="stock_warehouse_view_form_editable" model="ir.ui.view">
<field name="name">stock.warehouse.form.editable</field>
<field name="model">stock.warehouse</field>
<field name="inherit_id" ref="stock.view_warehouse"/>
<field name="groups_id" eval="[(4, ref('stock.group_stock_multi_warehouses'))]"/>
<field name="arch" type="xml">
<xpath expr="//form" position="attributes">
<attribute name="create">true</attribute>
</xpath>
</field>
</record>
<record id="view_warehouse_tree" model="ir.ui.view">
<field name="name">stock.warehouse.tree</field>
<field name="model">stock.warehouse</field>
<field name="arch" type="xml">
<tree string="Warehouse" create="false">
<tree string="Warehouse">
<field name="sequence" widget="handle"/>
<field name="name"/>
<field name="active" invisible="1"/>
@@ -93,18 +81,6 @@
</field>
</record>
<record id="stock_warehouse_view_tree_editable" model="ir.ui.view">
<field name="name">stock.warehouse.tree.editable</field>
<field name="model">stock.warehouse</field>
<field name="inherit_id" ref="stock.view_warehouse_tree"/>
<field name="groups_id" eval="[(4, ref('stock.group_stock_multi_warehouses'))]"/>
<field name="arch" type="xml">
<xpath expr="//tree" position="attributes">
<attribute name="create">true</attribute>
</xpath>
</field>
</record>
<record id="stock_warehouse_view_search" model="ir.ui.view">
<field name="name">stock.warehouse.search</field>
<field name="model">stock.warehouse</field>
@@ -14,7 +14,7 @@
<div class="content-group">
<div class="row mt16"
id="website_warehouse_setting"
attrs="{'invisible': [('group_stock_multi_warehouses', '=', False)]}">
groups="stock.group_stock_multi_warehouses">
<label for="website_warehouse_id" string="Warehouse" class="col-lg-3 o_light_label" />
<field name="website_warehouse_id"/>
</div>