Skip to content

Commit

Permalink
[MIG] stock_removal_by_location_priority: Migration to 17.0
Browse files Browse the repository at this point in the history
closes #501

Signed-off-by: Matias Velazquez <[email protected]>
  • Loading branch information
jcadhoc committed Jul 31, 2024
1 parent 3c1c079 commit 969ae4c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 21 deletions.
4 changes: 2 additions & 2 deletions stock_removal_by_location_priority/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
'name': 'Stock Removal by Location priority',
'version': "16.0.1.0.0",
'version': "17.0.1.0.0",
'category': 'Warehouse Management',
'sequence': 14,
'summary': '',
Expand All @@ -18,7 +18,7 @@
],
'demo': [
],
'installable': False,
'installable': True,
'auto_install': False,
'application': False,
'pre_init_hook': 'pre_init_hook',
Expand Down
22 changes: 11 additions & 11 deletions stock_removal_by_location_priority/init_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,41 @@
logger = logging.getLogger(__name__)


def pre_init_hook(cr):
def pre_init_hook(env):
"""
The objective of this hook is to speed up the installation
of the module on an existing Odoo instance.
Without this script, big databases can take a long time to install this
module.
"""
set_stock_location_removal_priority_default(cr)
set_stock_quant_removal_priority_default(cr)
set_stock_location_removal_priority_default(env)
set_stock_quant_removal_priority_default(env)


def set_stock_location_removal_priority_default(cr):
cr.execute("""SELECT column_name
def set_stock_location_removal_priority_default(env):
env.cr.execute("""SELECT column_name
FROM information_schema.columns
WHERE table_name='stock_location' AND
column_name='removal_priority'""")
if not cr.fetchone():
if not env.cr.fetchone():
logger.info('Creating field removal_priority on stock_location')
cr.execute(
env.cr.execute(
"""
ALTER TABLE stock_location
ADD COLUMN removal_priority integer
DEFAULT 10;
""")


def set_stock_quant_removal_priority_default(cr):
cr.execute("""SELECT column_name
def set_stock_quant_removal_priority_default(env):
env.cr.execute("""SELECT column_name
FROM information_schema.columns
WHERE table_name='stock_quant' AND
column_name='removal_priority'""")
if not cr.fetchone():
if not env.cr.fetchone():
logger.info('Creating field removal_priority on stock_quant')
cr.execute(
env.cr.execute(
"""
ALTER TABLE stock_quant
ADD COLUMN removal_priority integer
Expand Down
13 changes: 9 additions & 4 deletions stock_removal_by_location_priority/models/stock_quant.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@ class StockQuant(models.Model):
related='location_id.removal_priority',
store=True,
)

@api.model
def _get_removal_strategy_order(self, removal_strategy=None):
def _get_removal_strategy_domain_order(self, domain, removal_strategy, qty):
if removal_strategy == 'priority':
return domain, 'removal_priority ASC, id'
return super()._get_removal_strategy_domain_order(domain, removal_strategy, qty)

def _get_removal_strategy_sort_key(self, removal_strategy):
if removal_strategy == 'priority':
return 'removal_priority ASC, id'
return super()._get_removal_strategy_order(removal_strategy)
return lambda q: (q.removal_priority, q.id), False
return super()._get_removal_strategy_sort_key(removal_strategy)
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
<field name="model">stock.location</field>
<field name="inherit_id" ref="stock.view_location_form"/>
<field name="arch" type="xml">
<field name="removal_strategy_id" position="after">
<field name="removal_strategy_method" invisible="1"/>
<field name="removal_priority" attrs="{'invisible': [('removal_strategy_method', '!=', 'priority')]}"/>
</field>
<xpath expr="//group[@name='additional_info']" position="after">
<group string="Logistica" name="logistics">
<field name="removal_strategy_method" invisible="1"/>
<field name="removal_priority"/>
</group>
</xpath>
</field>
</record>

Expand Down

0 comments on commit 969ae4c

Please sign in to comment.