Merge PR #1400 into 14.0

Signed-off-by alexis-via
This commit is contained in:
OCA-git-bot
2022-12-12 14:28:23 +00:00
3 changed files with 27 additions and 6 deletions

View File

@@ -39,7 +39,7 @@ class AccountCashDeposit(models.Model):
)
date = fields.Date(
string="Date",
readonly=True,
states={"done": [("readonly", "=", True)]},
tracking=True,
copy=False,
help="Used as date for the journal entry.",
@@ -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):
@@ -266,7 +281,7 @@ class AccountCashDeposit(models.Model):
def _prepare_account_move(self, vals):
self.ensure_one()
date = vals["date"]
date = vals.get("date") or self.date
op_type = self.operation_type
total_amount_comp_cur = self.currency_id._convert(
self.total_amount, self.company_id.currency_id, self.company_id, date
@@ -313,7 +328,7 @@ class AccountCashDeposit(models.Model):
vals = {"state": "done"}
if force_date:
vals["date"] = force_date
else:
elif not self.date:
vals["date"] = fields.Date.context_today(self)
return vals

View File

@@ -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)
)

View File

@@ -68,6 +68,10 @@
/>
<field name="cash_journal_id" />
<field name="bank_journal_id" />
<field
name="coin_amount"
attrs="{'invisible': [('operation_type', '!=', 'deposit')]}"
/>
</group>
<group name="right">
<field name="total_amount" />