Odoo AppCenter Implementation

Hallo zusammen,

ich bin gerade dabei mir ein AppCenter für Odoo zu bauen… leider komm ich nicht hinter die Logik… was genau wie wann abgefragt und validiert wird…

Habe dazu schon kurz Kontakt mit @stefan.feilmeier aufgenommen und wir haben ausgemacht, einen eigenen Thread dafür zu erstellen.

Eventuell kann @c.lehne mir/uns da weiterhelfen ? :wink:

from odoo import http
from odoo.http import request
import logging

_logger = logging.getLogger(__name__)

class AppCenterController(http.Controller):

    @http.route('/openems_app_center/is_key_applicable', type='json', auth='user')
    def is_key_applicable(self, key, edgeId, appId=None):
        _logger.debug("Received request - key: %s, edgeId: %s, appId: %s", key, edgeId, appId)
        try:
            Key = request.env['app_center.key']
            domain = [('name', '=', key)]
            if appId:
                domain += [('app_id', '=', appId)]
            else:
                domain += [('app_id', '=', False)]  # Handle case where appId is None

            _logger.debug("Search domain: %s", domain)
            key_record = Key.search(domain, limit=1)

            if key_record:
                _logger.debug("Key record found: %s", key_record)
                # Update logic
                update_values = {
                    'is_active': True,
                    'edge_id': edgeId if not key_record.edge_id else key_record.edge_id
                }
                if appId:
                    update_values['usage_count'] = key_record.usage_count + 1
                    _logger.debug("Incrementing usage count for key record: %s", key_record)

                key_record.sudo().write(update_values)

                return {
                    'is_applicable': True,
                    'additionalInfo': {
                        'keyId': str(key_record.id),
                        'bundles': self.get_bundles(key_record),
                        'registrations': self.get_registrations(key_record),
                        'usages': self.get_usages(key_record)
                    }
                }
            else:
                _logger.warning("No key record found for key: %s", key)
                return {'is_applicable': False, 'additionalInfo': {}}

        except Exception as e:
            _logger.error("Error in is_key_applicable: %s", e)
            return {'error': str(e)}


    def get_bundles(self, key_record):
        # Hypothetical implementation: Retrieve bundles linked to the key
        BundleModel = request.env['app_center.bundle']
        bundles = BundleModel.search([('key_id', '=', key_record.id)])
        return [{'bundleId': bundle.id, 'name': bundle.name} for bundle in bundles]

    def get_registrations(self, key_record):
        # Hypothetical implementation: Retrieve registrations linked to the key
        RegistrationModel = request.env['app_center.registration']
        registrations = RegistrationModel.search([('key_id', '=', key_record.id)])
        return [{'edgeId': registration.edge_id, 'appId': registration.app_id} for registration in registrations]

    def get_usages(self, key_record):
        if not key_record:
            return []
        return [{
            'appId': key_record.app_id,
            'installedInstances': key_record.usage_count
        }]

Hab mir einmal kurz ein eigenes Odoo Modul erstellt aber komme irgendwie nicht ganz weiter…