account_cash_deposit: add support for loose coins in deposits
Adds a new field for loose coin amount for deposits: this field is useful if your bank has a coin counting machine that allows you to deposit coins without putting them in rolls.
This commit is contained in:
parent
e448e08371
commit
665fb16693
@ -98,6 +98,16 @@ class AccountCashDeposit(models.Model):
|
|||||||
states={"draft": [("readonly", "=", False)]},
|
states={"draft": [("readonly", "=", False)]},
|
||||||
tracking=True,
|
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(
|
total_amount = fields.Monetary(
|
||||||
compute="_compute_total_amount",
|
compute="_compute_total_amount",
|
||||||
string="Total Amount",
|
string="Total Amount",
|
||||||
@ -115,7 +125,12 @@ class AccountCashDeposit(models.Model):
|
|||||||
"name_company_unique",
|
"name_company_unique",
|
||||||
"unique(company_id, name)",
|
"unique(company_id, name)",
|
||||||
"A cash deposit/order with this reference already exists in this company.",
|
"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")
|
@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}
|
mapped_data = {x["parent_id"][0]: x["subtotal"] for x in rg_res}
|
||||||
for rec in self:
|
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")
|
@api.depends("move_id.line_ids.reconciled", "company_id")
|
||||||
def _compute_is_reconcile(self):
|
def _compute_is_reconcile(self):
|
||||||
|
@ -93,6 +93,7 @@ class TestAccountCashDeposit(TransactionCase):
|
|||||||
self.assertEqual(order.move_id.ref, order.display_name)
|
self.assertEqual(order.move_id.ref, order.display_name)
|
||||||
|
|
||||||
def test_cash_deposit(self):
|
def test_cash_deposit(self):
|
||||||
|
coin_amount = 12.42
|
||||||
deposit = (
|
deposit = (
|
||||||
self.env["account.cash.deposit"]
|
self.env["account.cash.deposit"]
|
||||||
.with_context(default_operation_type="deposit")
|
.with_context(default_operation_type="deposit")
|
||||||
@ -102,6 +103,7 @@ class TestAccountCashDeposit(TransactionCase):
|
|||||||
"currency_id": self.currency.id,
|
"currency_id": self.currency.id,
|
||||||
"cash_journal_id": self.cash_journal.id,
|
"cash_journal_id": self.cash_journal.id,
|
||||||
"bank_journal_id": self.bank_journal.id,
|
"bank_journal_id": self.bank_journal.id,
|
||||||
|
"coin_amount": coin_amount,
|
||||||
"line_ids": [
|
"line_ids": [
|
||||||
(0, 0, {"cash_unit_id": self.cash_unit_note.id, "qty": 3}),
|
(0, 0, {"cash_unit_id": self.cash_unit_note.id, "qty": 3}),
|
||||||
(0, 0, {"cash_unit_id": self.cash_unit_coinroll.id, "qty": 6}),
|
(0, 0, {"cash_unit_id": self.cash_unit_coinroll.id, "qty": 6}),
|
||||||
@ -116,7 +118,7 @@ class TestAccountCashDeposit(TransactionCase):
|
|||||||
total = (
|
total = (
|
||||||
3 * self.cash_unit_note.total_value
|
3 * self.cash_unit_note.total_value
|
||||||
+ 6 * self.cash_unit_coinroll.total_value
|
+ 6 * self.cash_unit_coinroll.total_value
|
||||||
)
|
) + coin_amount
|
||||||
self.assertFalse(
|
self.assertFalse(
|
||||||
deposit.currency_id.compare_amounts(deposit.total_amount, total)
|
deposit.currency_id.compare_amounts(deposit.total_amount, total)
|
||||||
)
|
)
|
||||||
|
@ -68,6 +68,10 @@
|
|||||||
/>
|
/>
|
||||||
<field name="cash_journal_id" />
|
<field name="cash_journal_id" />
|
||||||
<field name="bank_journal_id" />
|
<field name="bank_journal_id" />
|
||||||
|
<field
|
||||||
|
name="coin_amount"
|
||||||
|
attrs="{'invisible': [('operation_type', '!=', 'deposit')]}"
|
||||||
|
/>
|
||||||
</group>
|
</group>
|
||||||
<group name="right">
|
<group name="right">
|
||||||
<field name="total_amount" />
|
<field name="total_amount" />
|
||||||
|
Loading…
x
Reference in New Issue
Block a user