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

Permitir adjuntar documentos con categorias concretas #168

Merged
merged 5 commits into from
Sep 10, 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
37 changes: 37 additions & 0 deletions migrations/5.0.24.9.0/post-0003_init_attach_categ_field.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# -*- coding: utf-8 -*-
import logging
import pooler

from tools import config
from oopgrade.oopgrade import load_data_records


def up(cursor, installed_version):
if not installed_version:
return
if config.updating_all:
return
logger = logging.getLogger('openerp.migration')

logger.info("Creating pooler")
pool = pooler.get_pool(cursor.dbname)

logger.info("Creating table: giscedata.polissa")
pool.get("poweremail.templates")._auto_init(cursor, context={'module': 'poweremail'})
logger.info("Table created succesfully.")

logger.info("Updating XMLs")
list_of_records = [
"poweremail_template_form",
]
load_data_records(
cursor, 'poweremail', 'poweremail_template_view.xml', list_of_records, mode='update'
)
logger.info("XMLs succesfully updated.")


def down(cursor, installed_version):
pass


migrate = up
16 changes: 16 additions & 0 deletions poweremail_send_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,18 @@ def add_template_attachments(self, cr, uid, template, mail_id, context=None):
attachment_ids_templ.append(new_id)
return attachment_ids_templ

def add_record_attachments(self, cursor, uid, template, src_rec_id, context=None):
attachment_ids = []
if template.attach_record_items:
attachment_o = self.pool.get('ir.attachment')
attachment_sp = [('res_model', '=', template.object_name.model),
('res_id', '=', src_rec_id)]

if template.record_attachment_categories:
attachment_sp.append(('category_id', 'in', [c.id for c in template.record_attachment_categories]))
attachment_ids = attachment_o.search(cursor, uid, attachment_sp, context=context)
return attachment_ids

def create_partner_event(self, cr, uid, template, vals, data, src_rec_id, mail_id, attachment_ids, context=None):
if context is None:
context = {}
Expand Down Expand Up @@ -516,6 +528,10 @@ def save_to_mailbox(self, cr, uid, ids, context=None):
# Add template attachments
attachment_ids_templ = self.add_template_attachments(cr, uid, template, mail_id, context=ctx)
attachment_ids.extend(attachment_ids_templ)
# Add record attachments
attachment_ids_record = self.add_record_attachments(cr, uid, template, src_rec_id, context=ctx)
attachment_ids.extend(attachment_ids_record)

if attachment_ids:
mailbox_vals = {
'pem_attachments_ids': [[6, 0, attachment_ids]],
Expand Down
15 changes: 11 additions & 4 deletions poweremail_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,11 @@ def _get_model_data_name_search(
relation='ir.attachment',
string='Attachments'),
'attach_record_items': fields.boolean('Attach record items', select=2, help=u"Si es marca aquesta opcio, s'enviaran com a fitxers adjunts del email tots els adjunts del registre utilitzat per renderitzar el email."),
'record_attachment_categories': fields.many2many('ir.attachment.category',
'template_attachment_category_rel',
'templ_id', 'categ_id',
string="Record attachment categories",
help="Only attach record attachments with the included categories in case there's any."),
'model_data_name': fields.function(
_get_model_data_name, string='Code',
type='char', size=250, method=True,
Expand Down Expand Up @@ -951,10 +956,12 @@ def _generate_attach_reports(self, cursor, user, template, record_ids, mail, con
# vinculats als record_ids i afegirlos a la llista de attach_ids
if template.attach_record_items:
for record_id in record_ids:
ids = attachment_obj.search(cursor, user, [
('res_model', '=', template.object_name.model),
('res_id', '=', record_id)
], context=context)
attachment_sp = [('res_model', '=', template.object_name.model),
('res_id', '=', record_id)]

if template.record_attachment_categories:
attachment_sp.append(('category_id', 'in', [c.id for c in template.record_attachment_categories]))
ids = attachment_obj.search(cursor, user, attachment_sp, context=context)
attachment_id.extend(ids)

attach_ids = attachment_obj.search(cursor, user, search_params, context=context)
Expand Down
4 changes: 4 additions & 0 deletions poweremail_template_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@
<field name="file_name" colspan="2" />
<field name="report_template" colspan="2" domain="[('model','=',model_int_name)]" />
<field name="attach_record_items" colspan="2"/>
<group attrs="{'invisible':[('attach_record_items', '!=', True)]}" colspan="8">
<newline/>
<field name="record_attachment_categories" colspan="8"/>
</group>
<field name="tmpl_attachment_ids" colspan="4" nolabel="1"/>
<separator string="Static attachments" colspan="4"/>
<field name="ir_attachment_ids" colspan="4" nolabel="1"/>
Expand Down
40 changes: 1 addition & 39 deletions wizard/wizard_poweremail_preview.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,46 +139,8 @@ def action_send_static_mail(self, cursor, uid, ids, context=None):
if not template:
raise Exception("The requested template could not be loaded")

from_account = template_obj.get_from_account_id_from_template(
cursor, uid, template.id, context=context
)

# Evaluates an expression and returns its value
# recid: ID of the target record under evaluation
# message: The expression to be evaluated
# template: BrowseRecord object of the current template
# return: Computed message (unicode) or u""

pem_too = get_value(
cursor, uid, model_id, message=template.def_to,
template=template, context=context
)
def_subject = get_value(
cursor, uid, model_id, message=template.def_subject,
template=template, context=context
)

body_text = get_value(
cursor, uid, model_id, message=template.def_body_text,
template=template, context=context
)
mailbox_id = template_obj.generate_mail(cursor, uid, template_id, model_id, context=context)

mail_vals = {
'pem_from': tools.ustr(from_account['name']) + \
"<" + tools.ustr(from_account['email_id']) + ">",
'pem_to': pem_too,
'pem_cc': False,
'pem_bcc': False,
'pem_subject': def_subject,
'pem_body_text': body_text,
'pem_account_id': from_account['id'],
'priority': '1',
'state': 'na',
'mail_type': 'multipart/alternative',
'template_id': template_id
}

mailbox_id = mailbox_obj.create(cursor, uid, mail_vals)
if wizard.save_to_drafts_prev:
mailbox_obj.write(cursor, uid, mailbox_id, {'folder': 'drafts'}, context=context)

Expand Down