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

[15.0][ADD] account_invoice_sale_attachment #3392

Open
wants to merge 1 commit into
base: 15.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
95 changes: 95 additions & 0 deletions account_invoice_sale_attachment/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
===============================
Account Invoice Sale Attachment
===============================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:6338887aa40094db146e7a57cdf37bf46f6f98e562efa611c85e6848ea491e08
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |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%2Fsale--workflow-lightgray.png?logo=github
:target: https://github.com/OCA/sale-workflow/tree/15.0/account_invoice_sale_attachment
:alt: OCA/sale-workflow
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/sale-workflow-15-0/sale-workflow-15-0-account_invoice_sale_attachment
: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/sale-workflow&target_branch=15.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module allows the automatic attachment of related sale order documents when an
invoice is sent.

This module is especially useful for businesses that require the inclusion of
sale order details when sending invoices, ensuring that customers have all
necessary documentation at their fingertips.

**Table of contents**

.. contents::
:local:

Configuration
=============

1. Select a partner.
2. In the Sales/Purchases tab, check the box "Allow Joining Sale Order Documents".

Usage
=====

1. Create an invoice linked to one or more sale orders.
2. Click the Send by Email.
3. The system will automatically generate and attach the sale order documents to the invoice email.
4. The email sent to the customer will include the invoice and all attached sale order documents.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/sale-workflow/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 <https://github.com/OCA/sale-workflow/issues/new?body=module:%20account_invoice_sale_attachment%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

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

Credits
=======

Authors
~~~~~~~

* ACSONE SA/NV

Contributors
~~~~~~~~~~~~

* Souheil Bejaoui <[email protected]>

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/sale-workflow <https://github.com/OCA/sale-workflow/tree/15.0/account_invoice_sale_attachment>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 2 additions & 0 deletions account_invoice_sale_attachment/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import models
from . import wizards
12 changes: 12 additions & 0 deletions account_invoice_sale_attachment/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright 2024 ACSONE SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
"name": "Account Invoice Sale Attachment",
"version": "15.0.1.0.0",
"license": "AGPL-3",
"author": "ACSONE SA/NV, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/sale-workflow",
"depends": ["sale"],
"data": ["views/res_partner.xml"],
}
3 changes: 3 additions & 0 deletions account_invoice_sale_attachment/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import res_partner
from . import account_move
from . import sale_order
21 changes: 21 additions & 0 deletions account_invoice_sale_attachment/models/account_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2024 ACSONE SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import models


class AccountMove(models.Model):

_inherit = "account.move"

def action_invoice_sent(self):
res = super().action_invoice_sent()
if not self.partner_id.allow_invoice_sale_order_attachment:
return res
sale_orders = self.invoice_line_ids.sale_line_ids.mapped("order_id")
if not sale_orders:
return res

Check warning on line 17 in account_invoice_sale_attachment/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

account_invoice_sale_attachment/models/account_move.py#L17

Added line #L17 was not covered by tests
res["context"][
"sale_order_attachments"
] = sale_orders._get_sale_document_attachments().ids
return res
20 changes: 20 additions & 0 deletions account_invoice_sale_attachment/models/res_partner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2024 ACSONE SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, fields, models


class ResPartner(models.Model):

_inherit = "res.partner"

allow_invoice_sale_order_attachment = fields.Boolean(
string="Allow Joining Sale Order Documents",
default=False,
help="If enabled, sale order documents will be attached to the invoice email.",
)

@api.model
def _commercial_fields(self):
res = super()._commercial_fields()
return res + ["allow_invoice_sale_order_attachment"]
44 changes: 44 additions & 0 deletions account_invoice_sale_attachment/models/sale_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Copyright 2024 ACSONE SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

import base64

from odoo import fields, models


class SaleOrder(models.Model):

_inherit = "sale.order"

sale_document_attachment = fields.Binary(copy=False, attachment=True, readonly=True)

def _prepare_sale_document_attachment_vals(self):
pdf_data = self.env.ref("sale.action_report_saleorder")._render_qweb_pdf(
self.ids
)[0]
return {
"name": self.name,
"type": "binary",
"datas": base64.b64encode(pdf_data).decode("utf-8"),
"res_model": self._name,
"res_field": "sale_document_attachment",
"res_id": self.id,
}

def _create_sale_document_attachment(self):
self.ensure_one()
self.env["ir.attachment"].create(
[rec._prepare_sale_document_attachment_vals() for rec in self]
)

def _get_sale_document_attachments(self):
for rec in self:
if not rec.sale_document_attachment:
rec._create_sale_document_attachment()
return self.env["ir.attachment"].search(
[
("res_id", "in", self.ids),
("res_model", "=", self._name),
("res_field", "=", "sale_document_attachment"),
]
)
2 changes: 2 additions & 0 deletions account_invoice_sale_attachment/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1. Select a partner.
2. In the Sales/Purchases tab, check the box "Allow Joining Sale Order Documents".
1 change: 1 addition & 0 deletions account_invoice_sale_attachment/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Souheil Bejaoui <[email protected]>
6 changes: 6 additions & 0 deletions account_invoice_sale_attachment/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
This module allows the automatic attachment of related sale order documents when an
invoice is sent.

This module is especially useful for businesses that require the inclusion of
sale order details when sending invoices, ensuring that customers have all
necessary documentation at their fingertips.
4 changes: 4 additions & 0 deletions account_invoice_sale_attachment/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
1. Create an invoice linked to one or more sale orders.
2. Click the Send by Email.
3. The system will automatically generate and attach the sale order documents to the invoice email.
4. The email sent to the customer will include the invoice and all attached sale order documents.
Loading
Loading