diff --git a/account_billing_from_cutoff/README.rst b/account_billing_from_cutoff/README.rst new file mode 100644 index 00000000..e8f337b9 --- /dev/null +++ b/account_billing_from_cutoff/README.rst @@ -0,0 +1,100 @@ +=========================== +Account Billing From Cutoff +=========================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:3bd2ac035fb32366e6528bd429c87079ed4698590167692e1f9a8ed091e726f6 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png + :target: https://odoo-community.org/page/development-status + :alt: Alpha +.. |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%2Fl10n--japan-lightgray.png?logo=github + :target: https://github.com/OCA/l10n-japan/tree/16.0/account_billing_from_cutoff + :alt: OCA/l10n-japan +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/l10n-japan-16-0/l10n-japan-16-0-account_billing_from_cutoff + :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/l10n-japan&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module creates billings for partners with Summary Invoicing enabled, based on the +cutoff date of their invoices. + +.. IMPORTANT:: + This is an alpha version, the data model and design can change at any time without warning. + Only for development or testing purpose, do not use in production. + `More details on development status `_ + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +To enable Summary Invoicing for a partner: + +- Go to Contacts and select the partner. +- In the Accounting tab, enable Summary Invoicing. Billings for this partner + will then be created based on the invoices’ cutoff date. + +Usage +===== + +To use this module, + +- Go to *Invoicing -> Customers or Vendors -> Create Billing From Cutoff* +- Set the cutoff date and click on *Create Billings* + +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 +~~~~~~~ + +* Quartile + +Contributors +~~~~~~~~~~~~ + +- Quartile \<\> + - Aung Ko Ko Lin + +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/l10n-japan `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/account_billing_from_cutoff/__init__.py b/account_billing_from_cutoff/__init__.py new file mode 100644 index 00000000..aee8895e --- /dev/null +++ b/account_billing_from_cutoff/__init__.py @@ -0,0 +1,2 @@ +from . import models +from . import wizards diff --git a/account_billing_from_cutoff/__manifest__.py b/account_billing_from_cutoff/__manifest__.py new file mode 100644 index 00000000..420ef0ec --- /dev/null +++ b/account_billing_from_cutoff/__manifest__.py @@ -0,0 +1,19 @@ +# Copyright 2025 Quartile (https://www.quartile.co) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Account Billing From Cutoff", + "version": "16.0.1.0.0", + "depends": ["account_billing", "account_payment_term_cutoff_day"], + "author": "Quartile, Odoo Community Association (OCA)", + "license": "AGPL-3", + "website": "https://github.com/OCA/l10n-japan", + "category": "Accounting", + "data": [ + "security/ir.model.access.csv", + "wizards/account_billing_cutoff.xml", + "views/res_partner_views.xml", + ], + "development_status": "Alpha", + "installable": True, +} diff --git a/account_billing_from_cutoff/models/__init__.py b/account_billing_from_cutoff/models/__init__.py new file mode 100644 index 00000000..91fed54d --- /dev/null +++ b/account_billing_from_cutoff/models/__init__.py @@ -0,0 +1 @@ +from . import res_partner diff --git a/account_billing_from_cutoff/models/res_partner.py b/account_billing_from_cutoff/models/res_partner.py new file mode 100644 index 00000000..ffefd5cb --- /dev/null +++ b/account_billing_from_cutoff/models/res_partner.py @@ -0,0 +1,14 @@ +# Copyright 2025 Quartile (https://www.quartile.co) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class ResPartner(models.Model): + _inherit = "res.partner" + + use_summary_invoicing = fields.Boolean( + string="Summary Invoicing", + help="If enabled, invoices for this partner will be grouped into a billing " + "when using the 'Create Billings' wizard.", + ) diff --git a/account_billing_from_cutoff/readme/CONFIGURE.rst b/account_billing_from_cutoff/readme/CONFIGURE.rst new file mode 100644 index 00000000..0c8efb67 --- /dev/null +++ b/account_billing_from_cutoff/readme/CONFIGURE.rst @@ -0,0 +1,5 @@ +To enable Summary Invoicing for a partner: + +- Go to Contacts and select the partner. +- In the Accounting tab, enable Summary Invoicing. Billings for this partner + will then be created based on the invoices’ cutoff date. diff --git a/account_billing_from_cutoff/readme/CONTRIBUTORS.rst b/account_billing_from_cutoff/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..a8a2dfb2 --- /dev/null +++ b/account_billing_from_cutoff/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +- Quartile \<\> + - Aung Ko Ko Lin diff --git a/account_billing_from_cutoff/readme/DESCRIPTION.rst b/account_billing_from_cutoff/readme/DESCRIPTION.rst new file mode 100644 index 00000000..6ee8bda0 --- /dev/null +++ b/account_billing_from_cutoff/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +This module creates billings for partners with Summary Invoicing enabled, based on the +cutoff date of their invoices. diff --git a/account_billing_from_cutoff/readme/USAGE.rst b/account_billing_from_cutoff/readme/USAGE.rst new file mode 100644 index 00000000..f24a11f1 --- /dev/null +++ b/account_billing_from_cutoff/readme/USAGE.rst @@ -0,0 +1,4 @@ +To use this module, + +- Go to *Invoicing -> Customers or Vendors -> Create Billing From Cutoff* +- Set the cutoff date and click on *Create Billings* diff --git a/account_billing_from_cutoff/security/ir.model.access.csv b/account_billing_from_cutoff/security/ir.model.access.csv new file mode 100644 index 00000000..b7e55b41 --- /dev/null +++ b/account_billing_from_cutoff/security/ir.model.access.csv @@ -0,0 +1,2 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_wiz_account_billing_cutoff,access_wiz_account_billing_cutoff,model_wiz_account_billing_cutoff,account.group_account_invoice,1,1,1,1 diff --git a/account_billing_from_cutoff/static/description/index.html b/account_billing_from_cutoff/static/description/index.html new file mode 100644 index 00000000..44f1cdd0 --- /dev/null +++ b/account_billing_from_cutoff/static/description/index.html @@ -0,0 +1,450 @@ + + + + + +Account Billing From Cutoff + + + +
+

Account Billing From Cutoff

+ + +

Alpha License: AGPL-3 OCA/l10n-japan Translate me on Weblate Try me on Runboat

+

This module creates billings for partners with Summary Invoicing enabled, based on the +cutoff date of their invoices.

+
+

Important

+

This is an alpha version, the data model and design can change at any time without warning. +Only for development or testing purpose, do not use in production. +More details on development status

+
+

Table of contents

+ +
+

Configuration

+

To enable Summary Invoicing for a partner:

+
    +
  • Go to Contacts and select the partner.
  • +
  • In the Accounting tab, enable Summary Invoicing. Billings for this partner +will then be created based on the invoices’ cutoff date.
  • +
+
+
+

Usage

+

To use this module,

+
    +
  • Go to Invoicing -> Customers or Vendors -> Create Billing From Cutoff
  • +
  • Set the cutoff date and click on Create Billings
  • +
+
+
+

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

+
    +
  • Quartile
  • +
+
+
+

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/l10n-japan project on GitHub.

+

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

+
+
+
+ + diff --git a/account_billing_from_cutoff/tests/__init__.py b/account_billing_from_cutoff/tests/__init__.py new file mode 100644 index 00000000..cee3ad4d --- /dev/null +++ b/account_billing_from_cutoff/tests/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2025 Quartile (https://www.quartile.co) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import test_account_billing_from_cutoff diff --git a/account_billing_from_cutoff/tests/test_account_billing_from_cutoff.py b/account_billing_from_cutoff/tests/test_account_billing_from_cutoff.py new file mode 100644 index 00000000..ea50ce7d --- /dev/null +++ b/account_billing_from_cutoff/tests/test_account_billing_from_cutoff.py @@ -0,0 +1,151 @@ +# Copyright 2025 Quartile +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from datetime import date + +from odoo import Command +from odoo.tests.common import TransactionCase + + +class TestBillingFromCutoff(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.journal_sale = cls.env["account.journal"].search([("type", "=", "sale")])[0] + cls.invoice_model = cls.env["account.move"] + cls.partner_1 = cls.env["res.partner"].create( + {"name": "Test Partner 1", "use_summary_invoicing": True} + ) + cls.partner_2 = cls.env["res.partner"].create({"name": "Test Partner 2"}) + cls.payment_term = cls.env.ref( + "account.account_payment_term_end_following_month" + ) + cls.payment_term.line_ids.write({"months": 1, "cutoff_day": 20}) + cls.product = cls.env.ref("product.product_product_4") + cls.currency_eur = cls.env.ref("base.EUR") + cls.currency_eur.active = True + cls.currency_usd = cls.env.ref("base.USD") + cls.currency_usd.active = True + cls.account_receivable = cls.env["account.account"].search( + [ + ( + "account_type", + "=", + "asset_receivable", + ) + ], + limit=1, + ) + cls.account_revenue = cls.env["account.account"].search( + [ + ( + "account_type", + "=", + "income", + ), + ("company_id", "=", cls.env.company.id), + ], + limit=1, + ) + + def create_invoice(self, partner, currency, invoice_date): + """Returns an open invoice""" + invoice = self.invoice_model.create( + { + "partner_id": partner.id, + "currency_id": currency.id, + "move_type": "out_invoice", + "invoice_date": invoice_date, + "invoice_payment_term_id": self.payment_term.id, + "invoice_line_ids": [ + Command.create( + { + "product_id": self.product.id, + "quantity": 1, + "price_unit": 100.00, + "name": "Test", + "account_id": self.account_revenue.id, + } + ) + ], + } + ) + invoice.action_post() + return invoice + + def _run_create_billing_wizard(self, cutoff): + wiz = ( + self.env["wiz.account.billing.cutoff"] + .with_context(default_bill_type="out_invoice") + .create({"cutoff_date": cutoff}) + ) + return wiz.action_create_billings() + + def _created_billing_ids(self, action): + dom = action.get("domain") or [] + for term in dom: + _, _, ids = term + return list(ids) + return [] + + def test_billing_created_for_summary_partner(self): + inv_1 = self.create_invoice( + partner=self.partner_1, + currency=self.currency_usd, + invoice_date=date(2025, 9, 15), + ) + inv_2 = self.create_invoice( + partner=self.partner_2, + currency=self.currency_usd, + invoice_date=date(2025, 9, 15), + ) + inv_3 = self.create_invoice( + partner=self.partner_1, + currency=self.currency_usd, + invoice_date=date(2025, 9, 21), + ) + inv_4 = self.create_invoice( + partner=self.partner_2, + currency=self.currency_usd, + invoice_date=date(2025, 9, 21), + ) + inv_5 = self.create_invoice( + partner=self.partner_1, + currency=self.currency_eur, + invoice_date=date(2025, 9, 21), + ) + inv_6 = self.create_invoice( + partner=self.partner_2, + currency=self.currency_eur, + invoice_date=date(2025, 9, 21), + ) + # 1) cutoff = 2025-09-30 → only partner_1’s 2025-09-15 (inv_1) qualifies + action = self._run_create_billing_wizard(date(2025, 9, 30)) + billing_ids = self._created_billing_ids(action) + billings = self.env["account.billing"].browse(billing_ids) + self.assertEqual(len(billings), 1) + self.assertEqual(billings.billing_line_ids.mapped("move_id"), inv_1) + # 2) cutoff = 2025-10-31 → partner_1 USD/EUR for 2025-09-21 (inv_3, inv_5) + # Already-billed inv_1 must NOT be included again. + action = self._run_create_billing_wizard(date(2025, 10, 31)) + billing_ids = self._created_billing_ids(action) + billings = self.env["account.billing"].browse(billing_ids) + self.assertEqual(len(billings), 2) + self.assertEqual(billings.billing_line_ids.mapped("move_id"), inv_3 | inv_5) + # 3) Re-run same cutoff → nothing new (already billed and still in billed/draft states) + action = self._run_create_billing_wizard(date(2025, 10, 31)) + billing_ids = self._created_billing_ids(action) + billings = self.env["account.billing"].browse(billing_ids) + self.assertFalse(billings) + # 4) Cancel existing billings, enable summary on partner_2, rerun → 4 billings + # (p1 USD/EUR again because previous are cancelled; plus p2 USD/EUR) + self.env["account.billing"].browse([]).search([]).write({"state": "cancel"}) + self.partner_2.use_summary_invoicing = True + action = self._run_create_billing_wizard(date(2025, 10, 31)) + billing_ids = self._created_billing_ids(action) + billings = self.env["account.billing"].browse(billing_ids) + self.assertEqual(len(billings), 4) + self.assertEqual( + billings.billing_line_ids.mapped("move_id"), + inv_1 | inv_2 | inv_3 | inv_4 | inv_5 | inv_6, + ) diff --git a/account_billing_from_cutoff/views/res_partner_views.xml b/account_billing_from_cutoff/views/res_partner_views.xml new file mode 100644 index 00000000..de702553 --- /dev/null +++ b/account_billing_from_cutoff/views/res_partner_views.xml @@ -0,0 +1,18 @@ + + + res.partner.form + res.partner + + + + + + + + + + diff --git a/account_billing_from_cutoff/wizards/__init__.py b/account_billing_from_cutoff/wizards/__init__.py new file mode 100644 index 00000000..3787a862 --- /dev/null +++ b/account_billing_from_cutoff/wizards/__init__.py @@ -0,0 +1 @@ +from . import account_billing_cutoff diff --git a/account_billing_from_cutoff/wizards/account_billing_cutoff.py b/account_billing_from_cutoff/wizards/account_billing_cutoff.py new file mode 100644 index 00000000..895984dc --- /dev/null +++ b/account_billing_from_cutoff/wizards/account_billing_cutoff.py @@ -0,0 +1,65 @@ +# Copyright 2025 Quartile (https://www.quartile.co) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from collections import defaultdict + +from odoo import fields, models + + +class AccountBillingCutoff(models.TransientModel): + _name = "wiz.account.billing.cutoff" + _description = "Account Billing From Cutoff" + + cutoff_date = fields.Date(required=True, default=fields.Date.context_today) + bill_type = fields.Selection( + selection=[("out_invoice", "Customer Invoice"), ("in_invoice", "Vendor Bill")], + readonly=True, + default=lambda self: self._context.get("bill_type", False), + ) + + def _allowed_move_types(self): + if self.bill_type == "out_invoice": + return ["out_invoice", "out_refund", "out_receipt"] + return ["in_invoice", "in_refund", "in_receipt"] + + def _search_moves_domain(self): + billed_move_ids = ( + self.env["account.billing.line"] + .search( + [ + ("billing_id.state", "in", ["draft", "billed"]), + ] + ) + .mapped("move_id") + .ids + ) + return [ + ("id", "not in", billed_move_ids), + ("partner_id.use_summary_invoicing", "=", True), + ("company_id", "=", self.env.company.id), + ("state", "=", "posted"), + ("payment_state", "!=", "paid"), + ("move_type", "in", self._allowed_move_types()), + ("cutoff_date", "<=", self.cutoff_date), + ] + + def action_create_billings(self): + moves = self.env["account.move"].search(self._search_moves_domain()) + if not moves: + return {"type": "ir.actions.act_window_close"} + groups = defaultdict(lambda: self.env["account.move"]) + for m in moves: + key = (m.partner_id.id, m.currency_id.id) + groups[key] |= m + billings = self.env["account.billing"] + for (partner_id, _currency_id), recs in groups.items(): + partner = self.env["res.partner"].browse(partner_id) + billings |= recs._create_billing(partner) + return { + "type": "ir.actions.act_window", + "name": "Billings", + "res_model": "account.billing", + "view_mode": "tree,form", + "domain": [("id", "in", billings.ids)], + "target": "current", + } diff --git a/account_billing_from_cutoff/wizards/account_billing_cutoff.xml b/account_billing_from_cutoff/wizards/account_billing_cutoff.xml new file mode 100644 index 00000000..63ce1a14 --- /dev/null +++ b/account_billing_from_cutoff/wizards/account_billing_cutoff.xml @@ -0,0 +1,54 @@ + + + + wiz.account.billing.cutoff + wiz.account.billing.cutoff + +
+ + + + + + + + +
+
+
+
+
+ + Create Billing From Cutoff + wiz.account.billing.cutoff + form + {'bill_type':'out_invoice'} + new + + + Create Billing From Cutoff + wiz.account.billing.cutoff + form + {'bill_type':'in_invoice'} + new + + + +
diff --git a/setup/account_billing_from_cutoff/odoo/addons/account_billing_from_cutoff b/setup/account_billing_from_cutoff/odoo/addons/account_billing_from_cutoff new file mode 120000 index 00000000..65075eb6 --- /dev/null +++ b/setup/account_billing_from_cutoff/odoo/addons/account_billing_from_cutoff @@ -0,0 +1 @@ +../../../../account_billing_from_cutoff \ No newline at end of file diff --git a/setup/account_billing_from_cutoff/setup.py b/setup/account_billing_from_cutoff/setup.py new file mode 100644 index 00000000..28c57bb6 --- /dev/null +++ b/setup/account_billing_from_cutoff/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)