mirror of
https://github.com/bringout/oca-ocb-vertical-industry.git
synced 2026-04-21 17:52:02 +02:00
19.0 vanilla
This commit is contained in:
parent
4607ccbd2e
commit
825ff6514e
487 changed files with 184979 additions and 195262 deletions
3
odoo-bringout-oca-ocb-fleet/fleet/wizard/__init__.py
Normal file
3
odoo-bringout-oca-ocb-fleet/fleet/wizard/__init__.py
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from . import fleet_vehicle_send_mail
|
||||
|
|
@ -0,0 +1,84 @@
|
|||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import api, fields, models, _
|
||||
|
||||
|
||||
class FleetVehicleSendMail(models.TransientModel):
|
||||
_name = 'fleet.vehicle.send.mail'
|
||||
_inherit = ['mail.composer.mixin']
|
||||
_description = 'Send mails to Drivers'
|
||||
|
||||
vehicle_ids = fields.Many2many('fleet.vehicle', string='Vehicles', required=True)
|
||||
author_id = fields.Many2one('res.partner', 'Author', required=True, default=lambda self: self.env.user.partner_id.id)
|
||||
template_id = fields.Many2one(domain=lambda self: [('model_id', '=', self.env['ir.model']._get('fleet.vehicle').id)])
|
||||
attachment_ids = fields.Many2many(
|
||||
'ir.attachment', 'fleet_vehicle_mail_compose_message_ir_attachments_rel',
|
||||
'wizard_id', 'attachment_id',
|
||||
string='Attachments',
|
||||
bypass_search_access=True,
|
||||
)
|
||||
|
||||
@api.depends('subject')
|
||||
def _compute_render_model(self):
|
||||
self.render_model = 'fleet.vehicle'
|
||||
|
||||
@api.onchange('template_id')
|
||||
def _onchange_template_id(self):
|
||||
self.attachment_ids = self.template_id.attachment_ids
|
||||
|
||||
def action_send(self):
|
||||
self.ensure_one()
|
||||
without_emails = self.vehicle_ids.driver_id.filtered(lambda a: not a.email)
|
||||
if without_emails:
|
||||
return {
|
||||
'type': 'ir.actions.client',
|
||||
'tag': 'display_notification',
|
||||
'params': {
|
||||
'type': 'danger',
|
||||
'message': _("The following vehicle drivers are missing an email address: %s.", ', '.join(without_emails.mapped("name"))),
|
||||
}
|
||||
}
|
||||
|
||||
if self.template_id:
|
||||
subjects = self._render_field(field='subject', res_ids=self.vehicle_ids.ids)
|
||||
bodies = self._render_field(field='body', res_ids=self.vehicle_ids.ids)
|
||||
else:
|
||||
subjects = {vehicle.id: self.subject for vehicle in self.vehicle_ids}
|
||||
bodies = {vehicle.id: self.body for vehicle in self.vehicle_ids}
|
||||
|
||||
for vehicle in self.vehicle_ids:
|
||||
vehicle.message_post(
|
||||
author_id=self.author_id.id,
|
||||
body=bodies[vehicle.id],
|
||||
email_layout_xmlid='mail.mail_notification_light',
|
||||
message_type='comment',
|
||||
partner_ids=vehicle.driver_id.ids,
|
||||
subject=subjects[vehicle.id],
|
||||
)
|
||||
|
||||
def action_save_as_template(self):
|
||||
model = self.env['ir.model']._get('fleet.vehicle')
|
||||
template_name = _("Vehicle: Mass mail drivers")
|
||||
template = self.env['mail.template'].create({
|
||||
'name': template_name,
|
||||
'subject': self.subject or False,
|
||||
'body_html': self.body or False,
|
||||
'model_id': model.id,
|
||||
'use_default_to': True,
|
||||
})
|
||||
|
||||
if self.attachment_ids:
|
||||
attachments = self.env['ir.attachment'].sudo().browse(self.attachment_ids.ids).filtered(lambda a: a.create_uid.id == self.env.uid)
|
||||
if attachments:
|
||||
attachments.write({'res_model': template._name, 'res_id': template.id})
|
||||
template.attachment_ids |= self.attachment_ids
|
||||
|
||||
self.write({'template_id': template.id})
|
||||
|
||||
return {
|
||||
'type': 'ir.actions.act_window',
|
||||
'view_mode': 'form',
|
||||
'res_id': template.id,
|
||||
'res_model': 'mail.template',
|
||||
'target': 'new',
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
<?xml version="1.0"?>
|
||||
<odoo>
|
||||
<record id="fleet_vehicle_send_mail_view_form" model="ir.ui.view">
|
||||
<field name="model">fleet.vehicle.send.mail</field>
|
||||
<field name="arch" type="xml">
|
||||
<form>
|
||||
<group>
|
||||
<field name="subject" placeholder="Communication about your vehicle." required="1"/>
|
||||
</group>
|
||||
<field name="body" nolabel="1" class="oe-bordered-editor"
|
||||
widget="html_mail"
|
||||
placeholder="Write your message here..."
|
||||
force_save="1"/>
|
||||
<group>
|
||||
<field name="attachment_ids" widget="many2many_binary"/>
|
||||
<field name="template_id" string="Load template"/>
|
||||
</group>
|
||||
<footer>
|
||||
<button name="action_send" string="Send" type="object" class="btn-primary" data-hotkey="q"/>
|
||||
<button string="Cancel" class="btn-secondary" special="cancel" data-hotkey="x"/>
|
||||
<button name="action_save_as_template" string="Save as new template" type="object" class="btn-secondary"/>
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
Loading…
Add table
Add a link
Reference in a new issue