Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
##############################################################################
#
# Xbus Common, for Odoo
# Copyright © 2023 XCG Consulting <https://xcg-consulting.fr>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from odoo import fields, models, tools
class XbusMessage(models.Model):
"""Represents an Xbus message."""
_name = "xbus.message"
_description = "Xbus Message"
# No creation or automatic column for this table, it is used with an external system
_auto = False
_log_access = False
_order = "envelope_id DESC, id DESC"
_rec_name = "uid"
envelope_id = fields.Many2one(
string="Envelope", comodel_name="xbus.envelope", required=True
)
# When setting the uid, the checksum value needs to be computed too.
# As checksum is a bigint, there is no field type matching it so it is not done
# there, instead it is expected the UID will never be written and that the field
# is only used to display information
uid = fields.Char(string="UID", readonly=True)
type = fields.Selection([], required=True)
header = fields.Binary(attachment=False)
body = fields.Binary(attachment=False, required=True)
link_ids = fields.One2many(
comodel_name="xbus.message.link",
string="Linked Records",
inverse_name="message_id",
)
def init(self):
super().init()
self.env.cr.execute(
"""CREATE TABLE IF NOT EXISTS xbus_message (
id serial primary key,
envelope_id integer not null REFERENCES xbus_envelope(id),
uid uuid null,
type character varying not null,
header bytea null,
body bytea not null,
checksum bigint not null default 0
)"""
)
tools.create_index(
self._cr, "xbus_message_envelope_id_index", self._table, ["envelope_id"]
)
tools.create_index(self._cr, "xbus_message_uid_index", self._table, ["uid"])
tools.create_index(self._cr, "xbus_message_type_index", self._table, ["type"])