diff --git a/account_cash_deposit/models/account_cash_deposit.py b/account_cash_deposit/models/account_cash_deposit.py
index 5d7750c0..4a76008c 100644
--- a/account_cash_deposit/models/account_cash_deposit.py
+++ b/account_cash_deposit/models/account_cash_deposit.py
@@ -98,6 +98,16 @@ class AccountCashDeposit(models.Model):
states={"draft": [("readonly", "=", False)]},
tracking=True,
)
+ coin_amount = fields.Monetary(
+ string="Loose Coin Amount",
+ currency_field="currency_id",
+ readonly=True,
+ states={"draft": [("readonly", "=", False)]},
+ tracking=True,
+ help="If your bank has a coin counting machine, enter the total amount "
+ "of coins counted by the machine instead of creating a line for each type "
+ "of coin.",
+ )
total_amount = fields.Monetary(
compute="_compute_total_amount",
string="Total Amount",
@@ -115,7 +125,12 @@ class AccountCashDeposit(models.Model):
"name_company_unique",
"unique(company_id, name)",
"A cash deposit/order with this reference already exists in this company.",
- )
+ ),
+ (
+ "coin_amount_positive",
+ "CHECK(coin_amount >= 0)",
+ "The loose coin amount must be positive or null.",
+ ),
]
@api.constrains("cash_journal_id", "currency_id")
@@ -189,7 +204,7 @@ class AccountCashDeposit(models.Model):
)
mapped_data = {x["parent_id"][0]: x["subtotal"] for x in rg_res}
for rec in self:
- rec.total_amount = mapped_data.get(rec.id, 0)
+ rec.total_amount = mapped_data.get(rec.id, 0) + rec.coin_amount
@api.depends("move_id.line_ids.reconciled", "company_id")
def _compute_is_reconcile(self):
diff --git a/account_cash_deposit/tests/test_cash_deposit.py b/account_cash_deposit/tests/test_cash_deposit.py
index c911fea8..ed351b5f 100644
--- a/account_cash_deposit/tests/test_cash_deposit.py
+++ b/account_cash_deposit/tests/test_cash_deposit.py
@@ -93,6 +93,7 @@ class TestAccountCashDeposit(TransactionCase):
self.assertEqual(order.move_id.ref, order.display_name)
def test_cash_deposit(self):
+ coin_amount = 12.42
deposit = (
self.env["account.cash.deposit"]
.with_context(default_operation_type="deposit")
@@ -102,6 +103,7 @@ class TestAccountCashDeposit(TransactionCase):
"currency_id": self.currency.id,
"cash_journal_id": self.cash_journal.id,
"bank_journal_id": self.bank_journal.id,
+ "coin_amount": coin_amount,
"line_ids": [
(0, 0, {"cash_unit_id": self.cash_unit_note.id, "qty": 3}),
(0, 0, {"cash_unit_id": self.cash_unit_coinroll.id, "qty": 6}),
@@ -116,7 +118,7 @@ class TestAccountCashDeposit(TransactionCase):
total = (
3 * self.cash_unit_note.total_value
+ 6 * self.cash_unit_coinroll.total_value
- )
+ ) + coin_amount
self.assertFalse(
deposit.currency_id.compare_amounts(deposit.total_amount, total)
)
diff --git a/account_cash_deposit/views/account_cash_deposit.xml b/account_cash_deposit/views/account_cash_deposit.xml
index 10efbf3a..e8a74d41 100644
--- a/account_cash_deposit/views/account_cash_deposit.xml
+++ b/account_cash_deposit/views/account_cash_deposit.xml
@@ -68,6 +68,10 @@
/>
+