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

17.0: Widget map and new map field #2953

Open
wants to merge 16 commits into
base: 17.0
Choose a base branch
from
Open

17.0: Widget map and new map field #2953

wants to merge 16 commits into from

Conversation

drkpkg
Copy link

@drkpkg drkpkg commented Oct 11, 2024

Previous PR: #2917

I decided do a refactor for this module and let the previous PR stay in closed and dropped.

This new widget is a combination of the map field and the map widget. It allows you
to display a map in the form and to select a location by dragging a marker on the map.

I did the pre commit and all was good this time.

The python instance of the field is fields.Map.

from odoo import models, fields, api, _

_logger = logging.getLogger(__name__)

class MyModel(models.Model):
    _name = 'my.model'

    name = fields.Char(string='Name')
    location = fields.Map(string=_('Location'))

    @api.onchange('location')
    def _onchange_location(self):
        """
        This will be called when the location is changed.
        """
        if self.location:
            _logger.info('Location: %s', self.location)

The xml file should look like this:

<odoo>
    <data>
        <record id="view_my_model_form" model="ir.ui.view">
            <field name="name">my.model.form</field>
            <field name="model">my.model</field>
            <field name="arch" type="xml">
                <form string="My Model">
                    <sheet>
                        <group>
                            <field name="name" />
                            <field name="location" widget="map" />
                        </group>
                    </sheet>
                </form>
            </field>
        </record>
    </data>
</odoo>

Note:

Sorry if i duplicate this PR but I think it is the correct way due the refactor.

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.

Hi @drkpkg. Thanks a lot for sharing. It looks very nice !

Some remarks :

  • blocking point : OCA module still contains leaflet lib. I think we should mutualize. For exemp. for exemple, create a specific module named "web_leafet_lib" and make both module depending on the "lib" module. What do you think ?

  • Question : why use lib version 1.4.0 ? it looks quite old (the latest version is 1.9.4).

  • I think that the name of the field is incorrect. (fields.Map) It doesn't contains a map but a GPS coordinate, AFAIU. So it should be something like fields.Coordinate, (or something similar)

I tried to test it locally.

first error

when trying to display a map widget

    float(value.split(",")[0])
AttributeError: 'NoneType' object has no attribute 'split'

Second error

(when trying to display a map widget)

UncaughtPromiseError > OwlError

Uncaught Promise > The following error occurred in onWillStart: "The loading of /map_field/static/lib/leaflet/leaflet.js failed"

I set the PR as draft, feel free to put it as ready, when finished. Thanks !

@legalsylvain legalsylvain marked this pull request as draft October 11, 2024 15:04
@drkpkg drkpkg marked this pull request as ready for review October 12, 2024 19:44
@drkpkg
Copy link
Author

drkpkg commented Oct 12, 2024

Hi @drkpkg. Thanks a lot for sharing. It looks very nice !

Some remarks :

  • blocking point : OCA module still contains leaflet lib. I think we should mutualize. For exemp. for exemple, create a specific module named "web_leafet_lib" and make both module depending on the "lib" module. What do you think ?
  • Question : why use lib version 1.4.0 ? it looks quite old (the latest version is 1.9.4).
  • I think that the name of the field is incorrect. (fields.Map) It doesn't contains a map but a GPS coordinate, AFAIU. So it should be something like fields.Coordinate, (or something similar)

I think create a new contribution should be better. After that we can document about the new module. This will be a good start to prevent break modules due this change.

I tried to test it locally.

first error

when trying to display a map widget

    float(value.split(",")[0])
AttributeError: 'NoneType' object has no attribute 'split'

Second error

(when trying to display a map widget)

UncaughtPromiseError > OwlError

Uncaught Promise > The following error occurred in onWillStart: "The loading of /map_field/static/lib/leaflet/leaflet.js failed"

I set the PR as draft, feel free to put it as ready, when finished. Thanks !

Yes, I was working on it and I finished when I read this, sorry!

PS: Now leaflet 1.94 is used.

legalsylvain added a commit to grap/geospatial that referenced this pull request Oct 12, 2024
…aflet_lib, to be used by other modules, like 'web_widget_map'. (see : OCA/web#2953)
@legalsylvain
Copy link
Contributor

Hi @drkpkg. I splitted the a module that contains leaflet lib in two modules here : OCA/geospatial#380

  • could you review this PR ?
  • once merged, we can port the module web_leaflet_lib in V17.0, and make your module depends on the generic module.

Note : the module provide a parameter to define the tile system to be used. (https://github.com/OCA/geospatial/blob/16.0/web_view_leaflet_map/demo/ir_config_parameter.xml#L14)
So you can use it in your module, to avoid to :

@drkpkg
Copy link
Author

drkpkg commented Oct 12, 2024

Hi @drkpkg. I splitted the a module that contains leaflet lib in two modules here : OCA/geospatial#380

  • could you review this PR ?
  • once merged, we can port the module web_leaflet_lib in V17.0, and make your module depends on the generic module.

Note : the module provide a parameter to define the tile system to be used. (https://github.com/OCA/geospatial/blob/16.0/web_view_leaflet_map/demo/ir_config_parameter.xml#L14) So you can use it in your module, to avoid to :

Dependency updated. Runboat failed, but now the module will have the dependency from web_view_leaflet_map.

@legalsylvain
Copy link
Contributor

Dependency updated. Runboat failed, but now the module will have the dependency from web_view_leaflet_map.

That can not work immediately !

note : the name is not web_view_leaflet_map but web_leaflet_lib.

thanks !

@drkpkg drkpkg changed the title Widget map with fixes. 17.0: Widget map and new map field Oct 16, 2024
@drkpkg
Copy link
Author

drkpkg commented Oct 16, 2024

Dependency updated. Runboat failed, but now the module will have the dependency from web_view_leaflet_map.

That can not work immediately !

note : the name is not web_view_leaflet_map but web_leaflet_lib.

thanks !

I did a little PR for leaflet OCA/geospatial#381
I think we can start with this, what do you think?

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

Successfully merging this pull request may close these issues.

2 participants