Skip to content

Commit

Permalink
[NEW] lcc_comchain_base: add discard account request
Browse files Browse the repository at this point in the history
  • Loading branch information
SeddikKadi authored and vaab committed Feb 18, 2024
1 parent fb7a8cf commit 554c043
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lcc_comchain_base/datamodel/comchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,25 @@ class ComchainActivateInfo(Datamodel):
recipient_id = fields.Integer(required=False)


class ComchainDiscardInfo(Datamodel):
_name = "comchain.discard.info"

address = fields.String(required=True)
recipient_id = fields.Integer(required=True)


class ComchainActivateList(Datamodel):
_name = "comchain.activate.list"

accounts = fields.List(NestedModel("comchain.activate.info"), required=True)


class ComchainDiscardList(Datamodel):
_name = "comchain.discard.list"

accounts = fields.List(NestedModel("comchain.discard.info"), required=True)


class ComchainAccountInfo(Datamodel):
_name = "comchain.account"

Expand Down
25 changes: 25 additions & 0 deletions lcc_comchain_base/services/comchain_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from odoo.addons.base_rest import restapi
from odoo.addons.base_rest_datamodel.restapi import Datamodel
from odoo.addons.component.core import Component
from odoo.http import request

_logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -93,6 +94,30 @@ def activate(self, params):
wallet_id.activate(account.type, account.credit_min, account.credit_max)
return True

@restapi.method(
[(["/discard"], "POST")],
input_param=Datamodel("comchain.discard.list"),
)
def discard(self, params):
"""Discard comchain accounts"""
wallet_obj = self.env["res.partner.backend"]
for account in params.accounts:
wallet_id = wallet_obj.search(
[
("comchain_id", "=", account.address),
("partner_id", "=", account.recipient_id),
],
limit=2,
)
if len(wallet_id) == 0:
raise NotFound("Wallet %s not found in Odoo" % account.address)
if len(wallet_id) > 1:
raise NotImplementedError(
"Several wallets retrieved with same address. Please contact your administrator"
)
wallet_id.write({"active": False})
return True

@restapi.method(
[(["/credit"], "POST")],
input_param=Datamodel("comchain.credit.info"),
Expand Down

0 comments on commit 554c043

Please sign in to comment.