diff options
| author | Rémy Voet (ryv) <ryv@odoo.com> | 2020-04-14 12:13:54 +0000 |
|---|---|---|
| committer | Rémy Voet (ryv) <ryv@odoo.com> | 2020-05-25 08:50:02 +0000 |
| commit | 8414e6b9fde7bfcd0977fbb85464a73ab6f61a05 (patch) | |
| tree | 71f3550a4f7a25e598ba8b62ee222ff1f709825e | |
| parent | 82ca6b92c89a73a7a261decc10d0ea6ea8a573fa (diff) | |
[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>
| -rw-r--r-- | addons/stock/data/stock_demo.xml | 71 | ||||
| -rw-r--r-- | addons/stock/models/res_config_settings.py | 7 | ||||
| -rw-r--r-- | addons/stock/models/stock_warehouse.py | 20 | ||||
| -rw-r--r-- | addons/stock/static/src/js/basic_model.js | 16 | ||||
| -rw-r--r-- | addons/stock/views/res_config_settings_views.xml | 17 | ||||
| -rw-r--r-- | addons/stock/views/stock_template.xml | 1 | ||||
| -rw-r--r-- | addons/stock/views/stock_warehouse_views.xml | 28 | ||||
| -rw-r--r-- | addons/website_sale_stock/views/res_config_settings_views.xml | 2 |
8 files changed, 75 insertions, 87 deletions
diff --git a/addons/stock/data/stock_demo.xml b/addons/stock/data/stock_demo.xml index 94678cdf3c4..51bb53d5469 100644 --- a/addons/stock/data/stock_demo.xml +++ b/addons/stock/data/stock_demo.xml @@ -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_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> - - <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> + <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">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> <!-- Activate Lots options as demo data depends on it --> <record id="base.group_user" model="res.groups"> diff --git a/addons/stock/models/res_config_settings.py b/addons/stock/models/res_config_settings.py index 886c24a48a3..2b135322358 100644 --- a/addons/stock/models/res_config_settings.py +++ b/addons/stock/models/res_config_settings.py @@ -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: diff --git a/addons/stock/models/stock_warehouse.py b/addons/stock/models/stock_warehouse.py index f83d4bd030f..ead232b7cdd 100644 --- a/addons/stock/models/stock_warehouse.py +++ b/addons/stock/models/stock_warehouse.py @@ -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: diff --git a/addons/stock/static/src/js/basic_model.js b/addons/stock/static/src/js/basic_model.js new file mode 100644 index 00000000000..6a5653c6314 --- /dev/null +++ b/addons/stock/static/src/js/basic_model.js @@ -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'); + } + } +}); +}); diff --git a/addons/stock/views/res_config_settings_views.xml b/addons/stock/views/res_config_settings_views.xml index 3a9a1b89384..860f7f56e7a 100644 --- a/addons/stock/views/res_config_settings_views.xml +++ b/addons/stock/views/res_config_settings_views.xml @@ -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 > quality control > stock for incoming products, pick > pack > 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)."> diff --git a/addons/stock/views/stock_template.xml b/addons/stock/views/stock_template.xml index 92c47e7ccf4..2e9be903377 100644 --- a/addons/stock/views/stock_template.xml +++ b/addons/stock/views/stock_template.xml @@ -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> diff --git a/addons/stock/views/stock_warehouse_views.xml b/addons/stock/views/stock_warehouse_views.xml index 4b213ea7d82..c25df973d78 100644 --- a/addons/stock/views/stock_warehouse_views.xml +++ b/addons/stock/views/stock_warehouse_views.xml @@ -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> diff --git a/addons/website_sale_stock/views/res_config_settings_views.xml b/addons/website_sale_stock/views/res_config_settings_views.xml index 77b7e6818ef..64b527e5b99 100644 --- a/addons/website_sale_stock/views/res_config_settings_views.xml +++ b/addons/website_sale_stock/views/res_config_settings_views.xml @@ -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> |
