diff --git a/pos_customer_required_fields/README.rst b/pos_customer_required_fields/README.rst index 01a747d7c5..4b2e98083b 100644 --- a/pos_customer_required_fields/README.rst +++ b/pos_customer_required_fields/README.rst @@ -17,13 +17,13 @@ Point Of Sale - Customer required fields :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fpos-lightgray.png?logo=github - :target: https://github.com/OCA/pos/tree/12.0/pos_customer_required_fields + :target: https://github.com/OCA/pos/tree/16.0/pos_customer_required_fields :alt: OCA/pos .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png - :target: https://translation.odoo-community.org/projects/pos-12-0/pos-12-0-pos_customer_required_fields + :target: https://translation.odoo-community.org/projects/pos-16-0/pos-16-0-pos_customer_required_fields :alt: Translate me on Weblate .. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png - :target: https://runboat.odoo-community.org/builds?repo=OCA/pos&target_branch=12.0 + :target: https://runboat.odoo-community.org/builds?repo=OCA/pos&target_branch=16.0 :alt: Try me on Runboat |badge1| |badge2| |badge3| |badge4| |badge5| @@ -62,13 +62,13 @@ To create or edit partner from PoS #. Click on client button #. required filed are highlight (in green) -.. figure:: https://raw.githubusercontent.com/OCA/pos/12.0/pos_customer_required_fields/static/description/pos_edit_customer.png +.. figure:: https://raw.githubusercontent.com/OCA/pos/16.0/pos_customer_required_fields/static/description/pos_edit_customer.png If you choose an existing partner with missing informations while validating the payment you will be ask to collect missing customer informations. -.. figure:: https://raw.githubusercontent.com/OCA/pos/12.0/pos_customer_required_fields/static/description/pos_customer_missing_fields.png +.. figure:: https://raw.githubusercontent.com/OCA/pos/16.0/pos_customer_required_fields/static/description/pos_customer_missing_fields.png Bug Tracker =========== @@ -76,7 +76,7 @@ Bug Tracker Bugs are tracked on `GitHub Issues `_. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us to smash it by providing a detailed and welcomed -`feedback `_. +`feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -116,6 +116,6 @@ Current `maintainer `__: |maintainer-petrus-v| -This module is part of the `OCA/pos `_ project on GitHub. +This module is part of the `OCA/pos `_ project on GitHub. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/pos_customer_required_fields/__manifest__.py b/pos_customer_required_fields/__manifest__.py index 189280c3b6..5a933d8b2b 100644 --- a/pos_customer_required_fields/__manifest__.py +++ b/pos_customer_required_fields/__manifest__.py @@ -4,7 +4,7 @@ { "name": "Point Of Sale - Customer required fields", "summary": "Define customer required field used in PoS order.", - "version": "12.0.1.0.1", + "version": "16.0.1.0.0", "category": "Point of Sale", "author": "Pierre Verkest, Odoo Community Association (OCA)", "website": "https://github.com/OCA/pos", @@ -16,12 +16,15 @@ "point_of_sale", ], "data": [ - "templates/assets.xml", "views/view_pos_config.xml", ], - "qweb": [ - "static/src/xml/pos.xml", - ], + "assets": { + "point_of_sale.assets": [ + "pos_customer_required_fields/static/src/xml/PartnerDetailsEdit.xml", + "pos_customer_required_fields/static/src/js/PartnerDetailsEdit.js", + "pos_customer_required_fields/static/src/css/pos.css", + ] + }, "demo": [], "installable": True, } diff --git a/pos_customer_required_fields/i18n/fr.po b/pos_customer_required_fields/i18n/fr.po index 13560b456b..c2b5de74de 100644 --- a/pos_customer_required_fields/i18n/fr.po +++ b/pos_customer_required_fields/i18n/fr.po @@ -4,29 +4,37 @@ # msgid "" msgstr "" -"Project-Id-Version: Odoo Server 12.0\n" +"Project-Id-Version: Odoo Server 16.0\n" "Report-Msgid-Bugs-To: \n" -"Last-Translator: <>\n" +"POT-Creation-Date: 2024-10-01 11:34+0000\n" +"PO-Revision-Date: 2024-10-01 11:34+0000\n" +"Last-Translator: \n" "Language-Team: \n" -"Language: \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: \n" "Plural-Forms: \n" +#. module: pos_customer_required_fields +#: model:ir.model,name:pos_customer_required_fields.model_res_config_settings +msgid "Config Settings" +msgstr "Paramètres de configuration" + #. module: pos_customer_required_fields #: model:ir.model,name:pos_customer_required_fields.model_res_partner msgid "Contact" -msgstr "Contact" +msgstr "" #. module: pos_customer_required_fields -#: code:addons/pos_customer_required_fields/models/res_partner.py:24 +#. odoo-python +#: code:addons/pos_customer_required_fields/models/res_partner.py:0 #, python-format msgid "Following required field(s) is/are not set: %s." msgstr "Le(s) champ(s) requis suivant n'est/ne sont pas renseigné(s) : %s." #. module: pos_customer_required_fields #: model:ir.model.fields,help:pos_customer_required_fields.field_pos_config__res_partner_required_fields_ids +#: model:ir.model.fields,help:pos_customer_required_fields.field_res_config_settings__pos_res_partner_required_fields_ids msgid "" "List of fields that are required while creating or updating a res partner " "from the point of sale." @@ -35,39 +43,27 @@ msgstr "" "point de vente (choisir uniquement parmis les champs disponible dans " "l'interface)." -#. module: pos_customer_required_fields -#. openerp-web -#: code:addons/pos_customer_required_fields/static/src/js/screens.js:33 -#, python-format -msgid "Missing customer data" -msgstr "" - #. module: pos_customer_required_fields #: model:ir.model.fields,field_description:pos_customer_required_fields.field_pos_config__res_partner_required_fields_ids +#: model:ir.model.fields,field_description:pos_customer_required_fields.field_res_config_settings__pos_res_partner_required_fields_ids +#: model_terms:ir.ui.view,arch_db:pos_customer_required_fields.pos_config_view_form msgid "Partner required fields" msgstr "Contact (client): champs requis" #. module: pos_customer_required_fields #: model:ir.model.fields,field_description:pos_customer_required_fields.field_pos_config__res_partner_required_fields_names -msgid "Partner required fields name" +#: model:ir.model.fields,field_description:pos_customer_required_fields.field_res_config_settings__pos_res_partner_required_fields_names +msgid "Partner required fields names" msgstr "Nom technique des champs requis" #. module: pos_customer_required_fields #: model:ir.model,name:pos_customer_required_fields.model_pos_config msgid "Point of Sale Configuration" -msgstr "Paramètrage du point de vente" - -#. module: pos_customer_required_fields -#. openerp-web -#: code:addons/pos_customer_required_fields/static/src/js/screens.js:34 -#, python-format -msgid "" -"Some data on the customer you picked are missing. Use the customer screen to " -"edit: " -msgstr "" +msgstr "Paramétrage du point de vente" #. module: pos_customer_required_fields #: model:ir.model.fields,help:pos_customer_required_fields.field_pos_config__res_partner_required_fields_names +#: model:ir.model.fields,help:pos_customer_required_fields.field_res_config_settings__pos_res_partner_required_fields_names msgid "Technical fields to avoid adding ir.model.fields in pos model" msgstr "Champ technique utilisé dans l'interface du point de vente" @@ -77,12 +73,10 @@ msgid "" "This ensure following fields are set in partner while\n" " creating from the pos order.\n" "\n" -" Also if user pick an existing partner created in " -"the\n" -" backend without that field, user will be prompt " -"to\n" +" Also if user pick an existing partner created in the\n" +" backend without that field, user will be prompt to\n" " add that information." msgstr "" "Permet de verifier que l'ensemble des champs suivant sont définis sur les " -"clients des commandes de point de vente ainsi qu'à l'édition ou création des " -"clients depuis le point de vente." +"clients des commandes de point de vente ainsi qu'à l'édition ou création des" +" clients depuis le point de vente." \ No newline at end of file diff --git a/pos_customer_required_fields/i18n/it.po b/pos_customer_required_fields/i18n/it.po deleted file mode 100644 index 9ad13efbcc..0000000000 --- a/pos_customer_required_fields/i18n/it.po +++ /dev/null @@ -1,97 +0,0 @@ -# Translation of Odoo Server. -# This file contains the translation of the following modules: -# * pos_customer_required_fields -# -msgid "" -msgstr "" -"Project-Id-Version: Odoo Server 12.0\n" -"Report-Msgid-Bugs-To: \n" -"PO-Revision-Date: 2023-03-22 13:23+0000\n" -"Last-Translator: mymage \n" -"Language-Team: none\n" -"Language: it\n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: \n" -"Plural-Forms: nplurals=2; plural=n != 1;\n" -"X-Generator: Weblate 4.14.1\n" - -#. module: pos_customer_required_fields -#: model:ir.model,name:pos_customer_required_fields.model_res_partner -msgid "Contact" -msgstr "Contatto" - -#. module: pos_customer_required_fields -#: code:addons/pos_customer_required_fields/models/res_partner.py:24 -#, python-format -msgid "Following required field(s) is/are not set: %s." -msgstr "I(l) seguenti(e) campi(o) richiesti(o) non è(sono) impostati: %s." - -#. module: pos_customer_required_fields -#: model:ir.model.fields,help:pos_customer_required_fields.field_pos_config__res_partner_required_fields_ids -msgid "" -"List of fields that are required while creating or updating a res partner " -"from the point of sale." -msgstr "" -"Elenco dei campi richiesti dal punto vendtia nella creazione o aggiornamento " -"di una maschera res_partner." - -#. module: pos_customer_required_fields -#. openerp-web -#: code:addons/pos_customer_required_fields/static/src/js/screens.js:33 -#, python-format -msgid "Missing customer data" -msgstr "Dati cliente mancanti" - -#. module: pos_customer_required_fields -#: model:ir.model.fields,field_description:pos_customer_required_fields.field_pos_config__res_partner_required_fields_ids -msgid "Partner required fields" -msgstr "Campi partner richiesti" - -#. module: pos_customer_required_fields -#: model:ir.model.fields,field_description:pos_customer_required_fields.field_pos_config__res_partner_required_fields_names -msgid "Partner required fields name" -msgstr "nome campi partner richiesti" - -#. module: pos_customer_required_fields -#: model:ir.model,name:pos_customer_required_fields.model_pos_config -msgid "Point of Sale Configuration" -msgstr "Configurazione punto vendita" - -#. module: pos_customer_required_fields -#. openerp-web -#: code:addons/pos_customer_required_fields/static/src/js/screens.js:34 -#, python-format -msgid "" -"Some data on the customer you picked are missing. Use the customer screen to " -"edit: " -msgstr "" -"Mancano alcuni dati del cliente selezionato. Utilizzare la maschera cliente " -"per modificarli: " - -#. module: pos_customer_required_fields -#: model:ir.model.fields,help:pos_customer_required_fields.field_pos_config__res_partner_required_fields_names -msgid "Technical fields to avoid adding ir.model.fields in pos model" -msgstr "" -"Campo tecnico per evitare di aggiungere ir.model.fields nel modello pos" - -#. module: pos_customer_required_fields -#: model_terms:ir.ui.view,arch_db:pos_customer_required_fields.pos_config_view_form -msgid "" -"This ensure following fields are set in partner while\n" -" creating from the pos order.\n" -"\n" -" Also if user pick an existing partner created in " -"the\n" -" backend without that field, user will be prompt " -"to\n" -" add that information." -msgstr "" -"Questo assicura che i campi seguenti siano impostati nel partner\n" -" durante la creazione da punto vendita.\n" -"\n" -" Inoltre se l'utente seleziona un partner " -"esistente creato\n" -" nel backend senza il campo, verrà chiesto " -"all'utente\n" -" di aggiungere l'informazione." diff --git a/pos_customer_required_fields/i18n/pos_customer_required_fields.pot b/pos_customer_required_fields/i18n/pos_customer_required_fields.pot index 79438d3878..bfba7830b3 100644 --- a/pos_customer_required_fields/i18n/pos_customer_required_fields.pot +++ b/pos_customer_required_fields/i18n/pos_customer_required_fields.pot @@ -1,49 +1,55 @@ # Translation of Odoo Server. # This file contains the translation of the following modules: -# * pos_customer_required_fields +# * pos_customer_required_fields # msgid "" msgstr "" -"Project-Id-Version: Odoo Server 12.0\n" +"Project-Id-Version: Odoo Server 16.0\n" "Report-Msgid-Bugs-To: \n" -"Last-Translator: <>\n" +"POT-Creation-Date: 2024-10-09 09:24+0000\n" +"PO-Revision-Date: 2024-10-09 09:24+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: pos_customer_required_fields +#: model:ir.model,name:pos_customer_required_fields.model_res_config_settings +msgid "Config Settings" +msgstr "" + #. module: pos_customer_required_fields #: model:ir.model,name:pos_customer_required_fields.model_res_partner msgid "Contact" msgstr "" #. module: pos_customer_required_fields -#: code:addons/pos_customer_required_fields/models/res_partner.py:24 +#. odoo-python +#: code:addons/pos_customer_required_fields/models/res_partner.py:0 #, python-format msgid "Following required field(s) is/are not set: %s." msgstr "" #. module: pos_customer_required_fields #: model:ir.model.fields,help:pos_customer_required_fields.field_pos_config__res_partner_required_fields_ids -msgid "List of fields that are required while creating or updating a res partner from the point of sale." -msgstr "" - -#. module: pos_customer_required_fields -#. openerp-web -#: code:addons/pos_customer_required_fields/static/src/js/screens.js:33 -#, python-format -msgid "Missing customer data" +#: model:ir.model.fields,help:pos_customer_required_fields.field_res_config_settings__pos_res_partner_required_fields_ids +msgid "" +"List of fields that are required while creating or updating a res partner " +"from the point of sale." msgstr "" #. module: pos_customer_required_fields #: model:ir.model.fields,field_description:pos_customer_required_fields.field_pos_config__res_partner_required_fields_ids +#: model:ir.model.fields,field_description:pos_customer_required_fields.field_res_config_settings__pos_res_partner_required_fields_ids msgid "Partner required fields" msgstr "" #. module: pos_customer_required_fields #: model:ir.model.fields,field_description:pos_customer_required_fields.field_pos_config__res_partner_required_fields_names -msgid "Partner required fields name" +#: model:ir.model.fields,field_description:pos_customer_required_fields.field_res_config_settings__pos_res_partner_required_fields_names +msgid "Partner required fields names" msgstr "" #. module: pos_customer_required_fields @@ -51,25 +57,19 @@ msgstr "" msgid "Point of Sale Configuration" msgstr "" -#. module: pos_customer_required_fields -#. openerp-web -#: code:addons/pos_customer_required_fields/static/src/js/screens.js:34 -#, python-format -msgid "Some data on the customer you picked are missing. Use the customer screen to edit: " -msgstr "" - #. module: pos_customer_required_fields #: model:ir.model.fields,help:pos_customer_required_fields.field_pos_config__res_partner_required_fields_names +#: model:ir.model.fields,help:pos_customer_required_fields.field_res_config_settings__pos_res_partner_required_fields_names msgid "Technical fields to avoid adding ir.model.fields in pos model" msgstr "" #. module: pos_customer_required_fields #: model_terms:ir.ui.view,arch_db:pos_customer_required_fields.pos_config_view_form -msgid "This ensure following fields are set in partner while\n" +msgid "" +"This ensure following fields are set in partner while\n" " creating from the pos order.\n" "\n" " Also if user pick an existing partner created in the\n" " backend without that field, user will be prompt to\n" " add that information." msgstr "" - diff --git a/pos_customer_required_fields/models/__init__.py b/pos_customer_required_fields/models/__init__.py index 2a70979df1..7383d51558 100644 --- a/pos_customer_required_fields/models/__init__.py +++ b/pos_customer_required_fields/models/__init__.py @@ -1,5 +1,3 @@ -# Copyright 2022 Moka Tourisme (https://www.mokatourisme.fr). -# @author Pierre Verkest -# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -from . import res_partner +from . import res_config_settings from . import pos_config +from . import res_partner diff --git a/pos_customer_required_fields/models/pos_config.py b/pos_customer_required_fields/models/pos_config.py index e806f32666..306799b5ea 100644 --- a/pos_customer_required_fields/models/pos_config.py +++ b/pos_customer_required_fields/models/pos_config.py @@ -17,7 +17,7 @@ class PosConfig(models.Model): ), ) res_partner_required_fields_names = fields.Char( - string="Partner required fields name", + string="Partner required fields names", compute="_compute_res_partner_required_fields_names", help="Technical fields to avoid adding ir.model.fields in pos model", ) diff --git a/pos_customer_required_fields/models/res_config_settings.py b/pos_customer_required_fields/models/res_config_settings.py new file mode 100644 index 0000000000..66403e284f --- /dev/null +++ b/pos_customer_required_fields/models/res_config_settings.py @@ -0,0 +1,19 @@ +# Copyright 2022 Moka Tourisme (https://www.mokatourisme.fr). +# @author Pierre Verkest +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo import fields, models + + +class ResConfigSettings(models.TransientModel): + _inherit = "res.config.settings" + + pos_res_partner_required_fields_ids = fields.Many2many( + related="pos_config_id.res_partner_required_fields_ids", + string="Partner required fields", + readonly=False, + ) + pos_res_partner_required_fields_names = fields.Char( + related="pos_config_id.res_partner_required_fields_names", + string="Partner required fields names", + readonly=False, + ) diff --git a/pos_customer_required_fields/models/res_partner.py b/pos_customer_required_fields/models/res_partner.py index a3c5a92308..f9c8d9f128 100644 --- a/pos_customer_required_fields/models/res_partner.py +++ b/pos_customer_required_fields/models/res_partner.py @@ -5,7 +5,7 @@ from odoo.exceptions import ValidationError -class PosOrder(models.Model): +class ResPartner(models.Model): _inherit = "res.partner" @api.model diff --git a/pos_customer_required_fields/static/description/index.html b/pos_customer_required_fields/static/description/index.html index c8eecdaf50..7169604cee 100644 --- a/pos_customer_required_fields/static/description/index.html +++ b/pos_customer_required_fields/static/description/index.html @@ -1,4 +1,3 @@ - @@ -9,10 +8,11 @@ /* :Author: David Goodger (goodger@python.org) -:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $ +:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $ :Copyright: This stylesheet has been placed in the public domain. Default cascading style sheet for the HTML output of Docutils. +Despite the name, some widely supported CSS2 features are used. See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to customize this style sheet. @@ -275,7 +275,7 @@ margin-left: 2em ; margin-right: 2em } -pre.code .ln { color: grey; } /* line numbers */ +pre.code .ln { color: gray; } /* line numbers */ pre.code, code { background-color: #eeeeee } pre.code .comment, code .comment { color: #5C6576 } pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold } @@ -301,7 +301,7 @@ span.pre { white-space: pre } -span.problematic { +span.problematic, pre.problematic { color: red } span.section-subtitle { @@ -369,7 +369,7 @@

Point Of Sale - Customer required fields

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !! source digest: sha256:5e1195e22d1cb20ca6b0ced42d6ae852966f3e8817a742d5e9c193708fd1b3ef !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> -

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

+

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

This module enforce users to properly define customer fields created from point of sale or used in pos order.

From PoS config you will be able to define required fields.

@@ -410,13 +410,13 @@

Usage

  • required filed are highlight (in green)
  • -https://raw.githubusercontent.com/OCA/pos/12.0/pos_customer_required_fields/static/description/pos_edit_customer.png +https://raw.githubusercontent.com/OCA/pos/16.0/pos_customer_required_fields/static/description/pos_edit_customer.png

    If you choose an existing partner with missing informations while validating the payment you will be ask to collect missing customer informations.

    -https://raw.githubusercontent.com/OCA/pos/12.0/pos_customer_required_fields/static/description/pos_customer_missing_fields.png +https://raw.githubusercontent.com/OCA/pos/16.0/pos_customer_required_fields/static/description/pos_customer_missing_fields.png
    @@ -424,7 +424,7 @@

    Bug Tracker

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

    +feedback.

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

    @@ -449,13 +449,15 @@

    Contributors

    Maintainers

    This module is maintained by the OCA.

    -Odoo Community Association + +Odoo Community Association +

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

    Current maintainer:

    petrus-v

    -

    This module is part of the OCA/pos project on GitHub.

    +

    This module is part of the OCA/pos project on GitHub.

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

    diff --git a/pos_customer_required_fields/static/description/pos_edit_customer.png b/pos_customer_required_fields/static/description/pos_edit_customer.png index 79a258937c..187c4f9930 100644 Binary files a/pos_customer_required_fields/static/description/pos_edit_customer.png and b/pos_customer_required_fields/static/description/pos_edit_customer.png differ diff --git a/pos_customer_required_fields/static/src/css/pos.css b/pos_customer_required_fields/static/src/css/pos.css index 62bec581a2..98cabab020 100644 --- a/pos_customer_required_fields/static/src/css/pos.css +++ b/pos_customer_required_fields/static/src/css/pos.css @@ -4,7 +4,7 @@ License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). */ input:required { - background: rgb(110, 200, 155) !important; + background: rgb(210, 210, 255) !important; color: white !important; - border: solid 2px rgb(110, 200, 155) !important; + border: solid 2px rgb(210, 210, 255) !important; } diff --git a/pos_customer_required_fields/static/src/js/PartnerDetailsEdit.js b/pos_customer_required_fields/static/src/js/PartnerDetailsEdit.js new file mode 100644 index 0000000000..adde43ff18 --- /dev/null +++ b/pos_customer_required_fields/static/src/js/PartnerDetailsEdit.js @@ -0,0 +1,40 @@ +odoo.define("pos_customer_required_fields.PartnerDetailsEdit", function (require) { + "use strict"; + + const {useState, onMounted} = owl; + const PartnerDetailsEdit = require("point_of_sale.PartnerDetailsEdit"); + const Registries = require("point_of_sale.Registries"); + + const RequiredFieldsPartnerDetailsEdit = (OriginalPartnerDetailsEdit) => + class extends OriginalPartnerDetailsEdit { + setup() { + super.setup(); + this.changes = useState({ + ...this.changes, + pos_config_id: this.env.pos.config.id || null, + }); + + const required_fields = this.env.pos.config + .res_partner_required_fields_names + ? this.env.pos.config.res_partner_required_fields_names.split(",") + : null; + + onMounted(() => { + if (required_fields && required_fields.length > 0) { + required_fields.forEach(function (field_name) { + var inputField = document.querySelector( + `input[name="${field_name.trim()}"]` + ); + if (inputField) { + inputField.setAttribute("required", true); + } + }); + } + }); + } + }; + + Registries.Component.extend(PartnerDetailsEdit, RequiredFieldsPartnerDetailsEdit); + + return PartnerDetailsEdit; +}); diff --git a/pos_customer_required_fields/static/src/js/screens.js b/pos_customer_required_fields/static/src/js/screens.js deleted file mode 100644 index b57dd9f878..0000000000 --- a/pos_customer_required_fields/static/src/js/screens.js +++ /dev/null @@ -1,60 +0,0 @@ -/* - Copyright 2022 Moka Tourisme (https://www.mokatourisme.fr). - @author Pierre Verkest - License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). - */ -odoo.define("pos_customers_required_fields.screens", function (require) { - "use strict"; - - var screens = require("point_of_sale.screens"); - - screens.PaymentScreenWidget.include({ - missing_customer_fields: function () { - const customer = this.pos.get_order().get_client(); - if (!customer || this.pos.config.res_partner_required_fields_names === "") { - // In case customer is not required there are no missing fields - // there are some other check that ensure if customer is - // required or not, it's not the intent of this method to decide - return []; - } - return this.pos.config.res_partner_required_fields_names - .split(",") - .filter(function (name) { - if (!customer[name]) { - return true; - } - return false; - }); - }, - order_is_valid: function (force_validation) { - const missing_fields = this.missing_customer_fields(); - if (missing_fields.length > 0) { - this.gui.show_popup("error", { - title: _t("Missing customer data"), - body: - _t( - "Some data on the customer you picked are missing. Use the customer screen to edit: " - ) + missing_fields, - }); - return false; - } - return this._super.apply(this, arguments); - }, - }); - - screens.ClientListScreenWidget.include({ - display_client_details: function (visibility, partner, clickpos) { - this._super.apply(this, arguments); - var inputs = this.$("div.client-details-contents input"); - if (visibility === "edit") { - const required_fields = - this.pos.config.res_partner_required_fields_names.split(","); - _.each(inputs, function (input_element) { - if (required_fields.indexOf(input_element.name) >= 0) { - $(input_element).prop("required", true); - } - }); - } - }, - }); -}); diff --git a/pos_customer_required_fields/static/src/xml/PartnerDetailsEdit.xml b/pos_customer_required_fields/static/src/xml/PartnerDetailsEdit.xml new file mode 100644 index 0000000000..706f3b1eb8 --- /dev/null +++ b/pos_customer_required_fields/static/src/xml/PartnerDetailsEdit.xml @@ -0,0 +1,20 @@ + + + + +
    + +
    +
    +
    +
    diff --git a/pos_customer_required_fields/static/src/xml/pos.xml b/pos_customer_required_fields/static/src/xml/pos.xml deleted file mode 100644 index 435b11b263..0000000000 --- a/pos_customer_required_fields/static/src/xml/pos.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - -
    - -
    -
    -
    -
    diff --git a/pos_customer_required_fields/tests/test_res_partner.py b/pos_customer_required_fields/tests/test_res_partner.py index 853c05d371..413a0f9e86 100644 --- a/pos_customer_required_fields/tests/test_res_partner.py +++ b/pos_customer_required_fields/tests/test_res_partner.py @@ -11,19 +11,7 @@ class TestCreateResPartnerFromPointOfSaleControledFields(TestPointOfSaleCommon): def setUp(self): super().setUp() - self.ResPartner = self.env["res.partner"] - self.ModelFields = self.env["ir.model.fields"] - - def test_create_from_ui(self): - """ - Simulation of res.partner coming from the interface - """ - self.pos_config.open_session_cb() - - self.pos_config.res_partner_required_fields_ids = self.ModelFields.search( - [("model", "=", "res.partner"), ("name", "in", ["street", "zip"])] - ) - pos_res_partner_payload = { + self.pos_res_partner_payload = { "pos_config_id": str( self.pos_config.id ), # frontend input type hidden send as text @@ -40,44 +28,44 @@ def test_create_from_ui(self): "vat": False, "zip": "66888", } + self.ResPartner = self.env["res.partner"] + self.ModelFields = self.env["ir.model.fields"] + + def test_create_from_ui(self): + """ + Simulation of res.partner coming from the interface + """ + self.pos_config.open_existing_session_cb() + + self.pos_config.res_partner_required_fields_ids = self.ModelFields.search( + [("model", "=", "res.partner"), ("name", "in", ["street", "zip"])] + ) # I create an order on an open session partner = self.ResPartner.browse( - self.ResPartner.create_from_ui(pos_res_partner_payload) + self.ResPartner.create_from_ui(self.pos_res_partner_payload) ) self.assertEqual(partner.street, "1r") self.assertEqual(partner.zip, "66888") def test_create_from_ui_missing_field(self): - self.pos_config.open_session_cb() + self.pos_config.open_existing_session_cb() self.pos_config.res_partner_required_fields_ids = self.ModelFields.search( [("model", "=", "res.partner"), ("name", "in", ["name", "zip"])] ) - pos_res_partner_payload = { - "pos_config_id": self.pos_config.id, - "barcode": False, - "city": False, - "country_id": "75", - "email": False, - "id": False, - "is_company": False, - "name": "test création", - "phone": False, - "property_product_pricelist": 1, - "street": False, - "vat": False, - "zip": False, - } + + self.pos_res_partner_payload["zip"] = False + with self.assertRaisesRegex( ValidationError, r"Following required field\(s\) is/are not set: Zip" ): - self.ResPartner.create_from_ui(pos_res_partner_payload) + self.ResPartner.create_from_ui(self.pos_res_partner_payload) def test_update_existing_partner_missing_information(self): - self.pos_config.open_session_cb() - partner = self.ResPartner.create( + self.pos_config.open_existing_session_cb() + self.ResPartner.create( { "name": "test", "zip": "22322", @@ -86,24 +74,10 @@ def test_update_existing_partner_missing_information(self): self.pos_config.res_partner_required_fields_ids = self.ModelFields.search( [("model", "=", "res.partner"), ("name", "in", ["phone", "zip"])] ) - pos_res_partner_payload = { - "pos_config_id": self.pos_config.id, - "barcode": False, - "city": False, - "country_id": "75", - "email": False, - "firstname": "test", - "id": partner.id, - "is_company": False, - "lastname": "création", - "name": "test création", - "phone": False, - "property_product_pricelist": 1, - "street": False, - "vat": False, - "zip": False, - } + + self.pos_res_partner_payload["zip"] = False + with self.assertRaisesRegex( ValidationError, r"Following required field\(s\) is/are not set: Phone, Zip" ): - self.ResPartner.create_from_ui(pos_res_partner_payload) + self.ResPartner.create_from_ui(self.pos_res_partner_payload) diff --git a/pos_customer_required_fields/views/view_pos_config.xml b/pos_customer_required_fields/views/view_pos_config.xml index 5737f8e0b9..deb13356ce 100644 --- a/pos_customer_required_fields/views/view_pos_config.xml +++ b/pos_customer_required_fields/views/view_pos_config.xml @@ -5,17 +5,14 @@ License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). --> - - pos.config - + + res.config.settings + - +
    -