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

[T-6490][17.0][ADD] crm_lead_attach_related_saleorder_report #12

Merged
merged 1 commit into from
Sep 25, 2024
Merged
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
83 changes: 83 additions & 0 deletions crm_lead_attach_related_saleorder_report/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
========================================
Crm Lead Attach Related Saleorder Report
========================================

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

.. |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-sygel--technology%2Fsy--crm-lightgray.png?logo=github
:target: https://github.com/sygel-technology/sy-crm/tree/17.0/crm_lead_attach_related_saleorder_report
:alt: sygel-technology/sy-crm

|badge1| |badge2| |badge3|

This module allow to attach sale documents into the opportunity and send
them.

**Table of contents**

.. contents::
:local:

Usage
=====

To use this module, you need to:

1. Select a opportunity.
2. Create quotations, related with the opportunity.
3. When you send a mail from opportunity, will appear one new button
named 'Attach Sale Documents', this only appear in opportunities if
this have quotations in "draft/sent" state. Note: This also only
appears if sending messages individually, mass editing on multiple
opportunities is not supported.
4. Click this button and the system will attach the sale reports related
with the opportunity.

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

Bugs are tracked on `GitHub Issues <https://github.com/sygel-technology/sy-crm/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/sygel-technology/sy-crm/issues/new?body=module:%20crm_lead_attach_related_saleorder_report%0Aversion:%2017.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
-------

* Sygel

Contributors
------------

- Harald Panten harald.panten@sygel.es
- Valentin Vinagre valentin.vinagre@sygel.es
- Alberto Martínez alberto.martinez@sygel.es

Other credits
-------------

Inspired in the old mail_sale_documents_from_opportunity v12 module

Maintainers
-----------

This module is part of the `sygel-technology/sy-crm <https://github.com/sygel-technology/sy-crm/tree/17.0/crm_lead_attach_related_saleorder_report>`_ project on GitHub.

You are welcome to contribute.
4 changes: 4 additions & 0 deletions crm_lead_attach_related_saleorder_report/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright 2020 Valentin Vinagre <valentin.vinagre@sygel.es>
Tisho99 marked this conversation as resolved.
Show resolved Hide resolved
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import models
16 changes: 16 additions & 0 deletions crm_lead_attach_related_saleorder_report/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2020 Valentin Vinagre <valentin.vinagre@sygel.es>
Tisho99 marked this conversation as resolved.
Show resolved Hide resolved
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Crm Lead Attach Related Saleorder Report",
"version": "17.0.1.0.0",
"category": "Sale",
"summary": "Allow to attach sale documents into the opportunity and send them.",
"author": "Sygel",
"website": "https://github.com/sygel-technology/sy-crm",
"license": "AGPL-3",
"depends": [
"sale_crm",
],
"data": ["views/crm_lead.xml", "views/mail_compose_message.xml"],
"installable": True,
}
41 changes: 41 additions & 0 deletions crm_lead_attach_related_saleorder_report/i18n/ca_ES.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * crm_lead_attach_related_saleorder_report
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 17.0+e\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-08-09 10:54+0000\n"
"PO-Revision-Date: 2024-08-09 10:54+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: crm_lead_attach_related_saleorder_report
#: model_terms:ir.ui.view,arch_db:crm_lead_attach_related_saleorder_report.email_compose_message_wizard_form_inherited_attach_related_saleorder_report
msgid "Attach Sale Documents"
msgstr "Adjunta documents de venda"

#. module: crm_lead_attach_related_saleorder_report
#: model:ir.model.fields,field_description:crm_lead_attach_related_saleorder_report.field_mail_compose_message__check_add_sale_attachments
msgid "Check sale attachments"
msgstr "Comprova els adjunts de venda"

#. module: crm_lead_attach_related_saleorder_report
#: model:ir.model,name:crm_lead_attach_related_saleorder_report.model_mail_compose_message
msgid "Email composition wizard"
msgstr "Assistent de redacció d'emails"

#. module: crm_lead_attach_related_saleorder_report
#: model:ir.model,name:crm_lead_attach_related_saleorder_report.model_crm_lead
msgid "Lead/Opportunity"
msgstr "Iniciativa/Oportunitat"

#. module: crm_lead_attach_related_saleorder_report
#: model_terms:ir.ui.view,arch_db:crm_lead_attach_related_saleorder_report.crm_lead_view_form_inherited_attach_related_saleorder_report
msgid "Send Quotations"
msgstr "Enviar pressupostos"
41 changes: 41 additions & 0 deletions crm_lead_attach_related_saleorder_report/i18n/es.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * crm_lead_attach_related_saleorder_report
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 17.0+e\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-08-09 10:50+0000\n"
"PO-Revision-Date: 2024-08-09 10:50+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: crm_lead_attach_related_saleorder_report
#: model_terms:ir.ui.view,arch_db:crm_lead_attach_related_saleorder_report.email_compose_message_wizard_form_inherited_attach_related_saleorder_report
msgid "Attach Sale Documents"
msgstr "Adjuntar documentos de venta"

#. module: crm_lead_attach_related_saleorder_report
#: model:ir.model.fields,field_description:crm_lead_attach_related_saleorder_report.field_mail_compose_message__check_add_sale_attachments
msgid "Check sale attachments"
msgstr "Consultar adjuntos de venta"

#. module: crm_lead_attach_related_saleorder_report
#: model:ir.model,name:crm_lead_attach_related_saleorder_report.model_mail_compose_message
msgid "Email composition wizard"
msgstr "Asistente de redacción de correo electrónico"

#. module: crm_lead_attach_related_saleorder_report
#: model:ir.model,name:crm_lead_attach_related_saleorder_report.model_crm_lead
msgid "Lead/Opportunity"
msgstr "Lead/Oportunidad"

#. module: crm_lead_attach_related_saleorder_report
#: model_terms:ir.ui.view,arch_db:crm_lead_attach_related_saleorder_report.crm_lead_view_form_inherited_attach_related_saleorder_report
msgid "Send Quotations"
msgstr "Enviar presupuestos"
5 changes: 5 additions & 0 deletions crm_lead_attach_related_saleorder_report/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Copyright 2020 Valentin Vinagre <valentin.vinagre@sygel.es>
Tisho99 marked this conversation as resolved.
Show resolved Hide resolved
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import crm_lead
from . import mail_compose_message
29 changes: 29 additions & 0 deletions crm_lead_attach_related_saleorder_report/models/crm_lead.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright 2020 Valentin Vinagre <valentin.vinagre@sygel.es>
Tisho99 marked this conversation as resolved.
Show resolved Hide resolved
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import models


class CrmLead(models.Model):
_inherit = "crm.lead"

def action_send_documents_sale(self):
"""
This function opens a window to compose an email.
"""
self.ensure_one()
ctx = {
"default_model": "crm.lead",
"default_res_ids": self.ids,
"default_composition_mode": "comment",
"force_email": True,
}
return {
"type": "ir.actions.act_window",
"view_type": "form",
"view_mode": "form",
"res_model": "mail.compose.message",
"views": [(False, "form")],
"target": "new",
"context": ctx,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# Copyright 2020 Valentin Vinagre <valentin.vinagre@sygel.es>
Tisho99 marked this conversation as resolved.
Show resolved Hide resolved
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).


from odoo import api, fields, models

from odoo.addons.mail.tools.parser import parse_res_ids


def _reopen(self, res_id, model, context=None):
# save original model in context, because selecting the list of available
# templates requires a model in context
context = dict(context or {}, default_model=model)
return {
"type": "ir.actions.act_window",
"view_mode": "form",
"view_type": "form",
"res_id": res_id,
"res_model": self._name,
"target": "new",
"context": context,
}


class MailComposeMessage(models.TransientModel):
_inherit = "mail.compose.message"

check_add_sale_attachments = fields.Boolean(
string="Check sale attachments", compute="_compute_check_add_sale_attachments"
)

@api.depends("model", "res_ids")
def _compute_check_add_sale_attachments(self):
for sel in self:
orders_ids = ()
lead_ids = parse_res_ids(self.env.context.get("active_ids"))
if sel.model == "crm.lead" and len(lead_ids) == 1:
orders_ids = (
self.env[self.model]
.browse(lead_ids)
.order_ids.filtered(lambda x: x.state in ("draft", "sent"))
)
sel.check_add_sale_attachments = any(orders_ids)

def calculate_sale_attachments(self):
self.ensure_one()
template_id = self.env.ref("sale.email_template_edi_sale")
lead_ids = parse_res_ids(self.env.context.get("active_ids"))
lead_objs = self.env[self.model].browse(lead_ids)
sale_ids = lead_objs.order_ids.filtered(lambda x: x.state in ("draft", "sent"))
if sale_ids:
rendered_values = template_id._generate_template(
sale_ids.ids,
(
"attachment_ids",
"report_template_ids",
),
)
attachment_ids = []
for r_value in rendered_values.values():
if rendered_values.get("attachment_ids"):
attachment_ids += rendered_values.get("attachment_ids")
# transform attachments into attachment_ids; not attached to the
# document because this will be done further in the posting
# process, allowing to clean database if email not send
if r_value.get("attachments"):
attachment_ids += (
self.env["ir.attachment"]
.create(
[
{
"name": attach_fname,
"datas": attach_datas,
"res_model": "mail.compose.message",
"res_id": 0,
"type": "binary",
}
for attach_fname, attach_datas in r_value.pop(
"attachments"
)
]
)
.ids
)
if attachment_ids:
self.write({"attachment_ids": [(4, id) for id in attachment_ids]})
sale_ids.filtered(lambda x: x.state == "draft").action_quotation_sent()
return _reopen(self, self.id, self.model, context=self._context)
3 changes: 3 additions & 0 deletions crm_lead_attach_related_saleorder_report/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- Harald Panten <harald.panten@sygel.es>
- Valentin Vinagre <valentin.vinagre@sygel.es>
- Alberto Martínez <alberto.martinez@sygel.es>
1 change: 1 addition & 0 deletions crm_lead_attach_related_saleorder_report/readme/CREDITS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Inspired in the old mail_sale_documents_from_opportunity v12 module
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This module allow to attach sale documents into the opportunity and send them.
7 changes: 7 additions & 0 deletions crm_lead_attach_related_saleorder_report/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
To use this module, you need to:

1. Select a opportunity.
2. Create quotations, related with the opportunity.
3. When you send a mail from opportunity, will appear one new button named 'Attach Sale Documents', this only appear in opportunities if this have quotations in "draft/sent" state.
Note: This also only appears if sending messages individually, mass editing on multiple opportunities is not supported.
4. Click this button and the system will attach the sale reports related with the opportunity.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading