diff --git a/account_billing_portal/README.rst b/account_billing_portal/README.rst new file mode 100644 index 00000000..6c002599 --- /dev/null +++ b/account_billing_portal/README.rst @@ -0,0 +1,112 @@ +====================== +Account Billing Portal +====================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:89babb2f094b4575c62722a24872eaccae37cdc5edc018aaaf18c671e7d243a1 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Faccount--invoicing-lightgray.png?logo=github + :target: https://github.com/OCA/account-invoicing/tree/18.0/account_billing_portal + :alt: OCA/account-invoicing +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/account-invoicing-18-0/account-invoicing-18-0-account_billing_portal + :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-invoicing&target_branch=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module adds a portal view for account billings. It allows users to +change the portal billing report template via a configurable setting. It +also adds the ability to send emails to partners directly from billing +records with the billing report attached. + +.. 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 choose the billing portal template: + +- Go to *Invoicing → Configuration → Settings*. +- Set a value in **Choose Billing Email Template**. If set, this + template will be used when sending billing emails to + customers/vendors. If left empty, the default template from the + *Account Billing Portal* module will be used instead. +- Set a value in **Choose Billing Portal Report**. If set, this report + will be used in the billing portal and as the PDF attachment in + billing emails. If left empty, the standard report from the *Account + Billing* module will be used instead. + +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. + +.. |maintainer-yostashiro| image:: https://github.com/yostashiro.png?size=40px + :target: https://github.com/yostashiro + :alt: yostashiro +.. |maintainer-aungkokolin1997| image:: https://github.com/aungkokolin1997.png?size=40px + :target: https://github.com/aungkokolin1997 + :alt: aungkokolin1997 + +Current `maintainers `__: + +|maintainer-yostashiro| |maintainer-aungkokolin1997| + +This module is part of the `OCA/account-invoicing `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/account_billing_portal/__init__.py b/account_billing_portal/__init__.py new file mode 100644 index 00000000..91c5580f --- /dev/null +++ b/account_billing_portal/__init__.py @@ -0,0 +1,2 @@ +from . import controllers +from . import models diff --git a/account_billing_portal/__manifest__.py b/account_billing_portal/__manifest__.py new file mode 100644 index 00000000..df0bfe0e --- /dev/null +++ b/account_billing_portal/__manifest__.py @@ -0,0 +1,22 @@ +# Copyright 2025 Quartile (https://www.quartile.co) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "Account Billing Portal", + "version": "18.0.1.0.0", + "author": "Quartile, Odoo Community Association (OCA)", + "category": "Accounting", + "website": "https://github.com/OCA/account-invoicing", + "license": "AGPL-3", + "depends": ["account_billing"], + "data": [ + "security/account_billing_portal_security.xml", + "security/ir.model.access.csv", + "data/mail_template_data.xml", + "views/account_billing_portal_templates.xml", + "views/account_billing_views.xml", + "views/res_config_settings_views.xml", + ], + "maintainers": ["yostashiro", "aungkokolin1997"], + "development_status": "Alpha", + "installable": True, +} diff --git a/account_billing_portal/controllers/__init__.py b/account_billing_portal/controllers/__init__.py new file mode 100644 index 00000000..8c3feb6f --- /dev/null +++ b/account_billing_portal/controllers/__init__.py @@ -0,0 +1 @@ +from . import portal diff --git a/account_billing_portal/controllers/portal.py b/account_billing_portal/controllers/portal.py new file mode 100644 index 00000000..209c7e3d --- /dev/null +++ b/account_billing_portal/controllers/portal.py @@ -0,0 +1,158 @@ +# Copyright 2025 Quartile (https://www.quartile.co) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from collections import OrderedDict + +from odoo import _, http +from odoo.exceptions import AccessError, MissingError +from odoo.http import request + +from odoo.addons.portal.controllers.portal import CustomerPortal +from odoo.addons.portal.controllers.portal import pager as portal_pager + + +class CustomerPortalBilling(CustomerPortal): + def _show_report(self, model, report_type, report_ref, download=False): + if model._name != "account.billing": + return super()._show_report(model, report_type, report_ref, download) + billing_report = request.env.user.company_id.billing_portal_report + if billing_report: + external_id = billing_report.get_external_id() + report_ref = external_id.get(billing_report.id) + return super()._show_report(model, report_type, report_ref, download) + + def _get_billing_domain(self, bill_type=None): + domain = [("state", "=", "billed")] + if bill_type: + domain.append(("bill_type", "=", bill_type)) + return domain + + def _prepare_home_portal_values(self, counters): + values = super()._prepare_home_portal_values(counters) + Billing = request.env["account.billing"] + if "customer_bill_count" in counters: + values["customer_bill_count"] = ( + Billing.search_count(self._get_billing_domain("out_invoice")) + if Billing.has_access("read") + else 0 + ) + if "vendor_bill_count" in counters: + values["vendor_bill_count"] = ( + Billing.search_count(self._get_billing_domain("in_invoice")) + if Billing.has_access("read") + else 0 + ) + return values + + def _get_billing_searchbar_sortings(self): + return { + "date": {"label": _("Newest"), "order": "create_date desc, id desc"}, + "billing_date": {"label": _("Billing Date"), "order": "date desc, id desc"}, + "name": {"label": _("Name"), "order": "name asc, id asc"}, + } + + def _render_billing_portal( + self, + page, + sortby, + filterby, + searchbar_filters, + default_filter, + ): + values = self._prepare_portal_layout_values() + Billing = request.env["account.billing"] + domain = self._get_billing_domain() + searchbar_sortings = self._get_billing_searchbar_sortings() + if not sortby: + sortby = "date" + order = searchbar_sortings[sortby]["order"] + if searchbar_filters: + if not filterby or filterby not in searchbar_filters: + filterby = default_filter + domain += searchbar_filters[filterby]["domain"] + count = Billing.search_count(domain) + pager = portal_pager( + url="/my/billings", + url_args={"sortby": sortby, "filterby": filterby}, + total=count, + page=page, + step=self._items_per_page, + ) + billings = Billing.search( + domain, order=order, limit=self._items_per_page, offset=pager["offset"] + ) + request.session["my_billing_history"] = billings.ids[:100] + values.update( + { + "billings": billings, + "page_name": "billing", + "pager": pager, + "searchbar_sortings": searchbar_sortings, + "sortby": sortby, + "searchbar_filters": OrderedDict(sorted(searchbar_filters.items())), + "filterby": filterby, + "default_url": "/my/billings", + } + ) + return request.render("account_billing_portal.portal_my_billings", values) + + @http.route( + ["/my/billings", "/my/billings/page/"], + type="http", + auth="user", + website=True, + ) + def portal_my_billings(self, page=1, sortby=None, filterby=None, **kw): + return self._render_billing_portal( + page, + sortby, + filterby, + { + "all": { + "label": _("All"), + "domain": [("state", "=", "billed")], + }, + "out_invoice": { + "label": _("Customer Bills"), + "domain": [("bill_type", "=", "out_invoice")], + }, + "in_invoice": { + "label": _("Vendor Bills"), + "domain": [("bill_type", "=", "in_invoice")], + }, + }, + "all", + ) + + def _billing_get_page_view_values(self, billing, access_token, **kwargs): + values = { + "billing": billing, + "page_name": "billing", + "report_type": "html", + } + return self._get_page_view_values( + billing, access_token, values, "my_billing_history", False, **kwargs + ) + + @http.route( + ["/my/billings/"], type="http", auth="public", website=True + ) + def portal_my_billing( + self, billing_id, access_token=None, report_type=None, download=False, **kw + ): + try: + billing_sudo = self._document_check_access( + "account.billing", billing_id, access_token + ) + except (AccessError, MissingError): + return request.redirect("/my") + if report_type in ("html", "pdf", "text"): + pdf_report_name = "account_billing.report_account_billing" + return self._show_report( + model=billing_sudo, + report_type=report_type, + report_ref=pdf_report_name, + download=download, + ) + values = self._billing_get_page_view_values(billing_sudo, access_token, **kw) + return request.render("account_billing_portal.portal_my_billing", values) diff --git a/account_billing_portal/data/mail_template_data.xml b/account_billing_portal/data/mail_template_data.xml new file mode 100644 index 00000000..5f6e19ab --- /dev/null +++ b/account_billing_portal/data/mail_template_data.xml @@ -0,0 +1,37 @@ + + + + Billing + + {{ object.company_id.name }} Billing (Ref {{ object.name or 'n/a' }}) + {{ object.partner_id.id }} + Sent billing to customer/vendor + +
+

+ Dear Brandon Freeman + + (Azure Interior) + +

+ Please find attached the billing from YourCompany. +

+ If you have any questions, please do not hesitate to contact us. +

+ Best regards, + +
+
+ + +

+
+
+ {{ object.partner_id.lang }} + +
+
diff --git a/account_billing_portal/i18n/ja.po b/account_billing_portal/i18n/ja.po new file mode 100644 index 00000000..35e1d41f --- /dev/null +++ b/account_billing_portal/i18n/ja.po @@ -0,0 +1,264 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_billing_portal +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 18.0+e\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2026-02-16 05:51+0000\n" +"PO-Revision-Date: 2026-02-16 05:51+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_billing_portal +#: model:mail.template,body_html:account_billing_portal.email_template_billing +msgid "" +"
\n" +"

\n" +" Dear Brandon Freeman\n" +" \n" +" (Azure Interior)\n" +" \n" +"

\n" +" Please find attached the billing from YourCompany.\n" +"

\n" +" If you have any questions, please do not hesitate to contact us.\n" +"

\n" +" Best regards,\n" +" \n" +"
\n" +"
\n" +" \n" +" \n" +"

\n" +"
\n" +" " +msgstr "" + +#. module: account_billing_portal +#: model_terms:ir.ui.view,arch_db:account_billing_portal.portal_my_billing +msgid " Download" +msgstr " ダウンロード" + +#. module: account_billing_portal +#: model:ir.model.fields,field_description:account_billing_portal.field_account_billing__access_warning +msgid "Access warning" +msgstr "アクセス警告" + +#. module: account_billing_portal +#: model:ir.model,name:account_billing_portal.model_account_billing +msgid "Account Billing" +msgstr "合計請求書" + +#. module: account_billing_portal +#. odoo-python +#: code:addons/account_billing_portal/controllers/portal.py:0 +msgid "All" +msgstr "全て" + +#. module: account_billing_portal +#: model:mail.template,name:account_billing_portal.email_template_billing +msgid "Billing" +msgstr "合計請求書" + +#. module: account_billing_portal +#: model_terms:ir.ui.view,arch_db:account_billing_portal.portal_my_billings +msgid "Billing #" +msgstr "合計請求書" + +#. module: account_billing_portal +#. odoo-python +#: code:addons/account_billing_portal/controllers/portal.py:0 +#: model_terms:ir.ui.view,arch_db:account_billing_portal.portal_my_billings +msgid "Billing Date" +msgstr "合計請求日" + +#. module: account_billing_portal +#: model:ir.model.fields,field_description:account_billing_portal.field_res_company__billing_portal_report +#: model:ir.model.fields,field_description:account_billing_portal.field_res_config_settings__billing_portal_report +msgid "Billing Portal Report" +msgstr "合計請求書ポータルレポート" + +#. module: account_billing_portal +#: model:ir.model.fields,field_description:account_billing_portal.field_res_company__billing_email_template_id +#: model:ir.model.fields,field_description:account_billing_portal.field_res_config_settings__billing_email_template_id +msgid "Billing email template" +msgstr "合計請求書メールテンプレート" + +#. module: account_billing_portal +#: model_terms:ir.ui.view,arch_db:account_billing_portal.portal_my_billings +#: model_terms:ir.ui.view,arch_db:account_billing_portal.portal_my_home_menu_billing +msgid "Billings" +msgstr "合計請求書" + +#. module: account_billing_portal +#: model_terms:ir.ui.view,arch_db:account_billing_portal.view_invoice_config_settings +msgid "Choose Billing Email Template" +msgstr "合計請求書メールテンプレートを選択" + +#. module: account_billing_portal +#: model_terms:ir.ui.view,arch_db:account_billing_portal.view_invoice_config_settings +msgid "Choose Billing Portal Report" +msgstr "合計請求書ポータルレポートを選択" + +#. module: account_billing_portal +#: model_terms:ir.ui.view,arch_db:account_billing_portal.portal_my_billing +msgid "Communication history" +msgstr "通信履歴" + +#. module: account_billing_portal +#: model:ir.model,name:account_billing_portal.model_res_company +msgid "Companies" +msgstr "会社" + +#. module: account_billing_portal +#. odoo-python +#: code:addons/account_billing_portal/models/account_billing.py:0 +msgid "Compose Email" +msgstr "Eメール作成" + +#. module: account_billing_portal +#: model:ir.model,name:account_billing_portal.model_res_config_settings +msgid "Config Settings" +msgstr "コンフィグ設定" + +#. module: account_billing_portal +#. odoo-python +#: code:addons/account_billing_portal/controllers/portal.py:0 +msgid "Customer Bills" +msgstr "顧客請求書" + +#. module: account_billing_portal +#: model:ir.model.fields,help:account_billing_portal.field_account_billing__access_url +msgid "Customer Portal URL" +msgstr "顧客ポータルURL" + +#. module: account_billing_portal +#: model_terms:ir.ui.view,arch_db:account_billing_portal.portal_my_billing +msgid "Download" +msgstr "ダウンロード" + +#. module: account_billing_portal +#: model_terms:ir.ui.view,arch_db:account_billing_portal.portal_my_home_billing +msgid "Follow, download or pay our billings" +msgstr "確認、ダウンロード、またはお支払いが可能です" + +#. module: account_billing_portal +#: model_terms:ir.ui.view,arch_db:account_billing_portal.portal_my_home_billing +msgid "Follow, download or pay your billings" +msgstr "確認、ダウンロード、またはお支払いが可能です" + +#. module: account_billing_portal +#: model_terms:ir.ui.view,arch_db:account_billing_portal.view_invoice_config_settings +msgid "" +"If set, this report will be used for both the billing portal and the billing" +" email attachment sent to the partner. If left empty, the standard report " +"from the Account Billing module will be used instead." +msgstr "設定されている場合、このレポートは請求ポータルおよび取引先へ送信される請求メールの" +"添付ファイルの両方に使用されます。未設定の場合は、Account Billing の標準レポートが使用されます。" + +#. module: account_billing_portal +#. odoo-python +#: code:addons/account_billing_portal/controllers/portal.py:0 +msgid "Name" +msgstr "名称" + +#. module: account_billing_portal +#. odoo-python +#: code:addons/account_billing_portal/controllers/portal.py:0 +msgid "Newest" +msgstr "最新" + +#. module: account_billing_portal +#: model_terms:ir.ui.view,arch_db:account_billing_portal.portal_my_home_billing +msgid "Our Billings" +msgstr "当社からの合計請求書" + +#. module: account_billing_portal +#. odoo-python +#: code:addons/account_billing_portal/models/account_billing.py:0 +msgid "Please configure the Billing Email Template in the settings." +msgstr "設定画面で合計請求書メールテンプレートを設定してください" + +#. module: account_billing_portal +#. odoo-python +#: code:addons/account_billing_portal/models/account_billing.py:0 +msgid "Please configure the Billing Portal Report in the settings." +msgstr "設定画面で合計請求書ポータルレポートを設定してください" + +#. module: account_billing_portal +#: model:ir.model.fields,field_description:account_billing_portal.field_account_billing__access_url +msgid "Portal Access URL" +msgstr "ポータルアクセスURL" + +#. module: account_billing_portal +#: model_terms:ir.ui.view,arch_db:account_billing_portal.view_account_billing_form_inherit +msgid "Preview" +msgstr "プレビュー" + +#. module: account_billing_portal +#: model_terms:ir.ui.view,arch_db:account_billing_portal.view_account_billing_form_inherit +msgid "Preview Billing" +msgstr "プレビュー合計請求書" + +#. module: account_billing_portal +#: model:ir.model.fields,field_description:account_billing_portal.field_account_billing__access_token +msgid "Security Token" +msgstr "セキュリティトークン" + +#. module: account_billing_portal +#: model_terms:ir.ui.view,arch_db:account_billing_portal.view_invoice_config_settings +msgid "" +"Select the email template used for billing emails. If left empty, the " +"default template provided by Account Billing Portal will be used." +msgstr "請求メールに使用するメールテンプレートを選択してください。" +"未設定の場合は、Account Billing Portalが提供するデフォルトメールテンプレートが使用されます。" + +#. module: account_billing_portal +#: model_terms:ir.ui.view,arch_db:account_billing_portal.view_account_billing_form_inherit +msgid "Send by Email" +msgstr "Eメールで送信" + +#. module: account_billing_portal +#: model:mail.template,description:account_billing_portal.email_template_billing +msgid "Sent billing to customer/vendor" +msgstr "顧客/仕入先へ合計請求書を送信" + +#. module: account_billing_portal +#: model:ir.model.fields,help:account_billing_portal.field_res_company__billing_email_template_id +#: model:ir.model.fields,help:account_billing_portal.field_res_config_settings__billing_email_template_id +msgid "Template used for sending billing emails." +msgstr "合計請求書メール送信に使用されるテンプレートです。" + +#. module: account_billing_portal +#: model_terms:ir.ui.view,arch_db:account_billing_portal.portal_my_billings +msgid "There are currently no billings for your account." +msgstr "現在、お客様のアカウントに合計請求書はありません。" + +#. module: account_billing_portal +#: model:ir.model.fields,help:account_billing_portal.field_res_company__billing_portal_report +#: model:ir.model.fields,help:account_billing_portal.field_res_config_settings__billing_portal_report +msgid "" +"This report template will be used in the billing portal to show the billing." +msgstr "このレポートテンプレートは、請求ポータルで請求書を表示するために使用されます。" + +#. module: account_billing_portal +#. odoo-python +#: code:addons/account_billing_portal/controllers/portal.py:0 +msgid "Vendor Bills" +msgstr "仕入先請求書" + +#. module: account_billing_portal +#: model_terms:ir.ui.view,arch_db:account_billing_portal.portal_my_home_billing +msgid "Your Billings" +msgstr "貴社からの合計請求書" + +#. module: account_billing_portal +#: model:mail.template,subject:account_billing_portal.email_template_billing +msgid "{{ object.company_id.name }} Billing (Ref {{ object.name or 'n/a' }})" +msgstr "{{ object.company_id.name }} 合計請求書 (Ref {{ object.name or 'n/a' }})" diff --git a/account_billing_portal/models/__init__.py b/account_billing_portal/models/__init__.py new file mode 100644 index 00000000..77c3a66b --- /dev/null +++ b/account_billing_portal/models/__init__.py @@ -0,0 +1,3 @@ +from . import account_billing +from . import res_company +from . import res_config_settings diff --git a/account_billing_portal/models/account_billing.py b/account_billing_portal/models/account_billing.py new file mode 100644 index 00000000..ed8d5d2c --- /dev/null +++ b/account_billing_portal/models/account_billing.py @@ -0,0 +1,114 @@ +# Copyright 2025 Quartile (https://www.quartile.co) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +import base64 + +from odoo import Command, _, fields, models, tools +from odoo.exceptions import UserError +from odoo.tools.safe_eval import safe_eval + + +class AccountBilling(models.Model): + _inherit = ["account.billing", "portal.mixin"] + _name = "account.billing" + + def _compute_access_url(self): + super()._compute_access_url() + for billing in self: + billing.access_url = f"/my/billings/{billing.id}" + return + + def _get_report_base_filename(self): + self.ensure_one() + return self.name + + def _get_eval_context(self): + """Get evaluation context for safe_eval expressions.""" + return { + "time": tools.safe_eval.time, + "datetime": tools.safe_eval.datetime, + "dateutil": tools.safe_eval.dateutil, + "timezone": tools.safe_eval.pytz.timezone, + "context_today": lambda: fields.Date.context_today(self), + "object": self, + } + + def action_billing_send(self): + self.ensure_one() + template = self.company_id.billing_email_template_id or self.env.ref( + "account_billing_portal.email_template_billing" + ) + if not template: + raise UserError( + _("Please configure the Billing Email Template in the settings.") + ) + try: + compose_form_id = self.env["ir.model.data"]._xmlid_lookup( + "mail.email_compose_message_wizard_form" + )[1] + except ValueError: + compose_form_id = False + ctx = dict(self.env.context or {}) + report = self.company_id.billing_portal_report or self.env.ref( + "account_billing.report_account_billing" + ) + if not report: + raise UserError( + _("Please configure the Billing Portal Report in the settings.") + ) + pdf_content, _type = report._render_qweb_pdf(report.id, self.ids) + if report.print_report_name: + eval_context = self._get_eval_context() + attachment_name = safe_eval(report.print_report_name, eval_context) + else: + attachment_name = self.display_name if self.display_name else "BILLING" + if not attachment_name.endswith(".pdf"): + attachment_name = f"{attachment_name}.pdf" + attach = self.env["ir.attachment"].create( + { + "name": attachment_name, + "type": "binary", + "datas": base64.b64encode(pdf_content), + "mimetype": "application/pdf", + "res_model": "account.billing", + "res_id": self.id, + } + ) + email_xml_id = "mail.mail_notification_layout_with_responsible_signature" + ctx.update( + { + "default_model": "account.billing", + "default_res_ids": self.ids, + "default_template_id": template.id, + "default_composition_mode": "comment", + "default_email_layout_xmlid": email_xml_id, + "default_attachment_ids": [Command.set([attach.id])], + "email_notification_allow_footer": True, + "force_email": True, + } + ) + return { + "name": _("Compose Email"), + "type": "ir.actions.act_window", + "view_mode": "form", + "res_model": "mail.compose.message", + "views": [(compose_form_id, "form")], + "view_id": compose_form_id, + "target": "new", + "context": ctx, + } + + def preview_billing(self): + self.ensure_one() + return { + "type": "ir.actions.act_url", + "target": "self", + "url": self.get_portal_url(), + } + + def validate_billing(self): + res = super().validate_billing() + for rec in self.filtered(lambda x: x.state == "billed"): + if rec.partner_id not in rec.message_partner_ids: + rec.message_subscribe([rec.partner_id.id]) + return res diff --git a/account_billing_portal/models/res_company.py b/account_billing_portal/models/res_company.py new file mode 100644 index 00000000..68d738c8 --- /dev/null +++ b/account_billing_portal/models/res_company.py @@ -0,0 +1,21 @@ +# 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 ResCompany(models.Model): + _inherit = "res.company" + + billing_email_template_id = fields.Many2one( + "mail.template", + string="Billing email template", + domain=[("model", "=", "account.billing")], + help="Template used for sending billing emails.", + ) + billing_portal_report = fields.Many2one( + "ir.actions.report", + domain=[("model", "=", "account.billing")], + help="This report template will be used in the billing portal to " + "show the billing.", + ) diff --git a/account_billing_portal/models/res_config_settings.py b/account_billing_portal/models/res_config_settings.py new file mode 100644 index 00000000..d361198c --- /dev/null +++ b/account_billing_portal/models/res_config_settings.py @@ -0,0 +1,17 @@ +# 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 ResConfigSettings(models.TransientModel): + _inherit = "res.config.settings" + + billing_email_template_id = fields.Many2one( + related="company_id.billing_email_template_id", + readonly=False, + ) + billing_portal_report = fields.Many2one( + related="company_id.billing_portal_report", + readonly=False, + ) diff --git a/account_billing_portal/pyproject.toml b/account_billing_portal/pyproject.toml new file mode 100644 index 00000000..4231d0cc --- /dev/null +++ b/account_billing_portal/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/account_billing_portal/readme/CONFIGURE.md b/account_billing_portal/readme/CONFIGURE.md new file mode 100644 index 00000000..429c2eb5 --- /dev/null +++ b/account_billing_portal/readme/CONFIGURE.md @@ -0,0 +1,13 @@ +To choose the billing portal template: + +- Go to *Invoicing → Configuration → Settings*. +- Set a value in **Choose Billing Email Template**. + If set, this template will be used when sending billing emails to + customers/vendors. + If left empty, the default template from the *Account Billing Portal* + module will be used instead. +- Set a value in **Choose Billing Portal Report**. + If set, this report will be used in the billing portal and as the PDF + attachment in billing emails. + If left empty, the standard report from the *Account Billing* module + will be used instead. diff --git a/account_billing_portal/readme/CONTRIBUTORS.md b/account_billing_portal/readme/CONTRIBUTORS.md new file mode 100644 index 00000000..faae3280 --- /dev/null +++ b/account_billing_portal/readme/CONTRIBUTORS.md @@ -0,0 +1,2 @@ +- [Quartile](https://www.quartile.co): + - Aung Ko Ko Lin diff --git a/account_billing_portal/readme/DESCRIPTION.md b/account_billing_portal/readme/DESCRIPTION.md new file mode 100644 index 00000000..2577a23d --- /dev/null +++ b/account_billing_portal/readme/DESCRIPTION.md @@ -0,0 +1,4 @@ +This module adds a portal view for account billings. It allows users to change the +portal billing report template via a configurable setting. It also adds the ability +to send emails to partners directly from billing records with the billing report +attached. diff --git a/account_billing_portal/security/account_billing_portal_security.xml b/account_billing_portal/security/account_billing_portal_security.xml new file mode 100644 index 00000000..974235e9 --- /dev/null +++ b/account_billing_portal/security/account_billing_portal_security.xml @@ -0,0 +1,19 @@ + + + + Portal Billings + + [('state', '=', 'billed'), ('message_partner_ids','child_of',[user.commercial_partner_id.id])] + + + + Portal Billing Lines + + [('state', '=', 'billed'), ('billing_id.message_partner_ids','child_of',[user.commercial_partner_id.id])] + + + diff --git a/account_billing_portal/security/ir.model.access.csv b/account_billing_portal/security/ir.model.access.csv new file mode 100644 index 00000000..0f9fc7a2 --- /dev/null +++ b/account_billing_portal/security/ir.model.access.csv @@ -0,0 +1,3 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_account_billing_portal,account.billing.portal,account_billing.model_account_billing,base.group_portal,1,0,0,0 +access_account_billing_line_portal,account.billing.line.portal,account_billing.model_account_billing_line,base.group_portal,1,0,0,0 diff --git a/account_billing_portal/static/description/index.html b/account_billing_portal/static/description/index.html new file mode 100644 index 00000000..5ce5223f --- /dev/null +++ b/account_billing_portal/static/description/index.html @@ -0,0 +1,453 @@ + + + + + +Account Billing Portal + + + +
+

Account Billing Portal

+ + +

Alpha License: AGPL-3 OCA/account-invoicing Translate me on Weblate Try me on Runboat

+

This module adds a portal view for account billings. It allows users to +change the portal billing report template via a configurable setting. It +also adds the ability to send emails to partners directly from billing +records with the billing report attached.

+
+

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 choose the billing portal template:

+
    +
  • Go to Invoicing → Configuration → Settings.
  • +
  • Set a value in Choose Billing Email Template. If set, this +template will be used when sending billing emails to +customers/vendors. If left empty, the default template from the +Account Billing Portal module will be used instead.
  • +
  • Set a value in Choose Billing Portal Report. If set, this report +will be used in the billing portal and as the PDF attachment in +billing emails. If left empty, the standard report from the Account +Billing module will be used instead.
  • +
+
+
+

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.

+

Current maintainers:

+

yostashiro aungkokolin1997

+

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

+

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

+
+
+
+ + diff --git a/account_billing_portal/tests/__init__.py b/account_billing_portal/tests/__init__.py new file mode 100644 index 00000000..82403515 --- /dev/null +++ b/account_billing_portal/tests/__init__.py @@ -0,0 +1 @@ +from . import test_account_billing_portal diff --git a/account_billing_portal/tests/test_account_billing_portal.py b/account_billing_portal/tests/test_account_billing_portal.py new file mode 100644 index 00000000..fb68bb07 --- /dev/null +++ b/account_billing_portal/tests/test_account_billing_portal.py @@ -0,0 +1,113 @@ +# Copyright 2025 Quartile (https://www.quartile.co) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import Command, fields +from odoo.tests.common import HttpCase, tagged + + +@tagged("post_install", "-at_install") +class TestAccountBillingPortal(HttpCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.company = cls.env.company + cls.portal_partner = cls.env["res.partner"].create( + { + "name": "Portal Partner", + "email": "portal.partner@example.com", + } + ) + cls.portal_user = ( + cls.env["res.users"] + .with_context(no_reset_password=True) + .create( + { + "name": "Portal User", + "login": "portal_user", + "password": "portal_user", + "email": "portal_user@example.com", + "partner_id": cls.portal_partner.id, + "groups_id": [Command.set([cls.env.ref("base.group_portal").id])], + "company_id": cls.company.id, + "company_ids": [Command.set([cls.company.id])], + } + ) + ) + cls.product = cls.env["product.product"].create({"name": "Test Product"}) + cls.account_revenue = cls.env["account.account"].search( + [ + ("account_type", "=", "income"), + ("company_ids", "=", cls.company.id), + ], + limit=1, + ) + inv1 = cls._create_posted_invoice(partner_id=cls.portal_partner.id, amount=100) + inv2 = cls._create_posted_invoice(partner_id=cls.portal_partner.id, amount=200) + action = (inv1 + inv2).action_create_billing() + cls.portal_billing = cls.env["account.billing"].browse(action["res_id"]) + cls.portal_billing.validate_billing() + cls.other_partner = cls.env["res.partner"].create( + { + "name": "Other Partner", + "email": "other.partner@example.com", + } + ) + inv3 = cls._create_posted_invoice(partner_id=cls.other_partner.id, amount=123) + action2 = inv3.action_create_billing() + cls.other_billing = cls.env["account.billing"].browse(action2["res_id"]) + cls.other_billing.validate_billing() + + @classmethod + def _create_posted_invoice(cls, partner_id, amount, move_type="out_invoice"): + move = cls.env["account.move"].create( + { + "partner_id": partner_id, + "move_type": move_type, + "invoice_date": fields.Date.context_today(cls.env.user), + "date": fields.Date.context_today(cls.env.user), + "invoice_line_ids": [ + Command.create( + { + "name": "Test line", + "product_id": cls.product.id, + "quantity": 1, + "price_unit": amount, + "account_id": cls.account_revenue.id, + } + ) + ], + } + ) + move.action_post() + return move + + def test_portal_billings_list_renders(self): + self.authenticate(self.portal_user.login, "portal_user") + res = self.url_open("/my/billings") + self.assertEqual(res.status_code, 200) + self.assertIn(self.portal_billing.name, res.text) + + def test_portal_billing_detail_renders(self): + self.authenticate(self.portal_user.login, "portal_user") + res = self.url_open(f"/my/billings/{self.portal_billing.id}") + self.assertEqual(res.status_code, 200) + self.assertIn(self.portal_billing.name, res.text) + + def test_portal_billing_detail_redirects_when_not_allowed(self): + self.authenticate(self.portal_user.login, "portal_user") + res = self.url_open( + f"/my/billings/{self.other_billing.id}", allow_redirects=False + ) + self.assertNotEqual(res.status_code, 200) + self.assertTrue(res.headers.get("Location", "").endswith("/my")) + + def test_action_billing_send(self): + result = self.portal_billing.action_billing_send() + self.assertEqual(result["type"], "ir.actions.act_window") + self.assertEqual(result["res_model"], "mail.compose.message") + self.assertEqual(result["target"], "new") + # Check that a PDF attachment was created and linked in context + ctx = result["context"] + attach_ids = ctx["default_attachment_ids"][0][2] + attachment = self.env["ir.attachment"].browse(attach_ids[0]) + self.assertTrue(attachment) diff --git a/account_billing_portal/views/account_billing_portal_templates.xml b/account_billing_portal/views/account_billing_portal_templates.xml new file mode 100644 index 00000000..183220d4 --- /dev/null +++ b/account_billing_portal/views/account_billing_portal_templates.xml @@ -0,0 +1,168 @@ + + + + + + + +