mirror of
https://github.com/OCA/account-financial-tools.git
synced 2025-02-02 12:47:26 +02:00
[ADD] Improve usability
This commit is contained in:
@@ -101,7 +101,7 @@ class TestAccountClearancePlan(TransactionCase):
|
||||
clearance_plan = self.create_and_fill_wizard().save()
|
||||
self.assertEqual(clearance_plan.journal_id.id, self.general_journal.id)
|
||||
self.assertEqual(clearance_plan.amount_to_allocate, 800.0)
|
||||
self.assertEqual(clearance_plan.amount_allocated, 800.0)
|
||||
self.assertEqual(clearance_plan.amount_unallocated, 0.0)
|
||||
|
||||
def test_wizard_negative_amount(self):
|
||||
clearance_plan_wizard = self.create_and_fill_wizard()
|
||||
|
||||
@@ -9,6 +9,12 @@ class AccountClearancePlanLine(models.TransientModel):
|
||||
_name = "account.clearance.plan.line"
|
||||
_description = "Clearance Plan Line"
|
||||
|
||||
name = fields.Char(
|
||||
string="Label",
|
||||
required=True,
|
||||
default=lambda self:
|
||||
self.env.user.company_id.clearance_plan_move_line_name,
|
||||
)
|
||||
clearance_plan_id = fields.Many2one(
|
||||
comodel_name="account.clearance.plan", required=True
|
||||
)
|
||||
@@ -42,17 +48,19 @@ class AccountClearancePlan(models.TransientModel):
|
||||
help="Internal note of the new journal entry that will be generated.",
|
||||
)
|
||||
amount_to_allocate = fields.Float(string="Total Amount to Allocate", readonly=True)
|
||||
amount_allocated = fields.Float(
|
||||
string="Amount Allocated", compute="_compute_amount_allocated"
|
||||
amount_unallocated = fields.Float(
|
||||
string="Amount Unallocated", compute="_compute_amount_unallocated"
|
||||
)
|
||||
clearance_plan_line_ids = fields.One2many(
|
||||
comodel_name="account.clearance.plan.line", inverse_name="clearance_plan_id"
|
||||
)
|
||||
|
||||
@api.onchange("clearance_plan_line_ids")
|
||||
def _compute_amount_allocated(self):
|
||||
def _compute_amount_unallocated(self):
|
||||
for rec in self:
|
||||
rec.amount_allocated = sum(rec.clearance_plan_line_ids.mapped("amount"))
|
||||
rec.amount_unallocated = rec.amount_to_allocate - sum(
|
||||
rec.clearance_plan_line_ids.mapped("amount")
|
||||
)
|
||||
|
||||
def _get_move_lines_from_context(self):
|
||||
active_model = self._context.get("active_model")
|
||||
@@ -124,7 +132,6 @@ class AccountClearancePlan(models.TransientModel):
|
||||
def _create_clearance_move_lines(self, move):
|
||||
account_id = self.move_line_ids.mapped("account_id")
|
||||
partner_id = self.move_line_ids.mapped("partner_id")
|
||||
move_line_name = self.env.user.company_id.clearance_plan_move_line_name
|
||||
negative_amount_residual = sum(move.line_ids.mapped("amount_residual")) < 0
|
||||
for line in self.clearance_plan_line_ids:
|
||||
self.env["account.move.line"].with_context(
|
||||
@@ -135,7 +142,7 @@ class AccountClearancePlan(models.TransientModel):
|
||||
"debit": line.amount if negative_amount_residual else 0,
|
||||
"credit": line.amount if not negative_amount_residual else 0,
|
||||
"date_maturity": line.date_maturity,
|
||||
"name": move_line_name,
|
||||
"name": line.name,
|
||||
"account_id": account_id.id,
|
||||
"partner_id": partner_id.id,
|
||||
}
|
||||
@@ -143,10 +150,8 @@ class AccountClearancePlan(models.TransientModel):
|
||||
|
||||
def confirm_plan(self):
|
||||
self.ensure_one()
|
||||
if self.amount_to_allocate != self.amount_allocated:
|
||||
raise UserError(
|
||||
_("Amount to allocate and amount allocated must be equals.")
|
||||
)
|
||||
if self.amount_unallocated != 0:
|
||||
raise UserError(_("%s still to allocate.") % self.amount_unallocated)
|
||||
|
||||
move = self.env["account.move"].create(
|
||||
{
|
||||
|
||||
@@ -11,12 +11,13 @@
|
||||
<field name="move_ref"/>
|
||||
<field name="move_narration"/>
|
||||
<field name="amount_to_allocate"/>
|
||||
<field name="amount_allocated"/>
|
||||
<field name="amount_unallocated"/>
|
||||
</group>
|
||||
<notebook>
|
||||
<page string="Clearance Plan Board">
|
||||
<field name="clearance_plan_line_ids">
|
||||
<tree editable="bottom">
|
||||
<field name="name"/>
|
||||
<field name="date_maturity"/>
|
||||
<field name="amount"/>
|
||||
</tree>
|
||||
|
||||
Reference in New Issue
Block a user