[IMP] account_payment_order: add payment lines smart button on invoice

This commit is contained in:
Luc De Meyer
2023-06-23 20:46:49 +02:00
parent 2cbf1d5f04
commit 0137e46889
3 changed files with 59 additions and 0 deletions

View File

@@ -27,6 +27,7 @@ class AccountMove(models.Model):
states={"draft": [("readonly", False)]},
default="none",
)
payment_line_count = fields.Integer(compute="_compute_payment_line_count")
@api.depends("payment_mode_id", "line_ids", "line_ids.payment_mode_id")
def _compute_payment_order_ok(self):
@@ -38,6 +39,14 @@ class AccountMove(models.Model):
payment_mode = move.payment_mode_id
move.payment_order_ok = payment_mode.payment_order_ok
def _compute_payment_line_count(self):
for move in self:
move.payment_line_count = len(
self.env["account.payment.line"]._search(
[("move_line_id", "in", self.line_ids.ids)]
)
)
def _get_payment_order_communication_direct(self):
"""Retrieve the communication string for this direct item."""
communication = self.payment_reference or self.ref or self.name or ""
@@ -207,3 +216,20 @@ class AccountMove(models.Model):
}
)
return action
def action_payment_lines(self):
self.ensure_one()
action = self.env["ir.actions.act_window"]._for_xml_id(
"account_payment_order.account_payment_line_action"
)
action.update(
{
"domain": [("move_line_id", "in", self.line_ids.ids)],
"context": dict(
self.env.context,
account_payment_line_main_view=1,
form_view_ref="account_payment_order.account_payment_line_form_readonly",
),
}
)
return action

View File

@@ -39,6 +39,21 @@
]}"
/>
</button>
<div name="button_box" position="inside">
<button
name="action_payment_lines"
type="object"
attrs="{'invisible': [('payment_line_count', '=', 0)]}"
icon="fa-bars"
help="Payment Order Lines"
>
<field
string="Payment Lines"
name="payment_line_count"
widget="statinfo"
/>
</button>
</div>
<field name="payment_mode_id" position="after">
<field name="payment_order_ok" invisible="1" />
</field>

View File

@@ -7,6 +7,7 @@
<form string="Payment Lines">
<group name="main" col="2">
<group name="left">
<field name="state" invisible="1" />
<field name="company_id" invisible="1" />
<field
name="order_id"
@@ -50,6 +51,23 @@
</form>
</field>
</record>
<record id="account_payment_line_form_readonly" model="ir.ui.view">
<field name="name">account.payment.line.form.readonly</field>
<field name="model">account.payment.line</field>
<field
name="inherit_id"
ref="account_payment_order.account_payment_line_form"
/>
<field name="mode">primary</field>
<field name="arch" type="xml">
<form position="attributes">
<attribute name="create">0</attribute>
<attribute name="edit">0</attribute>
<attribute name="delete">0</attribute>
<attribute name="duplicate">0</attribute>
</form>
</field>
</record>
<record id="account_payment_line_tree" model="ir.ui.view">
<field name="name">account.payment.line.tree</field>
<field name="model">account.payment.line</field>