Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[13.0] [FIX] stock: Added a method in stock.warehouse to allow override his … #63

Open
wants to merge 1 commit into
base: 13.0
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions addons/stock/models/stock_warehouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,21 +93,24 @@ def _compute_show_resupply(self):
for warehouse in self:
warehouse.show_resupply = warehouse.user_has_groups("stock.group_stock_multi_warehouses") and warehouse.warehouse_count

def _create_and_get_stock_location_id(self, values):
return self.env['stock.location'].create(values).id

@api.model
def create(self, vals):
# create view location for warehouse then create all locations
loc_vals = {'name': _(vals.get('code')), 'usage': 'view',
'location_id': self.env.ref('stock.stock_location_locations').id}
Comment on lines 102 to 103
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it not better to have a prepare method for this ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be even better. But we also need the _create method to place our sudo().

if vals.get('company_id'):
loc_vals['company_id'] = vals.get('company_id')
vals['view_location_id'] = self.env['stock.location'].create(loc_vals).id
vals['view_location_id'] = self._create_and_get_stock_location_id(loc_vals)
sub_locations = self._get_locations_values(vals)

for field_name, values in sub_locations.items():
values['location_id'] = vals['view_location_id']
if vals.get('company_id'):
values['company_id'] = vals.get('company_id')
vals[field_name] = self.env['stock.location'].with_context(active_test=False).create(values).id
vals[field_name] = self._create_and_get_stock_location_id(values)

# actually create WH
warehouse = super(Warehouse, self).create(vals)
Expand Down