Skip to content

Commit

Permalink
[ADD] website_event_attendee_fields_custom: временный модуль для мигр…
Browse files Browse the repository at this point in the history
…ации данных
  • Loading branch information
em230418 committed Nov 22, 2024
1 parent 6e215f4 commit 175d670
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 0 deletions.
24 changes: 24 additions & 0 deletions website_event_attendee_fields_custom/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
===============================
Event guest info (deprecated)
===============================

This module is required only for migrating to Odoo 17.0
After moving all fields declaration to other modules, this module can be safely removed.

Credits
=======

Contributors
------------

* `Eugene Molotov <https://github.com/em230418>`__

Sponsors
--------

* `Tribal Gathering <https://www.tribalgathering.com/>`__

Maintainers
-----------

* `IT-Projects LLC <https://it-projects.info>`__
1 change: 1 addition & 0 deletions website_event_attendee_fields_custom/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
18 changes: 18 additions & 0 deletions website_event_attendee_fields_custom/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": """Event guest info (deprecated)""",
"version": "17.0.1.0.0",
"author": "IT-Projects LLC, Eugene Molotov",
"support": "[email protected]",
"website": "https://github.com/it-projects-llc/website-addons",
"license": "AGPL-3",
"depends": [
"website_event_attendee_fields",
"partner_contact_birthdate",
"partner_firstname",
"partner_identification",
"partner_contact_nationality",
],
"data": [
"data.xml",
],
}
28 changes: 28 additions & 0 deletions website_event_attendee_fields_custom/data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="partner_firstname.field_res_partner__firstname" model="ir.model.fields">
<field name="attendee_field" eval="True" />
</record>

<record id="partner_firstname.field_res_partner__lastname" model="ir.model.fields">
<field name="attendee_field" eval="True" />
</record>

<record
id="partner_contact_nationality.field_res_partner__nationality_id"
model="ir.model.fields"
>
<field name="attendee_field" eval="True" />
</record>

<record id="field_res_partner__passport" model="ir.model.fields">
<field name="attendee_field" eval="True" />
</record>

<record
id="partner_contact_birthdate.field_res_partner__birthdate_date"
model="ir.model.fields"
>
<field name="attendee_field" eval="True" />
</record>
</odoo>
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
def migrate(cr, installed_version):
from odoo import SUPERUSER_ID, api

env = api.Environment(cr, SUPERUSER_ID, {})
q_ref = {}

cr.execute(
"""
select eaf.id, f.id, f.name, f.field_description, f.domain
from event_event_attendee_field eaf
left join ir_model_fields f on eaf.field_id = f.id
"""
)
for row in cr.fetchall():
af_id = row[0]
field_id = row[1]
field_name = row[2]
q_title = row[3]

cr.execute(
"UPDATE ir_model_fields SET attendee_field = TRUE WHERE id = %s", [field_id]
)
if field_name in ("company_name", "phone", "email", "name"):
q_ref[af_id] = {
"question_type": field_name,
"title": q_title,
}
else:
if field_name in ("firstname", "lastname"):
q_title += " as on ID"

q_ref[af_id] = {
"question_type": "partner_field",
"partner_field": field_id,
"partner_field_domain": row[4] or "[]",
"title": q_title,
}

cr.execute(
"""
select event_event_id, array_agg(event_event_attendee_field_id)
from event_event_event_event_attendee_field_rel
group by event_event_id;
"""
)
for row in cr.fetchall():
event_id = row[0]

cr.execute("DELETE FROM event_question WHERE id = %s", [event_id])

for af_id in sorted(row[1]):
vals = {
"event_id": event_id,
"sequence": 10 * af_id,
}
q_vals = q_ref.get(af_id) or {}

vals.update(q_vals)
env["event.question"].create(vals)
18 changes: 18 additions & 0 deletions website_event_attendee_fields_custom/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from odoo import fields, models


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

passport = fields.Char(
string="Passport Number",
compute=lambda s: s._compute_identification(
"passport",
"passport",
),
inverse=lambda s: s._inverse_identification(
"passport",
"passport",
),
search=lambda s, *a: s._search_identification("passport", *a),
)
3 changes: 3 additions & 0 deletions website_event_attendee_fields_custom/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"

0 comments on commit 175d670

Please sign in to comment.