diff --git a/account_check_deposit/models/account_check_deposit.py b/account_check_deposit/models/account_check_deposit.py
index 20bcb57eb..b90d64243 100644
--- a/account_check_deposit/models/account_check_deposit.py
+++ b/account_check_deposit/models/account_check_deposit.py
@@ -72,7 +72,8 @@ class AccountCheckDeposit(models.Model):
journal_id = fields.Many2one(
comodel_name="account.journal",
string="Journal",
- domain=[("type", "=", "bank"), ("bank_account_id", "=", False)],
+ domain="[('company_id', '=', company_id), ('type', '=', 'bank'), "
+ "('bank_account_id', '=', False)]",
required=True,
check_company=True,
states={"done": [("readonly", "=", True)]},
@@ -136,6 +137,21 @@ class AccountCheckDeposit(models.Model):
compute="_compute_check_deposit", store=True, string="Reconcile"
)
+ @api.model
+ def default_get(self, fields_list):
+ res = super().default_get(fields_list)
+ ajo = self.env["account.journal"]
+ company_id = res.get("company_id")
+ # pre-set journal_id and bank_journal_id is there is only one
+ domain = [("company_id", "=", company_id), ("type", "=", "bank")]
+ journals = ajo.search(domain + [("bank_account_id", "=", False)])
+ if len(journals) == 1:
+ res["journal_id"] = journals.id
+ bank_journals = ajo.search(domain + [("bank_account_id", "!=", False)])
+ if len(bank_journals) == 1:
+ res["bank_journal_id"] = bank_journals.id
+ return res
+
@api.constrains("currency_id", "check_payment_ids", "company_id")
def _check_deposit(self):
for deposit in self:
@@ -198,6 +214,7 @@ class AccountCheckDeposit(models.Model):
"journal_id": self.journal_id.id,
"date": self.deposit_date,
"ref": _("Check Deposit %s") % self.name,
+ "company_id": self.company_id.id,
}
return move_vals
@@ -205,7 +222,7 @@ class AccountCheckDeposit(models.Model):
def _prepare_move_line_vals(self, line):
assert line.debit > 0, "Debit must have a value"
return {
- "name": _("Check Ref. %s") % line.ref,
+ "name": line.ref and _("Check Ref. %s") % line.ref or False,
"credit": line.debit,
"debit": 0.0,
"account_id": line.account_id.id,
@@ -289,3 +306,29 @@ class AccountCheckDeposit(models.Model):
report = self.env.ref("account_check_deposit.report_account_check_deposit")
action = report.report_action(self)
return action
+
+ def get_all_checks(self):
+ self.ensure_one()
+ all_pending_checks = self.env["account.move.line"].search(
+ [
+ ("company_id", "=", self.company_id.id),
+ ("reconciled", "=", False),
+ ("account_id", "=", self.journal_id.payment_debit_account_id.id),
+ ("debit", ">", 0),
+ ("check_deposit_id", "=", False),
+ ("currency_id", "=", self.currency_id.id),
+ ]
+ )
+ if all_pending_checks:
+ all_pending_checks.write({"check_deposit_id": self.id})
+ else:
+ raise UserError(
+ _(
+ "There are no received checks in account '%s' in currency '%s' "
+ "that are not already in this check deposit."
+ )
+ % (
+ self.journal_id.payment_debit_account_id.display_name,
+ self.currency_id.display_name,
+ )
+ )
diff --git a/account_check_deposit/readme/USAGE.rst b/account_check_deposit/readme/USAGE.rst
index f8f516f9b..302f20474 100644
--- a/account_check_deposit/readme/USAGE.rst
+++ b/account_check_deposit/readme/USAGE.rst
@@ -5,6 +5,8 @@ invoice and click on the button *Register Payment* and select the
When you want to deposit checks to the bank, go to the menu
*Invoicing > Accounting > Miscellaneous > Check Deposit*, create a new check deposit and set the
journal *Checks Received* and select the bank account on which you want to
-credit the checks. Then click on *Add a line* to select the checks you want to
-deposit at the bank. Eventually, validate the deposit and print the report
-(you probably want to customize this report).
+credit the checks.
+
+Then click on the button *Get All Received Checks* if you want to deposit all the waiting received checks, or select the checks one by one by clicking on *Add a line*.
+
+Eventually, validate the deposit and print the report (you probably want to customize this report).
diff --git a/account_check_deposit/views/account_check_deposit_view.xml b/account_check_deposit/views/account_check_deposit_view.xml
index 4053609d8..c3b27440e 100644
--- a/account_check_deposit/views/account_check_deposit_view.xml
+++ b/account_check_deposit/views/account_check_deposit_view.xml
@@ -11,7 +11,14 @@
account.check.deposit
@@ -102,17 +111,26 @@
account.check.deposit.tree
account.check.deposit
-
-
+
+
-
-
-
+
+
+
-
+
@@ -122,6 +140,10 @@
+
-
+
-
+
+
+ account.check.deposit
+
+
+
+
+
+
+
+
Checks Deposits
account.check.deposit
- tree,form
+ tree,form,pivot