[REF] *stock*: rename location destination fields
The stock convention on location name is always to name the destination `location_dest_id`. It was not the case on the stock rule model Task: 2648449 Part-of: odoo/odoo#80434
This commit is contained in:
@@ -90,7 +90,7 @@ class StockRule(models.Model):
|
||||
return values['bom_id']
|
||||
return self.env['mrp.bom']._bom_find(product_id, picking_type=self.picking_type_id, bom_type='normal', company_id=company_id.id)[product_id]
|
||||
|
||||
def _prepare_mo_vals(self, product_id, product_qty, product_uom, location_id, name, origin, company_id, values, bom):
|
||||
def _prepare_mo_vals(self, product_id, product_qty, product_uom, location_dest_id, name, origin, company_id, values, bom):
|
||||
date_planned = self._get_date_planned(product_id, company_id, values)
|
||||
date_deadline = values.get('date_deadline') or date_planned + relativedelta(days=company_id.manufacturing_lead) + relativedelta(days=product_id.produce_delay)
|
||||
return {
|
||||
@@ -99,8 +99,8 @@ class StockRule(models.Model):
|
||||
'product_description_variants': values.get('product_description_variants'),
|
||||
'product_qty': product_qty,
|
||||
'product_uom_id': product_uom.id,
|
||||
'location_src_id': self.location_src_id.id or self.picking_type_id.default_location_src_id.id or location_id.id,
|
||||
'location_dest_id': location_id.id,
|
||||
'location_src_id': self.location_src_id.id or self.picking_type_id.default_location_src_id.id or location_dest_id.id,
|
||||
'location_dest_id': location_dest_id.id,
|
||||
'bom_id': bom.id,
|
||||
'date_deadline': date_deadline,
|
||||
'date_planned_start': date_planned,
|
||||
|
||||
@@ -107,7 +107,7 @@ class StockWarehouse(models.Model):
|
||||
rules = super(StockWarehouse, self)._get_global_route_rules_values()
|
||||
location_src = self.manufacture_steps == 'mrp_one_step' and self.lot_stock_id or self.pbm_loc_id
|
||||
production_location = self._get_production_location()
|
||||
location_id = self.manufacture_steps == 'pbm_sam' and self.sam_loc_id or self.lot_stock_id
|
||||
location_dest_id = self.manufacture_steps == 'pbm_sam' and self.sam_loc_id or self.lot_stock_id
|
||||
rules.update({
|
||||
'manufacture_pull_id': {
|
||||
'depends': ['manufacture_steps', 'manufacture_to_resupply'],
|
||||
@@ -120,8 +120,8 @@ class StockWarehouse(models.Model):
|
||||
},
|
||||
'update_values': {
|
||||
'active': self.manufacture_to_resupply,
|
||||
'name': self._format_rulename(location_id, False, 'Production'),
|
||||
'location_id': location_id.id,
|
||||
'name': self._format_rulename(location_dest_id, False, 'Production'),
|
||||
'location_dest_id': location_dest_id.id,
|
||||
'propagate_cancel': self.manufacture_steps == 'pbm_sam'
|
||||
},
|
||||
},
|
||||
@@ -133,7 +133,7 @@ class StockWarehouse(models.Model):
|
||||
'action': 'pull',
|
||||
'auto': 'manual',
|
||||
'route_id': self._find_global_route('stock.route_warehouse0_mto', _('Make To Order')).id,
|
||||
'location_id': production_location.id,
|
||||
'location_dest_id': production_location.id,
|
||||
'location_src_id': location_src.id,
|
||||
'picking_type_id': self.manu_type_id.id
|
||||
},
|
||||
@@ -151,7 +151,7 @@ class StockWarehouse(models.Model):
|
||||
'auto': 'manual',
|
||||
'route_id': self._find_global_route('stock.route_warehouse0_mto', _('Make To Order')).id,
|
||||
'name': self._format_rulename(self.lot_stock_id, self.pbm_loc_id, 'MTO'),
|
||||
'location_id': self.pbm_loc_id.id,
|
||||
'location_dest_id': self.pbm_loc_id.id,
|
||||
'location_src_id': self.lot_stock_id.id,
|
||||
'picking_type_id': self.pbm_type_id.id
|
||||
},
|
||||
@@ -174,7 +174,7 @@ class StockWarehouse(models.Model):
|
||||
'auto': 'manual',
|
||||
'route_id': self._find_global_route('mrp.route_warehouse0_manufacture', _('Manufacture')).id,
|
||||
'name': self._format_rulename(self.sam_loc_id, self.lot_stock_id, False),
|
||||
'location_id': self.lot_stock_id.id,
|
||||
'location_dest_id': self.lot_stock_id.id,
|
||||
'location_src_id': self.sam_loc_id.id,
|
||||
'picking_type_id': self.sam_type_id.id
|
||||
},
|
||||
|
||||
@@ -135,7 +135,7 @@ class TestProcurement(TestMrpCommon):
|
||||
self.env['stock.location']._parent_store_compute()
|
||||
warehouse.reception_route_id.rule_ids.filtered(
|
||||
lambda p: p.location_src_id == warehouse.wh_input_stock_loc_id and
|
||||
p.location_id == warehouse.wh_qc_stock_loc_id).write({
|
||||
p.location_dest_id == warehouse.wh_qc_stock_loc_id).write({
|
||||
'procure_method': 'make_to_stock'
|
||||
})
|
||||
|
||||
|
||||
@@ -507,7 +507,7 @@ class TestUnbuild(TestMrpCommon):
|
||||
'action': 'push',
|
||||
'picking_type_id': self.ref('stock.picking_type_internal'),
|
||||
'location_src_id': unbuild_location.id,
|
||||
'location_id': self.stock_location.id,
|
||||
'location_dest_id': self.stock_location.id,
|
||||
})],
|
||||
})
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ class TestMultistepManufacturingWarehouse(TestMrpCommon):
|
||||
self._check_location_and_routes()
|
||||
# Check locations of existing pull rule
|
||||
self.assertFalse(self.warehouse.pbm_route_id.rule_ids, 'only the update of global manufacture route should happen.')
|
||||
self.assertEqual(self.warehouse.manufacture_pull_id.location_id.id, self.warehouse.lot_stock_id.id)
|
||||
self.assertEqual(self.warehouse.manufacture_pull_id.location_dest_id.id, self.warehouse.lot_stock_id.id)
|
||||
|
||||
def test_01_warehouse_twostep_manufacturing(self):
|
||||
""" Warehouse testing for picking before manufacturing """
|
||||
@@ -78,7 +78,7 @@ class TestMultistepManufacturingWarehouse(TestMrpCommon):
|
||||
warehouse.manufacture_steps = 'pbm'
|
||||
self._check_location_and_routes()
|
||||
self.assertEqual(len(self.warehouse.pbm_route_id.rule_ids), 2)
|
||||
self.assertEqual(self.warehouse.manufacture_pull_id.location_id.id, self.warehouse.lot_stock_id.id)
|
||||
self.assertEqual(self.warehouse.manufacture_pull_id.location_dest_id.id, self.warehouse.lot_stock_id.id)
|
||||
|
||||
def test_02_warehouse_twostep_manufacturing(self):
|
||||
""" Warehouse testing for picking ans store after manufacturing """
|
||||
@@ -86,7 +86,7 @@ class TestMultistepManufacturingWarehouse(TestMrpCommon):
|
||||
warehouse.manufacture_steps = 'pbm_sam'
|
||||
self._check_location_and_routes()
|
||||
self.assertEqual(len(self.warehouse.pbm_route_id.rule_ids), 3)
|
||||
self.assertEqual(self.warehouse.manufacture_pull_id.location_id.id, self.warehouse.sam_loc_id.id)
|
||||
self.assertEqual(self.warehouse.manufacture_pull_id.location_dest_id.id, self.warehouse.sam_loc_id.id)
|
||||
|
||||
def test_manufacturing_3_steps(self):
|
||||
""" Test MO/picking before manufacturing/picking after manufacturing
|
||||
|
||||
@@ -75,7 +75,7 @@ class StockWarehouse(models.Model):
|
||||
'auto': 'manual',
|
||||
'route_id': self._find_global_route('stock.route_warehouse0_mto', _('Make To Order')).id,
|
||||
'name': self._format_rulename(self.lot_stock_id, subcontract_location_id, 'MTO'),
|
||||
'location_id': subcontract_location_id.id,
|
||||
'location_dest_id': subcontract_location_id.id,
|
||||
'location_src_id': self.lot_stock_id.id,
|
||||
'picking_type_id': self.subcontracting_resupply_type_id.id
|
||||
},
|
||||
@@ -93,7 +93,7 @@ class StockWarehouse(models.Model):
|
||||
'route_id': self._find_global_route('mrp_subcontracting.route_resupply_subcontractor_mto',
|
||||
_('Resupply Subcontractor on Order')).id,
|
||||
'name': self._format_rulename(self.lot_stock_id, subcontract_location_id, False),
|
||||
'location_id': production_location_id.id,
|
||||
'location_dest_id': production_location_id.id,
|
||||
'location_src_id': subcontract_location_id.id,
|
||||
'picking_type_id': self.subcontracting_resupply_type_id.id
|
||||
},
|
||||
|
||||
@@ -105,14 +105,14 @@ class TestSubcontractingFlows(TestMrpSubcontractingCommon):
|
||||
'company_id': self.env.company.id,
|
||||
})
|
||||
self.subcontractor_partner1.property_stock_subcontractor = partner_subcontract_location.id
|
||||
resupply_rule = resupply_sub_on_order_route.rule_ids.filtered(lambda l:
|
||||
l.location_id == self.comp1.property_stock_production and
|
||||
l.location_src_id == self.env.company.subcontracting_location_id)
|
||||
resupply_rule = resupply_sub_on_order_route.rule_ids.filtered(lambda r:
|
||||
r.location_dest_id == self.comp1.property_stock_production and
|
||||
r.location_src_id == self.env.company.subcontracting_location_id)
|
||||
resupply_rule.copy({'location_src_id': partner_subcontract_location.id})
|
||||
resupply_warehouse_rule = self.warehouse.route_ids.rule_ids.filtered(lambda l:
|
||||
l.location_id == self.env.company.subcontracting_location_id and
|
||||
l.location_src_id == self.warehouse.lot_stock_id)
|
||||
resupply_warehouse_rule.copy({'location_id': partner_subcontract_location.id})
|
||||
resupply_warehouse_rule = self.warehouse.route_ids.rule_ids.filtered(lambda r:
|
||||
r.location_dest_id == self.env.company.subcontracting_location_id and
|
||||
r.location_src_id == self.warehouse.lot_stock_id)
|
||||
resupply_warehouse_rule.copy({'location_dest_id': partner_subcontract_location.id})
|
||||
# Add a manufacturing lead time to check that the resupply delivery is correctly planned 2 days
|
||||
# before the subcontracting receipt
|
||||
self.finished.produce_delay = 2
|
||||
|
||||
@@ -22,7 +22,7 @@ class ResCompany(models.Model):
|
||||
vals.append({
|
||||
'name': '%s → %s' % (supplier_location.name, subcontracting_location.name),
|
||||
'action': 'buy',
|
||||
'location_id': subcontracting_location.id,
|
||||
'location_dest_id': subcontracting_location.id,
|
||||
'location_src_id': supplier_location.id,
|
||||
'procure_method': 'make_to_stock',
|
||||
'route_id': route.id,
|
||||
|
||||
@@ -8,6 +8,6 @@ class StockRule(models.Model):
|
||||
_inherit = 'stock.rule'
|
||||
|
||||
def _prepare_purchase_order(self, company_id, origins, values):
|
||||
if 'partner_id' not in values[0] and self.location_id.id == company_id.subcontracting_location_id.id:
|
||||
if 'partner_id' not in values[0] and self.location_dest_id.id == company_id.subcontracting_location_id.id:
|
||||
values[0]['partner_id'] = values[0]['group_id'].partner_id.id
|
||||
return super()._prepare_purchase_order(company_id, origins, values)
|
||||
|
||||
@@ -30,7 +30,7 @@ class StockWarehouse(models.Model):
|
||||
'route_id': self._find_global_route('mrp_subcontracting_dropshipping.route_subcontracting_dropshipping',
|
||||
_('Dropship Subcontractor on Order')).id,
|
||||
'name': self._format_rulename(subcontract_location_id, production_location_id, False),
|
||||
'location_id': production_location_id.id,
|
||||
'location_dest_id': production_location_id.id,
|
||||
'location_src_id': subcontract_location_id.id,
|
||||
'picking_type_id': self.subcontracting_type_id.id
|
||||
},
|
||||
|
||||
@@ -135,7 +135,7 @@ class StockWarehouse(models.Model):
|
||||
'update_values': {
|
||||
'active': self.buy_to_resupply,
|
||||
'name': self._format_rulename(location_id, False, 'Buy'),
|
||||
'location_id': location_id.id,
|
||||
'location_dest_id': location_id.id,
|
||||
'propagate_cancel': self.reception_steps != 'one_step',
|
||||
}
|
||||
}
|
||||
|
||||
@@ -184,7 +184,7 @@ class TestReorderingRule(TransactionCase):
|
||||
'rule_ids': [
|
||||
(0, False, {
|
||||
'name': 'Buy',
|
||||
'location_id': warehouse_1.lot_stock_id.id,
|
||||
'location_dest_id': warehouse_1.lot_stock_id.id,
|
||||
'company_id': self.env.company.id,
|
||||
'action': 'buy',
|
||||
'sequence': 2,
|
||||
@@ -194,7 +194,7 @@ class TestReorderingRule(TransactionCase):
|
||||
(0, False, {
|
||||
'name': 'ressuply from stock',
|
||||
'location_src_id': warehouse_1.lot_stock_id.id,
|
||||
'location_id': outside_loc.id,
|
||||
'location_dest_id': outside_loc.id,
|
||||
'company_id': self.env.company.id,
|
||||
'action': 'pull',
|
||||
'procure_method': 'mts_else_mto',
|
||||
@@ -547,7 +547,7 @@ class TestReorderingRule(TransactionCase):
|
||||
mto_rule = self.env['stock.rule'].search(
|
||||
[('warehouse_id', '=', warehouse.id),
|
||||
('procure_method', '=', 'mts_else_mto'),
|
||||
('location_id', '=', customer_loc.id)
|
||||
('location_dest_id', '=', customer_loc.id)
|
||||
]
|
||||
)
|
||||
route_mto = self.env["stock.route"].create({
|
||||
|
||||
@@ -1372,7 +1372,7 @@ class TestSaleMrpFlow(ValuationReconciliationTestCommon):
|
||||
'action': 'pull',
|
||||
'picking_type_id': self.company_data['default_warehouse'].in_type_id.id,
|
||||
'location_src_id': stock_location_components.id,
|
||||
'location_id': self.ref('stock.stock_location_customers'),
|
||||
'location_dest_id': self.ref('stock.stock_location_customers'),
|
||||
})],
|
||||
})
|
||||
|
||||
@@ -1384,7 +1384,7 @@ class TestSaleMrpFlow(ValuationReconciliationTestCommon):
|
||||
'action': 'pull',
|
||||
'picking_type_id': self.company_data['default_warehouse'].in_type_id.id,
|
||||
'location_src_id': stock_location_14.id,
|
||||
'location_id': self.ref('stock.stock_location_customers'),
|
||||
'location_dest_id': self.ref('stock.stock_location_customers'),
|
||||
})],
|
||||
})
|
||||
|
||||
|
||||
@@ -787,7 +787,7 @@ class StockMove(models.Model):
|
||||
else:
|
||||
rule = self.sudo().env['procurement.group']._search_rule(move.route_ids, move.product_packaging_id, move.product_id, warehouse_id, domain)
|
||||
# Make sure it is not returning the return
|
||||
if rule and (not move.origin_returned_move_id or move.origin_returned_move_id.location_dest_id.id != rule.location_id.id):
|
||||
if rule and (not move.origin_returned_move_id or move.origin_returned_move_id.location_dest_id.id != rule.location_dest_id.id):
|
||||
new_move = rule._run_push(move)
|
||||
if new_move:
|
||||
new_moves.append(new_move)
|
||||
@@ -1867,7 +1867,7 @@ class StockMove(models.Model):
|
||||
product_id = move.product_id
|
||||
domain = [
|
||||
('location_src_id', '=', move.location_id.id),
|
||||
('location_id', '=', move.location_dest_id.id),
|
||||
('location_dest_id', '=', move.location_dest_id.id),
|
||||
('action', '!=', 'push')
|
||||
]
|
||||
rules = self.env['procurement.group']._search_rule(False, move.product_packaging_id, product_id, move.warehouse_id, domain)
|
||||
|
||||
@@ -279,13 +279,13 @@ class StockWarehouseOrderpoint(models.Model):
|
||||
self = self.filtered(lambda o: not o.route_id)
|
||||
rules_groups = self.env['stock.rule'].read_group([
|
||||
('route_id.product_selectable', '!=', False),
|
||||
('location_id', 'in', self.location_id.ids),
|
||||
('location_dest_id', 'in', self.location_id.ids),
|
||||
('action', 'in', ['pull_push', 'pull'])
|
||||
], ['location_id', 'route_id'], ['location_id', 'route_id'], lazy=False)
|
||||
], ['location_dest_id', 'route_id'], ['location_dest_id', 'route_id'], lazy=False)
|
||||
for g in rules_groups:
|
||||
if not g.get('route_id'):
|
||||
continue
|
||||
orderpoints = self.filtered(lambda o: o.location_id.id == g['location_id'][0])
|
||||
orderpoints = self.filtered(lambda o: o.location_id.id == g['location_dest_id'][0])
|
||||
orderpoints.route_id = g['route_id']
|
||||
|
||||
def _get_lead_days_values(self):
|
||||
|
||||
@@ -59,7 +59,7 @@ class StockRule(models.Model):
|
||||
company_id = fields.Many2one('res.company', 'Company',
|
||||
default=lambda self: self.env.company,
|
||||
domain="[('id', '=?', route_company_id)]")
|
||||
location_id = fields.Many2one('stock.location', 'Destination Location', required=True, check_company=True)
|
||||
location_dest_id = fields.Many2one('stock.location', 'Destination Location', required=True, check_company=True)
|
||||
location_src_id = fields.Many2one('stock.location', 'Source Location', check_company=True)
|
||||
route_id = fields.Many2one('stock.route', 'Route', required=True, ondelete='cascade')
|
||||
route_company_id = fields.Many2one(related='route_id.company_id', string='Route Company')
|
||||
@@ -107,7 +107,7 @@ class StockRule(models.Model):
|
||||
Enable the delay alert if the picking type is a delivery
|
||||
"""
|
||||
self.location_src_id = self.picking_type_id.default_location_src_id.id
|
||||
self.location_id = self.picking_type_id.default_location_dest_id.id
|
||||
self.location_dest_id = self.picking_type_id.default_location_dest_id.id
|
||||
|
||||
@api.onchange('route_id', 'company_id')
|
||||
def _onchange_route(self):
|
||||
@@ -123,7 +123,7 @@ class StockRule(models.Model):
|
||||
_get_message_dict functions since it often requires those data.
|
||||
"""
|
||||
source = self.location_src_id and self.location_src_id.display_name or _('Source Location')
|
||||
destination = self.location_id and self.location_id.display_name or _('Destination Location')
|
||||
destination = self.location_dest_id and self.location_dest_id.display_name or _('Destination Location')
|
||||
operation = self.picking_type_id and self.picking_type_id.name or _('Operation Type')
|
||||
return source, destination, operation
|
||||
|
||||
@@ -147,7 +147,7 @@ class StockRule(models.Model):
|
||||
}
|
||||
return message_dict
|
||||
|
||||
@api.depends('action', 'location_id', 'location_src_id', 'picking_type_id', 'procure_method')
|
||||
@api.depends('action', 'location_dest_id', 'location_src_id', 'picking_type_id', 'procure_method')
|
||||
def _compute_action_message(self):
|
||||
""" Generate dynamicaly a message that describe the rule purpose to the
|
||||
end user.
|
||||
@@ -178,13 +178,13 @@ class StockRule(models.Model):
|
||||
new_date = fields.Datetime.to_string(move.date + relativedelta(days=self.delay))
|
||||
if self.auto == 'transparent':
|
||||
old_dest_location = move.location_dest_id
|
||||
move.write({'date': new_date, 'location_dest_id': self.location_id.id})
|
||||
move.write({'date': new_date, 'location_dest_id': self.location_dest_id.id})
|
||||
# make sure the location_dest_id is consistent with the move line location dest
|
||||
if move.move_line_ids:
|
||||
move.move_line_ids.location_dest_id = move.location_dest_id._get_putaway_strategy(move.product_id) or move.location_dest_id
|
||||
|
||||
# avoid looping if a push rule is not well configured; otherwise call again push_apply to see if a next step is defined
|
||||
if self.location_id != old_dest_location:
|
||||
if self.location_dest_id != old_dest_location:
|
||||
# TDE FIXME: should probably be done in the move model IMO
|
||||
return move._push_apply()[:1]
|
||||
else:
|
||||
@@ -203,7 +203,7 @@ class StockRule(models.Model):
|
||||
new_move_vals = {
|
||||
'origin': move_to_copy.origin or move_to_copy.picking_id.name or "/",
|
||||
'location_id': move_to_copy.location_dest_id.id,
|
||||
'location_dest_id': self.location_id.id,
|
||||
'location_dest_id': self.location_dest_id.id,
|
||||
'date': new_date,
|
||||
'company_id': company_id,
|
||||
'picking_id': False,
|
||||
@@ -270,7 +270,7 @@ class StockRule(models.Model):
|
||||
"""
|
||||
return []
|
||||
|
||||
def _get_stock_move_values(self, product_id, product_qty, product_uom, location_id, name, origin, company_id, values):
|
||||
def _get_stock_move_values(self, product_id, product_qty, product_uom, location_dest_id, name, origin, company_id, values):
|
||||
''' Returns a dictionary of values that will be used to create a stock move from a procurement.
|
||||
This function assumes that the given procurement has a rule (action == 'pull' or 'pull_push') set on it.
|
||||
|
||||
@@ -298,13 +298,13 @@ class StockRule(models.Model):
|
||||
qty_left = product_qty
|
||||
|
||||
move_dest_ids = []
|
||||
if not self.location_id.should_bypass_reservation():
|
||||
if not self.location_dest_id.should_bypass_reservation():
|
||||
move_dest_ids = values.get('move_dest_ids', False) and [(4, x.id) for x in values['move_dest_ids']] or []
|
||||
|
||||
# when create chained moves for inter-warehouse transfers, set the warehouses as partners
|
||||
if not partner and move_dest_ids:
|
||||
move_dest = values['move_dest_ids']
|
||||
if location_id == company_id.internal_transit_location_id:
|
||||
if location_dest_id == company_id.internal_transit_location_id:
|
||||
partners = move_dest.location_dest_id.warehouse_id.partner_id
|
||||
if len(partners) == 1:
|
||||
partner = partners
|
||||
@@ -312,13 +312,13 @@ class StockRule(models.Model):
|
||||
|
||||
move_values = {
|
||||
'name': name[:2000],
|
||||
'company_id': self.company_id.id or self.location_src_id.company_id.id or self.location_id.company_id.id or company_id.id,
|
||||
'company_id': self.company_id.id or self.location_src_id.company_id.id or self.location_dest_id.company_id.id or company_id.id,
|
||||
'product_id': product_id.id,
|
||||
'product_uom': product_uom.id,
|
||||
'product_uom_qty': qty_left,
|
||||
'partner_id': partner.id if partner else False,
|
||||
'location_id': self.location_src_id.id,
|
||||
'location_dest_id': location_id.id,
|
||||
'location_dest_id': location_dest_id.id,
|
||||
'move_dest_ids': move_dest_ids,
|
||||
'rule_id': self.id,
|
||||
'procure_method': self.procure_method,
|
||||
@@ -502,7 +502,7 @@ class ProcurementGroup(models.Model):
|
||||
|
||||
@api.model
|
||||
def _get_rule_domain(self, location, values):
|
||||
domain = ['&', ('location_id', '=', location.id), ('action', '!=', 'push')]
|
||||
domain = ['&', ('location_dest_id', '=', location.id), ('action', '!=', 'push')]
|
||||
# In case the method is called by the superuser, we need to restrict the rules to the
|
||||
# ones of the company. This is not useful as a regular user since there is a record
|
||||
# rule to filter out the rules based on the company.
|
||||
|
||||
@@ -395,7 +395,7 @@ class Warehouse(models.Model):
|
||||
},
|
||||
'update_values': {
|
||||
'name': self._format_rulename(location_id, location_dest_id, 'MTO'),
|
||||
'location_id': location_dest_id.id,
|
||||
'location_dest_id': location_dest_id.id,
|
||||
'location_src_id': location_id.id,
|
||||
'picking_type_id': picking_type_id.id,
|
||||
}
|
||||
@@ -571,7 +571,7 @@ class Warehouse(models.Model):
|
||||
existing_rule = self.env['stock.rule'].search([
|
||||
('picking_type_id', '=', rule_vals['picking_type_id']),
|
||||
('location_src_id', '=', rule_vals['location_src_id']),
|
||||
('location_id', '=', rule_vals['location_id']),
|
||||
('location_dest_id', '=', rule_vals['location_dest_id']),
|
||||
('route_id', '=', rule_vals['route_id']),
|
||||
('action', '=', rule_vals['action']),
|
||||
('active', '=', False),
|
||||
@@ -774,7 +774,7 @@ class Warehouse(models.Model):
|
||||
route_rule_values = {
|
||||
'name': self._format_rulename(routing.from_loc, routing.dest_loc, name_suffix),
|
||||
'location_src_id': routing.from_loc.id,
|
||||
'location_id': routing.dest_loc.id,
|
||||
'location_dest_id': routing.dest_loc.id,
|
||||
'action': routing.action,
|
||||
'auto': 'manual',
|
||||
'picking_type_id': routing.picking_type.id,
|
||||
@@ -822,13 +822,13 @@ class Warehouse(models.Model):
|
||||
Check routes being delivery bu this warehouse and change the rule going to transit location """
|
||||
Rule = self.env["stock.rule"]
|
||||
routes = self.env['stock.route'].search([('supplier_wh_id', '=', self.id)])
|
||||
rules = Rule.search(['&', '&', ('route_id', 'in', routes.ids), ('action', '!=', 'push'), ('location_id.usage', '=', 'transit')])
|
||||
rules = Rule.search(['&', '&', ('route_id', 'in', routes.ids), ('action', '!=', 'push'), ('location_dest_id.usage', '=', 'transit')])
|
||||
rules.write({
|
||||
'location_src_id': new_location.id,
|
||||
'procure_method': change_to_multiple and "make_to_order" or "make_to_stock"})
|
||||
if not change_to_multiple:
|
||||
# If single delivery we should create the necessary MTO rules for the resupply
|
||||
routings = [self.Routing(self.lot_stock_id, location, self.out_type_id, 'pull') for location in rules.mapped('location_id')]
|
||||
routings = [self.Routing(self.lot_stock_id, location, self.out_type_id, 'pull') for location in rules.location_dest_id]
|
||||
mto_vals = self._get_global_route_rules_values().get('mto_pull_id')
|
||||
values = mto_vals['create_values']
|
||||
mto_rule_vals = self._get_rule_values(routings, values, name_suffix='MTO')
|
||||
@@ -839,7 +839,7 @@ class Warehouse(models.Model):
|
||||
# We need to delete all the MTO stock rules, otherwise they risk to be used in the system
|
||||
Rule.search([
|
||||
'&', ('route_id', '=', self._find_global_route('stock.route_warehouse0_mto', _('Make To Order')).id),
|
||||
('location_id.usage', '=', 'transit'),
|
||||
('location_dest_id.usage', '=', 'transit'),
|
||||
('action', '!=', 'push'),
|
||||
('location_src_id', '=', self.lot_stock_id.id)]).write({'active': False})
|
||||
|
||||
@@ -853,7 +853,7 @@ class Warehouse(models.Model):
|
||||
'&',
|
||||
('action', '!=', 'push'),
|
||||
('location_src_id.usage', '=', 'transit')
|
||||
]).write({'location_id': new_location.id})
|
||||
]).write({'location_dest_id': new_location.id})
|
||||
|
||||
def _update_name_and_code(self, new_name=False, new_code=False):
|
||||
if new_code:
|
||||
|
||||
@@ -86,7 +86,7 @@ class ReportStockRule(models.AbstractModel):
|
||||
@api.model
|
||||
def _get_rule_loc(self, rule, product):
|
||||
rule.ensure_one()
|
||||
return {'rule': rule, 'source': rule.location_src_id, 'destination': rule.location_id}
|
||||
return {'rule': rule, 'source': rule.location_src_id, 'destination': rule.location_dest_id}
|
||||
|
||||
@api.model
|
||||
def _sort_locations(self, rules_and_loc, warehouses):
|
||||
|
||||
@@ -2433,8 +2433,8 @@ class TestRoutes(TestStockCommon):
|
||||
'group_id': procurement_group0.id,
|
||||
})
|
||||
|
||||
ship_location = pick_rule.location_id
|
||||
customer_location = push_rule.location_id
|
||||
ship_location = pick_rule.location_dest_id
|
||||
customer_location = push_rule.location_dest_id
|
||||
partners = self.env['res.partner'].search([], limit=2)
|
||||
partner0 = partners[0]
|
||||
partner1 = partners[1]
|
||||
@@ -2530,7 +2530,7 @@ class TestRoutes(TestStockCommon):
|
||||
'rule_ids': [(0, False, {
|
||||
'name': 'create a move to push location',
|
||||
'location_src_id': stock_location.id,
|
||||
'location_id': push_location.id,
|
||||
'location_dest_id': push_location.id,
|
||||
'company_id': self.env.company.id,
|
||||
'action': 'push',
|
||||
'auto': 'manual',
|
||||
@@ -2575,7 +2575,7 @@ class TestRoutes(TestStockCommon):
|
||||
'rule_ids': [(0, False, {
|
||||
'name': 'create a move to push location',
|
||||
'location_src_id': self.env.ref('stock.stock_location_stock').id,
|
||||
'location_id': new_loc.id,
|
||||
'location_dest_id': new_loc.id,
|
||||
'company_id': self.env.company.id,
|
||||
'action': 'push',
|
||||
'auto': 'transparent',
|
||||
@@ -3075,7 +3075,7 @@ class TestRoutes(TestStockCommon):
|
||||
'rule_ids': [(0, False, {
|
||||
'name': 'create a move to push location 1',
|
||||
'location_src_id': stock_location.id,
|
||||
'location_id': push_location_1.id,
|
||||
'location_dest_id': push_location_1.id,
|
||||
'company_id': self.env.company.id,
|
||||
'action': 'push',
|
||||
'auto': 'manual',
|
||||
@@ -3089,7 +3089,7 @@ class TestRoutes(TestStockCommon):
|
||||
'rule_ids': [(0, False, {
|
||||
'name': 'create a move to push location 2',
|
||||
'location_src_id': stock_location.id,
|
||||
'location_id': push_location_2.id,
|
||||
'location_dest_id': push_location_2.id,
|
||||
'company_id': self.env.company.id,
|
||||
'action': 'push',
|
||||
'auto': 'manual',
|
||||
|
||||
@@ -410,7 +410,7 @@ class TestMultiCompany(TransactionCase):
|
||||
'name': 'create a move to company b',
|
||||
'company_id': self.company_b.id,
|
||||
'location_src_id': intercom_location.id,
|
||||
'location_id': self.stock_location_b.id,
|
||||
'location_dest_id': self.stock_location_b.id,
|
||||
'action': 'push',
|
||||
'auto': 'manual',
|
||||
'picking_type_id': self.warehouse_b.in_type_id.id,
|
||||
|
||||
@@ -31,7 +31,7 @@ class TestProcRule(TransactionCase):
|
||||
'action': 'pull',
|
||||
'picking_type_id': self.ref('stock.picking_type_internal'),
|
||||
'location_src_id': self.ref('stock.stock_location_stock'),
|
||||
'location_id': self.ref('stock.stock_location_output'),
|
||||
'location_dest_id': self.ref('stock.stock_location_output'),
|
||||
})],
|
||||
})
|
||||
|
||||
@@ -121,7 +121,7 @@ class TestProcRule(TransactionCase):
|
||||
# get auto-created pull rule from when warehouse is created
|
||||
rule = self.env['stock.rule'].search([
|
||||
('route_id', '=', warehouse.reception_route_id.id),
|
||||
('location_id', '=', warehouse.lot_stock_id.id),
|
||||
('location_dest_id', '=', warehouse.lot_stock_id.id),
|
||||
('location_src_id', '=', self.env.ref('stock.stock_location_suppliers').id),
|
||||
('action', '=', 'pull'),
|
||||
('procure_method', '=', 'make_to_stock'),
|
||||
@@ -185,7 +185,7 @@ class TestProcRule(TransactionCase):
|
||||
self.env['stock.rule'].create({
|
||||
'name': 'Rule Supplier',
|
||||
'route_id': warehouse.reception_route_id.id,
|
||||
'location_id': warehouse.lot_stock_id.id,
|
||||
'location_dest_id': warehouse.lot_stock_id.id,
|
||||
'location_src_id': self.env.ref('stock.stock_location_suppliers').id,
|
||||
'action': 'pull',
|
||||
'delay': 9.0,
|
||||
@@ -266,7 +266,7 @@ class TestProcRule(TransactionCase):
|
||||
'action': 'pull',
|
||||
'picking_type_id': self.ref('stock.picking_type_internal'),
|
||||
'location_src_id': self.ref('stock.stock_location_stock'),
|
||||
'location_id': self.ref('stock.stock_location_output'),
|
||||
'location_dest_id': self.ref('stock.stock_location_output'),
|
||||
'group_propagation_option': 'fixed',
|
||||
'group_id': wave_pg.id,
|
||||
})],
|
||||
@@ -364,7 +364,7 @@ class TestProcRuleLoad(TransactionCase):
|
||||
self.env['stock.rule'].create({
|
||||
'name': 'Rule Shelf1',
|
||||
'route_id': warehouse.reception_route_id.id,
|
||||
'location_id': shelf1.id,
|
||||
'location_dest_id': shelf1.id,
|
||||
'location_src_id': stock_loc.id,
|
||||
'action': 'pull',
|
||||
'procure_method': 'make_to_order',
|
||||
@@ -373,7 +373,7 @@ class TestProcRuleLoad(TransactionCase):
|
||||
self.env['stock.rule'].create({
|
||||
'name': 'Rule Shelf2',
|
||||
'route_id': warehouse.reception_route_id.id,
|
||||
'location_id': shelf2.id,
|
||||
'location_dest_id': shelf2.id,
|
||||
'location_src_id': stock_loc.id,
|
||||
'action': 'pull',
|
||||
'procure_method': 'make_to_order',
|
||||
@@ -382,7 +382,7 @@ class TestProcRuleLoad(TransactionCase):
|
||||
self.env['stock.rule'].create({
|
||||
'name': 'Rule Supplier',
|
||||
'route_id': warehouse.reception_route_id.id,
|
||||
'location_id': warehouse.wh_input_stock_loc_id.id,
|
||||
'location_dest_id': warehouse.wh_input_stock_loc_id.id,
|
||||
'location_src_id': supplier_loc.id,
|
||||
'action': 'pull',
|
||||
'procure_method': 'make_to_stock',
|
||||
@@ -395,7 +395,7 @@ class TestProcRuleLoad(TransactionCase):
|
||||
self.env['stock.rule'].create({
|
||||
'name': 'Trap Rule',
|
||||
'route_id': wrong_route.id,
|
||||
'location_id': warehouse.wh_input_stock_loc_id.id,
|
||||
'location_dest_id': warehouse.wh_input_stock_loc_id.id,
|
||||
'location_src_id': supplier_loc.id,
|
||||
'action': 'pull',
|
||||
'procure_method': 'make_to_order',
|
||||
|
||||
@@ -129,7 +129,7 @@ class TestReportStockQuantity(tests.TransactionCase):
|
||||
self.env['stock.rule'].create({
|
||||
'name': 'Rule Supplier',
|
||||
'route_id': self.wh.reception_route_id.id,
|
||||
'location_id': self.wh.lot_stock_id.id,
|
||||
'location_dest_id': self.wh.lot_stock_id.id,
|
||||
'location_src_id': self.env.ref('stock.stock_location_suppliers').id,
|
||||
'action': 'pull',
|
||||
'delay': 1.0,
|
||||
|
||||
@@ -1723,7 +1723,7 @@ class TestStockFlow(TestStockCommon):
|
||||
rule.name = 'From InterCompany to Company 2'
|
||||
rule.action = 'pull'
|
||||
rule.picking_type_id = warehouse_company_2.out_type_id
|
||||
rule.location_id = self.env.ref('stock.stock_location_inter_wh')
|
||||
rule.location_dest_id = self.env.ref('stock.stock_location_inter_wh')
|
||||
rule.procure_method = 'make_to_stock'
|
||||
route_b = f.save()
|
||||
|
||||
@@ -1788,7 +1788,7 @@ class TestStockFlow(TestStockCommon):
|
||||
rule.name = 'From InterCompany to Company 2'
|
||||
rule.action = 'pull'
|
||||
rule.picking_type_id = warehouse_company_2.out_type_id
|
||||
rule.location_id = self.env.ref('stock.stock_location_inter_wh')
|
||||
rule.location_dest_id = self.env.ref('stock.stock_location_inter_wh')
|
||||
rule.procure_method = 'make_to_stock'
|
||||
route_b = f.save()
|
||||
|
||||
@@ -1804,7 +1804,7 @@ class TestStockFlow(TestStockCommon):
|
||||
rule.name = 'From InterCompany to Company 3'
|
||||
rule.action = 'pull'
|
||||
rule.picking_type_id = warehouse_company_3.out_type_id
|
||||
rule.location_id = self.env.ref('stock.stock_location_inter_wh')
|
||||
rule.location_dest_id = self.env.ref('stock.stock_location_inter_wh')
|
||||
rule.procure_method = 'make_to_stock'
|
||||
route_c = f.save()
|
||||
|
||||
|
||||
@@ -222,7 +222,7 @@
|
||||
<field name="sequence" widget="handle"/>
|
||||
<field name="action"/>
|
||||
<field name="location_src_id" options="{'no_create': True}"/>
|
||||
<field name="location_id" options="{'no_create': True}"/>
|
||||
<field name="location_dest_id" options="{'no_create': True}"/>
|
||||
</tree>
|
||||
</field>
|
||||
</group>
|
||||
|
||||
@@ -48,7 +48,7 @@
|
||||
<tree string="Rules">
|
||||
<field name="action"/>
|
||||
<field name="location_src_id" options="{'no_create': True}"/>
|
||||
<field name="location_id" options="{'no_create': True}"/>
|
||||
<field name="location_dest_id" options="{'no_create': True}"/>
|
||||
<field name="route_id"/>
|
||||
<field name="company_id" groups="base.group_multi_company"/>
|
||||
</tree>
|
||||
@@ -73,7 +73,7 @@
|
||||
<field name="action"/>
|
||||
<field name="picking_type_id"/>
|
||||
<field name="location_src_id" options="{'no_create': True}" attrs="{'required': [('action', 'in', ['pull', 'push', 'pull_push'])]}"/>
|
||||
<field name="location_id" options="{'no_create': True}"/>
|
||||
<field name="location_dest_id" options="{'no_create': True}"/>
|
||||
<field name="auto" attrs="{'invisible': [('action', 'not in', ['push', 'pull_push'])]}"/>
|
||||
<field name="procure_method" attrs="{'invisible': [('action', 'not in', ['pull', 'pull_push'])]}"/>
|
||||
</group>
|
||||
|
||||
@@ -94,7 +94,7 @@ class ResCompany(models.Model):
|
||||
dropship_vals.append({
|
||||
'name': '%s → %s' % (supplier_location.name, customer_location.name),
|
||||
'action': 'buy',
|
||||
'location_id': customer_location.id,
|
||||
'location_dest_id': customer_location.id,
|
||||
'location_src_id': supplier_location.id,
|
||||
'procure_method': 'make_to_stock',
|
||||
'route_id': dropship_route.id,
|
||||
|
||||
@@ -21,7 +21,7 @@ class ProcurementGroup(models.Model):
|
||||
@api.model
|
||||
def _get_rule_domain(self, location, values):
|
||||
if 'sale_line_id' in values and values.get('company_id'):
|
||||
return [('location_id', '=', location.id), ('action', '!=', 'push'), ('company_id', '=', values['company_id'].id)]
|
||||
return [('location_dest_id', '=', location.id), ('action', '!=', 'push'), ('company_id', '=', values['company_id'].id)]
|
||||
else:
|
||||
return super(ProcurementGroup, self)._get_rule_domain(location, values)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user