diff --git a/account_payment_term_extension/models/account_payment_term.py b/account_payment_term_extension/models/account_payment_term.py index 7b844225a1f..a00c98b0c19 100644 --- a/account_payment_term_extension/models/account_payment_term.py +++ b/account_payment_term_extension/models/account_payment_term.py @@ -35,26 +35,30 @@ def apply_holidays(self, date): return holiday.date_postponed return date + def _get_payment_days_due_date(self, date, payment_days): + if payment_days: + new_date = None + payment_days.sort() + days_in_month = calendar.monthrange(date.year, date.month)[1] + for day in payment_days: + if date.day <= day: + if day > days_in_month: + day = days_in_month + new_date = date + relativedelta(day=day) + break + if not new_date: + day = payment_days[0] + if day > days_in_month: + day = days_in_month + new_date = date + relativedelta(day=day, months=1) + return new_date + return date + def apply_payment_days(self, line, date): """Calculate the new date with days of payments""" if line.payment_days: payment_days = line._decode_payment_days(line.payment_days) - if payment_days: - new_date = None - payment_days.sort() - days_in_month = calendar.monthrange(date.year, date.month)[1] - for day in payment_days: - if date.day <= day: - if day > days_in_month: - day = days_in_month - new_date = date + relativedelta(day=day) - break - if not new_date: - day = payment_days[0] - if day > days_in_month: - day = days_in_month - new_date = date + relativedelta(day=day, months=1) - return new_date + return self._get_payment_days_due_date(date, payment_days) return date @api.depends( diff --git a/account_payment_term_partner_paydays/README.rst b/account_payment_term_partner_paydays/README.rst new file mode 100644 index 00000000000..f225d488a45 --- /dev/null +++ b/account_payment_term_partner_paydays/README.rst @@ -0,0 +1,100 @@ +=================================== +Payment Term - Partner Payment Days +=================================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:117c24bfceb4532d84c40254649a45acdc39bd64dd8684feadd25f86fe8d5781 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Faccount--payment-lightgray.png?logo=github + :target: https://github.com/OCA/account-payment/tree/17.0/account_payment_term_partner_paydays + :alt: OCA/account-payment +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/account-payment-17-0/account-payment-17-0-account_payment_term_partner_paydays + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/account-payment&target_branch=17.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows to define payment days for partners. These payment +days are later taken into account to compute the due date of an invoice. + +The partner payment days will overwrite any payment day configured in +the payment term lines. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +Go to **Invoicing > Customers > Customers** and edit any customer by +setting its payment days. + +Go to **Invoicing > Customers > Invoices** and create a new invoice. + +Select any payment term and set a date in the invoice. + +You must see the due date based on this payment term, taking into +account the partner payment days. + +**Example:** + +Payment term of 60 days. Partner payment days 1, 15. + +If the invoice date is the 5th of may, the due date will be the 15th of +july. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* ForgeFlow + +Contributors +------------ + +- Marina Alapont + +Maintainers +----------- + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +This module is part of the `OCA/account-payment `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/account_payment_term_partner_paydays/__init__.py b/account_payment_term_partner_paydays/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/account_payment_term_partner_paydays/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/account_payment_term_partner_paydays/__manifest__.py b/account_payment_term_partner_paydays/__manifest__.py new file mode 100644 index 00000000000..460c0ca2e43 --- /dev/null +++ b/account_payment_term_partner_paydays/__manifest__.py @@ -0,0 +1,18 @@ +# Copyright 2025 ForgeFlow S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Payment Term - Partner Payment Days", + "version": "17.0.1.0.0", + "category": "Accounting & Finance", + "summary": "Allows to define payment days for partners.", + "author": "ForgeFlow, Odoo Community Association (OCA)", + "maintainer": "OCA", + "website": "https://github.com/OCA/account-payment", + "license": "AGPL-3", + "depends": ["account_payment_term_extension"], + "data": [ + "views/res_partner_views.xml", + ], + "installable": True, +} diff --git a/account_payment_term_partner_paydays/i18n/account_payment_term_partner_paydays.pot b/account_payment_term_partner_paydays/i18n/account_payment_term_partner_paydays.pot new file mode 100644 index 00000000000..7bdef147352 --- /dev/null +++ b/account_payment_term_partner_paydays/i18n/account_payment_term_partner_paydays.pot @@ -0,0 +1,61 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_payment_term_partner_paydays +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 18.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2025-11-04 09:32+0000\n" +"PO-Revision-Date: 2025-11-04 09:32+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: account_payment_term_partner_paydays +#: model:ir.model,name:account_payment_term_partner_paydays.model_res_partner +msgid "Contact" +msgstr "" + +#. module: account_payment_term_partner_paydays +#: model:ir.model.fields,field_description:account_payment_term_partner_paydays.field_res_partner__customer_payment_days +#: model:ir.model.fields,field_description:account_payment_term_partner_paydays.field_res_users__customer_payment_days +msgid "Customer Payment day(s)" +msgstr "" + +#. module: account_payment_term_partner_paydays +#: model:ir.model,name:account_payment_term_partner_paydays.model_account_move +msgid "Journal Entry" +msgstr "" + +#. module: account_payment_term_partner_paydays +#: model:ir.model,name:account_payment_term_partner_paydays.model_account_payment_term +msgid "Payment Terms" +msgstr "" + +#. module: account_payment_term_partner_paydays +#: model:ir.model.fields,help:account_payment_term_partner_paydays.field_res_partner__customer_payment_days +#: model:ir.model.fields,help:account_payment_term_partner_paydays.field_res_users__customer_payment_days +msgid "" +"The day or days when the partner does the payments. To be used for computing" +" the invoices due date. Separate each payment day with dashes (-), commas " +"(,) or spaces ( )." +msgstr "" + +#. module: account_payment_term_partner_paydays +#: model:ir.model.fields,help:account_payment_term_partner_paydays.field_res_partner__supplier_payment_days +#: model:ir.model.fields,help:account_payment_term_partner_paydays.field_res_users__supplier_payment_days +msgid "" +"The day or days when you do the payments to this partner. To be used for " +"computing the bill due date. Separate each payment day with dashes (-), " +"commas (,) or spaces ( )." +msgstr "" + +#. module: account_payment_term_partner_paydays +#: model:ir.model.fields,field_description:account_payment_term_partner_paydays.field_res_partner__supplier_payment_days +#: model:ir.model.fields,field_description:account_payment_term_partner_paydays.field_res_users__supplier_payment_days +msgid "Vendor Payment day(s)" +msgstr "" diff --git a/account_payment_term_partner_paydays/i18n/ca_ES.po b/account_payment_term_partner_paydays/i18n/ca_ES.po new file mode 100644 index 00000000000..00535050058 --- /dev/null +++ b/account_payment_term_partner_paydays/i18n/ca_ES.po @@ -0,0 +1,67 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_payment_term_partner_paydays +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 18.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2025-11-04 09:35+0000\n" +"PO-Revision-Date: 2025-11-04 09:35+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: account_payment_term_partner_paydays +#: model:ir.model,name:account_payment_term_partner_paydays.model_res_partner +msgid "Contact" +msgstr "Contacte" + +#. module: account_payment_term_partner_paydays +#: model:ir.model.fields,field_description:account_payment_term_partner_paydays.field_res_partner__customer_payment_days +#: model:ir.model.fields,field_description:account_payment_term_partner_paydays.field_res_users__customer_payment_days +msgid "Customer Payment day(s)" +msgstr "Dies de pagament de client" + +#. module: account_payment_term_partner_paydays +#: model:ir.model,name:account_payment_term_partner_paydays.model_account_move +msgid "Journal Entry" +msgstr "Assentament comptable" + +#. module: account_payment_term_partner_paydays +#: model:ir.model,name:account_payment_term_partner_paydays.model_account_payment_term +msgid "Payment Terms" +msgstr "Terminis de pagament" + +#. module: account_payment_term_partner_paydays +#: model:ir.model.fields,help:account_payment_term_partner_paydays.field_res_partner__customer_payment_days +#: model:ir.model.fields,help:account_payment_term_partner_paydays.field_res_users__customer_payment_days +msgid "" +"The day or days when the partner does the payments. To be used for computing" +" the invoices due date. Separate each payment day with dashes (-), commas " +"(,) or spaces ( )." +msgstr "" +"El dia o dies en què el client fa els pagaments. S’utilitza per calcular la " +"data de venciment de les factures. Separa cada dia de pagament amb guions " +"(-), comes (,) o espais ( )." + +#. module: account_payment_term_partner_paydays +#: model:ir.model.fields,help:account_payment_term_partner_paydays.field_res_partner__supplier_payment_days +#: model:ir.model.fields,help:account_payment_term_partner_paydays.field_res_users__supplier_payment_days +msgid "" +"The day or days when you do the payments to this partner. To be used for " +"computing the bill due date. Separate each payment day with dashes (-), " +"commas (,) or spaces ( )." +msgstr "" +"El dia o dies en què fas els pagaments a aquest proveïdor. S’utilitza per " +"calcular la data de venciment de les factures. Separa cada dia de pagament " +"amb guions (-comes (,) o espais ( )." + +#. module: account_payment_term_partner_paydays +#: model:ir.model.fields,field_description:account_payment_term_partner_paydays.field_res_partner__supplier_payment_days +#: model:ir.model.fields,field_description:account_payment_term_partner_paydays.field_res_users__supplier_payment_days +msgid "Vendor Payment day(s)" +msgstr "Dies de pagament de proveïdor" diff --git a/account_payment_term_partner_paydays/i18n/es.po b/account_payment_term_partner_paydays/i18n/es.po new file mode 100644 index 00000000000..554ddafa955 --- /dev/null +++ b/account_payment_term_partner_paydays/i18n/es.po @@ -0,0 +1,67 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_payment_term_partner_paydays +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 18.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2025-11-04 09:33+0000\n" +"PO-Revision-Date: 2025-11-04 09:33+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: account_payment_term_partner_paydays +#: model:ir.model,name:account_payment_term_partner_paydays.model_res_partner +msgid "Contact" +msgstr "Contacto" + +#. module: account_payment_term_partner_paydays +#: model:ir.model.fields,field_description:account_payment_term_partner_paydays.field_res_partner__customer_payment_days +#: model:ir.model.fields,field_description:account_payment_term_partner_paydays.field_res_users__customer_payment_days +msgid "Customer Payment day(s)" +msgstr "Día(s) de pago de cliente" + +#. module: account_payment_term_partner_paydays +#: model:ir.model,name:account_payment_term_partner_paydays.model_account_move +msgid "Journal Entry" +msgstr "Asiento contable" + +#. module: account_payment_term_partner_paydays +#: model:ir.model,name:account_payment_term_partner_paydays.model_account_payment_term +msgid "Payment Terms" +msgstr "Condiciones de pago" + +#. module: account_payment_term_partner_paydays +#: model:ir.model.fields,help:account_payment_term_partner_paydays.field_res_partner__customer_payment_days +#: model:ir.model.fields,help:account_payment_term_partner_paydays.field_res_users__customer_payment_days +msgid "" +"The day or days when the partner does the payments. To be used for computing" +" the invoices due date. Separate each payment day with dashes (-), commas " +"(,) or spaces ( )." +msgstr "" +"El día o los dias en que el cliente realiza los pagos. Se utiliza para " +"calcular la fecha de vencimiento de las facturas. Separa cada dia de pago " +"con guiones (-), comas (,) o espacios ( )." + +#. module: account_payment_term_partner_paydays +#: model:ir.model.fields,help:account_payment_term_partner_paydays.field_res_partner__supplier_payment_days +#: model:ir.model.fields,help:account_payment_term_partner_paydays.field_res_users__supplier_payment_days +msgid "" +"The day or days when you do the payments to this partner. To be used for " +"computing the bill due date. Separate each payment day with dashes (-), " +"commas (,) or spaces ( )." +msgstr "" +"El día o los dias en que realizas los pagos a este proveedor. Se utiliza " +"para calcular la fecha de vencimiento de las facturas. Separa cada dia de " +"pago con guiones (-), comas (,) o espacios ( )." + +#. module: account_payment_term_partner_paydays +#: model:ir.model.fields,field_description:account_payment_term_partner_paydays.field_res_partner__supplier_payment_days +#: model:ir.model.fields,field_description:account_payment_term_partner_paydays.field_res_users__supplier_payment_days +msgid "Vendor Payment day(s)" +msgstr "Día(s) de pago de proveedor" diff --git a/account_payment_term_partner_paydays/models/__init__.py b/account_payment_term_partner_paydays/models/__init__.py new file mode 100644 index 00000000000..25e3ade8331 --- /dev/null +++ b/account_payment_term_partner_paydays/models/__init__.py @@ -0,0 +1,3 @@ +from . import account_payment_term +from . import account_move +from . import res_partner diff --git a/account_payment_term_partner_paydays/models/account_move.py b/account_payment_term_partner_paydays/models/account_move.py new file mode 100644 index 00000000000..aa905acf5b0 --- /dev/null +++ b/account_payment_term_partner_paydays/models/account_move.py @@ -0,0 +1,28 @@ +# Copyright 2025 ForgeFlow S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, models + + +class AccountMove(models.Model): + _inherit = "account.move" + + @api.depends( + "invoice_payment_term_id", + "invoice_date", + "currency_id", + "amount_total_in_currency_signed", + "invoice_date_due", + "partner_id", + ) + def _compute_needed_terms(self): + """Add the invoice type and the partner to the context to later use it in + the payment terms compute""" + for move in self: + ctx = self.env.context.copy() + if move.partner_id and move.is_invoice(True): + ctx.update( + {"partner_id": move.partner_id.id, "invoice_type": move.move_type} + ) + super(AccountMove, move.with_context(**ctx))._compute_needed_terms() + return True diff --git a/account_payment_term_partner_paydays/models/account_payment_term.py b/account_payment_term_partner_paydays/models/account_payment_term.py new file mode 100644 index 00000000000..a31b6b78316 --- /dev/null +++ b/account_payment_term_partner_paydays/models/account_payment_term.py @@ -0,0 +1,20 @@ +# Copyright 2025 ForgeFlow S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + + +from odoo import models + + +class AccountPaymentTerm(models.Model): + _inherit = "account.payment.term" + + def apply_payment_days(self, line, date): + """Calculate the new date taking into account the partner payment days""" + partner_id = self.env.context.get("partner_id") + if partner_id: + partner = self.env["res.partner"].browse(partner_id) + payment_days = partner._get_payment_days() + if payment_days: + decoded_payment_days = line._decode_payment_days(payment_days) + return self._get_payment_days_due_date(date, decoded_payment_days) + return super().apply_payment_days(line, date) diff --git a/account_payment_term_partner_paydays/models/res_partner.py b/account_payment_term_partner_paydays/models/res_partner.py new file mode 100644 index 00000000000..6f4d5da269d --- /dev/null +++ b/account_payment_term_partner_paydays/models/res_partner.py @@ -0,0 +1,32 @@ +# Copyright 2025 ForgeFlow S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + + +from odoo import fields, models + + +class Partner(models.Model): + _inherit = ["res.partner"] + + customer_payment_days = fields.Char( + string="Customer Payment day(s)", + help="The day or days when the partner does the payments. To be used " + "for computing the invoices due date. Separate each payment day" + " with dashes (-), commas (,) or spaces ( ).", + ) + + supplier_payment_days = fields.Char( + string="Vendor Payment day(s)", + help="The day or days when you do the payments to this partner. To be used " + "for computing the bill due date. Separate each payment day with dashes" + " (-), commas (,) or spaces ( ).", + ) + + def _get_payment_days(self): + """Return the payment days based on the invoice type""" + invoice_type = self.env.context.get("invoice_type") + if invoice_type == "in_invoice": + return self.supplier_payment_days + if invoice_type == "out_invoice": + return self.customer_payment_days + return False diff --git a/account_payment_term_partner_paydays/pyproject.toml b/account_payment_term_partner_paydays/pyproject.toml new file mode 100644 index 00000000000..4231d0cccb3 --- /dev/null +++ b/account_payment_term_partner_paydays/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/account_payment_term_partner_paydays/readme/CONTRIBUTORS.md b/account_payment_term_partner_paydays/readme/CONTRIBUTORS.md new file mode 100644 index 00000000000..25a2caefd61 --- /dev/null +++ b/account_payment_term_partner_paydays/readme/CONTRIBUTORS.md @@ -0,0 +1 @@ +- Marina Alapont \<\> diff --git a/account_payment_term_partner_paydays/readme/DESCRIPTION.md b/account_payment_term_partner_paydays/readme/DESCRIPTION.md new file mode 100644 index 00000000000..bae6986b995 --- /dev/null +++ b/account_payment_term_partner_paydays/readme/DESCRIPTION.md @@ -0,0 +1,5 @@ +This module allows to define payment days for partners. These payment days +are later taken into account to compute the due date of an invoice. + +The partner payment days will overwrite any payment day configured in the +payment term lines. diff --git a/account_payment_term_partner_paydays/readme/USAGE.md b/account_payment_term_partner_paydays/readme/USAGE.md new file mode 100644 index 00000000000..4df6c76dc6e --- /dev/null +++ b/account_payment_term_partner_paydays/readme/USAGE.md @@ -0,0 +1,14 @@ +Go to **Invoicing \> Customers \> Customers** and edit any customer by setting its payment days. + +Go to **Invoicing \> Customers \> Invoices** and create a new invoice. + +Select any payment term and set a date in the invoice. + +You must see the due date based on this payment term, taking into account the partner payment days. + + +**Example:** + +Payment term of 60 days. Partner payment days 1, 15. + +If the invoice date is the 5th of may, the due date will be the 15th of july. diff --git a/account_payment_term_partner_paydays/static/description/index.html b/account_payment_term_partner_paydays/static/description/index.html new file mode 100644 index 00000000000..070d7d6421a --- /dev/null +++ b/account_payment_term_partner_paydays/static/description/index.html @@ -0,0 +1,440 @@ + + + + + +Payment Term - Partner Payment Days + + + +
+

Payment Term - Partner Payment Days

+ + +

Beta License: AGPL-3 OCA/account-payment Translate me on Weblate Try me on Runboat

+

This module allows to define payment days for partners. These payment +days are later taken into account to compute the due date of an invoice.

+

The partner payment days will overwrite any payment day configured in +the payment term lines.

+

Table of contents

+ +
+

Usage

+

Go to Invoicing > Customers > Customers and edit any customer by +setting its payment days.

+

Go to Invoicing > Customers > Invoices and create a new invoice.

+

Select any payment term and set a date in the invoice.

+

You must see the due date based on this payment term, taking into +account the partner payment days.

+

Example:

+

Payment term of 60 days. Partner payment days 1, 15.

+

If the invoice date is the 5th of may, the due date will be the 15th of +july.

+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • ForgeFlow
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

This module is part of the OCA/account-payment project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/account_payment_term_partner_paydays/tests/__init__.py b/account_payment_term_partner_paydays/tests/__init__.py new file mode 100644 index 00000000000..f0bc0082023 --- /dev/null +++ b/account_payment_term_partner_paydays/tests/__init__.py @@ -0,0 +1 @@ +from . import test_account_payment_term_partner_paydays diff --git a/account_payment_term_partner_paydays/tests/test_account_payment_term_partner_paydays.py b/account_payment_term_partner_paydays/tests/test_account_payment_term_partner_paydays.py new file mode 100644 index 00000000000..c38eece7554 --- /dev/null +++ b/account_payment_term_partner_paydays/tests/test_account_payment_term_partner_paydays.py @@ -0,0 +1,68 @@ +import datetime + +from odoo import fields +from odoo.tests import TransactionCase + + +class TestAccountPaymentTermPartnerPaydays(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.payment_term_model = cls.env["account.payment.term"] + cls.invoice_model = cls.env["account.move"] + cls.partner = cls.env["res.partner"].create({"name": "Test Partner"}) + cls.product = cls.env["product.product"].create({"name": "Test product"}) + cls.payment_term_30 = cls.payment_term_model.create( + { + "name": "30 days", + "active": True, + "line_ids": [ + fields.Command.create( + { + "value": "percent", + "value_amount": 100.0, + "nb_days": 30, + }, + ), + ], + } + ) + + def test_payment_term_without_partner_payment_days(self): + due_date = self.payment_term_model.apply_payment_days( + self.payment_term_30.line_ids[0], datetime.date(2025, 5, 1) + ) + self.assertEqual(due_date, datetime.date(2025, 5, 1)) + + def test_payment_term_with_partner_payment_days(self): + self.partner.write( + {"customer_payment_days": "5, 15", "supplier_payment_days": "30"} + ) + + due_date = self.payment_term_model.with_context( + partner_id=self.partner.id, invoice_type="out_invoice" + ).apply_payment_days( + self.payment_term_30.line_ids[0], datetime.date(2025, 5, 1) + ) + self.assertEqual(due_date, datetime.date(2025, 5, 5)) + + due_date = self.payment_term_model.with_context( + partner_id=self.partner.id, invoice_type="out_invoice" + ).apply_payment_days( + self.payment_term_30.line_ids[0], datetime.date(2025, 5, 6) + ) + self.assertEqual(due_date, datetime.date(2025, 5, 15)) + + due_date = self.payment_term_model.with_context( + partner_id=self.partner.id, invoice_type="out_invoice" + ).apply_payment_days( + self.payment_term_30.line_ids[0], datetime.date(2025, 5, 26) + ) + self.assertEqual(due_date, datetime.date(2025, 6, 5)) + + due_date = self.payment_term_model.with_context( + partner_id=self.partner.id, invoice_type="in_invoice" + ).apply_payment_days( + self.payment_term_30.line_ids[0], datetime.date(2025, 5, 1) + ) + self.assertEqual(due_date, datetime.date(2025, 5, 30)) diff --git a/account_payment_term_partner_paydays/views/res_partner_views.xml b/account_payment_term_partner_paydays/views/res_partner_views.xml new file mode 100644 index 00000000000..1074b2d3b43 --- /dev/null +++ b/account_payment_term_partner_paydays/views/res_partner_views.xml @@ -0,0 +1,16 @@ + + + + res.partner.form + res.partner + + + + + + + + + + + diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 00000000000..205d608907c --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1 @@ +odoo-addon-account_payment_term_extension @ git+https://github.com/OCA/account-payment.git@refs/pull/907/head#subdirectory=account_payment_term_extension