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

[9.0] [MIG] stock_inventory_lockdown #282

Merged
merged 4 commits into from
Jun 9, 2017

Conversation

MiquelRForgeFlow
Copy link
Contributor

Standard migration.

@pedrobaeza pedrobaeza mentioned this pull request May 15, 2017
27 tasks
Copy link
Member

@StefanRijnhart StefanRijnhart left a comment

Choose a reason for hiding this comment

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

Thanks! Code reviewed and tested on runbot.

Copy link
Contributor

@LoisRForgeFlow LoisRForgeFlow left a comment

Choose a reason for hiding this comment

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

Functional and technical review 👍

Just to minor (not blocking) things:

  • It would be good to update the images of the description, they are v8.
  • Squash transifex commits.

@MiquelRForgeFlow MiquelRForgeFlow force-pushed the 9.0-mig-stock_inventory_lockdown branch from c4b0515 to 8fd3d9e Compare May 15, 2017 12:18
Copy link
Sponsor Contributor

@lmignon lmignon left a comment

Choose a reason for hiding this comment

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

@mreficent IMO we can improve the logic to check for locked locations.... and improve the performances. see my comments. What do you think about?

_inherit = 'stock.inventory'

@api.model
def _get_locations_open_inventories(self):
Copy link
Sponsor Contributor

Choose a reason for hiding this comment

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

@mreficent IMO if would be more efficient to allow to pass a location_ids parameter to this method and t use this paramaterd (if provided) into the domain for the search on inventories...
ex:

 @api.model
 def _get_locations_open_inventories(self, locations_ids = None):
    inventory_domain = [('state', '=', 'confirm')]
    if locations_ids:
        inventory_domain.append(('location_id', 'child_of', location_ids))
    inventories = self.search(inventory_domain)
    location_ids = inventories.mapped('location_id')
    location_domain = [
        ('location_id', 'child_of', location_ids.ids),
        ('usage', 'in', ['internal', 'transit'])]
     if locations_ids:
        location_domain.append(('location_id', 'child_of', location_ids))
    return self.env['stock.location'].search(location_domain)

In this way we will filter the result to the locations for which we want to check if an inventory exist.

@api.multi
def _check_inventory(self):
"""Error if an inventory is being conducted here"""
location_inventory_open_ids = self.env['stock.inventory'].sudo(
Copy link
Sponsor Contributor

Choose a reason for hiding this comment

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

@mreficent With the change proposed for _get_locations_open_inventories the method will be simplified

location_inventory_open_ids = self.env['stock.inventory'].sudo()._get_locations_open_inventories(self.ids)
if location_inventory_open_ids:
    raise ValidationError(...)

Lionel Sausin & Loïc Bellier and others added 3 commits May 31, 2017 10:34
This module is a feature extracted from stock_inventory_location.

Ported to v8 and new API
Adopted latest OCA standards
Added tests
@MiquelRForgeFlow MiquelRForgeFlow force-pushed the 9.0-mig-stock_inventory_lockdown branch from 8fd3d9e to 12a6ae3 Compare May 31, 2017 08:36
@MiquelRForgeFlow
Copy link
Contributor Author

@lmignon suggestion attended to 😊

"""
if not self.env.context.get('bypass_lockdown', False):
# Find the locked locations
locked_location_ids = self.env[
Copy link
Sponsor Contributor

Choose a reason for hiding this comment

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

@mreficent This code should be also modified to take advantage of the new paramater on _get_locations_open_inventories

if 'location_id' in vals.keys():
    locked_location_ids = self.env['stock.inventory']._get_locations_open_inventories(
        self.env['stock.location'].browse(vals['location_id']) + self.mapped('location_id')
    )
   if locked_location_ids:
        raise ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But then the raise message will not have explicit locations 😕

Copy link
Sponsor Contributor

@lmignon lmignon May 31, 2017

Choose a reason for hiding this comment

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

@mreficent

location_names = locked_location_ids.mapped('name')
raise ValidationError(
    _('An inventory is being conducted at the following '
      'location(s):\n%s') % "\n - ".join(location_names))

quant = super(StockQuant, self).create(vals)
if not self.env.context.get('bypass_lockdown', False):
locked_location_ids = self.env[
'stock.inventory']._get_locations_open_inventories()
Copy link
Sponsor Contributor

Choose a reason for hiding this comment

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

@mreficent same comment as above

@MiquelRForgeFlow MiquelRForgeFlow force-pushed the 9.0-mig-stock_inventory_lockdown branch from cf016db to ee0a3eb Compare May 31, 2017 13:43
@lmignon
Copy link
Sponsor Contributor

lmignon commented May 31, 2017

Lgtm code review only

@MiquelRForgeFlow MiquelRForgeFlow force-pushed the 9.0-mig-stock_inventory_lockdown branch from 3f8a631 to c5ad07e Compare June 1, 2017 09:49
Copy link
Sponsor Member

@JordiBForgeFlow JordiBForgeFlow left a comment

Choose a reason for hiding this comment

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

👍 Functional review

@JordiBForgeFlow JordiBForgeFlow merged commit c849748 into OCA:9.0 Jun 9, 2017
@LoisRForgeFlow LoisRForgeFlow deleted the 9.0-mig-stock_inventory_lockdown branch June 9, 2017 13:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants