Skip to content

Commit

Permalink
[IMP] lcc_lokavaluto_app_connection: change credit/debit pages displa…
Browse files Browse the repository at this point in the history
…y rules
  • Loading branch information
Stéphan Sainléger committed Oct 23, 2024
1 parent 60b87ef commit 0b1b87c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
30 changes: 16 additions & 14 deletions lcc_lokavaluto_app_connection/models/account_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,15 @@ class AccountInvoice(models.Model):
credit_request_ids = fields.One2many(
"credit.request", "invoice_id", string="Credit Requests"
)
has_credit_requests = fields.Boolean(
compute="_compute_has_credit_requests", store=False
)
debit_request_ids = fields.Many2many(
"debit.request", compute="_compute_debit_request_ids", string="Debit Requests"
)
has_debit_requests = fields.Boolean(
compute="_compute_has_debit_requests", store=False
)
global_credit_status = fields.Selection(
[
("todo", "To do"),
Expand All @@ -32,18 +38,23 @@ class AccountInvoice(models.Model):
global_lcc_amount_to_credit = fields.Float(
string="LCC amount to credit", compute="_compute_global_lcc_amounts"
)
digital_currency_invoice_type = fields.Selection(
[("none", "None"), ("credit", "Credit"), ("debit", "Debit")],
string="Digital Currency Invoice Type",
compute="_compute_digital_currency_invoice_type",
)

@api.depends("credit_request_ids")
def _compute_global_credit_status(self):
self.global_credit_status = status(
r.state == "done" for r in self.credit_request_ids
)

@api.depends("credit_request_ids")
def _compute_has_credit_requests(self):
for record in self:
record.has_credit_requests = bool(record.credit_request_ids)

@api.depends("debit_request_ids")
def _compute_has_debit_requests(self):
for record in self:
record.has_debit_requests = bool(record.debit_request_ids)

@api.depends("credit_request_ids")
def _compute_global_lcc_amounts(self):
done_requests = self.credit_request_ids.filtered(lambda x: x.state == "done")
Expand Down Expand Up @@ -78,15 +89,6 @@ def _compute_debit_request_ids(self):
]
)

@api.depends("debit_request_ids", "credit_request_ids")
def _compute_digital_currency_invoice_type(self):
if self.debit_request_ids:
self.digital_currency_invoice_type = "debit"
elif self.credit_request_ids:
self.digital_currency_invoice_type = "credit"
else:
self.digital_currency_invoice_type = "none"

def _invoice_paid_hook(self):
res = super(AccountInvoice, self)._invoice_paid_hook()
for invoice in self:
Expand Down
7 changes: 4 additions & 3 deletions lcc_lokavaluto_app_connection/views/account_invoice.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
<field name="inherit_id" ref="account.view_move_form" />
<field name="arch" type="xml">
<xpath expr="//notebook" position="inside">
<field name="digital_currency_invoice_type" invisible="1" />
<field name="has_credit_requests" invisible="1" />
<field name="has_debit_requests" invisible="1" />
<page name="credit_requests" string="Credit Request"
attrs="{'invisible': [('digital_currency_invoice_type', '!=', 'credit')]}">
attrs="{'invisible': [('has_credit_requests', '=', False)]}">
<div class="alert alert-success" role="alert"
attrs="{'invisible': [('global_lcc_amount_credited', '=', 0)]}">
<field name="global_lcc_amount_credited" readonly="True" /> units have been
Expand All @@ -28,7 +29,7 @@
</field>
</page>
<page name="debit_requests" string="Debit Request"
attrs="{'invisible': [('digital_currency_invoice_type', '!=', 'debit')]}">
attrs="{'invisible': [('has_debit_requests', '=', False)]}">
<field name="debit_request_ids" nolabel="1"
groups="lcc_lokavaluto_app_connection.group_wallet_accounts_manager">
<tree create="false" delete="false">
Expand Down

0 comments on commit 0b1b87c

Please sign in to comment.