diff --git a/delivery_carrier_option/README.rst b/delivery_carrier_option/README.rst new file mode 100644 index 0000000000..e6d7abc5f2 --- /dev/null +++ b/delivery_carrier_option/README.rst @@ -0,0 +1,88 @@ +======================= +Delivery Carrier Option +======================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:ec863ea454ac78b21548aad2e7786daaad02075270d3d13ae43c8fb16b89a56c + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fdelivery--carrier-lightgray.png?logo=github + :target: https://github.com/OCA/delivery-carrier/tree/18.0/delivery_carrier_option + :alt: OCA/delivery-carrier +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/delivery-carrier-18-0/delivery-carrier-18-0-delivery_carrier_option + :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/delivery-carrier&target_branch=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module adds the concept of option on carriers that can differ +depending on the picking This module doesn't do anything by itself, it +serves as a base module for other carrier-specific modules. + +**Table of contents** + +.. contents:: + :local: + +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 +------- + +* Camptocamp +* Akretion + +Contributors +------------ + +- David BEAL +- Sébastien BEAU +- Yannick Vaucher +- Alexis de Lattre +- Angel Moya +- Ismael Calvo +- Dave Lasley +- Timothée Ringeard +- Pimolnat Suntian +- Raphaël Reverdy + +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/delivery-carrier `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/delivery_carrier_option/__init__.py b/delivery_carrier_option/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/delivery_carrier_option/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/delivery_carrier_option/__manifest__.py b/delivery_carrier_option/__manifest__.py new file mode 100644 index 0000000000..f9be20248d --- /dev/null +++ b/delivery_carrier_option/__manifest__.py @@ -0,0 +1,20 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +{ + "name": "Delivery Carrier Option", + "version": "18.0.1.0.0", + "author": "Camptocamp,Akretion,Odoo Community Association (OCA)", + "category": "Delivery", + "depends": [ + "stock_delivery", + ], + "website": "https://github.com/OCA/delivery-carrier", + "data": [ + "views/stock_picking.xml", + "views/delivery_carrier.xml", + "security/ir.model.access.csv", + "views/delivery_carrier_template_option.xml", + "views/delivery_carrier_option.xml", + ], + "installable": True, + "license": "AGPL-3", +} diff --git a/delivery_carrier_option/models/__init__.py b/delivery_carrier_option/models/__init__.py new file mode 100644 index 0000000000..b8cd83e06a --- /dev/null +++ b/delivery_carrier_option/models/__init__.py @@ -0,0 +1,4 @@ +from . import delivery_carrier +from . import delivery_carrier_template_option +from . import delivery_carrier_option +from . import stock_picking diff --git a/delivery_carrier_option/models/delivery_carrier.py b/delivery_carrier_option/models/delivery_carrier.py new file mode 100644 index 0000000000..4450354e3e --- /dev/null +++ b/delivery_carrier_option/models/delivery_carrier.py @@ -0,0 +1,25 @@ +# Copyright 2012 Akretion . +# Copyright 2013-2016 Camptocamp SA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class DeliveryCarrier(models.Model): + _inherit = "delivery.carrier" + + available_option_ids = fields.One2many( + comodel_name="delivery.carrier.option", + inverse_name="carrier_id", + string="Option", + context={"active_test": False}, + ) + + def default_options(self): + """Returns default and available options for a carrier""" + self.ensure_one() + options = self.env["delivery.carrier.option"].browse() + for available_option in self.available_option_ids: + if available_option.mandatory or available_option.by_default: + options |= available_option + return options diff --git a/delivery_carrier_option/models/delivery_carrier_option.py b/delivery_carrier_option/models/delivery_carrier_option.py new file mode 100644 index 0000000000..28c5ff79e0 --- /dev/null +++ b/delivery_carrier_option/models/delivery_carrier_option.py @@ -0,0 +1,53 @@ +# Copyright 2012 Akretion . +# Copyright 2013-2016 Camptocamp SA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class DeliveryCarrierOption(models.Model): + """Option selected for a carrier method + + Those options define the list of available pre-added and available + to be added on delivery orders + + """ + + _name = "delivery.carrier.option" + _description = "Delivery carrier option" + _inherits = {"delivery.carrier.template.option": "tmpl_option_id"} + + active = fields.Boolean(default=True) + mandatory = fields.Boolean( + help=( + "If checked, this option is necessarily applied " + "to the delivery order. Mandatory options show up in orange " + "in the option widget on the picking." + ), + ) + by_default = fields.Boolean( + string="Applied by Default", + help="By check, user can choose to apply this option " + "to each Delivery Order\n using this delivery method", + ) + tmpl_option_id = fields.Many2one( + comodel_name="delivery.carrier.template.option", + string="Option", + required=True, + ondelete="cascade", + ) + carrier_id = fields.Many2one(comodel_name="delivery.carrier", string="Carrier") + readonly_flag = fields.Boolean( + help="When True, help to prevent the user to modify some fields " + "option (if attribute is defined in the view)", + ) + color = fields.Integer( + compute="_compute_color", + help="Orange if the option is mandatory, otherwise no color", + ) + + @api.depends("mandatory") + def _compute_color(self): + """Show that a tag is mandatory using the color attribute""" + for tag in self: + tag.color = 2 if tag.mandatory else False diff --git a/delivery_carrier_option/models/delivery_carrier_template_option.py b/delivery_carrier_option/models/delivery_carrier_template_option.py new file mode 100644 index 0000000000..064a1a5122 --- /dev/null +++ b/delivery_carrier_option/models/delivery_carrier_template_option.py @@ -0,0 +1,20 @@ +# Copyright 2012 Akretion . +# Copyright 2013-2016 Camptocamp SA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class DeliveryCarrierTemplateOption(models.Model): + """Available options for a carrier (partner)""" + + _name = "delivery.carrier.template.option" + _description = "Delivery carrier template option" + + partner_id = fields.Many2one(comodel_name="res.partner", string="Partner Carrier") + name = fields.Char(readonly=True) + code = fields.Char(readonly=True) + description = fields.Char( + readonly=True, + help="Allow to define a more complete description " "than in the name field.", + ) diff --git a/delivery_carrier_option/models/stock_picking.py b/delivery_carrier_option/models/stock_picking.py new file mode 100644 index 0000000000..932d17c405 --- /dev/null +++ b/delivery_carrier_option/models/stock_picking.py @@ -0,0 +1,48 @@ +# Copyright 2012-2015 Akretion . +# Copyright 2013-2016 Camptocamp SA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +import logging + +from odoo import api, fields, models + +_logger = logging.getLogger(__name__) + + +class StockPicking(models.Model): + _inherit = "stock.picking" + + option_ids = fields.Many2many( + comodel_name="delivery.carrier.option", + string="Options", + compute="_compute_option_ids", + store=True, + readonly=False, + ) + + @api.depends("carrier_id") + def _compute_option_ids(self): + for picking in self: + picking.option_ids = picking._get_default_options() + + def _get_default_options(self): + self.ensure_one() + default_options = [] + if self.carrier_id: + default_options = self.carrier_id.default_options() + return default_options + + @api.onchange("option_ids") + def onchange_option_ids(self): + if not self.carrier_id: + return + carrier = self.carrier_id + current_options = options = self.option_ids + for available_option in carrier.available_option_ids: + if ( + available_option.mandatory + and available_option.id not in self.option_ids.ids + ): + options |= available_option + if current_options != options: + self.option_ids = options diff --git a/delivery_carrier_option/pyproject.toml b/delivery_carrier_option/pyproject.toml new file mode 100644 index 0000000000..4231d0cccb --- /dev/null +++ b/delivery_carrier_option/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/delivery_carrier_option/readme/CONTRIBUTORS.md b/delivery_carrier_option/readme/CONTRIBUTORS.md new file mode 100644 index 0000000000..90852f9446 --- /dev/null +++ b/delivery_carrier_option/readme/CONTRIBUTORS.md @@ -0,0 +1,10 @@ +- David BEAL \<\> +- Sébastien BEAU \<\> +- Yannick Vaucher \<\> +- Alexis de Lattre \<\> +- Angel Moya \<\> +- Ismael Calvo \<\> +- Dave Lasley \<\> +- Timothée Ringeard \<\> +- Pimolnat Suntian \<\> +- Raphaël Reverdy \<\> diff --git a/delivery_carrier_option/readme/DESCRIPTION.md b/delivery_carrier_option/readme/DESCRIPTION.md new file mode 100644 index 0000000000..e3bc6143dd --- /dev/null +++ b/delivery_carrier_option/readme/DESCRIPTION.md @@ -0,0 +1,3 @@ +This module adds the concept of option on carriers that can differ +depending on the picking This module doesn't do anything by itself, it +serves as a base module for other carrier-specific modules. diff --git a/delivery_carrier_option/security/ir.model.access.csv b/delivery_carrier_option/security/ir.model.access.csv new file mode 100644 index 0000000000..609f97b534 --- /dev/null +++ b/delivery_carrier_option/security/ir.model.access.csv @@ -0,0 +1,8 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_delivery_carrier_option_salesman,delivery.carrier.option.salesman,model_delivery_carrier_option,sales_team.group_sale_salesman,1,0,0,0 +access_delivery_carrier_option_sale_manager,delivery.carrier.option.sale.manager,model_delivery_carrier_option,sales_team.group_sale_manager,1,1,1,1 +access_delivery_carrier_template_option_salesman,delivery.carrier.relation.option.salesman,model_delivery_carrier_template_option,sales_team.group_sale_salesman,1,0,0,0 +access_delivery_carrier_template_option_sales_manager,delivery.carrier.relation.option.sale.manager,model_delivery_carrier_template_option,sales_team.group_sale_manager,1,1,1,1 +access_delivery_carrier_option_stock_user,delivery.carrier.option stock_user,model_delivery_carrier_option,stock.group_stock_user,1,1,1,1 +access_delivery_carrier_template_option_stock_user,delivery.carrier.template.option stock_user,model_delivery_carrier_template_option,stock.group_stock_user,1,0,0,0 +access_delivery_carrier_template_option_stock_manager,delivery.carrier.template.option stock_manager,model_delivery_carrier_template_option,stock.group_stock_manager,1,1,1,1 diff --git a/delivery_carrier_option/static/description/icon.png b/delivery_carrier_option/static/description/icon.png new file mode 100644 index 0000000000..3a0328b516 Binary files /dev/null and b/delivery_carrier_option/static/description/icon.png differ diff --git a/delivery_carrier_option/static/description/index.html b/delivery_carrier_option/static/description/index.html new file mode 100644 index 0000000000..acdc727c96 --- /dev/null +++ b/delivery_carrier_option/static/description/index.html @@ -0,0 +1,435 @@ + + + + + +Delivery Carrier Option + + + +
+

Delivery Carrier Option

+ + +

Beta License: AGPL-3 OCA/delivery-carrier Translate me on Weblate Try me on Runboat

+

This module adds the concept of option on carriers that can differ +depending on the picking This module doesn’t do anything by itself, it +serves as a base module for other carrier-specific modules.

+

Table of contents

+ +
+

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

+
    +
  • Camptocamp
  • +
  • Akretion
  • +
+
+
+

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/delivery-carrier project on GitHub.

+

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

+
+
+
+ + diff --git a/delivery_carrier_option/tests/__init__.py b/delivery_carrier_option/tests/__init__.py new file mode 100644 index 0000000000..0e024d83db --- /dev/null +++ b/delivery_carrier_option/tests/__init__.py @@ -0,0 +1 @@ +from . import test_options diff --git a/delivery_carrier_option/tests/test_options.py b/delivery_carrier_option/tests/test_options.py new file mode 100644 index 0000000000..2f847328ab --- /dev/null +++ b/delivery_carrier_option/tests/test_options.py @@ -0,0 +1,49 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.tests.common import TransactionCase + + +class TestPickingOption(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.carrier = cls.env.ref("delivery.delivery_carrier") + cls.option1 = cls.env["delivery.carrier.option"].create( + { + "name": "Option1", + "code": "Code 1", + "carrier_id": cls.carrier.id, + } + ) + cls.option2 = cls.env["delivery.carrier.option"].create( + { + "name": "Option2", + "code": "Code 2", + "carrier_id": cls.carrier.id, + } + ) + cls.option3 = cls.env["delivery.carrier.option"].create( + { + "name": "Option3", + "code": "Code 3", + "carrier_id": cls.carrier.id, + "by_default": True, + } + ) + + def test_delivery_carrier_option_color(self): + self.assertFalse(self.option1.color) + self.option1.mandatory = True + self.assertEqual(self.option1.color, 2) + + def test_picking_default_options(self): + self.option1.mandatory = True + picking = self.env["stock.picking"].create( + { + "carrier_id": self.carrier.id, + "picking_type_id": self.env.ref("stock.picking_type_out").id, + } + ) + self.assertIn(self.option1, picking.option_ids) + self.assertNotIn(self.option2, picking.option_ids) + self.assertIn(self.option3, picking.option_ids) diff --git a/delivery_carrier_option/views/delivery_carrier.xml b/delivery_carrier_option/views/delivery_carrier.xml new file mode 100644 index 0000000000..c2140e796c --- /dev/null +++ b/delivery_carrier_option/views/delivery_carrier.xml @@ -0,0 +1,15 @@ + + + + delivery_base.delivery.carrier.view_form + delivery.carrier + + + + + + + + + + diff --git a/delivery_carrier_option/views/delivery_carrier_option.xml b/delivery_carrier_option/views/delivery_carrier_option.xml new file mode 100644 index 0000000000..147eafd7ca --- /dev/null +++ b/delivery_carrier_option/views/delivery_carrier_option.xml @@ -0,0 +1,38 @@ + + + + delivery_base.delivery_carrier_option.view_form + delivery.carrier.option + +
+ + + + + + + + + + + + + +
+
+
+ + + delivery_base.delivery_carrier_option.view_list + delivery.carrier.option + list + + + + + + + + + +
diff --git a/delivery_carrier_option/views/delivery_carrier_template_option.xml b/delivery_carrier_option/views/delivery_carrier_template_option.xml new file mode 100644 index 0000000000..5efc67050b --- /dev/null +++ b/delivery_carrier_option/views/delivery_carrier_template_option.xml @@ -0,0 +1,35 @@ + + + + delivery_base.delivery_carrier_option.view_form + delivery.carrier.template.option + +
+ + + + + + + + + + +
+
+
+ + + delivery_base.delivery_carrier_template_option.view_list + delivery.carrier.template.option + + + + + + + + +
diff --git a/delivery_carrier_option/views/stock_picking.xml b/delivery_carrier_option/views/stock_picking.xml new file mode 100644 index 0000000000..8c4e950879 --- /dev/null +++ b/delivery_carrier_option/views/stock_picking.xml @@ -0,0 +1,20 @@ + + + + stock.picking + + + + + + + +