[IMP] stock: simplify warehouse resupply
The default resupply feature can be configured by going on the route and activating it for the warehouse. This field is therefore useless and this commit remove it. The field 'resupply warehouses' is reworded an hidden when there is only one active warehouse PR:22085 TASK:38933
This commit is contained in:
committed by
Simon Lejeune
parent
c0794649f3
commit
16e9f8d46f
@@ -6,7 +6,7 @@
|
||||
<field name="model">stock.warehouse</field>
|
||||
<field name="inherit_id" ref="stock.view_warehouse"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='default_resupply_wh_id']" position="before">
|
||||
<xpath expr="//field[@name='resupply_wh_ids']" position="before">
|
||||
<field name="manufacture_to_resupply" />
|
||||
</xpath>
|
||||
<xpath expr="//field[@name='out_type_id']" position="after">
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
<field name="model">stock.warehouse</field>
|
||||
<field name="inherit_id" ref="stock.view_warehouse"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='default_resupply_wh_id']" position="before">
|
||||
<xpath expr="//field[@name='resupply_wh_ids']" position="before">
|
||||
<field name="buy_to_resupply" />
|
||||
</xpath>
|
||||
</field>
|
||||
|
||||
@@ -63,14 +63,11 @@ class Warehouse(models.Model):
|
||||
warehouse_count = fields.Integer(compute='_compute_warehouse_count')
|
||||
resupply_wh_ids = fields.Many2many(
|
||||
'stock.warehouse', 'stock_wh_resupply_table', 'supplied_wh_id', 'supplier_wh_id',
|
||||
'Resupply Warehouses')
|
||||
'Resupply From', help="Routes will be created automatically to resupply this warehouse from the warehouses ticked")
|
||||
resupply_route_ids = fields.One2many(
|
||||
'stock.location.route', 'supplied_wh_id', 'Resupply Routes',
|
||||
help="Routes will be created for these resupply warehouses and you can select them on products and product categories")
|
||||
default_resupply_wh_id = fields.Many2one(
|
||||
'stock.warehouse', 'Default Resupply Warehouse',
|
||||
help="Goods will always be resupplied from this warehouse")
|
||||
|
||||
warehouse_count = fields.Integer(compute='_compute_warehouse_count')
|
||||
_sql_constraints = [
|
||||
('warehouse_name_uniq', 'unique(name, company_id)', 'The name of the warehouse must be unique per company!'),
|
||||
('warehouse_code_uniq', 'unique(code, company_id)', 'The code of the warehouse must be unique per company!'),
|
||||
@@ -81,11 +78,6 @@ class Warehouse(models.Model):
|
||||
for warehouse in self:
|
||||
warehouse.warehouse_count = self.env['stock.warehouse'].search_count([('id', 'not in', warehouse.ids)])
|
||||
|
||||
@api.depends('default_resupply_wh_id', 'resupply_wh_ids')
|
||||
def onchange_resupply_warehouses(self):
|
||||
# If we are removing the default resupply, we don't have default_resupply_wh_id # TDE note: and we want one
|
||||
self.resupply_wh_ids |= self.default_resupply_wh_id
|
||||
|
||||
@api.model
|
||||
def create(self, vals):
|
||||
# create view location for warehouse then create all locations
|
||||
@@ -144,15 +136,6 @@ class Warehouse(models.Model):
|
||||
new_resupply_whs = self.browse([wh['id'] for wh in resupply_whs])
|
||||
old_resupply_whs = {warehouse.id: warehouse.resupply_wh_ids for warehouse in warehouses}
|
||||
|
||||
if 'default_resupply_wh_id' in vals:
|
||||
if vals.get('default_resupply_wh_id') and any(vals['default_resupply_wh_id'] == warehouse.id for warehouse in warehouses):
|
||||
raise UserError(_('The default resupply warehouse should be different than itself.'))
|
||||
for warehouse in warehouses.filtered(lambda wh: wh.default_resupply_wh_id):
|
||||
# remove the existing resupplying route on the warehouse
|
||||
to_remove_routes = Route.search([('supplied_wh_id', '=', warehouse.id), ('supplier_wh_id', '=', warehouse.default_resupply_wh_id.id)])
|
||||
for inter_wh_route in to_remove_routes:
|
||||
warehouse.write({'route_ids': [(3, inter_wh_route.id)]})
|
||||
|
||||
# If another partner assigned
|
||||
if vals.get('partner_id'):
|
||||
warehouses._update_partner_data(vals['partner_id'], vals.get('company_id'))
|
||||
@@ -170,7 +153,7 @@ class Warehouse(models.Model):
|
||||
to_add = new_resupply_whs - old_resupply_whs[warehouse.id]
|
||||
to_remove = old_resupply_whs[warehouse.id] - new_resupply_whs
|
||||
if to_add:
|
||||
warehouse.create_resupply_routes(to_add, warehouse.default_resupply_wh_id)
|
||||
warehouse.create_resupply_routes(to_add)
|
||||
if to_remove:
|
||||
Route.search([('supplied_wh_id', '=', warehouse.id), ('supplier_wh_id', 'in', to_remove.ids)]).write({'active': False})
|
||||
# TDE FIXME: shouldn't we remove stock rules also ? because this could make them global (not sure)
|
||||
@@ -270,7 +253,7 @@ class Warehouse(models.Model):
|
||||
crossdock_route = self._create_or_update_crossdock_route(routes_data)
|
||||
|
||||
# create route selectable on the product to resupply the warehouse from another one
|
||||
self.create_resupply_routes(self.resupply_wh_ids, self.default_resupply_wh_id)
|
||||
self.create_resupply_routes(self.resupply_wh_ids)
|
||||
|
||||
# return routes and mto stock rule to store on the warehouse
|
||||
return {
|
||||
@@ -362,7 +345,7 @@ class Warehouse(models.Model):
|
||||
self.env['stock.rule'].create(rule_vals)
|
||||
return crossdock_route
|
||||
|
||||
def create_resupply_routes(self, supplier_warehouses, default_resupply_wh):
|
||||
def create_resupply_routes(self, supplier_warehouses):
|
||||
Route = self.env['stock.location.route']
|
||||
Rule = self.env['stock.rule']
|
||||
|
||||
@@ -390,10 +373,6 @@ class Warehouse(models.Model):
|
||||
for pull_rule_vals in pull_rules_list:
|
||||
Rule.create(pull_rule_vals)
|
||||
|
||||
# if the warehouse is also set as default resupply method, assign this route automatically to the warehouse
|
||||
if supplier_wh == default_resupply_wh:
|
||||
(self | supplier_wh).write({'route_ids': [(4, inter_wh_route.id)]})
|
||||
|
||||
# Routing tools
|
||||
# ------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -202,7 +202,6 @@ class TestPickShip(TestStockCommon):
|
||||
'code': 'SWH'
|
||||
})
|
||||
warehouse_1.write({
|
||||
'default_resupply_wh_id': warehouse_2.id,
|
||||
'resupply_wh_ids': [(6, 0, [warehouse_2.id])]
|
||||
})
|
||||
resupply_route = self.env['stock.location.route'].search([('supplier_wh_id', '=', warehouse_2.id), ('supplied_wh_id', '=', warehouse_1.id)])
|
||||
@@ -1901,7 +1900,6 @@ class TestRoutes(TestStockCommon):
|
||||
'code': 'SWH'
|
||||
})
|
||||
warehouse_1.write({
|
||||
'default_resupply_wh_id': warehouse_2.id,
|
||||
'resupply_wh_ids': [(6, 0, [warehouse_2.id])]
|
||||
})
|
||||
resupply_route = self.env['stock.location.route'].search([('supplier_wh_id', '=', warehouse_2.id), ('supplied_wh_id', '=', warehouse_1.id)])
|
||||
|
||||
@@ -240,14 +240,12 @@ class TestWarehouse(TestStockCommon):
|
||||
warehouse_distribution = self.env['stock.warehouse'].create({
|
||||
'name': 'Dist.',
|
||||
'code': 'DIST',
|
||||
'default_resupply_wh_id': warehouse_stock.id,
|
||||
'resupply_wh_ids': [(6, 0, [warehouse_stock.id])]
|
||||
})
|
||||
|
||||
warehouse_shop = self.env['stock.warehouse'].create({
|
||||
'name': 'Shop',
|
||||
'code': 'SHOP',
|
||||
'default_resupply_wh_id': warehouse_distribution.id,
|
||||
'resupply_wh_ids': [(6, 0, [warehouse_distribution.id])]
|
||||
})
|
||||
|
||||
@@ -318,7 +316,6 @@ class TestWarehouse(TestStockCommon):
|
||||
warehouse_shop_wavre = self.env['stock.warehouse'].create({
|
||||
'name': 'Shop Wavre',
|
||||
'code': 'SHWV',
|
||||
'default_resupply_wh_id': warehouse_distribution_wavre.id,
|
||||
'resupply_wh_ids': [(6, 0, [warehouse_distribution_wavre.id])]
|
||||
})
|
||||
|
||||
@@ -330,7 +327,6 @@ class TestWarehouse(TestStockCommon):
|
||||
warehouse_shop_namur = self.env['stock.warehouse'].create({
|
||||
'name': 'Shop Namur',
|
||||
'code': 'SHNM',
|
||||
'default_resupply_wh_id': warehouse_distribution_namur.id,
|
||||
'resupply_wh_ids': [(6, 0, [warehouse_distribution_namur.id])]
|
||||
})
|
||||
|
||||
@@ -443,7 +439,6 @@ class TestResupply(TestStockCommon):
|
||||
self.warehouse_2 = self.env['stock.warehouse'].create({
|
||||
'name': 'Small Warehouse',
|
||||
'code': 'SWH',
|
||||
'default_resupply_wh_id': self.warehouse_1.id,
|
||||
'resupply_wh_ids': [(6, 0, [self.warehouse_1.id])]
|
||||
})
|
||||
|
||||
|
||||
@@ -36,7 +36,6 @@
|
||||
<field name="delivery_steps" widget='radio'/>
|
||||
</group>
|
||||
<group string="Resupply" groups="stock.group_stock_multi_warehouses">
|
||||
<field name="default_resupply_wh_id" widget='selection'/>
|
||||
<field name="warehouse_count" invisible="1"/>
|
||||
<field name="resupply_wh_ids" domain="[('id', '!=', id)]" widget='many2many_checkboxes' attrs="{'invisible': [('warehouse_count', '<', 1)]}"/>
|
||||
</group>
|
||||
|
||||
Reference in New Issue
Block a user