Skip to content

[IMP] website_event, website_event_sale: adapt JsonLd builder#5117

Draft
gppa-odoo wants to merge 1 commit intomaster-imp-website-schema-POC-design-gppafrom
master-schema-org-website-event-gppa
Draft

[IMP] website_event, website_event_sale: adapt JsonLd builder#5117
gppa-odoo wants to merge 1 commit intomaster-imp-website-schema-POC-design-gppafrom
master-schema-org-website-event-gppa

Conversation

@gppa-odoo
Copy link
Copy Markdown

No description provided.

@robodoo
Copy link
Copy Markdown

robodoo commented Apr 20, 2026

This PR targets the un-managed branch odoo-dev/odoo:master-imp-website-schema-POC-design-gppa, it needs to be retargeted before it can be merged.

@gppa-odoo gppa-odoo force-pushed the master-schema-org-website-event-gppa branch 2 times, most recently from 7e8d96b to d939689 Compare April 20, 2026 05:43
@gppa-odoo gppa-odoo changed the title [IMP] website_event: dummy push [IMP] website_event, website_event_sale: adapt JsonLd builder Apr 20, 2026
@gppa-odoo gppa-odoo force-pushed the master-schema-org-website-event-gppa branch 6 times, most recently from 931e756 to ffa2114 Compare April 20, 2026 05:53
"is_part_of": JsonLd("Organization", {"id": f"{base_url}/#organization"}),
})

def _get_breadcrumb_items(self):
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

def _get_breadcrumb_items(self, is_detail_page=False):
from website_sale, use this instead

@gppa-odoo gppa-odoo force-pushed the master-imp-website-schema-POC-design-gppa branch 4 times, most recently from 1c45c2e to 6290119 Compare April 27, 2026 10:03
Comment on lines +771 to +772
website = self.env['website'].get_current_website()
base_url = website.get_base_url()
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

you can direcly get the base url from self.get_base_url.

(website.name, base_url),
(self.env._("Events"), f"{base_url}/event"),
]
schemas.append(self._get_breadcrumb_structured_data(items))
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Instead doing this, can't we simply prepare the breadcrumb in same method _get_breadcrumb_items?

Simply pass the same params, is_details_page to this mehtod,

    def _get_breadcrumb_items(self, is_detail_page): 
        """Return breadcrumb items for a single event page."""
        self.ensure_one()
        website = self.env['website'].get_current_website()
        base_url = website.get_base_url()
        breadcrumb_items =  [
            (website.name, base_url),
            (self.env._("Events"), f"{base_url}/event"),
            (self.name, f"{base_url}{self.website_url}"),
        ]
        if is_detail_page:
            breadcrumb_items.append( (self.name, f"{base_url}{self.website_url}"))

        return breadcrumb_items

Doing this, current method will be simplified to

    def _to_structured_data(self, is_detail_page=False):
        schemas = super()._to_structured_data(is_detail_page=is_detail_page)
        breadcrumb_items = self._get_breadcrumb_items(is_detail_page)
        schemas.append(self._get_breadcrumb_structured_data(items))
        if is_detail_page:
            self.ensure_one()
            if event_schema := self._to_structured_data_event():
                schemas.append(event_schema)
        else:
            schemas.append(self._to_structured_data_collectionpage())
        return JsonLd.render_structured_data(schemas)
        

@gppa-odoo gppa-odoo force-pushed the master-imp-website-schema-POC-design-gppa branch 13 times, most recently from 3ca13a8 to 2ad4403 Compare April 30, 2026 11:32
@gppa-odoo gppa-odoo force-pushed the master-imp-website-schema-POC-design-gppa branch 4 times, most recently from cc131be to b5b3f8b Compare May 4, 2026 06:15
@gppa-odoo gppa-odoo force-pushed the master-schema-org-website-event-gppa branch 4 times, most recently from 9e46f0f to f4b8258 Compare May 4, 2026 07:05
@gppa-odoo gppa-odoo force-pushed the master-imp-website-schema-POC-design-gppa branch 4 times, most recently from 09e121f to a2ab279 Compare May 5, 2026 06:10
@gppa-odoo gppa-odoo force-pushed the master-schema-org-website-event-gppa branch 3 times, most recently from 1a7b5ea to 2c13541 Compare May 5, 2026 08:59
@gppa-odoo gppa-odoo force-pushed the master-imp-website-schema-POC-design-gppa branch 3 times, most recently from fa2ea77 to 8f90297 Compare May 5, 2026 10:10
@gppa-odoo gppa-odoo force-pushed the master-schema-org-website-event-gppa branch from 2c13541 to 1b33e0c Compare May 5, 2026 10:11
"startDate": JsonLd.to_iso_datetime(self.date_begin),
}
nested_schema_data: dict[str, JsonLd | list[JsonLd] | None] = {}
if image_url := website.image_url(self, 'image_1920'):
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
if image_url := website.image_url(self, 'image_1920'):
if image_url := self.website_id.image_url(self, 'image_1920'):

?

if self.organizer_id:
organizer_sudo = self.organizer_id.sudo()
if organizer_sudo == self.env.company.partner_id:
base_url = self.env['website'].get_current_website().get_base_url()
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
base_url = self.env['website'].get_current_website().get_base_url()
base_url = self.get_base_url()

:rtype: JsonLd | None
"""
self.ensure_one()
event_data = self._to_structured_data_summary_event()
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
event_data = self._to_structured_data_summary_event()
event_jsonld = self._to_structured_data_summary_event()

Comment on lines +708 to +715
if organizer_sudo == self.env.company.partner_id:
base_url = self.env['website'].get_current_website().get_base_url()
nested_schema_data["organizer"] = JsonLd("Organization", {"@id": f"{base_url}/#organization"})
else:
organizer_jsonld = JsonLd("Organization", {"name": organizer_sudo.name})
if organizer_sudo.website:
organizer_jsonld.set({"url": organizer_sudo.website})
nested_schema_data["organizer"] = organizer_jsonld
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
if organizer_sudo == self.env.company.partner_id:
base_url = self.env['website'].get_current_website().get_base_url()
nested_schema_data["organizer"] = JsonLd("Organization", {"@id": f"{base_url}/#organization"})
else:
organizer_jsonld = JsonLd("Organization", {"name": organizer_sudo.name})
if organizer_sudo.website:
organizer_jsonld.set({"url": organizer_sudo.website})
nested_schema_data["organizer"] = organizer_jsonld
organizer_data = {}
if organizer_sudo == self.env.company.partner_id:
organizer_data["@id"] = f"{self.get_base_url()}/#organization"
else:
organizer_data["name"] = organizer_sudo.name
if organizer_sudo.website:
organizer_data["name"] = organizer_sudo.website
nested_schema_data["organizer"] = JsonLd("Organization", organizer_data)

or

Suggested change
if organizer_sudo == self.env.company.partner_id:
base_url = self.env['website'].get_current_website().get_base_url()
nested_schema_data["organizer"] = JsonLd("Organization", {"@id": f"{base_url}/#organization"})
else:
organizer_jsonld = JsonLd("Organization", {"name": organizer_sudo.name})
if organizer_sudo.website:
organizer_jsonld.set({"url": organizer_sudo.website})
nested_schema_data["organizer"] = organizer_jsonld
organizer_data = {}
if organizer_sudo == self.env.company.partner_id:
organizer_data["@id"] = f"{self.get_base_url()}/#organization"
else:
organizer_data = {
"name": organizer_sudo.name,
"url": organizer_sudo.website
}
nested_schema_data["organizer"] = JsonLd("Organization", organizer_data)

"eventStatus": f"https://schema.org/{event_status}",
"eventAttendanceMode": "https://schema.org/OfflineEventAttendanceMode",
}
if description is not None:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
if description is not None:
if description:

nested_schema_data["organizer"] = organizer_jsonld

event_status = "EventCancelled" if self.kanban_state == 'cancel' else "EventScheduled"
offers_jsonld = [self._to_structured_data_ticket_offer(ticket) for ticket in self.event_ticket_ids]
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
offers_jsonld = [self._to_structured_data_ticket_offer(ticket) for ticket in self.event_ticket_ids]
offers_jsonlds = self._to_structured_data_ticket_offer()

You can move this loop inside the offers.

def _to_structured_data_ticket_offer(self, ticket):
    # builds ONE offer
    ...

def _to_structured_data_ticket_offers(self):
    return [
        self._to_structured_data_ticket_offer(ticket)
        for ticket in self.event_ticket_ids
    ]

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

/addons/website_event_sale/models/event_event.py

We are using this inside this file, It is lot more easier to extend when it's not returning a list.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

It is still not returning a list, you can always extend _to_structured_data_ticket_offer.

"validFrom": JsonLd.to_iso_datetime(ticket.start_sale_datetime),
"validThrough": JsonLd.to_iso_datetime(ticket.end_sale_datetime),
})
if availability == "https://schema.org/InStock":
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Instead this I would prefer to create a variable name is_available

is_available = not (ticket.is_sold_out or is_expired)

return JsonLd("CollectionPage", schema_data).add_nested(nested_schema_data)

def _get_breadcrumb_items(self, is_detail_page=False):
"""Return breadcrumb items for a single event page.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
"""Return breadcrumb items for a single event page.
"""Return breadcrumb items for a event page.

:rtype: list[JsonLd]
"""
schemas = super()._build_structured_data(is_detail_page=is_detail_page)
breadcrumb = self._build_breadcrumb_schema(
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
breadcrumb = self._build_breadcrumb_schema(
breadcrumb_jsonld = self._build_breadcrumb_schema(

)
if is_detail_page:
self.ensure_one()
if event_schema := self._to_structured_data_event():
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

isn;'t event_schema holds the jsonld? It's becoming confusing when sometime you refer it as schema & sometime as *_jsonld.

  • we can refer the main schema as schema & rest *_jsonld. like here, schemas will be same ( collection of all the schemas) & rest will become *_jsonld, like event_jsonld.

Comment on lines +17 to +18
website = self.env['website'].get_current_website()
if website.show_line_subtotals_tax_selection == 'tax_excluded':
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
website = self.env['website'].get_current_website()
if website.show_line_subtotals_tax_selection == 'tax_excluded':
if self.website_id.show_line_subtotals_tax_selection == 'tax_excluded':

use website_id , wherever available.

@gppa-odoo gppa-odoo force-pushed the master-schema-org-website-event-gppa branch from 1b33e0c to 0a8247e Compare May 6, 2026 05:02
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.

3 participants