Skip to content
Snippets Groups Projects
Commit 25e38275 authored by Nicolas Martinelli's avatar Nicolas Martinelli
Browse files

[FIX] stock: default location for scrap


- Create a default value for 'Source Location' or 'Scrap Location'
- Create a Scrap Order

the default value is not taken into account since it is overridden by
`_onchange_company_id`.

We avoid changing the location in case the company matches.

opw-2189578

closes odoo/odoo#44812

X-original-commit: 5c544adb
Signed-off-by: default avatarNicolas Martinelli (nim) <nim@odoo.com>
parent 95300401
Branches
Tags
No related merge requests found
......@@ -83,11 +83,15 @@ class StockScrap(models.Model):
def _onchange_company_id(self):
if self.company_id:
warehouse = self.env['stock.warehouse'].search([('company_id', '=', self.company_id.id)], limit=1)
self.location_id = warehouse.lot_stock_id
self.scrap_location_id = self.env['stock.location'].search([
('scrap_location', '=', True),
('company_id', 'in', [self.company_id.id, False]),
], limit=1)
# Change the locations only if their company doesn't match the company set, otherwise
# user defaults are overridden.
if self.location_id.company_id != self.company_id:
self.location_id = warehouse.lot_stock_id
if self.scrap_location_id.company_id != self.company_id:
self.scrap_location_id = self.env['stock.location'].search([
('scrap_location', '=', True),
('company_id', 'in', [self.company_id.id, False]),
], limit=1)
else:
self.location_id = False
self.scrap_location_id = False
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment