Commit a145299e authored by agb80's avatar agb80

Removed the activity to send the email to customers when validating invoice

As a result of the change done on the signals branch, the need to click on
button Validate for invoice atachment has been removed, there are some
customers that would like to review the mail before actually send the
email to the customer, that's why we are proposing to remove from the workflow
and instead use the Send Email button on the invoice form view to actually
send the email to customers.
parent 6ec5d101
Pipeline #593 skipped
......@@ -42,14 +42,6 @@
<field name="split_mode">XOR</field>
<field name="action">action_printable()</field>
</record>
<record id="workflow_activity_send_customer" model="workflow.activity">
<field name="kind">function</field>
<field name="name">send_customer</field>
<field name="join_mode">XOR</field>
<field model="workflow" name="wkf_id" ref="workflow_ir_attachment_facturae_mx_basic"/>
<field name="split_mode">XOR</field>
<field name="action">action_send_customer()</field>
</record>
<record id="workflow_activity_cancel" model="workflow.activity">
<field name="kind">function</field>
<field name="name">cancel</field>
......@@ -80,15 +72,13 @@
<field name="act_to" ref="workflow_activity_sign"/>
</record>
<record id="workflow_transition_act_sign_to_act_printable" model="workflow.transition">
<field name="signal"></field>
<field name="act_from" ref="workflow_activity_sign"/>
<field name="act_to" ref="workflow_activity_printable"/>
</record>
<record id="workflow_transition_act_printable_to_act_send_customer" model="workflow.transition">
<record id="workflow_transition_act_printable_to_act_done" model="workflow.transition">
<field name="signal"></field>
<field name="act_from" ref="workflow_activity_printable"/>
<field name="act_to" ref="workflow_activity_send_customer"/>
</record>
<record id="workflow_transition_act_send_customer_to_act_done" model="workflow.transition">
<field name="act_from" ref="workflow_activity_send_customer"/>
<field name="act_to" ref="workflow_activity_done"/>
</record>
<!-- from all states to cancel-->
......@@ -112,11 +102,6 @@
<field name="act_from" ref="workflow_activity_printable"/>
<field name="act_to" ref="workflow_activity_cancel"/>
</record>
<record id="workflow_transition_act_sent_customer_to_act_cancel" model="workflow.transition">
<field name="signal">signal_cancel</field>
<field name="act_from" ref="workflow_activity_send_customer"/>
<field name="act_to" ref="workflow_activity_cancel"/>
</record>
<record id="workflow_transition_act_done_to_act_cancel" model="workflow.transition">
<field name="signal">signal_cancel</field>
<field name="act_from" ref="workflow_activity_done"/>
......
......@@ -110,7 +110,6 @@ class ir_attachment_facturae_mx(orm.Model):
('confirmed', 'Confirmed'),
('signed', 'Signed'),
('printable', 'Printable Format Generated'),
('sent_customer', 'Sent Customer'),
('done', 'Done'),
('cancel', 'Cancelled'), ],
'State', readonly=True, required=True, help='State of attachments'
......@@ -219,8 +218,6 @@ class ir_attachment_facturae_mx(orm.Model):
'file_xml_sign_index': index_xml},
context=context
)
# TODO: Remove the need to commit database if not exception
cr.commit()
return True
def signal_printable(self, cr, uid, ids, context=None):
......@@ -275,90 +272,6 @@ class ir_attachment_facturae_mx(orm.Model):
'file_pdf_index': index_pdf},
context=context
)
# TODO: Remove the need to commit database if not exception
cr.commit()
return True
def signal_send_customer(self, cr, uid, ids, context=None):
"""
If attachment workflow hangs we need to send a signal to continue
"""
return self.action_send_customer(cr, uid, ids, context)
def action_send_customer(self, cr, uid, ids, context=None):
if context is None:
context = {}
attachments = []
# Grab invoice
invoice = self.browse(cr, uid, ids)[0].invoice_id
# Grab attachments
adjuntos = self.pool.get('ir.attachment').search(
cr, uid,
[('res_model', '=', 'account.invoice'), ('res_id', '=', invoice)]
)
for attach in self.pool.get('ir.attachment').browse(cr, uid, adjuntos):
attachments.append(attach.id)
# Send mail
obj_ir_mail_server = self.pool.get('ir.mail_server')
mail_server_id = obj_ir_mail_server.search(
cr, uid, [('name', '=', 'FacturaE')], context=None
)
if mail_server_id:
_logger.debug('Testing SMTP servers')
for smtp_server in obj_ir_mail_server.browse(
cr, uid, mail_server_id, context=context
):
try:
obj_ir_mail_server.connect(
smtp_server.smtp_host, smtp_server.smtp_port,
user=smtp_server.smtp_user,
password=smtp_server.smtp_pass,
encryption=smtp_server.smtp_encryption,
smtp_debug=smtp_server.smtp_debug)
except Exception, e:
raise orm.except_orm(
_("Connection test failed!"),
_("Configure outgoing mail server named FacturaE: %s")
% tools.ustr(e)
)
# Server tested, create mail content
_logger.debug('Start processing mail template')
template_pool = self.pool.get('email.template')
template_id = self.get_tmpl_email_id(cr, uid, ids, context=context)
values = template_pool.generate_email(
cr, uid, template_id, invoice.id, context=context
)
assert values.get('email_from'), 'email_from is missing or empty after template rendering, send_mail() cannot proceed'
# Get recipients
recipients = [int(values['email_recipients'])]
# Not exist this field on mail.mail module
del values['email_recipients']
# Create mail
mail_mail = self.pool.get('mail.mail')
msg_id = mail_mail.create(cr, uid, values, context=context)
# Process attachments
mail_mail.write(
cr, uid, msg_id,
{'attachment_ids': [(6, 0, attachments)]},
context=context
)
# Send mail
mail_mail.send(
cr, uid, [msg_id], recipient_ids=recipients,
context=context
)
else:
raise orm.except_orm(
_('Warning'),
_('Not Found outgoing mail server name of "FacturaE".'
'\nConfigure the outgoing mail server named "FacturaE"')
)
self.write(cr, uid, ids, {'state': 'done'}, context=context)
# TODO: Remove the need to commit database if not exception
cr.commit()
return True
def signal_cancel(self, cr, uid, ids, context=None):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment