Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[15.0][MIG] account_payment_batch_process: clean wizard layout #785

Open
wants to merge 2 commits into
base: 15.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 30 additions & 26 deletions account_payment_batch_process/wizard/account_payment_register.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
)
num2words = None


MAP_INVOICE_TYPE_PARTNER_TYPE = {
"out_invoice": "customer",
"out_refund": "customer",
Expand Down Expand Up @@ -58,6 +57,10 @@
readonly=False,
)
total_amount = fields.Float("Total Invoices:", compute="_compute_total")
group_by_partner = fields.Boolean(
default=False,
help="Enable grouping payments by partner",
)

def get_invoice_payment_line(self, invoice):
return (
Expand Down Expand Up @@ -258,7 +261,7 @@
}

def update_group_pay_data(
self, partner_id, group_data, data_get, check_amount_in_words
self, group_id, group_data, data_get, check_amount_in_words
):
# build memo value
if self.communication:
Expand All @@ -283,8 +286,8 @@
}
group_data.update(
{
partner_id: {
"partner_id": partner_id,
group_id: {
"partner_id": data_get.invoice_id.partner_id.id,
"partner_type": MAP_INVOICE_TYPE_PARTNER_TYPE[
data_get.invoice_id.move_type
],
Expand All @@ -299,27 +302,28 @@

def get_amount(self, memo, group_data, line):
line.payment_difference = line.balance - line.amount
partner_id = line.invoice_id.partner_id.id
if partner_id in group_data:
old_total = group_data[partner_id]["total"]
group_id = line.invoice_id.id

Check warning on line 305 in account_payment_batch_process/wizard/account_payment_register.py

View check run for this annotation

Codecov / codecov/patch

account_payment_batch_process/wizard/account_payment_register.py#L305

Added line #L305 was not covered by tests
if self.group_by_partner:
group_id = line.invoice_id.partner_id.id

Check warning on line 307 in account_payment_batch_process/wizard/account_payment_register.py

View check run for this annotation

Codecov / codecov/patch

account_payment_batch_process/wizard/account_payment_register.py#L307

Added line #L307 was not covered by tests

if group_id in group_data:
old_total = group_data[group_id]["total"]

Check warning on line 310 in account_payment_batch_process/wizard/account_payment_register.py

View check run for this annotation

Codecov / codecov/patch

account_payment_batch_process/wizard/account_payment_register.py#L310

Added line #L310 was not covered by tests
# build memo value
if self.communication:
memo = (
group_data[partner_id]["memo"]
group_data[group_id]["memo"]
+ " : "
+ self.communication
+ "-"
+ str(line.invoice_id.name)
)
else:
memo = (
group_data[partner_id]["memo"] + " : " + str(line.invoice_id.name)
)
memo = group_data[group_id]["memo"] + " : " + str(line.invoice_id.name)

Check warning on line 321 in account_payment_batch_process/wizard/account_payment_register.py

View check run for this annotation

Codecov / codecov/patch

account_payment_batch_process/wizard/account_payment_register.py#L321

Added line #L321 was not covered by tests
# Calculate amount in words
check_amount_in_words = self.total_amount_in_words(line, old_total)
group_data[partner_id].update(
group_data[group_id].update(

Check warning on line 324 in account_payment_batch_process/wizard/account_payment_register.py

View check run for this annotation

Codecov / codecov/patch

account_payment_batch_process/wizard/account_payment_register.py#L324

Added line #L324 was not covered by tests
{
"partner_id": partner_id,
"partner_id": line.invoice_id.partner_id.id,
"partner_type": MAP_INVOICE_TYPE_PARTNER_TYPE[
line.invoice_id.move_type
],
Expand All @@ -339,13 +343,13 @@
name = "Counterpart"
# Update with payment diff data
inv_val = self.get_payment_invoice_value(name, line)
group_data[partner_id]["inv_val"].update({line.invoice_id.id: inv_val})
group_data[group_id]["inv_val"].update({line.invoice_id.id: inv_val})

Check warning on line 346 in account_payment_batch_process/wizard/account_payment_register.py

View check run for this annotation

Codecov / codecov/patch

account_payment_batch_process/wizard/account_payment_register.py#L346

Added line #L346 was not covered by tests
else:
# calculate amount in words
check_amount_in_words = self.total_amount_in_words(line, 0)
# prepare name
self.update_group_pay_data(
partner_id, group_data, line, check_amount_in_words
group_id, group_data, line, check_amount_in_words
)

def _reconcile_open_invoices(
Expand Down Expand Up @@ -395,16 +399,16 @@
context.update({"group_data": group_data})
# making partner wise payment
payment_ids = []
for partner in list(group_data):
for group in list(group_data):
# update active_ids with active invoice ids
if context.get("active_ids", False) and group_data[partner].get(
if context.get("active_ids", False) and group_data[group].get(
"inv_val", False
):
context.update({"active_ids": list(group_data[partner]["inv_val"])})
context.update({"active_ids": list(group_data[group]["inv_val"])})

Check warning on line 407 in account_payment_batch_process/wizard/account_payment_register.py

View check run for this annotation

Codecov / codecov/patch

account_payment_batch_process/wizard/account_payment_register.py#L407

Added line #L407 was not covered by tests
payment = (
self.env["account.payment"] # pylint: disable=context-overridden
.with_context(context)
.create(self.get_payment_values(group_data=group_data[partner]))
.create(self.get_payment_values(group_data=group_data[group]))
)
payment_ids.append(payment.id)
payment.action_post()
Expand All @@ -421,13 +425,13 @@
[("account_id", "=", account.id), ("reconciled", "=", False)]
).reconcile()
if any(
group_data[partner]["inv_val"][inv.id]["payment_difference_handling"]
group_data[group]["inv_val"][inv.id]["payment_difference_handling"]
== "open"
for inv in invoices
):
for inv in invoices:
if (
group_data[partner]["inv_val"][inv.id][
group_data[group]["inv_val"][inv.id][
"payment_difference_handling"
]
== "open"
Expand All @@ -438,7 +442,7 @@
for line in inv.line_ids:
if line.amount_residual > 0 and payment_state == "paid":
line_amount = 0.0
partial_amount = group_data[partner]["inv_val"][inv.id][
partial_amount = group_data[group]["inv_val"][inv.id][

Check warning on line 445 in account_payment_batch_process/wizard/account_payment_register.py

View check run for this annotation

Codecov / codecov/patch

account_payment_batch_process/wizard/account_payment_register.py#L445

Added line #L445 was not covered by tests
"amount"
]
self._reconcile_open_invoices(
Expand All @@ -453,10 +457,10 @@
)
continue
if line.reconciled and payment_state == "partial":
line_amount = group_data[partner]["inv_val"][inv.id][
line_amount = group_data[group]["inv_val"][inv.id][

Check warning on line 460 in account_payment_batch_process/wizard/account_payment_register.py

View check run for this annotation

Codecov / codecov/patch

account_payment_batch_process/wizard/account_payment_register.py#L460

Added line #L460 was not covered by tests
"payment_difference"
]
partial_amount = group_data[partner]["inv_val"][inv.id][
partial_amount = group_data[group]["inv_val"][inv.id][

Check warning on line 463 in account_payment_batch_process/wizard/account_payment_register.py

View check run for this annotation

Codecov / codecov/patch

account_payment_batch_process/wizard/account_payment_register.py#L463

Added line #L463 was not covered by tests
"amount"
]
self._reconcile_open_invoices(
Expand All @@ -473,10 +477,10 @@
inv.update(
{
"payment_state": payment_state,
"amount_residual": group_data[partner]["inv_val"][inv.id][
"amount_residual": group_data[group]["inv_val"][inv.id][
"payment_difference"
],
"amount_residual_signed": group_data[partner]["inv_val"][
"amount_residual_signed": group_data[group]["inv_val"][
inv.id
]["payment_difference"],
}
Expand Down
93 changes: 53 additions & 40 deletions account_payment_batch_process/wizard/account_payment_register.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,52 +9,65 @@
<field name="inherit_id" ref="account.view_account_payment_register_form" />
<field name="arch" type="xml">
<xpath expr="//group" position="after">
<group invisible="not context.get('batch', False)">
<div invisible="not context.get('batch', False)">
<field name="is_customer" invisible="1" />
<group
string="Vendor Bills to Pay"
<h3
attrs="{'invisible': [('is_customer', '=', True)]}"
/>
<group
string="Customer Invoices Being Paid"
>Vendor Bills to Pay</h3>
<h3
attrs="{'invisible': [('is_customer', '=', False)]}"
/>
</group>
>Customer Invoices Being Paid</h3>
</div>
<group invisible="not context.get('batch', False)">
<group>
<field name="group_by_partner" />
<button
name="auto_fill_payments"
string="Auto-Fill Pay Amount"
type="object"
class="oe_highlight"
/>
<field name="invoice_payments" colspan="4" nolabel="1">
<tree editable="bottom" create="false">
<field
name="partner_id"
options="{'no_create_edit': True}"
/>
<field
name="invoice_id"
options="{'no_create_edit': True}"
/>
<field name="balance" />
<field name="amount" />
<field name="check_amount_in_words" invisible="1" />
<field name="payment_difference_handling" />
<field name="payment_difference" />
<field
name="writeoff_account_id"
string="Post Difference In"
attrs="{'required': [('payment_difference_handling', '=', 'reconcile'),('payment_difference', '!=', 0.0)]}"
/>
<field name="reason_code" />
<field
name="note"
attrs="{'required': [('payment_difference_handling', '=', 'reconcile'),('payment_difference', '!=', 0.0)]}"
/>
</tree>
</field>
name="auto_fill_payments"
string="Auto-Fill Pay Amount"
type="object"
class="oe_highlight"
/>
</group>
</group>
<notebook invisible="not context.get('batch', False)">
<page name="invoice_payments" string="Invoice Payments">
<field name="invoice_payments" nolabel="1">
<tree editable="bottom" create="false">
<field
name="partner_id"
options="{'no_create_edit': True}"
/>
<field
name="invoice_id"
options="{'no_create_edit': True}"
/>
<field
name="balance"
sum="Total Balance"
readonly="1"
force_save="1"
/>
<field name="amount" sum="Total Amount" />
<field name="check_amount_in_words" invisible="1" />
<field name="payment_difference_handling" />
<field
name="payment_difference"
sum="Total Difference"
/>
<field
name="writeoff_account_id"
string="Post Difference In"
attrs="{'required': [('payment_difference_handling', '=', 'reconcile'),('payment_difference', '!=', 0.0)]}"
/>
<field name="reason_code" />
<field
name="note"
attrs="{'required': [('payment_difference_handling', '=', 'reconcile'),('payment_difference', '!=', 0.0)]}"
/>
</tree>
</field>
</page>
</notebook>
<group invisible="not context.get('batch', False)" col="6">
<group colspan="4" />
<group>
Expand Down
Loading