account_check_deposit: usability improvements

Add button "Get All Received Checks"
Add default value for journal_id and bank_journal_id when there is only 1 possible value
Add hide/show options on lines
Improve multi-company handling
This commit is contained in:
Alexis de Lattre
2021-04-22 12:08:09 +02:00
committed by Víctor Martínez
parent 1cd87a73f2
commit e4db25fcd4
3 changed files with 104 additions and 27 deletions

View File

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

View File

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

View File

@@ -11,7 +11,14 @@
<field name="model">account.check.deposit</field>
<field name="arch" type="xml">
<form>
<header>
<header>
<button
name="get_all_checks"
states="draft"
type="object"
class="btn-primary"
string="Get All Received Checks"
/>
<button
name="validate_deposit"
states="draft"
@@ -69,28 +76,30 @@
('debit', '>', 0),
('check_deposit_id', '=', False),
('currency_id', '=', currency_id),
('account_id', '=', journal_default_account_id)]"
('account_id', '=', journal_default_account_id),
('company_id', '=', company_id),
]"
context="{'currency': currency_id,
'journal_id': journal_id}"
>
<tree>
<field name="date" />
<field name="date_maturity" />
<field name="journal_id" />
<field name="date_maturity" optional="hide" />
<field name="journal_id" optional="hide" />
<field name="move_id" />
<field name="ref" />
<field name="ref" optional="show" />
<field name="partner_id" />
<field name="name" />
<field name="debit" sum="1" />
<field name="credit" sum="1" />
<field name="name" optional="show" />
<field name="balance" sum="1" optional="show" />
<field
name="amount_currency"
groups="base.group_multi_currency"
sum="1"
optional="hide"
/>
<field name="currency_id" invisible="1" />
<field name="company_currency_id" invisible="1" />
<field name="full_reconcile_id" />
<field name="full_reconcile_id" optional="show" />
</tree>
</field>
</group>
@@ -102,17 +111,26 @@
<field name="name">account.check.deposit.tree</field>
<field name="model">account.check.deposit</field>
<field name="arch" type="xml">
<tree decoration-info="state == 'draft'">
<field name="name" />
<tree>
<field name="name" decoration-bf="1" />
<field name="deposit_date" />
<field name="journal_id" />
<field name="bank_journal_id" />
<field name="check_count" />
<field name="total_amount" />
<field name="currency_id" groups="base.group_multi_currency" />
<field name="is_reconcile" />
<field name="total_amount" decoration-bf="1" />
<field
name="currency_id"
groups="base.group_multi_currency"
optional="show"
/>
<field name="is_reconcile" optional="show" />
<field name="company_id" groups="base.group_multi_company" />
<field name="state" />
<field
name="state"
widget="badge"
decoration-info="state == 'draft'"
decoration-success="state == 'done'"
/>
</tree>
</field>
</record>
@@ -122,6 +140,10 @@
<field name="arch" type="xml">
<search>
<field name="name" string="Checks Deposit" />
<field
name="bank_journal_id"
domain="[('type', '=', 'bank'), ('bank_account_id', '!=', False)]"
/>
<filter
name="draft"
string="Draft"
@@ -139,24 +161,34 @@
string="Journal"
context="{'group_by': 'journal_id'}"
/>
<filter
name="currency_groupby"
string="Currency"
context="{'group_by': 'currency_id'}"
/>
<filter
name="bank_journal_id_groupby"
string="Bank Account"
context="{'group_by': 'bank_journal_id'}"
/>
<filter
name="currency_groupby"
string="Currency"
context="{'group_by': 'currency_id'}"
/>
</group>
</search>
</field>
</record>
</record>
<record id="check_deposit_pivot" model="ir.ui.view">
<field name="model">account.check.deposit</field>
<field name="arch" type="xml">
<pivot>
<field name="deposit_date" interval="month" type="row" />
<field name="bank_journal_id" type="col" />
<field name="check_count" type="measure" />
</pivot>
</field>
</record>
<record id="action_check_deposit_tree" model="ir.actions.act_window">
<field name="name">Checks Deposits</field>
<field name="res_model">account.check.deposit</field>
<field name="view_mode">tree,form</field>
<field name="view_mode">tree,form,pivot</field>
</record>
<menuitem
action="action_check_deposit_tree"