Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][ADD] pos_partner_location_map #1002

Merged
merged 2 commits into from
Apr 2, 2024

Conversation

geomer198
Copy link
Contributor

This module allows to select partner address directly on map. For this Google Maps are used.

@geomer198 geomer198 marked this pull request as draft May 20, 2023 20:13
@geomer198 geomer198 force-pushed the 16.0-pos_partner_location_map-add branch from 084c41c to 70eae27 Compare May 20, 2023 20:41
Copy link
Contributor

@legalsylvain legalsylvain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the name of the module should contain "google".

Comment on lines 9 to 15
}).then((response) => {
loadJS(
"https://maps.googleapis.com/maps/api/js?key=" +
response +
"&libraries=places"
);
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to add check here if resonse is not falsy.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved

@@ -0,0 +1,2 @@
This module allows to select partner address directly on map.
For this Google Maps are used.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this module heavily depends on google, it should be renamed to something like pos_partner_location_map_google. Because there are other services like google maps. For example yandex maps. https://yandex.ru/dev/maps/

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this module heavily depends on google, it should be renamed to something like pos_partner_location_map_google. Because there are other services like google maps. For example yandex maps. https://yandex.ru/dev/maps/
I think the name of the module should contain "google".

Hi @em230418 @legalsylvain thank you for the feedback! This module implements core behaviour for any map provide. Google Is just the first one on the list. This is why we have opted for such a name keeping OpenStreetMap as a "Roadmap/Todo" item So anyone could modify this module later without a need of creating a separate one for each map provider.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This module implements core behaviour for any map provide. Google Is just the first one on the list.

Do you plan to maintain behaviour of every map provider that is included to this module by others (1) or just google and OSM only (2)? If (2), you need to create seperate modules.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This module implements core behaviour for any map provide. Google Is just the first one on the list.

Do you plan to maintain behaviour of every map provider that is included to this module by others (1) or just google and OSM only (2)? If (2), you need to create seperate modules.

Yes, this module is designed to be extendable with other map providers as well

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, my question was incorrect.

So anyone could modify this module later without a need of creating a separate one for each map provider.

Do you plan to maintain behaviour of every map provider that WILL BE included to this module (pos_partner_location_map) by others (1) or just google and OSM only (2)? If (2), you need to create separate modules.

Yes, this module is designed to be extendable with other map providers as well

I don't have any doubt on this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, my question was incorrect.

So anyone could modify this module later without a need of creating a separate one for each map provider.

Do you plan to maintain behaviour of every map provider that WILL BE included to this module (pos_partner_location_map) by others (1) or just google and OSM only (2)? If (2), you need to create separate modules.

Yes, this module is designed to be extendable with other map providers as well

I don't have any doubt on this.

Yes if someone will open a PR with new map providers we will merge it when reviewed and approved.

"name": "Point of Sale - Customer Screen",
"version": "16.0.1.0.0",
"category": "Point Of Sale",
"summary": "Point of Sale - Customers can easily interact with point of sale",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Show and set partner location directly on map in POS

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved

@@ -0,0 +1,22 @@
{
"name": "Point of Sale - Customer Screen",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

POS Partner Location Map

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved

class ResPartner(models.Model):
_inherit = "res.partner"

map_partner_address = fields.Char()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This field might be misleading for a user. Because there are core Odoo fields used for the same goal.
We should parse this string into Odoo address fields instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved

Copy link
Contributor

@em230418 em230418 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also noting, that there is OCA module for google map integration. https://github.com/OCA/geospatial/tree/14.0/web_view_google_map

@ivs-cetmix
Copy link
Member

Also noting, that there is OCA module for google map integration. https://github.com/OCA/geospatial/tree/14.0/web_view_google_map

Yup we are aware of. However this one is based on the Odoo core module base_geolocalize for better compatibility

@geomer198 geomer198 marked this pull request as ready for review May 30, 2023 15:42
@geomer198
Copy link
Contributor Author

@isserver1, @legalsylvain, @em230418 Could you make code review please?

@legalsylvain
Copy link
Contributor

legalsylvain commented May 30, 2023

Hi @em230418 @legalsylvain thank you for the feedback! This module implements core behaviour for any map provide. Google Is just the first one on the list. This is why we have opted for such a name keeping OpenStreetMap as a "Roadmap/Todo" item So anyone could modify this module later without a need of creating a separate one for each map provider.

Not totally agree with that point. I think that if openstreetmap is in the roadmap, many modules should exists :

  • pos_partner_location_abstract (for common things)
  • pos_partner_location_google_map (for specific things).
  • pos_partner_location_openstreetmap (for specific things).

The module you provide is quite complex. (that is normal). So if tomorrow openstreetmap is implemented in the same module, we'll have a lot of useless code installed, that is not a good idea. (javascript asset related to google, or file like this address_google_struct.py). For maintenability reason also. If we implement osm in the same module as google, and a contributor want to migrate the module in version 17, the current design will ask to the contributor to migrate both features, even if one of the feature is not desired by the contributors.

At this step, I see two possibilities :
A) creating 2 modules, but maybe it's quite hard to split and we maybe don't know what is "common" at this step.
B) rename the current module into pos_partner_location_google_map and if an other contributor want to create a openstreetmap module, it can contribute pos_partner_location_openstreetmap_map and create a new module abstract and make the two modules (google and osm) depends on the new abstract module.

What do you think ?

@geomer198
Copy link
Contributor Author

Hi @em230418 @legalsylvain thank you for the feedback! This module implements core behaviour for any map provide. Google Is just the first one on the list. This is why we have opted for such a name keeping OpenStreetMap as a "Roadmap/Todo" item So anyone could modify this module later without a need of creating a separate one for each map provider.

Not totally agree with that point. I think that if openstreetmap is in the roadmap, many modules should exists :

* pos_partner_location_abstract (for common things)

* pos_partner_location_google_map (for specific things).

* pos_partner_location_openstreetmap (for specific things).

The module you provide is quite complex. (that is normal). So if tomorrow openstreetmap is implemented in the same module, we'll have a lot of useless code installed, that is not a good idea. (javascript asset related to google, or file like this address_google_struct.py). For maintenability reason also. If we implement osm in the same module as google, and a contributor want to migrate the module in version 17, the current design will ask to the contributor to migrate both features, even if one of the feature is not desired by the contributors.

At this step, I see two possibilities : A) creating 2 modules, but maybe it's quite hard to split and we maybe don't know what is "common" at this step. B) rename the current module into pos_partner_location_google_map and if an other contributor want to create a openstreetmap module, it can contribute pos_partner_location_openstreetmap_map and create a new module abstract and make the two modules (google and osm) depends on the new abstract module.

What do you think ?

I think that we can split the module into two separate ones pos_partner_location_base and pos_partner_location_google_map.
Can we keep both In the same pr or should make separate for each of them?

@legalsylvain
Copy link
Contributor

Can we keep both In the same pr or should make separate for each of them?

In general, in the OCA, it's recommended to separate PRs. however, in this case, module A doesn't make sense without module B, and vice versa. so i don't see any advantage in separating, you can do the refactor in the same branch. That will be easier.

Thanks a lot!

@geomer198 geomer198 marked this pull request as draft July 26, 2023 21:53
Copy link
Member

@GabbasovDinar GabbasovDinar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not testes. code LGTM, please squash commit by modules

@geomer198 geomer198 force-pushed the 16.0-pos_partner_location_map-add branch from 163f3c6 to 0605606 Compare August 8, 2023 20:49
@geomer198 geomer198 marked this pull request as ready for review August 8, 2023 20:50
Copy link
Member

@ivs-cetmix ivs-cetmix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functional ok

@ivs-cetmix
Copy link
Member

hey @legalsylvain @em230418 could you please check again? Would be great to have it merged

@legalsylvain legalsylvain added this to the 16.0 milestone Sep 26, 2023
@ivs-cetmix
Copy link
Member

@legalsylvain @em230418 I'm really sorry for bothering just didn't want to get it stalled

@legalsylvain
Copy link
Contributor

Sorry for the delay. I can take a look on runboat, but there is no link. Could you rebase, to relaunch the CI ?
thanks !

@geomer198 geomer198 force-pushed the 16.0-pos_partner_location_map-add branch from 0605606 to 1a44739 Compare November 28, 2023 17:48
Copy link
Contributor

@legalsylvain legalsylvain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General review : No functional review finally, I have no Google API key. So feature doesn't work on runboat.

Nitpicking + non blocking :
The lat / long are not well displayed in small screen. other fields added after will be maybe not well displayed. Maybe better to follow the classic rules "one field per line".

image

Nothing to do with your PR :
on runboat, I can not change data on partner form view (in PoS) and save. (changes are discarded).
Don't know why, but the bug is present also in runboat of 16.0 branch. so unrelated with your contribution. (but annoying !)

class ResConfigSettings(models.TransientModel):
_inherit = "res.config.settings"

auto_create_map_data = fields.Boolean(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question :
This fields looks to be not used (and not available in any view).
Did I missed something ?

class PosConfig(models.Model):
_inherit = "pos.config"

geolocalize_tech_name = fields.Char(compute="_compute_geolocalize")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand this field correctly, this should be a Selection field, don't you think ? (openstreetmap / googlemap). don't you think ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand this field correctly, this should be a Selection field, don't you think ? (openstreetmap / googlemap). don't you think ?

I thinks it's not better idea. This field is compute by Geo Provider configuration parameter. Provider we can update or add new what raise an error, that is why this field is just Char.

Comment on lines +9 to +19
@api.model
def _set_extended_data(self):
return {}

def _set_pos_config_parameter(self, tech_name, ext_vals=None):
_ = ext_vals or {}
for config in self:
config.geolocalize_tech_name = tech_name
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand very well why both functions are required.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand very well why both functions are required.

These functions helping fast and without problems configure new providers for POS.

_inherit = "pos.session"

def _loader_params_res_partner(self):
res = super(PosSession, self)._loader_params_res_partner()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpicking.

Suggested change
res = super(PosSession, self)._loader_params_res_partner()
res = super()._loader_params_res_partner()

) {
return true;
}
return super.accessToMap;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function call must be returned, not function itself.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function call must be returned, not function itself.

This function is a property, that is why super.accessToMap returned property value.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see.

}

onHandleMap() {
return false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returned value is not used. No need to return anything.

Comment on lines 65 to 68
this.geocoder.geocode({location: latLng}, (results, status) => {
if (status === google.maps.GeocoderStatus.OK) {
this.getFormattedAddress(results[0].place_id);
this.addrInput.el.value = results[0].formatted_address;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. geocode returns formatted address in results[0].formatted_address and here we also do something to get formatted address using "getFormattedAddress".
  2. this.address inside body getFormattedAddress could be set in 5 seconds if bad internet connection, meanwhile this.addrInput.el.value is set very quickly. Is it fine here? You are sure, we don't need to "await" for getFormattedAddress?

Comment on lines 74 to 75
update_marker(lat, lng) {
super.update_marker(lat, lng);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use "camelCase", not "snake_case". Since in js snake_case naming for methods is not popular.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I will change it.

Comment on lines 25 to 26
status = google.query_addr({"place_id": place_id})
return google.get_result() if status else {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On bad status, there should be warning indicated. At least in logs.

@geomer198
Copy link
Contributor Author

@legalsylvain @em230418 Could you check changes?

@geomer198 geomer198 force-pushed the 16.0-pos_partner_location_map-add branch 2 times, most recently from 039569b to 1601e38 Compare December 9, 2023 21:55
@@ -0,0 +1 @@
This module is base for module pos_partner_location_google_map (Google Map).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This module implements base functionality for using different map providers in POS.
It allows to select partner location directly on a map and stores selected location in the res.partner model.
It also tries to evaluate partner's address from coordinates and provides a helper function that generates location QR code.
NB: This is a core module which is meant to be used in further customisations.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Description is updated


def _compute_qr_code_url(self):
"""Compute QR Code URL for map provider"""
self.write({"qr_code_url": ""})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a non stored field. So using "write" will do no benefit here because no db tables are updated.
You should use "update" instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with you, applied proposed changes.

Copy link

@DemchukM DemchukM left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add author and license information to all files.
Everything else looks good

@geomer198 geomer198 force-pushed the 16.0-pos_partner_location_map-add branch from d7368bb to 6f28089 Compare December 16, 2023 17:11
Copy link
Member

@ivs-cetmix ivs-cetmix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finally LGTM

@legalsylvain
Copy link
Contributor

@em230418, could you update your review ?

Copy link

@DemchukM DemchukM left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@geomer198 geomer198 force-pushed the 16.0-pos_partner_location_map-add branch 3 times, most recently from 1dab65c to 37c54c5 Compare December 28, 2023 15:07
@ivs-cetmix
Copy link
Member

Hey @em230418 happy new year! Waiting for your updated review 😄

Comment on lines 47 to 73
if (this.accessToMap) {
await this.partnerMap();
} else {
this.showPopup("ErrorPopup", {
title: this.env._t("Map Error"),
body: this.env._t("Cannot access map functions!"),
});
}
} catch (e) {
if (
identifyError(e) instanceof ConnectionLostError ||
ConnectionAbortedError
) {
this.showPopup("OfflineErrorPopup", {
title: this.env._t("Network Error"),
body: this.env._t(
"Cannot access product information screen if offline."
),
});
} else {
this.showPopup("ErrorPopup", {
title: this.env._t("Unknown error"),
body: this.env._t(
"An unknown error prevents us from loading product information."
),
});
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we "await" from partnerMap, I suggest also to await "this.showPopup".

def setUp(self):
super(TestPointOfSaleCommon, self).setUp()

def test_loader_params_res_partner(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to override setUp here?

Comment on lines 19 to 21
partner = self.env["res.partner"].search([("id", "=", partner.id)])
self.assertEqual(partner.partner_latitude, 15.0)
self.assertFalse(partner.partner_longitude)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why running "search" instead of validating fields?

@geomer198
Copy link
Contributor Author

@em230418 Could you check changes?

@geomer198 geomer198 force-pushed the 16.0-pos_partner_location_map-add branch from 18d3684 to 0cbc999 Compare February 21, 2024 13:08
@ivs-cetmix
Copy link
Member

Hi @legalsylvain , would appreciate you having a look at this when you have time. Thank you in advance!)

@legalsylvain
Copy link
Contributor

Hi @legalsylvain , would appreciate you having a look at this when you have time. Thank you in advance!)

I can not test on runboat. But there are many approvals, so :

/ocabot merge nobump

@OCA-git-bot
Copy link
Contributor

Hey, thanks for contributing! Proceeding to merge this for you.
Prepared branch 16.0-ocabot-merge-pr-1002-by-legalsylvain-bump-nobump, awaiting test results.

@OCA-git-bot OCA-git-bot merged commit a34eb1e into OCA:16.0 Apr 2, 2024
5 of 7 checks passed
@OCA-git-bot
Copy link
Contributor

Congratulations, your PR was merged at ae161b8. Thanks a lot for contributing to OCA. ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants