🎉 Initialize module repository

This commit is contained in:
Marc Wempe
2026-04-03 23:08:58 +02:00
commit 09e436bbe4
12 changed files with 3122 additions and 0 deletions

3
models/__init__.py Normal file
View File

@@ -0,0 +1,3 @@
from . import mvd_tcg_deck
from . import mvd_tcg_deck_line
from . import res_config_settings

9
models/constants.py Normal file
View File

@@ -0,0 +1,9 @@
"""Shared constants for the MTG OpenAI analysis layer."""
DEFAULT_MTG_OPENAI_MODEL_NAME = "gpt-5-mini"
DEFAULT_MTG_OPENAI_API_BASE_URL = "https://api.openai.com/v1"
DEFAULT_MTG_OPENAI_REQUEST_TIMEOUT_SECONDS = 120
DEFAULT_MTG_OPENAI_ROLE_BATCH_SIZE = 24
DEFAULT_MTG_OPENAI_FILL_CANDIDATE_LIMIT = 240
DEFAULT_MTG_OPENAI_FILL_BATCH_SIZE = 24
DEFAULT_MTG_OPENAI_ALTERNATIVE_CANDIDATE_LIMIT = 36

2103
models/mvd_tcg_deck.py Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,14 @@
"""OpenAI fields for MTG deck lines."""
from odoo import fields, models
class MvdTcgDeckLine(models.Model):
"""Extend deck lines with persisted OpenAI role-analysis output."""
_inherit = "mvd.tcg.deck.line"
mtg_openai_role_rationale = fields.Text(
readonly=True,
copy=False,
)

View File

@@ -0,0 +1,71 @@
"""Settings for the OpenAI-backed MTG deck analysis layer."""
from odoo import api, fields, models
from odoo.exceptions import UserError, ValidationError
from .constants import (
DEFAULT_MTG_OPENAI_API_BASE_URL,
DEFAULT_MTG_OPENAI_ALTERNATIVE_CANDIDATE_LIMIT,
DEFAULT_MTG_OPENAI_FILL_BATCH_SIZE,
DEFAULT_MTG_OPENAI_FILL_CANDIDATE_LIMIT,
DEFAULT_MTG_OPENAI_MODEL_NAME,
DEFAULT_MTG_OPENAI_REQUEST_TIMEOUT_SECONDS,
DEFAULT_MTG_OPENAI_ROLE_BATCH_SIZE,
)
class ResConfigSettings(models.TransientModel):
"""Expose OpenAI deck-analysis defaults through Odoo settings."""
_inherit = "res.config.settings"
mtg_openai_api_key = fields.Char(
string="API Key",
config_parameter="mvd_tcg_mtg_deck_openai.api_key",
)
mtg_openai_model_name = fields.Char(
string="Default Model",
config_parameter="mvd_tcg_mtg_deck_openai.model_name",
default=DEFAULT_MTG_OPENAI_MODEL_NAME,
)
mtg_openai_api_base_url = fields.Char(
string="OpenAI API Base URL",
config_parameter="mvd_tcg_mtg_deck_openai.api_base_url",
default=DEFAULT_MTG_OPENAI_API_BASE_URL,
)
mtg_openai_request_timeout_seconds = fields.Integer(
string="OpenAI Request Timeout (s)",
config_parameter="mvd_tcg_mtg_deck_openai.request_timeout_seconds",
default=DEFAULT_MTG_OPENAI_REQUEST_TIMEOUT_SECONDS,
)
mtg_openai_role_batch_size = fields.Integer(
string="Role Analysis Batch Size",
config_parameter="mvd_tcg_mtg_deck_openai.role_batch_size",
default=DEFAULT_MTG_OPENAI_ROLE_BATCH_SIZE,
)
mtg_openai_fill_candidate_limit = fields.Integer(
string="Deck Fill Candidate Limit",
config_parameter="mvd_tcg_mtg_deck_openai.fill_candidate_limit",
default=DEFAULT_MTG_OPENAI_FILL_CANDIDATE_LIMIT,
)
mtg_openai_fill_batch_size = fields.Integer(
string="Deck Fill Batch Size",
config_parameter="mvd_tcg_mtg_deck_openai.fill_batch_size",
default=DEFAULT_MTG_OPENAI_FILL_BATCH_SIZE,
)
mtg_openai_alternative_candidate_limit = fields.Integer(
string="Alternative Candidate Limit",
config_parameter="mvd_tcg_mtg_deck_openai.alternative_candidate_limit",
default=DEFAULT_MTG_OPENAI_ALTERNATIVE_CANDIDATE_LIMIT,
)
@api.constrains("mtg_openai_api_base_url")
def _check_mtg_openai_api_base_url(self):
"""Restrict the OpenAI connector to the official HTTPS API host."""
for settings in self:
try:
self.env["mvd.tcg.deck"]._mtg_openai_validate_base_url(
settings.mtg_openai_api_base_url
)
except UserError as exc:
raise ValidationError(str(exc)) from exc