Skip to content
Snippets Groups Projects
Commit 61b5dd38 authored by Thomas Lefebvre (thle)'s avatar Thomas Lefebvre (thle)
Browse files

[FIX] membership: add payment terms on the invoice


Versions:
---------
- 14.0
- 15.0

Steps to reproduce:
-------------------
- in Members app, add a membership product;
- add a "Payment Terms" on a contact (Sales & Purchase tab);
- in Membership tab click on "Buy Membership";
- add the membership product and invoice;

Issue:
------
There is no payment term on the invoice.

Cause:
------
In the invoice creation flow, the following logic is not triggered:
```py
if self.is_sale_document(include_receipts=True) and self.partner_id:
	self.invoice_payment_term_id = self.partner_id.property_payment_term_id or self.invoice_payment_term_id
```
Consequently, we have no invoice_payment_term_id.

Solution:
---------
Specify `invoice_payment_term_id` in the values used for invoice creation.

Note:
-----
This FIX solution only handles the invoice creation
from the membership module, to be as non-invasive as possible.

In version 16.0, this is handled by the account module,
which has made the `invoice_payment_term_id` field computed and dependent on `partner_id`.

opw-3382398

closes odoo/odoo#130998

Signed-off-by: default avatarAndrea Grazioso (agr) <agr@odoo.com>
parent f210c4c9
No related branches found
No related tags found
No related merge requests found
......@@ -109,6 +109,7 @@ class Partner(models.Model):
invoice_vals_list.append({
'move_type': 'out_invoice',
'partner_id': partner.id,
'invoice_payment_term_id': partner.property_payment_term_id.id,
'invoice_line_ids': [
(0, None, {'product_id': product.id, 'quantity': 1, 'price_unit': amount, 'tax_ids': [(6, 0, product.taxes_id.ids)]})
]
......
......@@ -158,3 +158,23 @@ class TestMembership(TestMembershipCommon):
self.partner_1._compute_membership_state()
self.assertEqual(invoice.state, 'cancel')
self.assertEqual(self.partner_1.membership_state, 'canceled')
def test_apply_payment_term(self):
"""
Check if the payment term defined on the partner is applied to the invoice
"""
pay_term_15_days_after_today = self.env['account.payment.term'].create({
'name': '15 days after today',
'line_ids': [
(0, 0, {
'value': 'balance',
'days': 15,
'option': 'day_after_invoice_date',
}),
],
})
self.partner_1.write({
'property_payment_term_id': pay_term_15_days_after_today.id,
})
invoice = self.partner_1.create_membership_invoice(self.membership_1, 100.0)
self.assertEqual(invoice.invoice_payment_term_id, pay_term_15_days_after_today)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment