Skip to content
Draft
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions unpublish_product/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
12 changes: 12 additions & 0 deletions unpublish_product/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "auto unpublish product",
"version": "1.0.0",
"depends": ["base", "product", "website_sale", "stock"],
"author": "Mehul Kotak",
"category": "Task-3",
"description": "eCommerce",
"license": "LGPL-3",
"auto_install": True,
"installable": True,
"data": ["views/res_config_settings_view.xml"],
Comment on lines +2 to +11

Choose a reason for hiding this comment

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

Don't create new module directly update in community, make hook or something like it, it should check direct quantity if stock is not installed then override in website_sale_stock to adept depending on stock

}
3 changes: 3 additions & 0 deletions unpublish_product/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import res_config_settings
from . import product_template
from . import stock_quant
19 changes: 19 additions & 0 deletions unpublish_product/models/product_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from odoo import models


class ProductTemplate(models.Model):
_inherit = "product.template"

def check_and_unpublish(self):
enabled = (
self.env["ir.config_parameter"]
.sudo()
.get_param("unpublish_product.auto_unpublish_out_of_stock")
)

if not enabled:
return

for template in self:
if all(variant.free_qty <= 0 for variant in template.product_variant_ids):
template.website_published = False
10 changes: 10 additions & 0 deletions unpublish_product/models/res_config_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from odoo import fields, models


class ResConfigSettings(models.TransientModel):
_inherit = "res.config.settings"

auto_unpublish_out_of_stock = fields.Boolean(
string="Auto Unpublish Out-of-Stock Products",
config_parameter="unpublish_product.auto_unpublish_out_of_stock",
)
Comment on lines +7 to +10

Choose a reason for hiding this comment

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

make this setting company dependent, or website dependent 🤔

13 changes: 13 additions & 0 deletions unpublish_product/models/stock_quant.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from odoo import models


class StockQuant(models.Model):
_inherit = "stock.quant"

def write(self, vals):
res = super().write(vals)

products = self.mapped("product_id.product_tmpl_id")
products.check_and_unpublish()

return res
Comment on lines +7 to +13

Choose a reason for hiding this comment

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

Don't do it on write of quant, do it in product template directly

17 changes: 17 additions & 0 deletions unpublish_product/views/res_config_settings_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0"?>
<odoo>
<record id="res_config_settings_view_form" model="ir.ui.view">
<field name="name">res.config.settings.view.form.inherit</field>
<field name="model">res.config.settings</field>
<field name="inherit_id" ref="website_sale.res_config_settings_view_form"/>
<field name="arch" type="xml">

<setting id="product_attributes_setting" position="before">
<setting string="Unpublish out-of-stock products" id="unpublish_products" help="Unpublish/Republish product based on stock availability">
<field name="auto_unpublish_out_of_stock"/>
</setting>
</setting>

</field>
</record>
</odoo>