diff --git a/sale_coupon_free_shipping_default_product/README.rst b/sale_coupon_free_shipping_default_product/README.rst new file mode 100644 index 000000000..e69fe4d0f --- /dev/null +++ b/sale_coupon_free_shipping_default_product/README.rst @@ -0,0 +1,111 @@ +========================================= +Sale coupon free shipping default product +========================================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:412f63eb94f453413437a98bee6a85959543035f981f07dd871bca2848599b42 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png + :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html + :alt: License: LGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsale--promotion-lightgray.png?logo=github + :target: https://github.com/OCA/sale-promotion/tree/14.0/sale_coupon_free_shipping_default_product + :alt: OCA/sale-promotion +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/sale-promotion-14-0/sale-promotion-14-0-sale_coupon_free_shipping_default_product + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/sale-promotion&target_branch=14.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This modules allows to set a default product for the promotions when selecting free shipping + +**Table of contents** + +.. contents:: + :local: + +Use Cases / Context +=================== + +BUSINESS NEED: +This module addresses the issue of multiple "Free Shipping" products being +created whenever new promotion programs are configured. This redundancy leads +to inefficiencies and unnecessary clutter in the product database. Additionally, +while the "Free Shipping" product is set in the reward line product field, it is +not configured as a default product for free shipping. + +APPROACH +The apporach that we use was to inherit the couponProgram class and then change +the functionality of the create function. +The method checks if the reward_type in the vals dictionary is set to +"free_shipping". +If the condition is met, it retrieves the default "free shipping" product +configured at the company level using self.env.company.free_shipping_product_default. +If a default product is found, its ID is assigned to the discount_line_product_id +field in vals. + + +USEFUL INFORMATION: +This module depends on modules sale and coupon. +Different companies can choose different default products for free shipping. + + + + +Usage +===== + +Go to settings and set the product you want as a default for the free shiping promotion + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Ooops + +Contributors +~~~~~~~~~~~~ + +* Ooops404 + * Daniel Chionne + * Sylwester Krasinski + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +This module is part of the `OCA/sale-promotion `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/sale_coupon_free_shipping_default_product/__init__.py b/sale_coupon_free_shipping_default_product/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/sale_coupon_free_shipping_default_product/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/sale_coupon_free_shipping_default_product/__manifest__.py b/sale_coupon_free_shipping_default_product/__manifest__.py new file mode 100644 index 000000000..19e29cc51 --- /dev/null +++ b/sale_coupon_free_shipping_default_product/__manifest__.py @@ -0,0 +1,13 @@ +{ + "name": "Sale coupon free shipping default product", + "summary": "avoids creating multiple free shipping products", + "version": "14.0.1.0.0", + "category": "Hidden/Tools", + "author": "Ooops, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/sale-promotion", + "license": "LGPL-3", + "installable": True, + "depends": ["sale", "coupon", "sale_coupon_delivery"], + "data": ["views/res_config_settings_views.xml"], + "auto_install": False, +} diff --git a/sale_coupon_free_shipping_default_product/description/icon.png b/sale_coupon_free_shipping_default_product/description/icon.png new file mode 100755 index 000000000..3a0328b51 Binary files /dev/null and b/sale_coupon_free_shipping_default_product/description/icon.png differ diff --git a/sale_coupon_free_shipping_default_product/description/index.html b/sale_coupon_free_shipping_default_product/description/index.html new file mode 100644 index 000000000..e69de29bb diff --git a/sale_coupon_free_shipping_default_product/models/__init__.py b/sale_coupon_free_shipping_default_product/models/__init__.py new file mode 100644 index 000000000..1cf79b84e --- /dev/null +++ b/sale_coupon_free_shipping_default_product/models/__init__.py @@ -0,0 +1,3 @@ +from . import coupon_program +from . import res_config_settings +from . import res_company diff --git a/sale_coupon_free_shipping_default_product/models/coupon_program.py b/sale_coupon_free_shipping_default_product/models/coupon_program.py new file mode 100644 index 000000000..d64c83a33 --- /dev/null +++ b/sale_coupon_free_shipping_default_product/models/coupon_program.py @@ -0,0 +1,15 @@ +from odoo import api, models + + +class CouponProgram(models.Model): + _inherit = "coupon.program" + + @api.model + def create(self, vals): + if vals.get("reward_type") == "free_shipping": + product = self.env.company.free_shipping_product_default + if product: + vals["discount_line_product_id"] = product.id + program = super(CouponProgram, self).create(vals) + + return program diff --git a/sale_coupon_free_shipping_default_product/models/res_company.py b/sale_coupon_free_shipping_default_product/models/res_company.py new file mode 100644 index 000000000..d4eba009c --- /dev/null +++ b/sale_coupon_free_shipping_default_product/models/res_company.py @@ -0,0 +1,9 @@ +from odoo import fields, models + + +class ResCompany(models.Model): + _inherit = "res.company" + + free_shipping_product_default = fields.Many2one( + "product.product", string="Default promo product for free shipping" + ) diff --git a/sale_coupon_free_shipping_default_product/models/res_config_settings.py b/sale_coupon_free_shipping_default_product/models/res_config_settings.py new file mode 100644 index 000000000..8b91a5535 --- /dev/null +++ b/sale_coupon_free_shipping_default_product/models/res_config_settings.py @@ -0,0 +1,13 @@ +from odoo import fields, models + + +class ResConfigSettings(models.TransientModel): + _inherit = "res.config.settings" + + free_shipping_product_default = fields.Many2one( + comodel_name="product.product", + string="Default promo product for free shipping", + domain=[("type", "=", "service")], + related="company_id.free_shipping_product_default", + readonly=False, + ) diff --git a/sale_coupon_free_shipping_default_product/readme/CONTEXT.rst b/sale_coupon_free_shipping_default_product/readme/CONTEXT.rst new file mode 100644 index 000000000..8f3551f5c --- /dev/null +++ b/sale_coupon_free_shipping_default_product/readme/CONTEXT.rst @@ -0,0 +1,24 @@ +BUSINESS NEED: +This module addresses the issue of multiple "Free Shipping" products being +created whenever new promotion programs are configured. This redundancy leads +to inefficiencies and unnecessary clutter in the product database. Additionally, +while the "Free Shipping" product is set in the reward line product field, it is +not configured as a default product for free shipping. + +APPROACH +The apporach that we use was to inherit the couponProgram class and then change +the functionality of the create function. +The method checks if the reward_type in the vals dictionary is set to +"free_shipping". +If the condition is met, it retrieves the default "free shipping" product +configured at the company level using self.env.company.free_shipping_product_default. +If a default product is found, its ID is assigned to the discount_line_product_id +field in vals. + + +USEFUL INFORMATION: +This module depends on modules sale and coupon. +Different companies can choose different default products for free shipping. + + + diff --git a/sale_coupon_free_shipping_default_product/readme/CONTRIBUTORS.rst b/sale_coupon_free_shipping_default_product/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..9c599cc8f --- /dev/null +++ b/sale_coupon_free_shipping_default_product/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* Ooops404 + * Daniel Chionne + * Sylwester Krasinski diff --git a/sale_coupon_free_shipping_default_product/readme/DESCRIPTION.rst b/sale_coupon_free_shipping_default_product/readme/DESCRIPTION.rst new file mode 100644 index 000000000..0333d64f8 --- /dev/null +++ b/sale_coupon_free_shipping_default_product/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This modules allows to set a default product for the promotions when selecting free shipping diff --git a/sale_coupon_free_shipping_default_product/readme/USAGE.rst b/sale_coupon_free_shipping_default_product/readme/USAGE.rst new file mode 100644 index 000000000..3f574a0d5 --- /dev/null +++ b/sale_coupon_free_shipping_default_product/readme/USAGE.rst @@ -0,0 +1 @@ +Go to settings and set the product you want as a default for the free shiping promotion diff --git a/sale_coupon_free_shipping_default_product/static/description/index.html b/sale_coupon_free_shipping_default_product/static/description/index.html new file mode 100644 index 000000000..d3da851c9 --- /dev/null +++ b/sale_coupon_free_shipping_default_product/static/description/index.html @@ -0,0 +1,452 @@ + + + + + +Sale coupon free shipping default product + + + +
+

Sale coupon free shipping default product

+ + +

Beta License: LGPL-3 OCA/sale-promotion Translate me on Weblate Try me on Runboat

+

This modules allows to set a default product for the promotions when selecting free shipping

+

Table of contents

+ +
+

Use Cases / Context

+

BUSINESS NEED: +This module addresses the issue of multiple “Free Shipping” products being +created whenever new promotion programs are configured. This redundancy leads +to inefficiencies and unnecessary clutter in the product database. Additionally, +while the “Free Shipping” product is set in the reward line product field, it is +not configured as a default product for free shipping.

+

APPROACH +The apporach that we use was to inherit the couponProgram class and then change +the functionality of the create function. +The method checks if the reward_type in the vals dictionary is set to +“free_shipping”. +If the condition is met, it retrieves the default “free shipping” product +configured at the company level using self.env.company.free_shipping_product_default. +If a default product is found, its ID is assigned to the discount_line_product_id +field in vals.

+

USEFUL INFORMATION: +This module depends on modules sale and coupon. +Different companies can choose different default products for free shipping.

+
+
+

Usage

+

Go to settings and set the product you want as a default for the free shiping promotion

+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Ooops
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

This module is part of the OCA/sale-promotion project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/sale_coupon_free_shipping_default_product/tests/__init__.py b/sale_coupon_free_shipping_default_product/tests/__init__.py new file mode 100644 index 000000000..6187c3669 --- /dev/null +++ b/sale_coupon_free_shipping_default_product/tests/__init__.py @@ -0,0 +1 @@ +from . import test_sale_coupon_free_shipping_default_product \ No newline at end of file diff --git a/sale_coupon_free_shipping_default_product/tests/test_sale_coupon_free_shipping_default_product.py b/sale_coupon_free_shipping_default_product/tests/test_sale_coupon_free_shipping_default_product.py new file mode 100644 index 000000000..fc4ef519e --- /dev/null +++ b/sale_coupon_free_shipping_default_product/tests/test_sale_coupon_free_shipping_default_product.py @@ -0,0 +1,31 @@ +from odoo.tests import common + +class TestSaleCouponFreeShippingDefaultProduct(common.SavepointCase): + @classmethod + def setUpClass(cls): + + super(TestSaleCouponFreeShippingDefaultProduct, cls).setUpClass() + + cls.coupon_program_model = cls.env['coupon.program'] + cls.product_model = cls.env['product.product'] + + # Create a test product for free shipping + cls.free_shipping_product = cls.product_model.create({ + 'name': 'Free Shipping Product', + 'type': 'service', + 'list_price': 0.0, + }) + + # Set the company's default free shipping product + cls.env.company.write({'free_shipping_product_default': cls.free_shipping_product.id}) + + def test_create_coupon_with_free_shipping(self): + """Test coupon creation with reward_type set to 'free_shipping'.""" + vals = { + 'name': 'Free Shipping Test Program', + 'reward_type': 'free_shipping', + } + program = self.coupon_program_model.create(vals) + self.assertEqual( + program.discount_line_product_id.id, + self.free_shipping_product.id) diff --git a/sale_coupon_free_shipping_default_product/views/res_config_settings_views.xml b/sale_coupon_free_shipping_default_product/views/res_config_settings_views.xml new file mode 100644 index 000000000..72fbfa6c9 --- /dev/null +++ b/sale_coupon_free_shipping_default_product/views/res_config_settings_views.xml @@ -0,0 +1,13 @@ + + + res.config.settings.shipping.default.prod + res.config.settings + + + + + + + diff --git a/setup/sale_coupon_free_shipping_default_product/odoo/addons/sale_coupon_free_shipping_default_product b/setup/sale_coupon_free_shipping_default_product/odoo/addons/sale_coupon_free_shipping_default_product new file mode 120000 index 000000000..4253245d0 --- /dev/null +++ b/setup/sale_coupon_free_shipping_default_product/odoo/addons/sale_coupon_free_shipping_default_product @@ -0,0 +1 @@ +../../../../sale_coupon_free_shipping_default_product \ No newline at end of file diff --git a/setup/sale_coupon_free_shipping_default_product/setup.py b/setup/sale_coupon_free_shipping_default_product/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/sale_coupon_free_shipping_default_product/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)