From 0a758da7cf4ad6d6bf8358f27440c8f52d7db12e Mon Sep 17 00:00:00 2001 From: Unai Beristain Date: Mon, 8 Jul 2024 14:06:44 +0200 Subject: [PATCH 01/13] [MIG] event_registration_sale_line_contract: Migration to 16.0 --- .../README.rst | 28 +++++++++ .../__init__.py | 1 + .../__manifest__.py | 19 ++++++ .../i18n/es.po | 49 ++++++++++++++++ .../even_registration_sale_line_contract.pot | 48 +++++++++++++++ .../models/__init__.py | 3 + .../models/event_registration.py | 27 +++++++++ .../models/sale_order.py | 17 ++++++ .../models/sale_order_line.py | 19 ++++++ .../tests/__init__.py | 1 + ...t_event_registration_sale_line_contract.py | 58 +++++++++++++++++++ .../views/event_registration_views.xml | 50 ++++++++++++++++ .../event_registration_sale_line_contract | 1 + .../setup.py | 6 ++ 14 files changed, 327 insertions(+) create mode 100644 event_registration_sale_line_contract/README.rst create mode 100644 event_registration_sale_line_contract/__init__.py create mode 100644 event_registration_sale_line_contract/__manifest__.py create mode 100644 event_registration_sale_line_contract/i18n/es.po create mode 100644 event_registration_sale_line_contract/i18n/even_registration_sale_line_contract.pot create mode 100644 event_registration_sale_line_contract/models/__init__.py create mode 100644 event_registration_sale_line_contract/models/event_registration.py create mode 100644 event_registration_sale_line_contract/models/sale_order.py create mode 100644 event_registration_sale_line_contract/models/sale_order_line.py create mode 100644 event_registration_sale_line_contract/tests/__init__.py create mode 100644 event_registration_sale_line_contract/tests/test_event_registration_sale_line_contract.py create mode 100644 event_registration_sale_line_contract/views/event_registration_views.xml create mode 120000 setup/event_registration_sale_line_contract/odoo/addons/event_registration_sale_line_contract create mode 100644 setup/event_registration_sale_line_contract/setup.py diff --git a/event_registration_sale_line_contract/README.rst b/event_registration_sale_line_contract/README.rst new file mode 100644 index 0000000000..f836bb8481 --- /dev/null +++ b/event_registration_sale_line_contract/README.rst @@ -0,0 +1,28 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +===================================== +Event registration sale line contract +===================================== + +* In event registration 2 new fields, sale contract line, and sale contract. + +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 smash it by providing detailed and welcomed feedback. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Contributors +------------ + +* Berezi Amubieta +* Alfredo de la Fuente diff --git a/event_registration_sale_line_contract/__init__.py b/event_registration_sale_line_contract/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/event_registration_sale_line_contract/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/event_registration_sale_line_contract/__manifest__.py b/event_registration_sale_line_contract/__manifest__.py new file mode 100644 index 0000000000..9166abf1ae --- /dev/null +++ b/event_registration_sale_line_contract/__manifest__.py @@ -0,0 +1,19 @@ +# Copyright 2021 Alfredo de la Fuente - AvanzOSC +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +{ + "name": "Event Registration Sale Line Contract", + "version": "16.0.1.0.0", + "author": "Avanzosc", + "website": "https://github.com/avanzosc/odoo-addons", + "category": "Marketing/Events", + "depends": [ + "event_sale", + "sale_order_line_contract", + ], + "data": [ + "views/event_registration_views.xml", + ], + "license": "AGPL-3", + "installable": True, + "auto_install": True, +} diff --git a/event_registration_sale_line_contract/i18n/es.po b/event_registration_sale_line_contract/i18n/es.po new file mode 100644 index 0000000000..8810f34f89 --- /dev/null +++ b/event_registration_sale_line_contract/i18n/es.po @@ -0,0 +1,49 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * event_registration_sale_line_contract +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2021-05-25 12:40+0000\n" +"PO-Revision-Date: 2021-05-25 12:40+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: event_registration_sale_line_contract +#: model:ir.model.fields,field_description:event_registration_sale_line_contract.field_event_registration__contract_id +#: model_terms:ir.ui.view,arch_db:event_registration_sale_line_contract.view_registration_search +msgid "Contract" +msgstr "Contrato" + +#. module: event_registration_sale_line_contract +#: model:ir.model.fields,field_description:event_registration_sale_line_contract.field_event_registration__contract_line_id +#: model_terms:ir.ui.view,arch_db:event_registration_sale_line_contract.view_registration_search +msgid "Contract line" +msgstr "Línea contrato" + +#. module: event_registration_sale_line_contract +#: model:ir.model.fields,field_description:event_registration_sale_line_contract.field_event_registration__display_name +msgid "Display Name" +msgstr "Nombre mostrado" + +#. module: event_registration_sale_line_contract +#: model:ir.model,name:event_registration_sale_line_contract.model_event_registration +msgid "Event Registration" +msgstr "Registro de eventos" + +#. module: event_registration_sale_line_contract +#: model:ir.model.fields,field_description:event_registration_sale_line_contract.field_event_registration__id +msgid "ID" +msgstr "" + +#. module: event_registration_sale_line_contract +#: model:ir.model.fields,field_description:event_registration_sale_line_contract.field_event_registration____last_update +msgid "Last Modified on" +msgstr "Última modificación el" + diff --git a/event_registration_sale_line_contract/i18n/even_registration_sale_line_contract.pot b/event_registration_sale_line_contract/i18n/even_registration_sale_line_contract.pot new file mode 100644 index 0000000000..8aab7fa29e --- /dev/null +++ b/event_registration_sale_line_contract/i18n/even_registration_sale_line_contract.pot @@ -0,0 +1,48 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * event_registration_sale_line_contract +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2021-05-25 12:40+0000\n" +"PO-Revision-Date: 2021-05-25 12:40+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: event_registration_sale_line_contract +#: model:ir.model.fields,field_description:event_registration_sale_line_contract.field_event_registration__contract_id +#: model_terms:ir.ui.view,arch_db:event_registration_sale_line_contract.view_registration_search +msgid "Contract" +msgstr "" + +#. module: event_registration_sale_line_contract +#: model:ir.model.fields,field_description:event_registration_sale_line_contract.field_event_registration__contract_line_id +#: model_terms:ir.ui.view,arch_db:event_registration_sale_line_contract.view_registration_search +msgid "Contract line" +msgstr "" + +#. module: event_registration_sale_line_contract +#: model:ir.model.fields,field_description:event_registration_sale_line_contract.field_event_registration__display_name +msgid "Display Name" +msgstr "" + +#. module: event_registration_sale_line_contract +#: model:ir.model,name:event_registration_sale_line_contract.model_event_registration +msgid "Event Registration" +msgstr "" + +#. module: event_registration_sale_line_contract +#: model:ir.model.fields,field_description:event_registration_sale_line_contract.field_event_registration__id +msgid "ID" +msgstr "" + +#. module: event_registration_sale_line_contract +#: model:ir.model.fields,field_description:event_registration_sale_line_contract.field_event_registration____last_update +msgid "Last Modified on" +msgstr "" diff --git a/event_registration_sale_line_contract/models/__init__.py b/event_registration_sale_line_contract/models/__init__.py new file mode 100644 index 0000000000..6e3268f135 --- /dev/null +++ b/event_registration_sale_line_contract/models/__init__.py @@ -0,0 +1,3 @@ +from . import event_registration +from . import sale_order +from . import sale_order_line diff --git a/event_registration_sale_line_contract/models/event_registration.py b/event_registration_sale_line_contract/models/event_registration.py new file mode 100644 index 0000000000..3bf91cfd5c --- /dev/null +++ b/event_registration_sale_line_contract/models/event_registration.py @@ -0,0 +1,27 @@ +# Copyright 2021 Alfredo de la Fuente - AvanzOSC +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from odoo import fields, models + + +class EventRegistration(models.Model): + _inherit = "event.registration" + + contract_line_id = fields.Many2one( + string="Contract line", comodel_name="contract.line" + ) + contract_id = fields.Many2one( + string="Contract", + comodel_name="contract.contract", + related="contract_line_id.contract_id", + store=True, + ) + + def _synchronize_so_line_values(self, so_line): + reg_vals = super()._synchronize_so_line_values(so_line) + if so_line: + reg_vals.update( + { + "contract_line_id": so_line.contract_line_id.id, + } + ) + return reg_vals diff --git a/event_registration_sale_line_contract/models/sale_order.py b/event_registration_sale_line_contract/models/sale_order.py new file mode 100644 index 0000000000..34488cc875 --- /dev/null +++ b/event_registration_sale_line_contract/models/sale_order.py @@ -0,0 +1,17 @@ +# Copyright 2021 Alfredo de la Fuente - AvanzOSC +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from odoo import models + + +class SaleOrder(models.Model): + _inherit = "sale.order" + + def _action_confirm(self): + result = super()._action_confirm() + for sale in self: + lines = sale.order_line.filtered( + lambda x: x.contract_line_id and x.event_id and x.event_ticket_id + ) + if lines: + lines._update_event_registration_contract_line() + return result diff --git a/event_registration_sale_line_contract/models/sale_order_line.py b/event_registration_sale_line_contract/models/sale_order_line.py new file mode 100644 index 0000000000..d6542926e3 --- /dev/null +++ b/event_registration_sale_line_contract/models/sale_order_line.py @@ -0,0 +1,19 @@ +# Copyright 2021 Alfredo de la Fuente - AvanzOSC +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from odoo import models + + +class SaleOrderLine(models.Model): + _inherit = "sale.order.line" + + def _update_event_registration_contract_line(self): + for line in self: + cond = [ + ("event_id", "=", line.event_id.id), + ("event_ticket_id", "=", line.event_ticket_id.id), + ("sale_order_line_id", "=", line.id), + ("contract_line_id", "=", False), + ] + registration = self.env["event.registration"].search(cond) + if registration and len(registration) == 1: + registration.contract_line_id = line.contract_line_id.id diff --git a/event_registration_sale_line_contract/tests/__init__.py b/event_registration_sale_line_contract/tests/__init__.py new file mode 100644 index 0000000000..8fd50791a4 --- /dev/null +++ b/event_registration_sale_line_contract/tests/__init__.py @@ -0,0 +1 @@ +from . import test_event_registration_sale_line_contract diff --git a/event_registration_sale_line_contract/tests/test_event_registration_sale_line_contract.py b/event_registration_sale_line_contract/tests/test_event_registration_sale_line_contract.py new file mode 100644 index 0000000000..ce4dd9c5b1 --- /dev/null +++ b/event_registration_sale_line_contract/tests/test_event_registration_sale_line_contract.py @@ -0,0 +1,58 @@ +# Copyright 2021 Alfredo de la Fuente - AvanzOSC +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html +from odoo.tests import common, tagged + + +@tagged("post_install", "-at_install") +class TestEventRegistationSaleLineContract(common.SavepointCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.sale_obj = cls.env["sale.order"] + cls.registration_obj = cls.env["event.registration"] + cls.uom_unit = cls.env.ref("uom.product_uom_unit") + cls.event = cls.env.ref("event.event_0") + cls.company = cls.env["res.company"]._company_default_get("sale.order") + cls.partner = cls.env["res.partner"].create( + { + "name": "Partner sale order line contract", + "user_id": cls.env.ref("base.user_admin").id, + } + ) + cls.product = cls.env["product.product"].create( + { + "name": "Product sale order line contract", + "default_code": "Psolc", + "uom_id": cls.uom_unit.id, + "uom_po_id": cls.uom_unit.id, + "recurring_rule_type": "monthly", + "recurring_interval": 1, + } + ) + sale_line_vals = { + "product_id": cls.product.id, + "name": cls.product.name, + "product_uom_qty": 1, + "product_uom": cls.product.uom_id.id, + "price_unit": 100, + "event_id": cls.event.id, + } + sale_vals = { + "partner_id": cls.partner.id, + "partner_invoice_id": cls.partner.id, + "partner_shipping_id": cls.partner.id, + "company_id": cls.company.id, + "order_line": [(0, 0, sale_line_vals)], + } + cls.sale1 = cls.sale_obj.create(sale_vals) + + def test_event_registration_sale_line_contract(self): + self.sale1._action_confirm() + self.assertEqual(self.sale1.count_contracts, 1) + self.assertEqual(len(self.sale1.contract_ids[0].contract_line_ids), 1) + registration_vals = { + "event_id": self.event.id, + "sale_order_line_id": self.sale1.order_line[0].id, + } + registration1 = self.registration_obj.create(registration_vals) + self.assertEqual(registration1.contract_id, self.sale1.contract_ids[0]) diff --git a/event_registration_sale_line_contract/views/event_registration_views.xml b/event_registration_sale_line_contract/views/event_registration_views.xml new file mode 100644 index 0000000000..8e10542603 --- /dev/null +++ b/event_registration_sale_line_contract/views/event_registration_views.xml @@ -0,0 +1,50 @@ + + + + event.registration + + + + + + + + + + event.registration + + + + + + + + + + + + + + event.registration + + + + + + + + + diff --git a/setup/event_registration_sale_line_contract/odoo/addons/event_registration_sale_line_contract b/setup/event_registration_sale_line_contract/odoo/addons/event_registration_sale_line_contract new file mode 120000 index 0000000000..838050fdda --- /dev/null +++ b/setup/event_registration_sale_line_contract/odoo/addons/event_registration_sale_line_contract @@ -0,0 +1 @@ +../../../../event_registration_sale_line_contract \ No newline at end of file diff --git a/setup/event_registration_sale_line_contract/setup.py b/setup/event_registration_sale_line_contract/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/event_registration_sale_line_contract/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) From 624def4ad940b50a9cdca2e36a3ac59bf8f68b7f Mon Sep 17 00:00:00 2001 From: Unai Beristain Date: Fri, 5 Jul 2024 19:12:49 +0200 Subject: [PATCH 02/13] [ADD] website_sale_remove_pay_buttons --- .../addons/website_sale_remove_pay_buttons | 1 + .../website_sale_remove_pay_buttons/setup.py | 6 +++ website_sale_remove_pay_buttons/README.rst | 42 +++++++++++++++++++ website_sale_remove_pay_buttons/__init__.py | 0 .../__manifest__.py | 16 +++++++ .../views/website_sale_templates.xml | 22 ++++++++++ 6 files changed, 87 insertions(+) create mode 120000 setup/website_sale_remove_pay_buttons/odoo/addons/website_sale_remove_pay_buttons create mode 100644 setup/website_sale_remove_pay_buttons/setup.py create mode 100644 website_sale_remove_pay_buttons/README.rst create mode 100644 website_sale_remove_pay_buttons/__init__.py create mode 100644 website_sale_remove_pay_buttons/__manifest__.py create mode 100644 website_sale_remove_pay_buttons/views/website_sale_templates.xml diff --git a/setup/website_sale_remove_pay_buttons/odoo/addons/website_sale_remove_pay_buttons b/setup/website_sale_remove_pay_buttons/odoo/addons/website_sale_remove_pay_buttons new file mode 120000 index 0000000000..bad2a6ce3d --- /dev/null +++ b/setup/website_sale_remove_pay_buttons/odoo/addons/website_sale_remove_pay_buttons @@ -0,0 +1 @@ +../../../../website_sale_remove_pay_buttons \ No newline at end of file diff --git a/setup/website_sale_remove_pay_buttons/setup.py b/setup/website_sale_remove_pay_buttons/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/website_sale_remove_pay_buttons/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/website_sale_remove_pay_buttons/README.rst b/website_sale_remove_pay_buttons/README.rst new file mode 100644 index 0000000000..14a817c431 --- /dev/null +++ b/website_sale_remove_pay_buttons/README.rst @@ -0,0 +1,42 @@ +.. image:: https://img.shields.io/badge/license-AGPL--3-blue.png + :target: https://www.gnu.org/licenses/agpl + :alt: License: AGPL-3 + +=============================== +Website Sale Remove Pay Buttons +=============================== + +This module customizes the Odoo eCommerce functionality by removing the "Pay Now" and "Continue to Payment" buttons from the shopping cart page. This ensures that customers can only confirm their cart and continue shopping, without proceeding to the payment step directly from the website. + +Usage +----- + +The module achieves this behavior through the following modifications to the `website_sale` module templates: + +- **Remove 'Pay Now' button**: The button with the ID `o_payment_form_pay` is removed from the DOM using `xpath`. +- **Remove 'Continue to Payment' button**: The button with the class `btn btn-primary btn-lg btn-block` is removed from the DOM using `xpath`. + +Installation + +Dependencies +------------ + +This module depends on the following Odoo module: + +- `website_sale` + +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 smash it by providing detailed and welcomed feedback. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Contributors +------------ + +* Unai Beristain diff --git a/website_sale_remove_pay_buttons/__init__.py b/website_sale_remove_pay_buttons/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/website_sale_remove_pay_buttons/__manifest__.py b/website_sale_remove_pay_buttons/__manifest__.py new file mode 100644 index 0000000000..8b47460713 --- /dev/null +++ b/website_sale_remove_pay_buttons/__manifest__.py @@ -0,0 +1,16 @@ +{ + "name": "Website Sale Remove Pay Buttons", + "version": "16.0.1.0.0", + "category": "Website", + "summary": "Remove pay now and continue to payment buttons from website sale", + "author": "AvanzOSC", + "license": "AGPL-3", + "website": "https://github.com/avanzosc/odoo-addons", + "depends": [ + "website_sale", + ], + "data": [ + "views/website_sale_templates.xml", + ], + "installable": True, +} diff --git a/website_sale_remove_pay_buttons/views/website_sale_templates.xml b/website_sale_remove_pay_buttons/views/website_sale_templates.xml new file mode 100644 index 0000000000..e5428f09aa --- /dev/null +++ b/website_sale_remove_pay_buttons/views/website_sale_templates.xml @@ -0,0 +1,22 @@ + + + + + + From 177d0e4a0eaa834c2a4a9e57c311b6976921513d Mon Sep 17 00:00:00 2001 From: unaiberis <146723346+unaiberis@users.noreply.github.com> Date: Fri, 12 Jul 2024 09:01:13 +0200 Subject: [PATCH 03/13] [ADD] res_partner_pick_up_point (#2683) --- res_partner_pick_up_point/README.rst | 40 +++++++++++++++++ res_partner_pick_up_point/__init__.py | 1 + res_partner_pick_up_point/__manifest__.py | 17 +++++++ res_partner_pick_up_point/i18n/es.po | 34 ++++++++++++++ .../i18n/res_partner_pick_up_point.pot | 38 ++++++++++++++++ res_partner_pick_up_point/models/__init__.py | 2 + .../models/res_partner.py | 10 +++++ .../models/sale_order.py | 25 +++++++++++ .../views/res_partner_views.xml | 45 +++++++++++++++++++ .../odoo/addons/res_partner_pick_up_point | 1 + setup/res_partner_pick_up_point/setup.py | 6 +++ 11 files changed, 219 insertions(+) create mode 100644 res_partner_pick_up_point/README.rst create mode 100644 res_partner_pick_up_point/__init__.py create mode 100644 res_partner_pick_up_point/__manifest__.py create mode 100644 res_partner_pick_up_point/i18n/es.po create mode 100644 res_partner_pick_up_point/i18n/res_partner_pick_up_point.pot create mode 100644 res_partner_pick_up_point/models/__init__.py create mode 100644 res_partner_pick_up_point/models/res_partner.py create mode 100644 res_partner_pick_up_point/models/sale_order.py create mode 100644 res_partner_pick_up_point/views/res_partner_views.xml create mode 120000 setup/res_partner_pick_up_point/odoo/addons/res_partner_pick_up_point create mode 100644 setup/res_partner_pick_up_point/setup.py diff --git a/res_partner_pick_up_point/README.rst b/res_partner_pick_up_point/README.rst new file mode 100644 index 0000000000..61f7afea65 --- /dev/null +++ b/res_partner_pick_up_point/README.rst @@ -0,0 +1,40 @@ +.. image:: https://img.shields.io/badge/license-AGPL--3-blue.png + :target: https://www.gnu.org/licenses/agpl + :alt: License: AGPL-3 + +========================= +Res Partner Pick Up Point +========================= + +This module enhances the functionality of Odoo's Sales Orders by automatically setting the shipping address based on a designated "Pick Up Point" assigned to the customer. If a customer has a specific pick up point defined, that pick up point will be used as the shipping address for their orders. + +Usage +----- + +The module achieves this behavior through the following modifications to the `sale.order` model: + +- **`onchange_partner_id` method**: This method is triggered whenever the `partner_id` field changes in the Sales Order form. It checks if the customer (`partner_id`) has a `pick_up_point_id` assigned. If so, it sets `partner_shipping_id` to this pick up point. + +- **`create` method**: This method is overridden to intercept the creation of new Sales Orders (`sale.order`). If a `partner_id` is provided but `partner_shipping_id` is not specified, it checks if the associated partner (`res.partner`) has a `pick_up_point_id`. If yes, it assigns this pick up point as `partner_shipping_id`. + +- **`write` method**: This method is overridden to handle updates to existing Sales Orders. If `partner_id` is included in the update and `partner_shipping_id` is not specified, it checks if the associated partner (`res.partner`) has a `pick_up_point_id`. If yes, it assigns this pick up point as `partner_shipping_id`. + + +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 smash it by providing detailed and welcomed feedback. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Contributors +------------ + +* Ana Juaristi +* Unai Beristain diff --git a/res_partner_pick_up_point/__init__.py b/res_partner_pick_up_point/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/res_partner_pick_up_point/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/res_partner_pick_up_point/__manifest__.py b/res_partner_pick_up_point/__manifest__.py new file mode 100644 index 0000000000..61a812aca4 --- /dev/null +++ b/res_partner_pick_up_point/__manifest__.py @@ -0,0 +1,17 @@ +{ + "name": "Partner Pick Up Point", + "version": "16.0.1.0.0", + "category": "Extra Tools", + "summary": "Adds a pick up point field to partners and automates its use in sales orders", + "author": "AvanzOSC", + "license": "AGPL-3", + "website": "https://github.com/avanzosc/odoo-addons", + "depends": [ + "base", + "sale", + ], + "data": [ + "views/res_partner_views.xml", + ], + "installable": True, +} diff --git a/res_partner_pick_up_point/i18n/es.po b/res_partner_pick_up_point/i18n/es.po new file mode 100644 index 0000000000..d07a2fd515 --- /dev/null +++ b/res_partner_pick_up_point/i18n/es.po @@ -0,0 +1,34 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * res_partner_pick_up_point +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0+e\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2024-07-05 10:22+0000\n" +"PO-Revision-Date: 2024-07-05 10:22+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: res_partner_pick_up_point +#: model:ir.model,name:res_partner_pick_up_point.model_res_partner +msgid "Contact" +msgstr "Contacto" + +#. module: res_partner_pick_up_point +#: model:ir.model,name:res_partner_pick_up_point.model_sale_order +msgid "Sales Order" +msgstr "Pedido de Venta" + +#. module: res_partner_pick_up_point +#: model_terms:ir.ui.view,arch_db:res_partner_pick_up_point.view_partner_form_inherited +#: model_terms:ir.ui.view,arch_db:res_partner_pick_up_point.view_partner_search_inherited +#: model:ir.model.fields,field_description:res_partner_pick_up_point.field_res_partner__pick_up_point_id +#: model:ir.model.fields,field_description:res_partner_pick_up_point.field_res_users__pick_up_point_id +msgid "Pick Up Point" +msgstr "Punto de Recogida" diff --git a/res_partner_pick_up_point/i18n/res_partner_pick_up_point.pot b/res_partner_pick_up_point/i18n/res_partner_pick_up_point.pot new file mode 100644 index 0000000000..4d62140b57 --- /dev/null +++ b/res_partner_pick_up_point/i18n/res_partner_pick_up_point.pot @@ -0,0 +1,38 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * res_partner_pick_up_point +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0+e\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2024-07-05 10:21+0000\n" +"PO-Revision-Date: 2024-07-05 10:21+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: res_partner_pick_up_point +#: model:ir.model,name:res_partner_pick_up_point.model_res_partner +msgid "Contact" +msgstr "" + +#. module: res_partner_pick_up_point +#: model_terms:ir.ui.view,arch_db:res_partner_pick_up_point.view_partner_form_inherited +#: model_terms:ir.ui.view,arch_db:res_partner_pick_up_point.view_partner_search_inherited +msgid "Pick Up Point" +msgstr "" + +#. module: res_partner_pick_up_point +#: model:ir.model,name:res_partner_pick_up_point.model_sale_order +msgid "Sales Order" +msgstr "" + +#. module: res_partner_pick_up_point +#: model:ir.model.fields,field_description:res_partner_pick_up_point.field_res_partner__pick_up_point_id +#: model:ir.model.fields,field_description:res_partner_pick_up_point.field_res_users__pick_up_point_id +msgid "res.partner" +msgstr "" diff --git a/res_partner_pick_up_point/models/__init__.py b/res_partner_pick_up_point/models/__init__.py new file mode 100644 index 0000000000..17c6cc85d0 --- /dev/null +++ b/res_partner_pick_up_point/models/__init__.py @@ -0,0 +1,2 @@ +from . import res_partner +from . import sale_order diff --git a/res_partner_pick_up_point/models/res_partner.py b/res_partner_pick_up_point/models/res_partner.py new file mode 100644 index 0000000000..a3fa0bcd9b --- /dev/null +++ b/res_partner_pick_up_point/models/res_partner.py @@ -0,0 +1,10 @@ +from odoo import fields, models + + +class ResPartner(models.Model): + _inherit = "res.partner" + + pick_up_point_id = fields.Many2one( + "res.partner", + "Pick Up Point", + ) diff --git a/res_partner_pick_up_point/models/sale_order.py b/res_partner_pick_up_point/models/sale_order.py new file mode 100644 index 0000000000..a0782feb05 --- /dev/null +++ b/res_partner_pick_up_point/models/sale_order.py @@ -0,0 +1,25 @@ +from odoo import api, models + + +class SaleOrder(models.Model): + _inherit = "sale.order" + + @api.onchange("partner_id") + def onchange_pick_up_point_partner_id(self): + if self.partner_id.pick_up_point_id: + self.partner_shipping_id = self.partner_id.pick_up_point_id + + @api.model + def create(self, values): + if "partner_id" in values and not values.get("partner_shipping_id"): + partner_id = self.env["res.partner"].browse(values["partner_id"]) + if partner_id.pick_up_point_id: + values["partner_shipping_id"] = partner_id.pick_up_point_id.id + return super().create(values) + + def write(self, values): + if "partner_id" in values and "partner_shipping_id" not in values: + partner_id = self.env["res.partner"].browse(values["partner_id"]) + if partner_id.pick_up_point_id: + values["partner_shipping_id"] = partner_id.pick_up_point_id.id + return super().write(values) diff --git a/res_partner_pick_up_point/views/res_partner_views.xml b/res_partner_pick_up_point/views/res_partner_views.xml new file mode 100644 index 0000000000..914f23c439 --- /dev/null +++ b/res_partner_pick_up_point/views/res_partner_views.xml @@ -0,0 +1,45 @@ + + + res.partner.form.inherited + res.partner + + + + + + + + + + + + res.partner.tree.inherited + res.partner + + + + + + + + + + res.partner.search.inherited + res.partner + + + + + + + + + + + + + diff --git a/setup/res_partner_pick_up_point/odoo/addons/res_partner_pick_up_point b/setup/res_partner_pick_up_point/odoo/addons/res_partner_pick_up_point new file mode 120000 index 0000000000..fbe3d070c5 --- /dev/null +++ b/setup/res_partner_pick_up_point/odoo/addons/res_partner_pick_up_point @@ -0,0 +1 @@ +../../../../res_partner_pick_up_point \ No newline at end of file diff --git a/setup/res_partner_pick_up_point/setup.py b/setup/res_partner_pick_up_point/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/res_partner_pick_up_point/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) From 13d091c8837a26e8b01875dc23bbe4625a8e7a30 Mon Sep 17 00:00:00 2001 From: Alfredo Date: Thu, 4 Jul 2024 08:17:12 +0200 Subject: [PATCH 04/13] [ADD] stock_move_line_product_lot_reader: In detailed operations of pickings new field "Reader". --- stock_move_line_product_lot_reader/README.rst | 29 ++++++++ .../__init__.py | 1 + .../__manifest__.py | 15 +++++ .../i18n/ca_ES.po | 49 ++++++++++++++ .../i18n/en_GB.po | 49 ++++++++++++++ stock_move_line_product_lot_reader/i18n/es.po | 51 ++++++++++++++ stock_move_line_product_lot_reader/i18n/fr.po | 49 ++++++++++++++ .../stock_move_line_product_lot_reader.pot | 49 ++++++++++++++ .../models/__init__.py | 1 + .../models/stock_move_line.py | 66 +++++++++++++++++++ .../views/stock_move_line_views.xml | 19 ++++++ 11 files changed, 378 insertions(+) create mode 100644 stock_move_line_product_lot_reader/README.rst create mode 100644 stock_move_line_product_lot_reader/__init__.py create mode 100644 stock_move_line_product_lot_reader/__manifest__.py create mode 100644 stock_move_line_product_lot_reader/i18n/ca_ES.po create mode 100644 stock_move_line_product_lot_reader/i18n/en_GB.po create mode 100644 stock_move_line_product_lot_reader/i18n/es.po create mode 100644 stock_move_line_product_lot_reader/i18n/fr.po create mode 100644 stock_move_line_product_lot_reader/i18n/stock_move_line_product_lot_reader.pot create mode 100644 stock_move_line_product_lot_reader/models/__init__.py create mode 100644 stock_move_line_product_lot_reader/models/stock_move_line.py create mode 100644 stock_move_line_product_lot_reader/views/stock_move_line_views.xml diff --git a/stock_move_line_product_lot_reader/README.rst b/stock_move_line_product_lot_reader/README.rst new file mode 100644 index 0000000000..d399ac6cde --- /dev/null +++ b/stock_move_line_product_lot_reader/README.rst @@ -0,0 +1,29 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +================================== +Stock move line product lot reader +================================== + +* In detailed operations of pickings new field "Reader", to read with a reader + the "product", or "product lot", separated by a space. + +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 smash it by providing detailed and welcomed feedback. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Contributors +------------ + +* Alfredo de la Fuente +* Ana Juaristi diff --git a/stock_move_line_product_lot_reader/__init__.py b/stock_move_line_product_lot_reader/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/stock_move_line_product_lot_reader/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/stock_move_line_product_lot_reader/__manifest__.py b/stock_move_line_product_lot_reader/__manifest__.py new file mode 100644 index 0000000000..17020154cd --- /dev/null +++ b/stock_move_line_product_lot_reader/__manifest__.py @@ -0,0 +1,15 @@ +# Copyright 2024 Alfredo de la Fuente - AvanzOSC +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +{ + "name": "Stock Move Line Product Lot Reader", + "version": "16.0.1.0.0", + "author": "Avanzosc", + "website": "https://github.com/avanzosc/odoo-addons", + "category": "Inventory", + "license": "AGPL-3", + "depends": [ + "stock", + ], + "data": ["views/stock_move_line_views.xml"], + "installable": True, +} diff --git a/stock_move_line_product_lot_reader/i18n/ca_ES.po b/stock_move_line_product_lot_reader/i18n/ca_ES.po new file mode 100644 index 0000000000..eb5f7149cd --- /dev/null +++ b/stock_move_line_product_lot_reader/i18n/ca_ES.po @@ -0,0 +1,49 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_move_line_product_lot_reader +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2024-07-04 06:10+0000\n" +"PO-Revision-Date: 2024-07-04 06:10+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: stock_move_line_product_lot_reader +#. odoo-python +#: code:addons/stock_move_line_product_lot_reader/models/stock_move_line.py:0 +#, python-format +msgid "" +"Lot: %(lot)s, for product: %(product)s not found. Reader information: " +"%(reader)s" +msgstr "" + +#. module: stock_move_line_product_lot_reader +#: model:ir.model,name:stock_move_line_product_lot_reader.model_stock_move_line +msgid "Product Moves (Stock Move Line)" +msgstr "Moviment del producte (línia de moviment d'estoc)" + +#. module: stock_move_line_product_lot_reader +#. odoo-python +#: code:addons/stock_move_line_product_lot_reader/models/stock_move_line.py:0 +#, python-format +msgid "Product not found, reader information: %(reader)s" +msgstr "" + +#. module: stock_move_line_product_lot_reader +#: model:ir.model.fields,field_description:stock_move_line_product_lot_reader.field_stock_move_line__reader +msgid "Reader" +msgstr "" + +#. module: stock_move_line_product_lot_reader +#. odoo-python +#: code:addons/stock_move_line_product_lot_reader/models/stock_move_line.py:0 +#, python-format +msgid "Reader product: %(product)s, not found in stock move." +msgstr "" diff --git a/stock_move_line_product_lot_reader/i18n/en_GB.po b/stock_move_line_product_lot_reader/i18n/en_GB.po new file mode 100644 index 0000000000..08cbae1152 --- /dev/null +++ b/stock_move_line_product_lot_reader/i18n/en_GB.po @@ -0,0 +1,49 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_move_line_product_lot_reader +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2024-07-04 06:10+0000\n" +"PO-Revision-Date: 2024-07-04 06:10+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: stock_move_line_product_lot_reader +#. odoo-python +#: code:addons/stock_move_line_product_lot_reader/models/stock_move_line.py:0 +#, python-format +msgid "" +"Lot: %(lot)s, for product: %(product)s not found. Reader information: " +"%(reader)s" +msgstr "" + +#. module: stock_move_line_product_lot_reader +#: model:ir.model,name:stock_move_line_product_lot_reader.model_stock_move_line +msgid "Product Moves (Stock Move Line)" +msgstr "" + +#. module: stock_move_line_product_lot_reader +#. odoo-python +#: code:addons/stock_move_line_product_lot_reader/models/stock_move_line.py:0 +#, python-format +msgid "Product not found, reader information: %(reader)s" +msgstr "" + +#. module: stock_move_line_product_lot_reader +#: model:ir.model.fields,field_description:stock_move_line_product_lot_reader.field_stock_move_line__reader +msgid "Reader" +msgstr "" + +#. module: stock_move_line_product_lot_reader +#. odoo-python +#: code:addons/stock_move_line_product_lot_reader/models/stock_move_line.py:0 +#, python-format +msgid "Reader product: %(product)s, not found in stock move." +msgstr "" diff --git a/stock_move_line_product_lot_reader/i18n/es.po b/stock_move_line_product_lot_reader/i18n/es.po new file mode 100644 index 0000000000..ca5ec7a248 --- /dev/null +++ b/stock_move_line_product_lot_reader/i18n/es.po @@ -0,0 +1,51 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_move_line_product_lot_reader +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2024-07-04 06:11+0000\n" +"PO-Revision-Date: 2024-07-04 06:11+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: stock_move_line_product_lot_reader +#. odoo-python +#: code:addons/stock_move_line_product_lot_reader/models/stock_move_line.py:0 +#, python-format +msgid "" +"Lot: %(lot)s, for product: %(product)s not found. Reader information: " +"%(reader)s" +msgstr "" +"Lote: %(lot)s, para producto: %(product)s no encontrado. Información lector: " +"%(reader)s" + +#. module: stock_move_line_product_lot_reader +#: model:ir.model,name:stock_move_line_product_lot_reader.model_stock_move_line +msgid "Product Moves (Stock Move Line)" +msgstr "Movimientos productos (Stock Move Line)" + +#. module: stock_move_line_product_lot_reader +#. odoo-python +#: code:addons/stock_move_line_product_lot_reader/models/stock_move_line.py:0 +#, python-format +msgid "Product not found, reader information: %(reader)s" +msgstr "Producto no encontrado, información lector: %(reader)s" + +#. module: stock_move_line_product_lot_reader +#: model:ir.model.fields,field_description:stock_move_line_product_lot_reader.field_stock_move_line__reader +msgid "Reader" +msgstr "Lector" + +#. module: stock_move_line_product_lot_reader +#. odoo-python +#: code:addons/stock_move_line_product_lot_reader/models/stock_move_line.py:0 +#, python-format +msgid "Reader product: %(product)s, not found in stock move." +msgstr "Producto leido: %(product)s, no encontrado en movimiento de stock." diff --git a/stock_move_line_product_lot_reader/i18n/fr.po b/stock_move_line_product_lot_reader/i18n/fr.po new file mode 100644 index 0000000000..3d59d4200d --- /dev/null +++ b/stock_move_line_product_lot_reader/i18n/fr.po @@ -0,0 +1,49 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_move_line_product_lot_reader +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2024-07-04 06:10+0000\n" +"PO-Revision-Date: 2024-07-04 06:10+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: stock_move_line_product_lot_reader +#. odoo-python +#: code:addons/stock_move_line_product_lot_reader/models/stock_move_line.py:0 +#, python-format +msgid "" +"Lot: %(lot)s, for product: %(product)s not found. Reader information: " +"%(reader)s" +msgstr "" + +#. module: stock_move_line_product_lot_reader +#: model:ir.model,name:stock_move_line_product_lot_reader.model_stock_move_line +msgid "Product Moves (Stock Move Line)" +msgstr "Mouvements de stock" + +#. module: stock_move_line_product_lot_reader +#. odoo-python +#: code:addons/stock_move_line_product_lot_reader/models/stock_move_line.py:0 +#, python-format +msgid "Product not found, reader information: %(reader)s" +msgstr "" + +#. module: stock_move_line_product_lot_reader +#: model:ir.model.fields,field_description:stock_move_line_product_lot_reader.field_stock_move_line__reader +msgid "Reader" +msgstr "" + +#. module: stock_move_line_product_lot_reader +#. odoo-python +#: code:addons/stock_move_line_product_lot_reader/models/stock_move_line.py:0 +#, python-format +msgid "Reader product: %(product)s, not found in stock move." +msgstr "" diff --git a/stock_move_line_product_lot_reader/i18n/stock_move_line_product_lot_reader.pot b/stock_move_line_product_lot_reader/i18n/stock_move_line_product_lot_reader.pot new file mode 100644 index 0000000000..57153129c7 --- /dev/null +++ b/stock_move_line_product_lot_reader/i18n/stock_move_line_product_lot_reader.pot @@ -0,0 +1,49 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_move_line_product_lot_reader +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2024-07-04 06:05+0000\n" +"PO-Revision-Date: 2024-07-04 06:05+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: stock_move_line_product_lot_reader +#. odoo-python +#: code:addons/stock_move_line_product_lot_reader/models/stock_move_line.py:0 +#, python-format +msgid "" +"Lot: %(lot)s, for product: %(product)s not found. Reader information: " +"%(reader)s" +msgstr "" + +#. module: stock_move_line_product_lot_reader +#: model:ir.model,name:stock_move_line_product_lot_reader.model_stock_move_line +msgid "Product Moves (Stock Move Line)" +msgstr "" + +#. module: stock_move_line_product_lot_reader +#. odoo-python +#: code:addons/stock_move_line_product_lot_reader/models/stock_move_line.py:0 +#, python-format +msgid "Product not found, reader information: %(reader)s" +msgstr "" + +#. module: stock_move_line_product_lot_reader +#: model:ir.model.fields,field_description:stock_move_line_product_lot_reader.field_stock_move_line__reader +msgid "Reader" +msgstr "" + +#. module: stock_move_line_product_lot_reader +#. odoo-python +#: code:addons/stock_move_line_product_lot_reader/models/stock_move_line.py:0 +#, python-format +msgid "Reader product: %(product)s, not found in stock move." +msgstr "" diff --git a/stock_move_line_product_lot_reader/models/__init__.py b/stock_move_line_product_lot_reader/models/__init__.py new file mode 100644 index 0000000000..431f51c274 --- /dev/null +++ b/stock_move_line_product_lot_reader/models/__init__.py @@ -0,0 +1 @@ +from . import stock_move_line diff --git a/stock_move_line_product_lot_reader/models/stock_move_line.py b/stock_move_line_product_lot_reader/models/stock_move_line.py new file mode 100644 index 0000000000..5bbc138b22 --- /dev/null +++ b/stock_move_line_product_lot_reader/models/stock_move_line.py @@ -0,0 +1,66 @@ +# Copyright 2024 Alfredo de la Fuente - AvanzOSC +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from odoo import _, api, fields, models +from odoo.exceptions import ValidationError + + +class StockMoveLine(models.Model): + _inherit = "stock.move.line" + + reader = fields.Char(copy=False) + + @api.onchange("reader") + def onchange_reader(self): + if self.reader: + pos = self.reader.find(" ") + cond = [("default_code", "=", self.reader)] + if pos > 0: + default_code = self.reader[0:pos] + cond = [("default_code", "=", default_code)] + product = self.env["product.product"].search(cond, limit=1) + if not product: + message = _("Product not found, reader information: %(reader)s") % { + "reader": self.reader, + } + raise ValidationError(message) + self.product_id = product.id + if pos > 0: + name = self.reader[pos + 1 : len(self.reader)] + cond = [("name", "=", name), ("product_id", "=", product.id)] + lot = self.env["stock.lot"].search(cond, limit=1) + if not lot: + message = _( + "Lot: %(lot)s, for product: %(product)s not found. " + "Reader information: %(reader)s" + ) % {"lot": name, "product": product.name, "reader": self.reader} + raise ValidationError(message) + self.lot_id = lot.id + if "from_stock_picking" in self.env.context and self.env.context.get( + "from_stock_picking", False + ): + stock_move = self.picking_id.move_ids_without_package.filtered( + lambda x: x.product_id == product + ) + if not stock_move: + message = _( + "Reader product: %(product)s, not found in stock move." + ) % { + "product": product.name, + } + raise ValidationError(message) + self.move_id = stock_move.id + + @api.model_create_multi + def create(self, vals_list): + for values in vals_list: + if ( + "reader" in values + and values.get("reader", False) + and "move_id" in values + and values.get("move_id", False) + and "product_id" not in values + ): + move = self.env["stock.move"].browse(values.get("move_id", False)) + values["product_id"] = move.product_id.id + lines = super().create(vals_list) + return lines diff --git a/stock_move_line_product_lot_reader/views/stock_move_line_views.xml b/stock_move_line_product_lot_reader/views/stock_move_line_views.xml new file mode 100644 index 0000000000..50aa27f2f8 --- /dev/null +++ b/stock_move_line_product_lot_reader/views/stock_move_line_views.xml @@ -0,0 +1,19 @@ + + + + stock.move.line + + + + + + + + From aa4c309d8552547a98c747466cbda5776065c192 Mon Sep 17 00:00:00 2001 From: Alfredo Date: Thu, 4 Jul 2024 11:14:56 +0200 Subject: [PATCH 05/13] Add generated README and setup files --- .../odoo/addons/stock_move_line_product_lot_reader | 1 + setup/stock_move_line_product_lot_reader/setup.py | 6 ++++++ 2 files changed, 7 insertions(+) create mode 120000 setup/stock_move_line_product_lot_reader/odoo/addons/stock_move_line_product_lot_reader create mode 100644 setup/stock_move_line_product_lot_reader/setup.py diff --git a/setup/stock_move_line_product_lot_reader/odoo/addons/stock_move_line_product_lot_reader b/setup/stock_move_line_product_lot_reader/odoo/addons/stock_move_line_product_lot_reader new file mode 120000 index 0000000000..9e95a609ce --- /dev/null +++ b/setup/stock_move_line_product_lot_reader/odoo/addons/stock_move_line_product_lot_reader @@ -0,0 +1 @@ +../../../../stock_move_line_product_lot_reader \ No newline at end of file diff --git a/setup/stock_move_line_product_lot_reader/setup.py b/setup/stock_move_line_product_lot_reader/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/stock_move_line_product_lot_reader/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) From 905ad0c10ca986e183e4be6dceb74be969e6ffcc Mon Sep 17 00:00:00 2001 From: Unai Beristain Date: Thu, 11 Jul 2024 16:13:42 +0200 Subject: [PATCH 06/13] [ADD] stock_automatic_lot_name_creation --- .../addons/stock_automatic_lot_name_creation | 1 + .../setup.py | 6 +++ stock_automatic_lot_name_creation/README.rst | 45 +++++++++++++++++++ stock_automatic_lot_name_creation/__init__.py | 1 + .../__manifest__.py | 14 ++++++ .../models/__init__.py | 1 + .../models/stock_move_line.py | 19 ++++++++ 7 files changed, 87 insertions(+) create mode 120000 setup/stock_automatic_lot_name_creation/odoo/addons/stock_automatic_lot_name_creation create mode 100644 setup/stock_automatic_lot_name_creation/setup.py create mode 100644 stock_automatic_lot_name_creation/README.rst create mode 100644 stock_automatic_lot_name_creation/__init__.py create mode 100644 stock_automatic_lot_name_creation/__manifest__.py create mode 100644 stock_automatic_lot_name_creation/models/__init__.py create mode 100644 stock_automatic_lot_name_creation/models/stock_move_line.py diff --git a/setup/stock_automatic_lot_name_creation/odoo/addons/stock_automatic_lot_name_creation b/setup/stock_automatic_lot_name_creation/odoo/addons/stock_automatic_lot_name_creation new file mode 120000 index 0000000000..84d4bc99c0 --- /dev/null +++ b/setup/stock_automatic_lot_name_creation/odoo/addons/stock_automatic_lot_name_creation @@ -0,0 +1 @@ +../../../../stock_automatic_lot_name_creation \ No newline at end of file diff --git a/setup/stock_automatic_lot_name_creation/setup.py b/setup/stock_automatic_lot_name_creation/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/stock_automatic_lot_name_creation/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/stock_automatic_lot_name_creation/README.rst b/stock_automatic_lot_name_creation/README.rst new file mode 100644 index 0000000000..221a0a3c0f --- /dev/null +++ b/stock_automatic_lot_name_creation/README.rst @@ -0,0 +1,45 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +================================= +Stock Automatic Lot Name Creation +================================= + +Overview +======== + +The Stock Automatic Lot Name Creation module enhances the functionality of stock move lines in Odoo by automatically assigning lot names under specific conditions. + +Features +======== + +- Automatically assigns lot names to stock move lines based on certain criteria. +- Conditions checked: + - If the picking type requires lot creation (`create_lots` is enabled). + - If the product is traceable (`product.product.tracking` is set to 'lot'). + - If the lot name field (`lot_name`) is empty, it assigns a lot name based on the picking name and origin. + + +Usage +===== + +Once installed, the module will automatically handle the assignment of lot names to stock move lines based on the configured conditions. + +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 smash it by providing detailed and welcomed feedback. + +Credits +======= + +Contributors +------------ +* Ana Juaristi +* Unai Beristain + +Do not contact contributors directly about support or help with technical issues. diff --git a/stock_automatic_lot_name_creation/__init__.py b/stock_automatic_lot_name_creation/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/stock_automatic_lot_name_creation/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/stock_automatic_lot_name_creation/__manifest__.py b/stock_automatic_lot_name_creation/__manifest__.py new file mode 100644 index 0000000000..00a06324b7 --- /dev/null +++ b/stock_automatic_lot_name_creation/__manifest__.py @@ -0,0 +1,14 @@ +{ + "name": "Stock Automatic Lot Name Creation", + "version": "16.0.1.0.0", + "summary": "Automatically assigns lot names to stock move lines under certain conditions.", + "category": "Warehouse", + "author": "AvanzOSC", + "website": "https://github.com/avanzosc/odoo-addons", + "license": "AGPL-3", + "depends": [ + "base", + "stock", + ], + "installable": True, +} diff --git a/stock_automatic_lot_name_creation/models/__init__.py b/stock_automatic_lot_name_creation/models/__init__.py new file mode 100644 index 0000000000..431f51c274 --- /dev/null +++ b/stock_automatic_lot_name_creation/models/__init__.py @@ -0,0 +1 @@ +from . import stock_move_line diff --git a/stock_automatic_lot_name_creation/models/stock_move_line.py b/stock_automatic_lot_name_creation/models/stock_move_line.py new file mode 100644 index 0000000000..d3947d322c --- /dev/null +++ b/stock_automatic_lot_name_creation/models/stock_move_line.py @@ -0,0 +1,19 @@ +from odoo import api, models + + +class StockMoveLine(models.Model): + _inherit = "stock.move.line" + + @api.model_create_multi + def create(self, vals_list): + for vals in vals_list: + picking_id = vals.get("picking_id") + product_id = vals.get("product_id") + product = self.env["product.product"].browse(product_id) + + if product and product.tracking == "lot" and not vals.get("lot_name"): + picking = self.env["stock.picking"].browse(picking_id) + origin = picking.origin or "" + vals["lot_name"] = f"{picking.name}-{origin}" + + return super().create(vals_list) From 3c681c2c4f90103ac6866d97b6f27875dbcdc8b4 Mon Sep 17 00:00:00 2001 From: Unai Beristain Date: Thu, 11 Jul 2024 15:52:18 +0200 Subject: [PATCH 07/13] [ADD] website_sale_cart_line_subtotal --- .../addons/website_sale_cart_line_subtotal | 1 + .../website_sale_cart_line_subtotal/setup.py | 6 +++ website_sale_cart_line_subtotal/README.rst | 47 +++++++++++++++++++ website_sale_cart_line_subtotal/__init__.py | 0 .../__manifest__.py | 16 +++++++ website_sale_cart_line_subtotal/i18n/es.po | 21 +++++++++ .../i18n/website_sale_cart_line_subtotal.pot | 21 +++++++++ .../views/website_sale_cart_lines.xml | 17 +++++++ 8 files changed, 129 insertions(+) create mode 120000 setup/website_sale_cart_line_subtotal/odoo/addons/website_sale_cart_line_subtotal create mode 100644 setup/website_sale_cart_line_subtotal/setup.py create mode 100644 website_sale_cart_line_subtotal/README.rst create mode 100644 website_sale_cart_line_subtotal/__init__.py create mode 100644 website_sale_cart_line_subtotal/__manifest__.py create mode 100644 website_sale_cart_line_subtotal/i18n/es.po create mode 100644 website_sale_cart_line_subtotal/i18n/website_sale_cart_line_subtotal.pot create mode 100644 website_sale_cart_line_subtotal/views/website_sale_cart_lines.xml diff --git a/setup/website_sale_cart_line_subtotal/odoo/addons/website_sale_cart_line_subtotal b/setup/website_sale_cart_line_subtotal/odoo/addons/website_sale_cart_line_subtotal new file mode 120000 index 0000000000..b26b14516a --- /dev/null +++ b/setup/website_sale_cart_line_subtotal/odoo/addons/website_sale_cart_line_subtotal @@ -0,0 +1 @@ +../../../../website_sale_cart_line_subtotal \ No newline at end of file diff --git a/setup/website_sale_cart_line_subtotal/setup.py b/setup/website_sale_cart_line_subtotal/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/website_sale_cart_line_subtotal/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/website_sale_cart_line_subtotal/README.rst b/website_sale_cart_line_subtotal/README.rst new file mode 100644 index 0000000000..1221a5e21f --- /dev/null +++ b/website_sale_cart_line_subtotal/README.rst @@ -0,0 +1,47 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +=============================== +Website Sale Cart Line Subtotal +=============================== + +Overview +-------- + +Adds Price Subtotal field to cart lines in website sale. + +Features +-------- + +- Adds a "Price Subtotal" field to the cart lines in the website sale module. +- Calculates the subtotal by multiplying the product quantity by the list price. + +Usage +----- + +Once installed, the `website_sale_cart_line_subtotal` module will enhance the cart view in the website sale module by displaying the subtotal of each line item based on the product quantity and list price. + +Technical Details +----------------- + +- The module extends the `website_sale.cart_lines` view to include a new "Price Subtotal" column. +- It calculates the subtotal dynamically using Odoo's templating language (QWeb). + +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 smash it by providing detailed and welcomed feedback. + +Credits +======= + +Contributors +------------ +* Ana Juaristi +* Unai Beristain + +Do not contact contributors directly about support or help with technical issues. diff --git a/website_sale_cart_line_subtotal/__init__.py b/website_sale_cart_line_subtotal/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/website_sale_cart_line_subtotal/__manifest__.py b/website_sale_cart_line_subtotal/__manifest__.py new file mode 100644 index 0000000000..56f25441de --- /dev/null +++ b/website_sale_cart_line_subtotal/__manifest__.py @@ -0,0 +1,16 @@ +{ + "name": "Website Sale Cart Line Subtotal", + "version": "16.0.1.0.0", + "license": "AGPL-3", + "summary": "Adds Price Subtotal field to cart lines in website sale.", + "category": "Website", + "author": "AvanzOSC", + "website": "https://github.com/avanzosc/odoo-addons", + "depends": [ + "website_sale", + ], + "data": [ + "views/website_sale_cart_lines.xml", + ], + "installable": True, +} diff --git a/website_sale_cart_line_subtotal/i18n/es.po b/website_sale_cart_line_subtotal/i18n/es.po new file mode 100644 index 0000000000..cdfb3cff21 --- /dev/null +++ b/website_sale_cart_line_subtotal/i18n/es.po @@ -0,0 +1,21 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * website_sale_cart_line_subtotal +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0+e\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2024-07-11 14:04+0000\n" +"PO-Revision-Date: 2024-07-11 14:04+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: website_sale_cart_line_subtotal +#: model_terms:ir.ui.view,arch_db:website_sale_cart_line_subtotal.website_sale_cart_lines_inherit +msgid "Price Subtotal" +msgstr "Subtotal" diff --git a/website_sale_cart_line_subtotal/i18n/website_sale_cart_line_subtotal.pot b/website_sale_cart_line_subtotal/i18n/website_sale_cart_line_subtotal.pot new file mode 100644 index 0000000000..f09ecde2c0 --- /dev/null +++ b/website_sale_cart_line_subtotal/i18n/website_sale_cart_line_subtotal.pot @@ -0,0 +1,21 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * website_sale_cart_line_subtotal +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0+e\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2024-07-11 14:03+0000\n" +"PO-Revision-Date: 2024-07-11 14:03+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: website_sale_cart_line_subtotal +#: model_terms:ir.ui.view,arch_db:website_sale_cart_line_subtotal.website_sale_cart_lines_inherit +msgid "Price Subtotal" +msgstr "" diff --git a/website_sale_cart_line_subtotal/views/website_sale_cart_lines.xml b/website_sale_cart_line_subtotal/views/website_sale_cart_lines.xml new file mode 100644 index 0000000000..8fcfe98b23 --- /dev/null +++ b/website_sale_cart_line_subtotal/views/website_sale_cart_lines.xml @@ -0,0 +1,17 @@ + + + + From e596dea306df542c50cfa537b328aad3d91eb2af Mon Sep 17 00:00:00 2001 From: Unai Beristain Date: Wed, 10 Jul 2024 11:05:10 +0200 Subject: [PATCH 08/13] [ADD] website_sale_float_cart_qty --- .../odoo/addons/website_sale_float_cart_qty | 1 + setup/website_sale_float_cart_qty/setup.py | 6 ++ website_sale_float_cart_qty/README.rst | 54 ++++++++++ website_sale_float_cart_qty/__init__.py | 1 + website_sale_float_cart_qty/__manifest__.py | 18 ++++ .../models/__init__.py | 1 + .../models/sale_order.py | 98 +++++++++++++++++++ .../static/src/js/float_qty.js | 60 ++++++++++++ 8 files changed, 239 insertions(+) create mode 120000 setup/website_sale_float_cart_qty/odoo/addons/website_sale_float_cart_qty create mode 100644 setup/website_sale_float_cart_qty/setup.py create mode 100644 website_sale_float_cart_qty/README.rst create mode 100644 website_sale_float_cart_qty/__init__.py create mode 100644 website_sale_float_cart_qty/__manifest__.py create mode 100644 website_sale_float_cart_qty/models/__init__.py create mode 100644 website_sale_float_cart_qty/models/sale_order.py create mode 100644 website_sale_float_cart_qty/static/src/js/float_qty.js diff --git a/setup/website_sale_float_cart_qty/odoo/addons/website_sale_float_cart_qty b/setup/website_sale_float_cart_qty/odoo/addons/website_sale_float_cart_qty new file mode 120000 index 0000000000..1522a757a5 --- /dev/null +++ b/setup/website_sale_float_cart_qty/odoo/addons/website_sale_float_cart_qty @@ -0,0 +1 @@ +../../../../website_sale_float_cart_qty \ No newline at end of file diff --git a/setup/website_sale_float_cart_qty/setup.py b/setup/website_sale_float_cart_qty/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/website_sale_float_cart_qty/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/website_sale_float_cart_qty/README.rst b/website_sale_float_cart_qty/README.rst new file mode 100644 index 0000000000..cf5c9736da --- /dev/null +++ b/website_sale_float_cart_qty/README.rst @@ -0,0 +1,54 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +================================ +Website Sale Float Cart Quantity +================================ + +Overview +-------- + +This module extends the functionality of the `website_sale` module in Odoo by allowing float quantities in the shopping cart instead of integer quantities. + +Features +-------- + +- Enables users to add fractional quantities of products to the shopping cart. +- Overrides the `_changeCartQuantity` function from `website_sale` to handle float quantities. +- Uses `parseFloat` instead of `parseInt` for value conversion on the client-side. + +Usage +----- + +- Users can add decimal quantities of products to the shopping cart from the online store. + +- Quantities are dynamically updated in the user interface after each quantity change. + +Development +----------- + +The `website_sale_float_cart_qty` module uses JavaScript to extend the functionality of Odoo's `website_sale` module. The `website_sale_float_cart_qty.js` file overrides the `_changeCartQuantity` function to handle float quantities and perform server communication via RPC. + +Contributions +------------- + +Contributions are welcome! If you want to contribute to the development of this module, feel free to submit a pull request or report issues on the official repository. + +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 smash it by providing detailed and welcomed feedback. + +Credits +======= + +Contributors +------------ +* Ana Juaristi +* Unai Beristain + +Do not contact contributors directly about support or help with technical issues. diff --git a/website_sale_float_cart_qty/__init__.py b/website_sale_float_cart_qty/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/website_sale_float_cart_qty/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/website_sale_float_cart_qty/__manifest__.py b/website_sale_float_cart_qty/__manifest__.py new file mode 100644 index 0000000000..9ce617421a --- /dev/null +++ b/website_sale_float_cart_qty/__manifest__.py @@ -0,0 +1,18 @@ +{ + "name": "Website Sale Float Cart Quantity", + "summary": "Allow float quantities in cart for website sale module", + "version": "16.0.1.0.0", + "category": "Website", + "license": "LGPL-3", + "website": "https://github.com/avanzosc/odoo-addons", + "author": "AvanzOSC", + "depends": [ + "website_sale", + ], + "assets": { + "web.assets_frontend": [ + "website_sale_float_cart_qty/static/src/js/float_qty.js", + ], + }, + "installable": True, +} diff --git a/website_sale_float_cart_qty/models/__init__.py b/website_sale_float_cart_qty/models/__init__.py new file mode 100644 index 0000000000..6aacb75313 --- /dev/null +++ b/website_sale_float_cart_qty/models/__init__.py @@ -0,0 +1 @@ +from . import sale_order diff --git a/website_sale_float_cart_qty/models/sale_order.py b/website_sale_float_cart_qty/models/sale_order.py new file mode 100644 index 0000000000..a6fd01de42 --- /dev/null +++ b/website_sale_float_cart_qty/models/sale_order.py @@ -0,0 +1,98 @@ +from odoo import _, fields, models +from odoo.exceptions import UserError + + +class SaleOrderInherit(models.Model): + _inherit = "sale.order" + + cart_quantity = fields.Float( + compute="_compute_cart_info", + ) + + def _cart_update(self, product_id, line_id=None, add_qty=0, set_qty=0, **kwargs): + """Add or set product quantity, add_qty can be negative""" + self.ensure_one() + self = self.with_company(self.company_id) + + if self.state != "draft": + self.env["request"].session.pop("sale_order_id", None) + self.env["request"].session.pop("website_sale_cart_quantity", None) + raise UserError( + _( + "It is forbidden to modify a sales order which is not in draft status." + ) + ) + + product = self.env["product.product"].browse(product_id).exists() + if add_qty and (not product or not product._is_add_to_cart_allowed()): + raise UserError( + _( + "The given product does not exist therefore it cannot be added to cart." + ) + ) + + if line_id is not False: + order_line = self._cart_find_product_line(product_id, line_id, **kwargs)[:1] + else: + order_line = self.env["sale.order.line"] + + quantity = 0 + if set_qty: + quantity = set_qty + elif add_qty: + if order_line: + quantity = order_line.product_uom_qty + add_qty + else: + quantity = add_qty + + if quantity > 0: + quantity, warning = self._verify_updated_quantity( + order_line, + product_id, + quantity, + **kwargs, + ) + else: + # If the line will be removed anyway, there is no need to verify + # the requested quantity update. + warning = "" + + order_line = self._cart_update_order_line( + product_id, quantity, order_line, **kwargs + ) + + if ( + order_line + and order_line.price_unit == 0 + and self.website_id.prevent_zero_price_sale + and product.detailed_type + not in self.env["product.template"]._get_product_types_allow_zero_price() + ): + raise UserError( + _( + """The given product does not have a price + therefore it cannot be added to cart.""", + ) + ) + + return { + "line_id": order_line.id, + "quantity": quantity, + "option_ids": list( + set( + order_line.option_line_ids.filtered( + lambda line: line.order_id == order_line.order_id + ).ids + ) + ), + "warning": warning, + } + + def _compute_cart_info(self): + for order in self: + order.cart_quantity = sum( + order.mapped("website_order_line.product_uom_qty") + ) + order.only_services = all( + line.product_id.type == "service" for line in order.website_order_line + ) diff --git a/website_sale_float_cart_qty/static/src/js/float_qty.js b/website_sale_float_cart_qty/static/src/js/float_qty.js new file mode 100644 index 0000000000..5c6f631be3 --- /dev/null +++ b/website_sale_float_cart_qty/static/src/js/float_qty.js @@ -0,0 +1,60 @@ +/** @odoo-module **/ + +import publicWidget from "web.public.widget"; +import wSaleUtils from "website_sale.utils"; +var core = require("web.core"); +require("website_sale.website_sale"); + +publicWidget.registry.WebsiteSale.include({ + /** + * Override the _changeCartQuantity method of WebsiteSale + */ + _changeCartQuantity: function ($input, value, $dom_optional, line_id, productIDs) { + console.log("Entering _changeCartQuantity function"); + + _.each($dom_optional, function (elem) { + $(elem).find(".js_quantity").text(value); + productIDs.push($(elem).find("span[data-product-id]").data("product-id")); + }); + $input.data("update_change", true); + + value = parseFloat($input.val() || 0); + + this._rpc({ + route: "/shop/cart/update_json", + params: { + line_id: line_id, + product_id: $input.data("product-id"), + set_qty: value, + }, + }).then(function (data) { + data.cart_quantity = parseFloat($input.val() || 0); + + $input.data("update_change", false); + var check_value = parseFloat($input.val() || 0); + if (isNaN(check_value)) { + check_value = 1.0; + } + if (value !== check_value) { + $input.trigger("change"); + return; + } + sessionStorage.setItem("website_sale_cart_quantity", data.cart_quantity); + if (!data.cart_quantity) { + window.location = "/shop/cart"; + return; + } + $input.val(data.quantity); + $(".js_quantity[data-line-id=" + line_id + "]") + .val(data.quantity) + .text(data.quantity); + + if (typeof wSaleUtils !== "undefined") { + wSaleUtils.updateCartNavBar(data); + wSaleUtils.showWarning(data.warning); + } + + core.bus.trigger("cart_amount_changed", data.amount, data.minor_amount); + }); + }, +}); From e104961cf8ec8358d36666c14d8668e6c70b34e6 Mon Sep 17 00:00:00 2001 From: Unai Beristain Date: Wed, 10 Jul 2024 16:28:35 +0200 Subject: [PATCH 09/13] [IMP] Convert odoo-module to odoo.define --- .../static/src/js/float_qty.js | 115 ++++++++++-------- 1 file changed, 65 insertions(+), 50 deletions(-) diff --git a/website_sale_float_cart_qty/static/src/js/float_qty.js b/website_sale_float_cart_qty/static/src/js/float_qty.js index 5c6f631be3..5ba7dc72c0 100644 --- a/website_sale_float_cart_qty/static/src/js/float_qty.js +++ b/website_sale_float_cart_qty/static/src/js/float_qty.js @@ -1,60 +1,75 @@ -/** @odoo-module **/ +odoo.define("website_sale_float_cart_qty.float_qty", function (require) { + "use strict"; -import publicWidget from "web.public.widget"; -import wSaleUtils from "website_sale.utils"; -var core = require("web.core"); -require("website_sale.website_sale"); + var publicWidget = require("web.public.widget"); + var wSaleUtils = require("website_sale.utils"); + var core = require("web.core"); + require("website_sale.website_sale"); -publicWidget.registry.WebsiteSale.include({ - /** - * Override the _changeCartQuantity method of WebsiteSale - */ - _changeCartQuantity: function ($input, value, $dom_optional, line_id, productIDs) { - console.log("Entering _changeCartQuantity function"); + publicWidget.registry.WebsiteSale.include({ + /** + * Override the _changeCartQuantity method of WebsiteSale + * @param {jQuery} $input - The jQuery object representing the input field. + * @param {Number} value - The new value of the input field. + * @param {Array} $dom_optional - Array of DOM elements. + * @param {Number} line_id - The line ID associated with the cart line. + * @param {Array} productIDs - Array of product IDs. + */ - _.each($dom_optional, function (elem) { - $(elem).find(".js_quantity").text(value); - productIDs.push($(elem).find("span[data-product-id]").data("product-id")); - }); - $input.data("update_change", true); + _changeCartQuantity: function ($input, value, $dom_optional, line_id, productIDs) { + _.each($dom_optional, function (elem) { + $(elem).find(".js_quantity").text(value); + productIDs.push($(elem).find("span[data-product-id]").data("product-id")); + }); + $input.data("update_change", true); - value = parseFloat($input.val() || 0); + $input.val($input.val().replace(",", ".")); - this._rpc({ - route: "/shop/cart/update_json", - params: { - line_id: line_id, - product_id: $input.data("product-id"), - set_qty: value, - }, - }).then(function (data) { - data.cart_quantity = parseFloat($input.val() || 0); + this._rpc({ + route: "/shop/cart/update_json", + params: { + line_id: line_id, + product_id: parseInt($input.data("product-id"), 10), + set_qty: value, + }, + }).then(function (data) { + $input.data("update_change", false); + var check_value = parseFloat($input.val() || 0, 10); + if (isNaN(check_value)) { + check_value = 1; + } + if (value !== check_value) { + $input.trigger("change"); + return; + } + sessionStorage.setItem("website_sale_cart_quantity", data.cart_quantity); + if (!data.cart_quantity) { + return (window.location = "/shop/cart"); + } + $input.val(data.quantity); + $(".js_quantity[data-line-id=" + line_id + "]") + .val(data.quantity) + .text(data.quantity); - $input.data("update_change", false); - var check_value = parseFloat($input.val() || 0); - if (isNaN(check_value)) { - check_value = 1.0; - } - if (value !== check_value) { - $input.trigger("change"); - return; - } - sessionStorage.setItem("website_sale_cart_quantity", data.cart_quantity); - if (!data.cart_quantity) { - window.location = "/shop/cart"; - return; - } - $input.val(data.quantity); - $(".js_quantity[data-line-id=" + line_id + "]") - .val(data.quantity) - .text(data.quantity); - - if (typeof wSaleUtils !== "undefined") { wSaleUtils.updateCartNavBar(data); wSaleUtils.showWarning(data.warning); - } + // Propagating the change to the express checkout forms + core.bus.trigger("cart_amount_changed", data.amount, data.minor_amount); + }); + }, - core.bus.trigger("cart_amount_changed", data.amount, data.minor_amount); - }); - }, + _onChangeCartQuantity: function (ev) { + var $input = $(ev.currentTarget); + if ($input.data("update_change")) { + return; + } + var value = $input.val().replace(",", "."); + value = parseFloat(value) || 1; + var $dom = $input.closest("tr"); + var $dom_optional = $dom.nextUntil(":not(.optional_product.info)"); + var line_id = parseInt($input.data("line-id"), 10); + var productIDs = [parseInt($input.data("product-id"), 10)]; + this._changeCartQuantity($input, value, $dom_optional, line_id, productIDs); + }, + }); }); From f03a43a11c231bc11ed60efd61db9969726e2940 Mon Sep 17 00:00:00 2001 From: Unai Beristain Date: Mon, 8 Jul 2024 16:32:39 +0200 Subject: [PATCH 10/13] [ADD] website_sale_order_to_cart --- .../odoo/addons/website_sale_order_to_cart | 1 + setup/website_sale_order_to_cart/setup.py | 6 ++ website_sale_order_to_cart/README.rst | 29 +++++++++ website_sale_order_to_cart/__init__.py | 2 + website_sale_order_to_cart/__manifest__.py | 19 ++++++ .../controllers/__init__.py | 1 + .../controllers/main.py | 36 +++++++++++ website_sale_order_to_cart/i18n/es.po | 41 ++++++++++++ .../i18n/website_sale_order_to_cart.pot | 41 ++++++++++++ website_sale_order_to_cart/models/__init__.py | 1 + .../models/sale_order.py | 25 ++++++++ .../views/sale_order_views.xml | 64 +++++++++++++++++++ .../views/website_templates.xml | 42 ++++++++++++ 13 files changed, 308 insertions(+) create mode 120000 setup/website_sale_order_to_cart/odoo/addons/website_sale_order_to_cart create mode 100644 setup/website_sale_order_to_cart/setup.py create mode 100644 website_sale_order_to_cart/README.rst create mode 100644 website_sale_order_to_cart/__init__.py create mode 100644 website_sale_order_to_cart/__manifest__.py create mode 100644 website_sale_order_to_cart/controllers/__init__.py create mode 100644 website_sale_order_to_cart/controllers/main.py create mode 100644 website_sale_order_to_cart/i18n/es.po create mode 100644 website_sale_order_to_cart/i18n/website_sale_order_to_cart.pot create mode 100644 website_sale_order_to_cart/models/__init__.py create mode 100644 website_sale_order_to_cart/models/sale_order.py create mode 100644 website_sale_order_to_cart/views/sale_order_views.xml create mode 100644 website_sale_order_to_cart/views/website_templates.xml diff --git a/setup/website_sale_order_to_cart/odoo/addons/website_sale_order_to_cart b/setup/website_sale_order_to_cart/odoo/addons/website_sale_order_to_cart new file mode 120000 index 0000000000..3c2c7b74f3 --- /dev/null +++ b/setup/website_sale_order_to_cart/odoo/addons/website_sale_order_to_cart @@ -0,0 +1 @@ +../../../../website_sale_order_to_cart \ No newline at end of file diff --git a/setup/website_sale_order_to_cart/setup.py b/setup/website_sale_order_to_cart/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/website_sale_order_to_cart/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/website_sale_order_to_cart/README.rst b/website_sale_order_to_cart/README.rst new file mode 100644 index 0000000000..894f583e80 --- /dev/null +++ b/website_sale_order_to_cart/README.rst @@ -0,0 +1,29 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +================================= +Website Sale Order to Cart Button +================================= + +* Add a button to move the sale order to the cart +* and another button to set it to Sent state from the website cart + + +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 smash it by providing detailed and welcomed feedback. + +Credits +======= + +Contributors +------------ +* Ana Juaristi +* Unai Beristain + +Do not contact contributors directly about support or help with technical issues. diff --git a/website_sale_order_to_cart/__init__.py b/website_sale_order_to_cart/__init__.py new file mode 100644 index 0000000000..91c5580fed --- /dev/null +++ b/website_sale_order_to_cart/__init__.py @@ -0,0 +1,2 @@ +from . import controllers +from . import models diff --git a/website_sale_order_to_cart/__manifest__.py b/website_sale_order_to_cart/__manifest__.py new file mode 100644 index 0000000000..ca2b7f8c47 --- /dev/null +++ b/website_sale_order_to_cart/__manifest__.py @@ -0,0 +1,19 @@ +# Copyright 2024 Unai Beristain - AvanzOSC +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +{ + "name": "Website Sale Order to Cart Button", + "version": "16.0.1.0.0", + "category": "Sales", + "summary": """Add a button to move the sale order to the cart + and another button to set it to Sent state from the website cart""", + "author": "AvanzOSC", + "website": "https://github.com/avanzosc/odoo-addons", + "license": "AGPL-3", + "depends": ["sale", "website_sale"], + "data": [ + "views/website_templates.xml", + "views/sale_order_views.xml", + ], + "installable": True, + "auto_install": False, +} diff --git a/website_sale_order_to_cart/controllers/__init__.py b/website_sale_order_to_cart/controllers/__init__.py new file mode 100644 index 0000000000..12a7e529b6 --- /dev/null +++ b/website_sale_order_to_cart/controllers/__init__.py @@ -0,0 +1 @@ +from . import main diff --git a/website_sale_order_to_cart/controllers/main.py b/website_sale_order_to_cart/controllers/main.py new file mode 100644 index 0000000000..d5cf40f6b6 --- /dev/null +++ b/website_sale_order_to_cart/controllers/main.py @@ -0,0 +1,36 @@ +from odoo import http +from odoo.http import request + + +class SaleOrderController(http.Controller): + + @http.route("/action_quotation_mark_send", type="http", auth="user", website=True) + def action_quotation_mark_send(self, **kwargs): + order_id = kwargs.get("order_id") + if order_id: + sale_order = request.env["sale.order"].sudo().browse(int(order_id)) + # Only change the order state if the partner_id of the order is the user + if sale_order and sale_order.partner_id == request.env.user.partner_id: + + sale_order.action_quotation_mark_send() + access_token = sale_order.access_token + + url = "/my/orders/{}?access_token={}".format( + sale_order.id, access_token + ) + + return request.redirect(url) + + return request.redirect("/shop") + + @http.route("/sale_order_to_cart", type="http", auth="user", website=True) + def sale_order_to_cart(self, **kwargs): + order_id = kwargs.get("order_id") + if order_id: + sale_order = request.env["sale.order"].sudo().browse(int(order_id)) + # Only change the order state if the partner_id of the order is the user + if sale_order and sale_order.partner_id == request.env.user.partner_id: + sale_order.sale_order_to_cart() + return request.redirect("/shop/cart") + + return request.redirect("/shop") diff --git a/website_sale_order_to_cart/i18n/es.po b/website_sale_order_to_cart/i18n/es.po new file mode 100644 index 0000000000..9d637924fd --- /dev/null +++ b/website_sale_order_to_cart/i18n/es.po @@ -0,0 +1,41 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * website_sale_order_to_cart +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0+e\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2024-07-10 11:04+0000\n" +"PO-Revision-Date: 2024-07-10 11:04+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: website_sale_order_to_cart +#: model_terms:ir.ui.view,arch_db:website_sale_order_to_cart.sale_order_portal_template_inherit +msgid "Change Order" +msgstr "Cambiar Pedido" + +#. module: website_sale_order_to_cart +#: model_terms:ir.ui.view,arch_db:website_sale_order_to_cart.sale_order_cart_inherit +msgid "Confirm Cart" +msgstr "Confirmar Carro" + +#. module: website_sale_order_to_cart +#: model_terms:ir.ui.view,arch_db:website_sale_order_to_cart.view_sale_order_form_inherit +msgid "Quotation Mark Sent" +msgstr "Marcar Presupuesto Enviado" + +#. module: website_sale_order_to_cart +#: model_terms:ir.ui.view,arch_db:website_sale_order_to_cart.view_sale_order_form_inherit +msgid "Sale Order To Cart" +msgstr "Pedido de venta al carrito" + +#. module: website_sale_order_to_cart +#: model:ir.model,name:website_sale_order_to_cart.model_sale_order +msgid "Sales Order" +msgstr "Pedido de venta" diff --git a/website_sale_order_to_cart/i18n/website_sale_order_to_cart.pot b/website_sale_order_to_cart/i18n/website_sale_order_to_cart.pot new file mode 100644 index 0000000000..fac494a2f8 --- /dev/null +++ b/website_sale_order_to_cart/i18n/website_sale_order_to_cart.pot @@ -0,0 +1,41 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * website_sale_order_to_cart +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0+e\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2024-07-10 11:04+0000\n" +"PO-Revision-Date: 2024-07-10 11:04+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: website_sale_order_to_cart +#: model_terms:ir.ui.view,arch_db:website_sale_order_to_cart.sale_order_portal_template_inherit +msgid "Change Order" +msgstr "" + +#. module: website_sale_order_to_cart +#: model_terms:ir.ui.view,arch_db:website_sale_order_to_cart.sale_order_cart_inherit +msgid "Confirm Cart" +msgstr "" + +#. module: website_sale_order_to_cart +#: model_terms:ir.ui.view,arch_db:website_sale_order_to_cart.view_sale_order_form_inherit +msgid "Quotation Mark Sent" +msgstr "" + +#. module: website_sale_order_to_cart +#: model_terms:ir.ui.view,arch_db:website_sale_order_to_cart.view_sale_order_form_inherit +msgid "Sale Order To Cart" +msgstr "" + +#. module: website_sale_order_to_cart +#: model:ir.model,name:website_sale_order_to_cart.model_sale_order +msgid "Sales Order" +msgstr "" diff --git a/website_sale_order_to_cart/models/__init__.py b/website_sale_order_to_cart/models/__init__.py new file mode 100644 index 0000000000..6aacb75313 --- /dev/null +++ b/website_sale_order_to_cart/models/__init__.py @@ -0,0 +1 @@ +from . import sale_order diff --git a/website_sale_order_to_cart/models/sale_order.py b/website_sale_order_to_cart/models/sale_order.py new file mode 100644 index 0000000000..d46ba6f8ea --- /dev/null +++ b/website_sale_order_to_cart/models/sale_order.py @@ -0,0 +1,25 @@ +from datetime import datetime + +from dateutil.relativedelta import relativedelta + +from odoo import models + + +class SaleOrder(models.Model): + _inherit = "sale.order" + + def action_quotation_mark_send(self): + self.state = "sent" + self.user_id = self.partner_id.user_id + + def sale_order_to_cart(self): + self.state = "draft" + current_website = self.env["website"].get_current_website() + if current_website: + self.website_id = current_website.id + + abandoned_delay = current_website.cart_abandoned_delay or 1.0 + abandoned_datetime = datetime.utcnow() - relativedelta( + hours=abandoned_delay + ) + self.date_order = abandoned_datetime diff --git a/website_sale_order_to_cart/views/sale_order_views.xml b/website_sale_order_to_cart/views/sale_order_views.xml new file mode 100644 index 0000000000..2d8c324a83 --- /dev/null +++ b/website_sale_order_to_cart/views/sale_order_views.xml @@ -0,0 +1,64 @@ + + + + sale.order.form.inherit + sale.order + + + + + + + + +