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

[IMP] sale_advance_payment: Use method lines #3512

Open
wants to merge 1 commit into
base: 17.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
62 changes: 59 additions & 3 deletions sale_advance_payment/wizard/sale_advance_payment_wzd.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,30 @@
required=True,
domain=[("type", "in", ("bank", "cash"))],
)
payment_method_line_id = fields.Many2one(
"account.payment.method.line",
string="Payment Method",
readonly=False,
store=True,
copy=False,
compute="_compute_payment_method_line_id",
domain="[('id', 'in', available_payment_method_line_ids)]",
help="Manual: Pay or Get paid by any method outside of Odoo.\n"
"Payment Providers: Each payment provider has its own Payment Method. "
"Request a transaction on/to a card thanks to a payment token saved "
"by the partner when buying or subscribing online.\n"
"Check: Pay bills by check and print it from Odoo.\n"
"Batch Deposit: Collect several customer checks at once generating and "
"submitting a batch deposit to your bank. Module account_batch_payment "
"is necessary.\n"
"SEPA Credit Transfer: Pay in the SEPA zone by submitting a SEPA "
"Credit Transfer file to your bank. Module account_sepa is necessary.\n"
"SEPA Direct Debit: Get paid in the SEPA zone thanks to a mandate your "
"partner will have granted to you. Module account_sepa is necessary.\n",
)
available_payment_method_line_ids = fields.Many2many(
"account.payment.method.line", compute="_compute_payment_method_line_fields"
)
journal_currency_id = fields.Many2one(
"res.currency",
"Journal Currency",
Expand All @@ -44,6 +68,40 @@
required=True,
)

@api.depends("available_payment_method_line_ids")
def _compute_payment_method_line_id(self):
"""Compute the 'payment_method_line_id' field.
This field is not computed in '_compute_payment_method_line_fields'
because it's a stored editable one.
"""
for pay in self:
available_payment_method_lines = pay.available_payment_method_line_ids

# Select the first available one by default.
if pay.payment_method_line_id in available_payment_method_lines:
pay.payment_method_line_id = pay.payment_method_line_id

Check warning on line 82 in sale_advance_payment/wizard/sale_advance_payment_wzd.py

View check run for this annotation

Codecov / codecov/patch

sale_advance_payment/wizard/sale_advance_payment_wzd.py#L82

Added line #L82 was not covered by tests
elif available_payment_method_lines:
pay.payment_method_line_id = available_payment_method_lines[0]._origin
else:
pay.payment_method_line_id = False

Check warning on line 86 in sale_advance_payment/wizard/sale_advance_payment_wzd.py

View check run for this annotation

Codecov / codecov/patch

sale_advance_payment/wizard/sale_advance_payment_wzd.py#L86

Added line #L86 was not covered by tests

@api.depends("payment_type", "journal_id", "currency_id")
def _compute_payment_method_line_fields(self):
for pay in self:
pay.available_payment_method_line_ids = (
pay.journal_id._get_available_payment_method_lines(pay.payment_type)
)
to_exclude = pay._get_payment_method_codes_to_exclude()
if to_exclude:
pay.available_payment_method_line_ids = (

Check warning on line 96 in sale_advance_payment/wizard/sale_advance_payment_wzd.py

View check run for this annotation

Codecov / codecov/patch

sale_advance_payment/wizard/sale_advance_payment_wzd.py#L96

Added line #L96 was not covered by tests
pay.available_payment_method_line_ids.filtered(
lambda line, to_exclude=to_exclude: line.code not in to_exclude
)
)

def _get_payment_method_codes_to_exclude(self):
return []

@api.depends("journal_id")
def _compute_get_journal_currency(self):
for wzd in self:
Expand Down Expand Up @@ -143,9 +201,7 @@
"journal_id": self.journal_id.id,
"currency_id": self.journal_currency_id.id,
"partner_id": partner_id,
"payment_method_id": self.env.ref(
"account.account_payment_method_manual_in"
).id,
"payment_method_line_id": self.payment_method_line_id.id,
}

def make_advance_payment(self):
Expand Down
6 changes: 6 additions & 0 deletions sale_advance_payment/wizard/sale_advance_payment_wzd_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Advance Payment">
<field name="available_payment_method_line_ids" invisible="1" />
<group>
<field name="order_id" invisible="1" />
<group colspan="4" col="4">
Expand All @@ -14,7 +15,12 @@
domain="[('type','in',['bank', 'cash'])]"
widget="selection"
select="1"
/>
<field
name="payment_method_line_id"
options="{'no_create': True, 'no_open': True}"
string="Payment Method"
required="1"
/>
<field name="payment_type" />
<field name="journal_currency_id" string="Currency" />
Expand Down
Loading