diff --git a/pos_customer_required_fields/README.rst b/pos_customer_required_fields/README.rst new file mode 100644 index 0000000000..4b2e98083b --- /dev/null +++ b/pos_customer_required_fields/README.rst @@ -0,0 +1,121 @@ +======================================== +Point Of Sale - Customer required fields +======================================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:5e1195e22d1cb20ca6b0ced42d6ae852966f3e8817a742d5e9c193708fd1b3ef + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fpos-lightgray.png?logo=github + :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-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=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +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. + +Using this module without `pos_customer_required` module you are +still able to create PoS order without customer. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +To define customer required field on PoS UI: + +#. Go to any PoS configuration *Point of Sale > Configuration > Point of Sale*. +#. Edit Partner required fields. + +.. warning:: + + Make sure to choose only `res.partner`'s fields present on the PoS UI. + +Usage +===== + +To create or edit partner from PoS + +#. Open PoS session +#. Click on client button +#. required filed are highlight (in green) + +.. 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/16.0/pos_customer_required_fields/static/description/pos_customer_missing_fields.png + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Pierre Verkest + +Contributors +~~~~~~~~~~~~ + + `Moka Tourisme `_ + + * Pierre Verkest + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +.. |maintainer-petrus-v| image:: https://github.com/petrus-v.png?size=40px + :target: https://github.com/petrus-v + :alt: petrus-v + +Current `maintainer `__: + +|maintainer-petrus-v| + +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/__init__.py b/pos_customer_required_fields/__init__.py new file mode 100644 index 0000000000..3eeeaef1c2 --- /dev/null +++ b/pos_customer_required_fields/__init__.py @@ -0,0 +1,4 @@ +# 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 models diff --git a/pos_customer_required_fields/__manifest__.py b/pos_customer_required_fields/__manifest__.py new file mode 100644 index 0000000000..a47ed2df60 --- /dev/null +++ b/pos_customer_required_fields/__manifest__.py @@ -0,0 +1,32 @@ +# Copyright 2022 Moka Tourisme (https://www.mokatourisme.fr). +# @author Pierre Verkest +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "Point Of Sale - Customer required fields", + "summary": "Define customer required field used in PoS order.", + "version": "16.0.1.0.0", + "category": "Point of Sale", + "author": "Pierre Verkest, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/pos", + "license": "AGPL-3", + "maintainers": [ + "petrus-v", + ], + "depends": [ + "point_of_sale", + "base", + "base_setup", + ], + "data": [ + "views/view_pos_config.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 new file mode 100644 index 0000000000..c2b5de74de --- /dev/null +++ b/pos_customer_required_fields/i18n/fr.po @@ -0,0 +1,82 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * pos_customer_required_fields +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \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" +"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 "" + +#. module: pos_customer_required_fields +#. 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." +msgstr "" +"Champs obligatoire lors de la création/modification d'un contact depuis le " +"point de vente (choisir uniquement parmis les champs disponible dans " +"l'interface)." + +#. 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 +#: 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 +#: 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" + +#. 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 "" +"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." \ No newline at end of file diff --git a/pos_customer_required_fields/models/__init__.py b/pos_customer_required_fields/models/__init__.py new file mode 100644 index 0000000000..66f393c34d --- /dev/null +++ b/pos_customer_required_fields/models/__init__.py @@ -0,0 +1,4 @@ +# 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 new file mode 100644 index 0000000000..86ce6457da --- /dev/null +++ b/pos_customer_required_fields/models/pos_config.py @@ -0,0 +1,31 @@ +# 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 api, fields, models + + +class PosConfig(models.Model): + _inherit = "pos.config" + + res_partner_required_fields_ids = fields.Many2many( + "ir.model.fields", + string="Partner required fields", + domain=[("model", "=", "res.partner")], + help=( + "List of fields that are required while creating " + "or updating a res partner from the point of sale." + ), + ) + res_partner_required_fields_names = fields.Char( + string="Partner required fields names", + compute="_compute_res_partner_required_fields_names", + help="Technical fields to avoid adding ir.model.fields in pos model", + store=True, + ) + + @api.depends("res_partner_required_fields_ids") + def _compute_res_partner_required_fields_names(self): + for config in self: + config.res_partner_required_fields_names = ",".join( + config.res_partner_required_fields_ids.mapped("name") + ) 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 new file mode 100644 index 0000000000..f9c8d9f128 --- /dev/null +++ b/pos_customer_required_fields/models/res_partner.py @@ -0,0 +1,27 @@ +# 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 _, api, models +from odoo.exceptions import ValidationError + + +class ResPartner(models.Model): + _inherit = "res.partner" + + @api.model + def create_from_ui(self, partner_data): + """Ensure all fields required pos session fields to be set.""" + pos_config_id = partner_data.pop("pos_config_id") + partner_id = super().create_from_ui(partner_data) + partner = self.browse(partner_id) + pos_config = self.env["pos.config"].browse(int(pos_config_id)) + missing_fields = [] + for field in pos_config.res_partner_required_fields_ids: + if not getattr(partner, field.name): + missing_fields.append(field.field_description) + if missing_fields: + raise ValidationError( + _("Following required field(s) is/are not set: %s.") + % ", ".join(missing_fields) + ) + return partner_id diff --git a/pos_customer_required_fields/readme/CONFIGURE.rst b/pos_customer_required_fields/readme/CONFIGURE.rst new file mode 100644 index 0000000000..807520f29b --- /dev/null +++ b/pos_customer_required_fields/readme/CONFIGURE.rst @@ -0,0 +1,8 @@ +To define customer required field on PoS UI: + +#. Go to any PoS configuration *Point of Sale > Configuration > Point of Sale*. +#. Edit Partner required fields. + +.. warning:: + + Make sure to choose only `res.partner`'s fields present on the PoS UI. diff --git a/pos_customer_required_fields/readme/CONTRIBUTORS.rst b/pos_customer_required_fields/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000000..71921392e8 --- /dev/null +++ b/pos_customer_required_fields/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ + `Moka Tourisme `_ + + * Pierre Verkest diff --git a/pos_customer_required_fields/readme/DESCRIPTION.rst b/pos_customer_required_fields/readme/DESCRIPTION.rst new file mode 100644 index 0000000000..f3ba571303 --- /dev/null +++ b/pos_customer_required_fields/readme/DESCRIPTION.rst @@ -0,0 +1,7 @@ +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. + +Using this module without `pos_customer_required` module you are +still able to create PoS order without customer. diff --git a/pos_customer_required_fields/readme/USAGE.rst b/pos_customer_required_fields/readme/USAGE.rst new file mode 100644 index 0000000000..adb36b57e1 --- /dev/null +++ b/pos_customer_required_fields/readme/USAGE.rst @@ -0,0 +1,13 @@ +To create or edit partner from PoS + +#. Open PoS session +#. Click on client button +#. required filed are highlight (in green) + +.. figure:: ../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:: ../static/description/pos_customer_missing_fields.png diff --git a/pos_customer_required_fields/static/description/icon.png b/pos_customer_required_fields/static/description/icon.png new file mode 100644 index 0000000000..65bf1a8d1a Binary files /dev/null and b/pos_customer_required_fields/static/description/icon.png differ diff --git a/pos_customer_required_fields/static/description/index.html b/pos_customer_required_fields/static/description/index.html new file mode 100644 index 0000000000..7169604cee --- /dev/null +++ b/pos_customer_required_fields/static/description/index.html @@ -0,0 +1,466 @@ + + + + + +Point Of Sale - Customer required fields + + + +
+

Point Of Sale - Customer required fields

+ + +

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.

+

Using this module without pos_customer_required module you are +still able to create PoS order without customer.

+

Table of contents

+ +
+

Configuration

+

To define customer required field on PoS UI:

+
    +
  1. Go to any PoS configuration Point of Sale > Configuration > Point of Sale.
  2. +
  3. Edit Partner required fields.
  4. +
+
+

Warning

+

Make sure to choose only res.partner’s fields present on the PoS UI.

+
+
+
+

Usage

+

To create or edit partner from PoS

+
    +
  1. Open PoS session
  2. +
  3. Click on client button
  4. +
  5. required filed are highlight (in green)
  6. +
+
+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/16.0/pos_customer_required_fields/static/description/pos_customer_missing_fields.png +
+
+
+

Bug Tracker

+

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

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Pierre Verkest
  • +
+
+
+

Contributors

+
+

Moka Tourisme

+
+ +
+
+
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

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

+

Current maintainer:

+

petrus-v

+

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_customer_missing_fields.png b/pos_customer_required_fields/static/description/pos_customer_missing_fields.png new file mode 100644 index 0000000000..25b77aa803 Binary files /dev/null and b/pos_customer_required_fields/static/description/pos_customer_missing_fields.png differ diff --git a/pos_customer_required_fields/static/description/pos_edit_customer.png b/pos_customer_required_fields/static/description/pos_edit_customer.png new file mode 100644 index 0000000000..be27379838 Binary files /dev/null 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 new file mode 100644 index 0000000000..98cabab020 --- /dev/null +++ b/pos_customer_required_fields/static/src/css/pos.css @@ -0,0 +1,10 @@ +/* + Copyright 2022 Moka Tourisme (https://www.mokatourisme.fr). + @author Pierre Verkest + License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +*/ +input:required { + background: rgb(210, 210, 255) !important; + color: white !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/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/templates/assets.xml b/pos_customer_required_fields/templates/assets.xml new file mode 100644 index 0000000000..b9d37ffa25 --- /dev/null +++ b/pos_customer_required_fields/templates/assets.xml @@ -0,0 +1,22 @@ + + + +