From bf02699b612a6eff7ffc5b1ae05bed2fba484728 Mon Sep 17 00:00:00 2001 From: luis Date: Tue, 24 Feb 2026 13:37:26 +0100 Subject: [PATCH] FoodcoopBCN/foodcoopbcn#167 add pos_product_available_link --- pos_product_available_link/README.rst | 43 +++++++++++++++++++ pos_product_available_link/__init__.py | 1 + pos_product_available_link/__manifest__.py | 13 ++++++ pos_product_available_link/models/__init__.py | 1 + pos_product_available_link/models/product.py | 32 ++++++++++++++ .../tests/test_product_available_link.py | 21 +++++++++ 6 files changed, 111 insertions(+) create mode 100644 pos_product_available_link/README.rst create mode 100644 pos_product_available_link/__init__.py create mode 100644 pos_product_available_link/__manifest__.py create mode 100644 pos_product_available_link/models/__init__.py create mode 100644 pos_product_available_link/models/product.py create mode 100644 pos_product_available_link/tests/test_product_available_link.py diff --git a/pos_product_available_link/README.rst b/pos_product_available_link/README.rst new file mode 100644 index 0000000..8956fc4 --- /dev/null +++ b/pos_product_available_link/README.rst @@ -0,0 +1,43 @@ +POS Product Available Link +========================= + +Automatically disables available_in_pos when sale_ok is unchecked on products. + +Features +======== + +* When you uncheck "Can be Sold" (sale_ok), the product is also removed from POS (available_in_pos). +* Prevents products with sale_ok=False from appearing in POS. + +Installation +============ + +Install this module as usual via Apps or with odoo-bin. + +Configuration +============= + +No configuration required. + +Usage +===== + +1. Go to Products. +2. Uncheck "Can be Sold". +3. The product will no longer be available in POS. + +Known issues / Roadmap +====================== + +* Only disables available_in_pos when sale_ok is unchecked. Does not re-enable. + +Credits +======= + +Authors +------- +* Your Name + +Contributors +------------ +* Odoo Community Association (OCA) diff --git a/pos_product_available_link/__init__.py b/pos_product_available_link/__init__.py new file mode 100644 index 0000000..0650744 --- /dev/null +++ b/pos_product_available_link/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/pos_product_available_link/__manifest__.py b/pos_product_available_link/__manifest__.py new file mode 100644 index 0000000..cfea84e --- /dev/null +++ b/pos_product_available_link/__manifest__.py @@ -0,0 +1,13 @@ +{ + "name": "POS Product Available Link", + "summary": "Automatically enable/disable available_in_pos when sale_ok is checked/unchecked.", + "version": "16.0.1.0.0", + "category": "Point of Sale", + "license": "AGPL-3", + "author": "Criptomart", + "website": "https://criptomart.net", + "depends": ["point_of_sale", "product"], + "data": [], + "installable": True, + "application": False, +} diff --git a/pos_product_available_link/models/__init__.py b/pos_product_available_link/models/__init__.py new file mode 100644 index 0000000..9649db7 --- /dev/null +++ b/pos_product_available_link/models/__init__.py @@ -0,0 +1 @@ +from . import product diff --git a/pos_product_available_link/models/product.py b/pos_product_available_link/models/product.py new file mode 100644 index 0000000..683e0e0 --- /dev/null +++ b/pos_product_available_link/models/product.py @@ -0,0 +1,32 @@ +# Copyright 2026 Your Name +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, models + + +class ProductTemplate(models.Model): + _inherit = "product.template" + + @api.onchange("sale_ok") + def _onchange_sale_ok_link_available_in_pos(self): + for product in self: + product.available_in_pos = product.sale_ok + + def write(self, vals): + if "sale_ok" in vals: + vals["available_in_pos"] = vals["sale_ok"] + return super().write(vals) + + +class ProductProduct(models.Model): + _inherit = "product.product" + + @api.onchange("sale_ok") + def _onchange_sale_ok_link_available_in_pos(self): + for product in self: + product.available_in_pos = product.sale_ok + + def write(self, vals): + if "sale_ok" in vals: + vals["available_in_pos"] = vals["sale_ok"] + return super().write(vals) diff --git a/pos_product_available_link/tests/test_product_available_link.py b/pos_product_available_link/tests/test_product_available_link.py new file mode 100644 index 0000000..95084f1 --- /dev/null +++ b/pos_product_available_link/tests/test_product_available_link.py @@ -0,0 +1,21 @@ +from odoo.tests.common import TransactionCase + + +class TestProductAvailableLink(TransactionCase): + def setUp(self): + super().setUp() + self.product = self.env["product.product"].create( + { + "name": "Test Product", + "sale_ok": True, + "available_in_pos": True, + } + ) + + def test_uncheck_sale_ok_disables_available_in_pos(self): + self.product.sale_ok = False + self.assertFalse(self.product.available_in_pos) + + def test_write_sale_ok_false_disables_available_in_pos(self): + self.product.write({"sale_ok": False}) + self.assertFalse(self.product.available_in_pos)