🎉 Initialize module repository
This commit is contained in:
2
wizards/__init__.py
Normal file
2
wizards/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
from . import mvd_tcg_mtg_lookup
|
||||
from . import mvd_tcg_mtg_scryfall_import
|
||||
59
wizards/mvd_tcg_mtg_lookup.py
Normal file
59
wizards/mvd_tcg_mtg_lookup.py
Normal file
@@ -0,0 +1,59 @@
|
||||
"""Transient helpers for ad-hoc MTG Scryfall lookups."""
|
||||
|
||||
from odoo import _, fields, models
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
|
||||
class MvdTcgMtgLookup(models.TransientModel):
|
||||
"""Import one MTG card reference from Scryfall."""
|
||||
|
||||
_name = "mvd.tcg.mtg.lookup"
|
||||
_description = "MTG Card Lookup"
|
||||
|
||||
query = fields.Char(required=True)
|
||||
lookup_mode = fields.Selection(
|
||||
selection=[
|
||||
("url", "Direct Scryfall URL or card id"),
|
||||
("exact", "Exact card name"),
|
||||
("fuzzy", "Fuzzy card name"),
|
||||
],
|
||||
default="fuzzy",
|
||||
required=True,
|
||||
)
|
||||
|
||||
def action_lookup_card(self):
|
||||
"""Look up one MTG card on Scryfall and open the upserted record.
|
||||
|
||||
Returns:
|
||||
dict: Form action for the upserted MTG card.
|
||||
|
||||
Raises:
|
||||
UserError: If the lookup query is empty or returns no card.
|
||||
"""
|
||||
self.ensure_one()
|
||||
self.env["mvd.tcg.mtg.scryfall.api"]._mtg_scryfall_check_manager_access()
|
||||
|
||||
query = (self.query or "").strip()
|
||||
if not query:
|
||||
raise UserError(_("Enter a card name or Scryfall card URL first."))
|
||||
|
||||
scryfall_api = self.env["mvd.tcg.mtg.scryfall.api"]
|
||||
payloads = scryfall_api.resolve_lookup_payloads(query, self.lookup_mode)
|
||||
mtg_card = self.env["mvd.tcg.card"].mtg_scryfall_upsert_group_from_payloads(
|
||||
payloads
|
||||
)
|
||||
if not mtg_card:
|
||||
raise UserError(_("No MTG card could be created from the Scryfall payload."))
|
||||
|
||||
action = self.env.ref("mvd_tcg_mtg.mvd_tcg_mtg_card_action").read()[0]
|
||||
action.update(
|
||||
{
|
||||
"view_mode": "form",
|
||||
"views": [
|
||||
(self.env.ref("mvd_tcg_mtg.mvd_tcg_mtg_card_view_form").id, "form")
|
||||
],
|
||||
"res_id": mtg_card.id,
|
||||
}
|
||||
)
|
||||
action.pop("domain", None)
|
||||
return action
|
||||
97
wizards/mvd_tcg_mtg_scryfall_import.py
Normal file
97
wizards/mvd_tcg_mtg_scryfall_import.py
Normal file
@@ -0,0 +1,97 @@
|
||||
"""Transient helpers for controlled MTG Scryfall set and batch imports."""
|
||||
|
||||
from odoo import _, fields, models
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
|
||||
class MvdTcgMtgScryfallImport(models.TransientModel):
|
||||
"""Collect one controlled MTG Scryfall set or batch import request."""
|
||||
|
||||
_name = "mvd.tcg.mtg.scryfall.import"
|
||||
_description = "MTG Scryfall Import"
|
||||
|
||||
import_mode = fields.Selection(
|
||||
selection=[
|
||||
("set", "Set Import"),
|
||||
("batch", "Batch Import"),
|
||||
],
|
||||
default="set",
|
||||
required=True,
|
||||
)
|
||||
set_codes_text = fields.Text(
|
||||
string="Set Codes",
|
||||
help="One set code per line or separated by commas.",
|
||||
)
|
||||
batch_input = fields.Text(
|
||||
string="Cards",
|
||||
help="One card reference per line. The selected lookup mode controls how each line is interpreted.",
|
||||
)
|
||||
lookup_mode = fields.Selection(
|
||||
selection=[
|
||||
("url", "Card Links or IDs"),
|
||||
("exact", "Exact Card Names"),
|
||||
("fuzzy", "Flexible Name Matching"),
|
||||
],
|
||||
default="url",
|
||||
required=True,
|
||||
string="Lookup Mode",
|
||||
)
|
||||
language_codes = fields.Char(
|
||||
default=lambda self: ",".join(
|
||||
self.env["mvd.tcg.mtg.scryfall.api"].get_import_language_codes()
|
||||
),
|
||||
required=True,
|
||||
help="Comma-separated Scryfall language codes imported for each print group.",
|
||||
)
|
||||
max_cards_per_set = fields.Integer(
|
||||
default=lambda self: self.env[
|
||||
"mvd.tcg.mtg.scryfall.api"
|
||||
].get_default_max_cards_per_set(),
|
||||
help="Optional maximum number of print groups imported per set. Use 0 for no limit.",
|
||||
)
|
||||
include_tokens = fields.Boolean(
|
||||
default=lambda self: self.env[
|
||||
"mvd.tcg.mtg.scryfall.api"
|
||||
].get_default_include_tokens(),
|
||||
help="Include token cards in set imports.",
|
||||
)
|
||||
|
||||
def action_import_cards(self):
|
||||
"""Create and execute one controlled Scryfall import run.
|
||||
|
||||
Returns:
|
||||
dict: Form action for the created import run.
|
||||
|
||||
Raises:
|
||||
UserError: If the selected import mode has no usable input.
|
||||
"""
|
||||
self.ensure_one()
|
||||
self.env["mvd.tcg.mtg.scryfall.api"]._mtg_scryfall_check_manager_access()
|
||||
|
||||
if self.import_mode == "set":
|
||||
input_text = (self.set_codes_text or "").strip()
|
||||
if not input_text:
|
||||
raise UserError(_("Enter at least one set code first."))
|
||||
if not self.env["mvd.tcg.mtg.scryfall.api"].parse_set_codes(input_text):
|
||||
raise UserError(_("Enter at least one valid set code first."))
|
||||
else:
|
||||
input_text = (self.batch_input or "").strip()
|
||||
if not input_text:
|
||||
raise UserError(_("Enter at least one batch lookup first."))
|
||||
if not self.env["mvd.tcg.mtg.scryfall.api"].parse_batch_queries(
|
||||
input_text,
|
||||
default_lookup_mode=self.lookup_mode,
|
||||
):
|
||||
raise UserError(_("Enter at least one valid batch lookup first."))
|
||||
|
||||
import_run = self.env["mvd.tcg.mtg.scryfall.import.run"].create(
|
||||
{
|
||||
"import_mode": self.import_mode,
|
||||
"lookup_mode": self.lookup_mode if self.import_mode == "batch" else False,
|
||||
"input_text": input_text,
|
||||
"language_codes": self.language_codes,
|
||||
"max_cards_per_set": self.max_cards_per_set if self.import_mode == "set" else 0,
|
||||
"include_tokens": self.include_tokens if self.import_mode == "set" else False,
|
||||
}
|
||||
)
|
||||
return import_run.action_execute_import()
|
||||
Reference in New Issue
Block a user