diff --git a/rental_base_extension/i18n/ca.po b/rental_base_extension/i18n/ca.po index 475c2c07c..aa861b609 100644 --- a/rental_base_extension/i18n/ca.po +++ b/rental_base_extension/i18n/ca.po @@ -56,6 +56,12 @@ msgstr "Signatura" msgid "Adopt & Sign" msgstr "Adopta i signa" +#. module: rental_base_extension +#: code:addons/rental_base_extension/models/product.py:0 +#, python-format +msgid "All variants already have a rental service." +msgstr "Totes les variants ja tenen un servei de lloguer." + #. module: rental_base_extension #. odoo-javascript #: code:addons/rental_base_extension/static/src/xml/signature_dialog.xml:0 @@ -78,11 +84,22 @@ msgstr "" msgid "Confirm & Sign" msgstr "Confirma i signa" +#. module: rental_base_extension +#: model_terms:ir.ui.view,arch_db:rental_base_extension.product_template_only_form_view +msgid "Create Rental Services" +msgstr "Crea serveis de lloguer" + #. module: rental_base_extension #: model_terms:ir.actions.act_window,help:rental_base_extension.sale_order_action_rental msgid "Create a new rental order!" msgstr "Creeu una nova comanda de lloguer!" +#. module: rental_base_extension +#: code:addons/rental_base_extension/models/product.py:0 +#, python-format +msgid "Created Rental Services" +msgstr "Serveis de lloguer creats" + #. module: rental_base_extension #. odoo-javascript #: code:addons/rental_base_extension/static/src/js/signature_widget.js:0 diff --git a/rental_base_extension/i18n/es.po b/rental_base_extension/i18n/es.po index efb0576af..0d62c080d 100644 --- a/rental_base_extension/i18n/es.po +++ b/rental_base_extension/i18n/es.po @@ -56,6 +56,12 @@ msgstr "Firma" msgid "Adopt & Sign" msgstr "Adoptar y firmar" +#. module: rental_base_extension +#: code:addons/rental_base_extension/models/product.py:0 +#, python-format +msgid "All variants already have a rental service." +msgstr "Todas las variantes ya tienen un servicio de alquiler." + #. module: rental_base_extension #. odoo-javascript #: code:addons/rental_base_extension/static/src/xml/signature_dialog.xml:0 @@ -78,11 +84,22 @@ msgstr "" msgid "Confirm & Sign" msgstr "Confirmar y firmar" +#. module: rental_base_extension +#: model_terms:ir.ui.view,arch_db:rental_base_extension.product_template_only_form_view +msgid "Create Rental Services" +msgstr "Crear servicios de alquiler" + #. module: rental_base_extension #: model_terms:ir.actions.act_window,help:rental_base_extension.sale_order_action_rental msgid "Create a new rental order!" msgstr "¡Cree un nuevo pedido de alquiler!" +#. module: rental_base_extension +#: code:addons/rental_base_extension/models/product.py:0 +#, python-format +msgid "Created Rental Services" +msgstr "Servicios de alquiler creados" + #. module: rental_base_extension #. odoo-javascript #: code:addons/rental_base_extension/static/src/js/signature_widget.js:0 diff --git a/rental_base_extension/i18n/rental_base_extension.pot b/rental_base_extension/i18n/rental_base_extension.pot index be1b514d1..4ff0134a4 100644 --- a/rental_base_extension/i18n/rental_base_extension.pot +++ b/rental_base_extension/i18n/rental_base_extension.pot @@ -51,6 +51,12 @@ msgstr "" msgid "Adopt & Sign" msgstr "" +#. module: rental_base_extension +#: code:addons/rental_base_extension/models/product.py:0 +#, python-format +msgid "All variants already have a rental service." +msgstr "" + #. module: rental_base_extension #. odoo-javascript #: code:addons/rental_base_extension/static/src/xml/signature_dialog.xml:0 @@ -90,11 +96,22 @@ msgstr "" msgid "Create Rental Service" msgstr "" +#. module: rental_base_extension +#: model_terms:ir.ui.view,arch_db:rental_base_extension.product_template_only_form_view +msgid "Create Rental Services" +msgstr "" + #. module: rental_base_extension #: model_terms:ir.actions.act_window,help:rental_base_extension.sale_order_action_rental msgid "Create a new rental order!" msgstr "" +#. module: rental_base_extension +#: code:addons/rental_base_extension/models/product.py:0 +#, python-format +msgid "Created Rental Services" +msgstr "" + #. module: rental_base_extension #: model_terms:ir.ui.view,arch_db:rental_base_extension.sale_order_view_search_rental msgid "Customer" @@ -216,6 +233,12 @@ msgstr "" msgid "Quotation Sent" msgstr "" +#. module: rental_base_extension +#: code:addons/rental_base_extension/models/product.py:0 +#, python-format +msgid "RENT-{}" +msgstr "" + #. module: rental_base_extension #: model:ir.model.fields,field_description:rental_base_extension.field_sale_order__rental_ids #: model_terms:ir.ui.view,arch_db:rental_base_extension.product_normal_form_view @@ -252,6 +275,12 @@ msgstr "" msgid "Rental Status" msgstr "" +#. module: rental_base_extension +#: code:addons/rental_base_extension/models/product.py:0 +#, python-format +msgid "Rental of a {}" +msgstr "" + #. module: rental_base_extension #: model_terms:ir.ui.view,arch_db:rental_base_extension.product_normal_form_view #: model_terms:ir.ui.view,arch_db:rental_base_extension.product_template_only_form_view diff --git a/rental_base_extension/models/__init__.py b/rental_base_extension/models/__init__.py index ba1c090c8..7baeb4153 100644 --- a/rental_base_extension/models/__init__.py +++ b/rental_base_extension/models/__init__.py @@ -1,3 +1,4 @@ +from . import product from . import res_company from . import res_config_settings from . import sale_order diff --git a/rental_base_extension/models/product.py b/rental_base_extension/models/product.py new file mode 100644 index 000000000..873ea2f9f --- /dev/null +++ b/rental_base_extension/models/product.py @@ -0,0 +1,45 @@ +# Copyright 2026 NuoBiT Solutions SL - Eric Antones +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) + +from odoo import _, models +from odoo.exceptions import UserError + + +class ProductTemplate(models.Model): + _inherit = "product.template" + + def action_create_rental_services(self): + self.ensure_one() + day_uom = self.env.ref("uom.product_uom_day") + variants_without_service = self.product_variant_ids.filtered( + lambda v: not v.rental_service_ids + ) + if not variants_without_service: + raise UserError(_("All variants already have a rental service.")) + created_products = self.env["product.product"] + for variant in variants_without_service: + variant_ctx = variant.with_context(display_default_code=False) + vals = { + "type": "service", + "sale_ok": True, + "purchase_ok": False, + "uom_id": day_uom.id, + "uom_po_id": day_uom.id, + "list_price": 1.0, + "name": _("Rental of a {}").format(variant_ctx.display_name), + "rented_product_id": variant.id, + "must_have_dates": True, + "categ_id": self.categ_id.id, + "invoice_policy": "order", + } + if variant.default_code: + vals["default_code"] = _("RENT-{}").format(variant.default_code) + created_products |= self.env["product.product"].create(vals) + return { + "type": "ir.actions.act_window", + "name": _("Created Rental Services"), + "res_model": "product.product", + "view_mode": "tree,form", + "domain": [("id", "in", created_products.ids)], + "target": "current", + } diff --git a/rental_base_extension/views/product_views.xml b/rental_base_extension/views/product_views.xml index 56ac2d067..eee441cda 100644 --- a/rental_base_extension/views/product_views.xml +++ b/rental_base_extension/views/product_views.xml @@ -2,7 +2,7 @@ - + product.template.form.inherit.rental_base_extension product.template @@ -13,7 +13,7 @@ position="attributes" > - {'invisible': [('type', '=', 'service')]} + {'invisible': [('type', '!=', 'product')]} @@ -56,7 +56,7 @@