Skip to content

Commit

Permalink
[MIG][17.0] stock_available:Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
bizzappdev committed Apr 25, 2024
1 parent 7d27070 commit e8c8638
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 57 deletions.
3 changes: 2 additions & 1 deletion stock_available/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@

{
"name": "Stock available to promise",
"version": "16.0.1.1.0",
"version": "17.0.1.0.0",
"author": "Numérigraphe, Sodexis, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/stock-logistics-availability",
"development_status": "Production/Stable",
"category": "Warehouse",
"depends": ["stock"],
"license": "AGPL-3",
"data": [
"data/ir_config_parameter.xml",
"views/product_template_view.xml",
"views/product_product_view.xml",
"views/res_config_settings_views.xml",
Expand Down
6 changes: 6 additions & 0 deletions stock_available/data/ir_config_parameter.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<odoo noupdate="1">
<record id="default_stock_available_mrp_based_on" model="ir.config_parameter">
<field name="key">stock_available.stock_available_mrp_based_on</field>
<field name="value">qty_available</field>
</record>
</odoo>
19 changes: 19 additions & 0 deletions stock_available/migrations/17.0.1.0.0/pre-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
def migrate(cr, version):
cr.execute(
"""SELECT id FROM ir_config_parameter WHERE key = 'stock_available.stock_available_mrp_based_on'"""
)
record = cr.fetchone()
if record:
query = """INSERT INTO ir_model_data (
name,
model,
module,
res_id,
noupdate)
VALUES (
'default_stock_available_mrp_based_on',
'ir.config_parameter',
'stock_available',
'%s',
True)"""
cr.execute(query, (record[0]))
1 change: 0 additions & 1 deletion stock_available/models/product_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@


class ProductProduct(models.Model):

"""Add a field for the stock available to promise.
Useful implementations need to be installed through the Settings menu or by
installing one of the modules stock_available_*
Expand Down
18 changes: 1 addition & 17 deletions stock_available/models/res_config_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,8 @@ def _get_stock_available_mrp_based_on(self):
stock_available_mrp_based_on = fields.Selection(
_get_stock_available_mrp_based_on,
string="based on",
config_parameter="stock_available.stock_available_mrp_based_on",
help="Choose the field of the product which will be used to compute "
"potential.\nIf empty, Quantity On Hand is used.\n"
"Only the quantity fields have meaning for computing stock",
)

@api.model
def get_values(self):
res = super(ResConfigSettings, self).get_values()
res.update(
stock_available_mrp_based_on=self.env["ir.config_parameter"]
.sudo()
.get_param("stock_available_mrp_based_on", "qty_available")
)
return res

def set_values(self):
res = super(ResConfigSettings, self).set_values()
self.env["ir.config_parameter"].sudo().set_param(
"stock_available_mrp_based_on", self.stock_available_mrp_based_on
)
return res
1 change: 0 additions & 1 deletion stock_available/tests/test_stock_available.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class TestStockLogisticsWarehouse(TransactionCase):
def test_res_config(self):
"""Test the config file"""
stock_setting = self.env["res.config.settings"].create({})

self.assertEqual(stock_setting.stock_available_mrp_based_on, "qty_available")
stock_setting.stock_available_mrp_based_on = "immediately_usable_qty"
stock_setting.set_values()
Expand Down
16 changes: 8 additions & 8 deletions stock_available/views/product_product_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,39 +15,39 @@
<button
type="object"
name="action_open_quants"
attrs="{'invisible':[('type', 'not in', ['product','consu'])]}"
invisible="type not in ('product', 'consu')"
class="oe_stat_button"
icon="fa-building-o"
>
<div class="o_field_widget o_stat_info">
<span class="o_stat_value" widget="statinfo">
<span class="o_stat_value d-flex gap-1">
<field
name="immediately_usable_qty"
widget="statinfo"
nolabel="1"
class="mr4"
class="oe_inline"
/>
<field name="uom_name" />
<field name="uom_name" class="oe_inline" />
</span>
<span class="o_stat_text">Available</span>
</div>
</button>
<button
type="object"
name="action_open_quants"
attrs="{'invisible':[('type', 'not in', ['product','consu'])]}"
invisible="type not in ('product', 'consu')"
class="oe_stat_button"
icon="fa-building-o"
>
<div class="o_field_widget o_stat_info">
<span class="o_stat_value" widget="statinfo">
<span class="o_stat_value d-flex gap-1">
<field
name="potential_qty"
widget="statinfo"
nolabel="1"
class="mr4"
class="oe_inline"
/>
<field name="uom_name" />
<field name="uom_name" class="oe_inline" />
</span>
<span class="o_stat_text">Potential</span>
</div>
Expand Down
16 changes: 8 additions & 8 deletions stock_available/views/product_template_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,39 +18,39 @@
<button
type="object"
name="action_open_quants"
attrs="{'invisible':[('type', 'not in', ['product','consu'])]}"
invisible="type not in ('product', 'consu')"
class="oe_stat_button"
icon="fa-building-o"
>
<div class="o_field_widget o_stat_info">
<span class="o_stat_value" widget="statinfo">
<span class="o_stat_value d-flex gap-1">
<field
name="immediately_usable_qty"
widget="statinfo"
nolabel="1"
class="mr4"
class="oe_inline"
/>
<field name="uom_name" />
<field name="uom_name" class="oe_inline" />
</span>
<span class="o_stat_text">Available</span>
</div>
</button>
<button
type="object"
name="action_open_quants"
attrs="{'invisible':[('type', 'not in', ['product','consu'])]}"
invisible="type not in ('product', 'consu')"
class="oe_stat_button"
icon="fa-building-o"
>
<div class="o_field_widget o_stat_info">
<span class="o_stat_value" widget="statinfo">
<span class="o_stat_value d-flex gap-1">
<field
name="potential_qty"
widget="statinfo"
nolabel="1"
class="mr4"
class="oe_inline"
/>
<field name="uom_name" />
<field name="uom_name" class="oe_inline" />
</span>
<span class="o_stat_text">Potential</span>
</div>
Expand Down
38 changes: 17 additions & 21 deletions stock_available/views/res_config_settings_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,34 @@
<field name="model">res.config.settings</field>
<field name="inherit_id" ref="stock.res_config_settings_view_form" />
<field name="arch" type="xml">
<xpath expr="//div[@data-key='stock']" position="inside">
<h2 id="available_info">Stock available to promise</h2>
<div class="row mt16 o_settings_container">
<div class="col-xs-12 col-md-6 o_setting_box">
<div class="o_setting_left_pane">
<field name="module_stock_available_immediately" />
</div>
<div class="o_setting_right_pane">
<label for="module_stock_available_immediately" />
</div>
</div>
<div class="col-xs-12 col-md-6 o_setting_box">
<xpath expr="//block[@id='schedule_info']" position="after">
<block title="Stock available to promise" name="available_info">
<setting>
<field name="module_stock_available_immediately" />
</setting>
<setting>
<div class="col-12 col-md-6 o_setting_box">
<div class="o_setting_left_pane">
<field name="module_stock_available_mrp" />
</div>
<div class="o_setting_right_pane">
<label for="module_stock_available_mrp" />
<div class="content-group">
<div
class="mt16"
attrs="{'invisible': [('module_stock_available_mrp', '=', False)]}"
>
class="mt16"
invisible="not module_stock_available_mrp"
>
<field
name="stock_available_mrp_based_on"
class="oe_inline"
attrs="{'required':[('module_stock_available_mrp','=',True)]}"
/>
name="stock_available_mrp_based_on"
class="oe_inline"
required="module_stock_available_mrp"
/>
</div>
</div>
</div>
</div>
</div>
</div>
</setting>
</block>
</xpath>
</field>
</record>
Expand Down

0 comments on commit e8c8638

Please sign in to comment.