From 7342f5b4218d10f4bd09307ed545ea877470f4e0 Mon Sep 17 00:00:00 2001 From: Maksim Shurupov Date: Sat, 18 May 2024 21:54:16 +0400 Subject: [PATCH] [ADD] pos_customer_screen_partner_location: Module added. --- .../README.rst | 98 ++++ .../__init__.py | 1 + .../__manifest__.py | 27 ++ .../controllers/__init__.py | 1 + .../controllers/main.py | 20 + .../readme/CONFIGURE.rst | 1 + .../readme/CONTEXT.rst | 2 + .../readme/DESCRIPTION.rst | 1 + .../readme/USAGE.rst | 12 + .../static/description/index.html | 440 ++++++++++++++++++ .../src/js/PartnerDetailsCustomerMap.esm.js | 83 ++++ .../static/src/portal/customer_screen_map.js | 111 +++++ .../static/src/xml/PartnerDetailsEdit.xml | 22 + .../views/customer_screen_template.xml | 38 ++ .../pos_customer_screen_partner_location | 1 + .../setup.py | 6 + 16 files changed, 864 insertions(+) create mode 100644 pos_customer_screen_partner_location/README.rst create mode 100644 pos_customer_screen_partner_location/__init__.py create mode 100644 pos_customer_screen_partner_location/__manifest__.py create mode 100644 pos_customer_screen_partner_location/controllers/__init__.py create mode 100644 pos_customer_screen_partner_location/controllers/main.py create mode 100644 pos_customer_screen_partner_location/readme/CONFIGURE.rst create mode 100644 pos_customer_screen_partner_location/readme/CONTEXT.rst create mode 100644 pos_customer_screen_partner_location/readme/DESCRIPTION.rst create mode 100644 pos_customer_screen_partner_location/readme/USAGE.rst create mode 100644 pos_customer_screen_partner_location/static/description/index.html create mode 100644 pos_customer_screen_partner_location/static/src/js/PartnerDetailsCustomerMap.esm.js create mode 100644 pos_customer_screen_partner_location/static/src/portal/customer_screen_map.js create mode 100644 pos_customer_screen_partner_location/static/src/xml/PartnerDetailsEdit.xml create mode 100644 pos_customer_screen_partner_location/views/customer_screen_template.xml create mode 120000 setup/pos_customer_screen_partner_location/odoo/addons/pos_customer_screen_partner_location create mode 100644 setup/pos_customer_screen_partner_location/setup.py diff --git a/pos_customer_screen_partner_location/README.rst b/pos_customer_screen_partner_location/README.rst new file mode 100644 index 0000000000..6c1f945ef1 --- /dev/null +++ b/pos_customer_screen_partner_location/README.rst @@ -0,0 +1,98 @@ +==================================== +POS Customer Screen Partner Location +==================================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:3a719765d3b0bd14c8e510cdea2b8dba4c4a53cd71560543ff2b24f5c27c039c + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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_screen_partner_location + :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_screen_partner_location + :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 allows POS customers to select their location on map on POS customer screen. + +**Table of contents** + +.. contents:: + :local: + +Use Cases / Context +=================== + +POS Partner Location module allows to select partner location on map in POS. However sometimes you would like your customer to select this location himself. +For example to select an address for goods delivery. + +Configuration +============= + +This module doesn't require any special configuration. However it requires POS Partner Location module configured properly. + +Usage +===== + +In POS: + +* Click the "Customer" button to open the customer list. +* Click on the "Details" button on the customer record to open details. +* Click on the "Screen" icon which is located next to the location button. + +After that pick on the customer screen: + +* Select a location on map. +* Click "Confirm" button. + +Selected location will be saved in the customer's partner profile. + +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 +~~~~~~~ + +* Cetmix + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +This module is part of the `OCA/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_screen_partner_location/__init__.py b/pos_customer_screen_partner_location/__init__.py new file mode 100644 index 0000000000..e046e49fbe --- /dev/null +++ b/pos_customer_screen_partner_location/__init__.py @@ -0,0 +1 @@ +from . import controllers diff --git a/pos_customer_screen_partner_location/__manifest__.py b/pos_customer_screen_partner_location/__manifest__.py new file mode 100644 index 0000000000..7976cf43cc --- /dev/null +++ b/pos_customer_screen_partner_location/__manifest__.py @@ -0,0 +1,27 @@ +# Copyright (C) 2024 Cetmix OÜ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "POS Customer Screen Partner Location", + "version": "16.0.1.0.0", + "category": "Point Of Sale", + "summary": "Select partner location in POS on the customer screen", + "author": "Cetmix, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/pos", + "license": "AGPL-3", + "depends": ["pos_partner_location_abstract"], + "data": [ + "views/customer_screen_template.xml", + ], + "assets": { + "point_of_sale.assets": [ + "pos_customer_screen_partner_location/static/src/js/*.js", + "pos_customer_screen_partner_location/static/src/xml/*.xml", + ], + "web.assets_tests": [], + "web.assets_frontend": [ + "pos_customer_screen_partner_location/static/src/portal/*.js", + ], + }, + "installable": True, +} diff --git a/pos_customer_screen_partner_location/controllers/__init__.py b/pos_customer_screen_partner_location/controllers/__init__.py new file mode 100644 index 0000000000..12a7e529b6 --- /dev/null +++ b/pos_customer_screen_partner_location/controllers/__init__.py @@ -0,0 +1 @@ +from . import main diff --git a/pos_customer_screen_partner_location/controllers/main.py b/pos_customer_screen_partner_location/controllers/main.py new file mode 100644 index 0000000000..067bc3939e --- /dev/null +++ b/pos_customer_screen_partner_location/controllers/main.py @@ -0,0 +1,20 @@ +from odoo import http +from odoo.http import request + + +class CustomerScreenPartnerLocation(http.Controller): + @http.route( + "/customer_screen_location///", + type="http", + auth="user", + website=True, + ) + def customer_screen_location(self, partner_id, pos_config_id): + partner = request.env["res.partner"].browse(partner_id) + return request.render( + "pos_customer_screen_partner_location.customer_screen_pos", + { + "partner": partner, + "config_id": pos_config_id, + }, + ) diff --git a/pos_customer_screen_partner_location/readme/CONFIGURE.rst b/pos_customer_screen_partner_location/readme/CONFIGURE.rst new file mode 100644 index 0000000000..8381cb49a1 --- /dev/null +++ b/pos_customer_screen_partner_location/readme/CONFIGURE.rst @@ -0,0 +1 @@ +This module doesn't require any special configuration. However it requires POS Partner Location module configured properly. diff --git a/pos_customer_screen_partner_location/readme/CONTEXT.rst b/pos_customer_screen_partner_location/readme/CONTEXT.rst new file mode 100644 index 0000000000..de11269a6a --- /dev/null +++ b/pos_customer_screen_partner_location/readme/CONTEXT.rst @@ -0,0 +1,2 @@ +POS Partner Location module allows to select partner location on map in POS. However sometimes you would like your customer to select this location himself. +For example to select an address for goods delivery. diff --git a/pos_customer_screen_partner_location/readme/DESCRIPTION.rst b/pos_customer_screen_partner_location/readme/DESCRIPTION.rst new file mode 100644 index 0000000000..03cc4d4f7c --- /dev/null +++ b/pos_customer_screen_partner_location/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This module allows POS customers to select their location on map on POS customer screen. diff --git a/pos_customer_screen_partner_location/readme/USAGE.rst b/pos_customer_screen_partner_location/readme/USAGE.rst new file mode 100644 index 0000000000..b7c55cc527 --- /dev/null +++ b/pos_customer_screen_partner_location/readme/USAGE.rst @@ -0,0 +1,12 @@ +In POS: + +* Click the "Customer" button to open the customer list. +* Click on the "Details" button on the customer record to open details. +* Click on the "Screen" icon which is located next to the location button. + +After that pick on the customer screen: + +* Select a location on map. +* Click "Confirm" button. + +Selected location will be saved in the customer's partner profile. diff --git a/pos_customer_screen_partner_location/static/description/index.html b/pos_customer_screen_partner_location/static/description/index.html new file mode 100644 index 0000000000..9c1e3166f8 --- /dev/null +++ b/pos_customer_screen_partner_location/static/description/index.html @@ -0,0 +1,440 @@ + + + + + +POS Customer Screen Partner Location + + + +
+

POS Customer Screen Partner Location

+ + +

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

+

This module allows POS customers to select their location on map on POS customer screen.

+

Table of contents

+ +
+

Use Cases / Context

+

POS Partner Location module allows to select partner location on map in POS. However sometimes you would like your customer to select this location himself. +For example to select an address for goods delivery.

+
+
+

Configuration

+

This module doesn’t require any special configuration. However it requires POS Partner Location module configured properly.

+
+
+

Usage

+

In POS:

+
    +
  • Click the “Customer” button to open the customer list.
  • +
  • Click on the “Details” button on the customer record to open details.
  • +
  • Click on the “Screen” icon which is located next to the location button.
  • +
+

After that pick on the customer screen:

+
    +
  • Select a location on map.
  • +
  • Click “Confirm” button.
  • +
+

Selected location will be saved in the customer’s partner profile.

+
+
+

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

+
    +
  • Cetmix
  • +
+
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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

+

This module is part of the OCA/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_screen_partner_location/static/src/js/PartnerDetailsCustomerMap.esm.js b/pos_customer_screen_partner_location/static/src/js/PartnerDetailsCustomerMap.esm.js new file mode 100644 index 0000000000..31fda3a558 --- /dev/null +++ b/pos_customer_screen_partner_location/static/src/js/PartnerDetailsCustomerMap.esm.js @@ -0,0 +1,83 @@ +/** @odoo-module alias=pos_customer_screen_partner_location.PartnerDetailsCustomerMap **/ + +import { + ConnectionAbortedError, + ConnectionLostError, +} from "@web/core/network/rpc_service"; +import PartnerDetailsEdit from "point_of_sale.PartnerDetailsEdit"; +import Registries from "point_of_sale.Registries"; +import {identifyError} from "point_of_sale.utils"; + +const PartnerDetailsCustomerMap = (PartnerDetailsEdit) => + class PartnerDetailsCustomerMap extends PartnerDetailsEdit { + setup() { + super.setup(); + } + + async customerMap() { + this.customer_display = window.open( + `/customer_screen_location/${this.props.partner.id}/${this.env.pos.config.id}/`, + "Customer Display", + "height=600,width=900" + ); + this.customer_display.addEventListener("message", (event) => { + if (event.data.tag === "set_data") { + for (const [key, value] of Object.entries(event.data.result)) { + this.props.partner[key] = value; + if (Array.isArray(value)) { + this.changes[key] = value[0]; + } else { + this.changes[key] = value; + } + } + this.customer_display.close(); + } + if (event.data.tag === "close") { + this.customer_display.close(); + if (event.data.message) { + this.showPopup("ErrorPopup", { + title: this.env._t("Error"), + body: event.data.message, + }); + } + } + }); + } + + async openCustomerMap() { + try { + if (this.accessToMap) { + await this.customerMap(); + } else { + await this.showPopup("ErrorPopup", { + title: this.env._t("Map Error"), + body: this.env._t("Cannot access map functions!"), + }); + } + } catch (e) { + console.warn(e); + if ( + identifyError(e) instanceof ConnectionLostError || + ConnectionAbortedError + ) { + await this.showPopup("OfflineErrorPopup", { + title: this.env._t("Network Error"), + body: this.env._t( + "Cannot access product information screen if offline." + ), + }); + } else { + await this.showPopup("ErrorPopup", { + title: this.env._t("Unknown error"), + body: this.env._t( + "An unknown error prevents us from loading product information." + ), + }); + } + } + } + }; + +Registries.Component.extend(PartnerDetailsEdit, PartnerDetailsCustomerMap); + +export default PartnerDetailsCustomerMap; diff --git a/pos_customer_screen_partner_location/static/src/portal/customer_screen_map.js b/pos_customer_screen_partner_location/static/src/portal/customer_screen_map.js new file mode 100644 index 0000000000..04ae9e1778 --- /dev/null +++ b/pos_customer_screen_partner_location/static/src/portal/customer_screen_map.js @@ -0,0 +1,111 @@ +odoo.define( + "pos_customer_screen_partner_location.customer_screen_map", + function (require) { + "use strict"; + + const publicWidget = require("web.public.widget"); + + publicWidget.registry.CustomerScreenMap = publicWidget.Widget.extend({ + selector: ".o_customer_screen", + events: { + "click .cancel": "_clickScreenClose", + "click .confirm": "_clickSendAndClose", + "change input[name='address']": "_inputChange", + }, + + /** + * @override + */ + start: function () { + const def = this._super.apply(this, arguments); + this.mapContainerRef = this.$(".partner-map-body")[0]; + this.addrInput = this.$("input[name='address']")[0]; + this.address = {}; + this.provider = ""; + this.partnerId = parseInt(this.el.dataset.id, 10) || 0; + this.posConfigId = parseInt(this.el.dataset.pos_id, 10) || 0; + const def1 = this.loadData(); + const def2 = this.onHandleMap(); + return Promise.all([def, def1, def2]).then(() => { + if (!this.provider) { + this.screenClose( + "Please install module for support customer screen map provider!" + ); + } + }); + }, + + loadData: function () { + return this._rpc({ + model: "res.partner", + method: "read", + args: [ + [this.partnerId], + ["contact_address", "partner_latitude", "partner_longitude"], + ], + kwargs: {load: false}, + }).then((result) => { + console.log(result); + if (result.length > 0) { + const data = result[0]; + this.lat = parseFloat(data.partner_latitude) || 0; + this.lng = parseFloat(data.partner_longitude) || 0; + this.contact_address = data.contact_address; + this.addrInput.value = data.contact_address; + } + }); + }, + + onHandleMap: function () { + return new Promise(() => {}); + }, + + updateMarker: function (lat, lng) { + this.lat = lat; + this.lng = lng; + }, + + sendAndClose: function () { + window.parent.postMessage( + { + tag: "set_data", + result: { + partner_latitude: this.lat, + partner_longitude: this.lng, + ...this.address, + }, + }, + window.location.origin + ); + }, + + screenClose: function (message = false) { + window.parent.postMessage( + { + tag: "close", + message: message || false, + }, + window.location.origin + ); + }, + + /* eslint no-empty-function: "warn"*/ + /* eslint no-unused-vars: "warn"*/ + setAddressByLocation: function (address) {}, + + _inputChange: function (event) { + this.setAddressByLocation(event.target.value); + }, + + _clickScreenClose: function (ev) { + ev.preventDefault(); + this.screenClose(); + }, + + _clickSendAndClose: function (ev) { + ev.preventDefault(); + this.sendAndClose(); + }, + }); + } +); diff --git a/pos_customer_screen_partner_location/static/src/xml/PartnerDetailsEdit.xml b/pos_customer_screen_partner_location/static/src/xml/PartnerDetailsEdit.xml new file mode 100644 index 0000000000..88e6440a02 --- /dev/null +++ b/pos_customer_screen_partner_location/static/src/xml/PartnerDetailsEdit.xml @@ -0,0 +1,22 @@ + + + + + + + + + + diff --git a/pos_customer_screen_partner_location/views/customer_screen_template.xml b/pos_customer_screen_partner_location/views/customer_screen_template.xml new file mode 100644 index 0000000000..bde40f6a76 --- /dev/null +++ b/pos_customer_screen_partner_location/views/customer_screen_template.xml @@ -0,0 +1,38 @@ + + + + + + diff --git a/setup/pos_customer_screen_partner_location/odoo/addons/pos_customer_screen_partner_location b/setup/pos_customer_screen_partner_location/odoo/addons/pos_customer_screen_partner_location new file mode 120000 index 0000000000..ee1e501928 --- /dev/null +++ b/setup/pos_customer_screen_partner_location/odoo/addons/pos_customer_screen_partner_location @@ -0,0 +1 @@ +../../../../pos_customer_screen_partner_location \ No newline at end of file diff --git a/setup/pos_customer_screen_partner_location/setup.py b/setup/pos_customer_screen_partner_location/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/pos_customer_screen_partner_location/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)