[ADD]ADD new notes in transaction module
This commit is contained in:
parent
5a74818a73
commit
b5b2b403ff
|
|
@ -1,6 +1,7 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from odoo import models, api, fields, _
|
from odoo import models, api, fields, _
|
||||||
|
import base64
|
||||||
|
from odoo.exceptions import ValidationError
|
||||||
TRACE_ACTIONS = [
|
TRACE_ACTIONS = [
|
||||||
('forward', _('Forwarded')),
|
('forward', _('Forwarded')),
|
||||||
('receive', _('Received')),
|
('receive', _('Received')),
|
||||||
|
|
@ -80,6 +81,7 @@ class AttachmentRule(models.Model):
|
||||||
entity_id = fields.Many2one(comodel_name='cm.entity', string='Unit Responsible', related='employee_id.parent_id',
|
entity_id = fields.Many2one(comodel_name='cm.entity', string='Unit Responsible', related='employee_id.parent_id',
|
||||||
store=True)
|
store=True)
|
||||||
file_save = fields.Binary('Save File')
|
file_save = fields.Binary('Save File')
|
||||||
|
external_drive_link = fields.Char('External Drive Link')
|
||||||
attachment_filename = fields.Char(string="Attachment Filename")
|
attachment_filename = fields.Char(string="Attachment Filename")
|
||||||
incoming_transaction_id = fields.Many2one(comodel_name='incoming.transaction', string='Incoming Transaction')
|
incoming_transaction_id = fields.Many2one(comodel_name='incoming.transaction', string='Incoming Transaction')
|
||||||
internal_transaction_id = fields.Many2one(comodel_name='internal.transaction', string='Internal Transaction')
|
internal_transaction_id = fields.Many2one(comodel_name='internal.transaction', string='Internal Transaction')
|
||||||
|
|
@ -87,6 +89,14 @@ class AttachmentRule(models.Model):
|
||||||
date = fields.Datetime(string='Date', default=fields.Datetime.now)
|
date = fields.Datetime(string='Date', default=fields.Datetime.now)
|
||||||
description = fields.Char(string='Description')
|
description = fields.Char(string='Description')
|
||||||
|
|
||||||
|
@api.constrains('file_save')
|
||||||
|
def _check_attachment_size(self):
|
||||||
|
max_size = 10 * 1024 * 1024 # 10 MB
|
||||||
|
for record in self:
|
||||||
|
if record.file_save:
|
||||||
|
file_size = len(base64.b64decode(record.file_save))
|
||||||
|
if file_size > max_size:
|
||||||
|
raise ValidationError(_('Attachment %s exceeds the maximum allowed size of 10 MB.') % record.attachment_filename)
|
||||||
|
|
||||||
class TransactionTrace(models.Model):
|
class TransactionTrace(models.Model):
|
||||||
_name = 'cm.transaction.trace'
|
_name = 'cm.transaction.trace'
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,8 @@ class Entity(models.Model):
|
||||||
_description = 'Transactions Contacts'
|
_description = 'Transactions Contacts'
|
||||||
_order = 'name'
|
_order = 'name'
|
||||||
|
|
||||||
|
employee_id = fields.Many2one('hr.employee', string='Delivery Employee')
|
||||||
|
company_name = fields.Char('Delivery Company')
|
||||||
def _normalize_arabic_text(self, text):
|
def _normalize_arabic_text(self, text):
|
||||||
translation_map = str.maketrans({
|
translation_map = str.maketrans({
|
||||||
# Define a dictionary to replace different forms of characters
|
# Define a dictionary to replace different forms of characters
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from odoo import models, api, fields, _
|
from odoo import models, api, fields, _
|
||||||
|
from odoo.exceptions import ValidationError
|
||||||
|
|
||||||
class InternalTransaction(models.Model):
|
class InternalTransaction(models.Model):
|
||||||
_name = 'internal.transaction'
|
_name = 'internal.transaction'
|
||||||
_inherit = ['transaction.transaction', 'mail.thread']
|
_inherit = ['transaction.transaction', 'mail.thread']
|
||||||
|
|
@ -58,6 +57,12 @@ class InternalTransaction(models.Model):
|
||||||
new_args.append(arg)
|
new_args.append(arg)
|
||||||
return super(InternalTransaction, self).search(new_args, offset=offset, limit=limit, order=order, count=count)
|
return super(InternalTransaction, self).search(new_args, offset=offset, limit=limit, order=order, count=count)
|
||||||
|
|
||||||
|
def unlink(self):
|
||||||
|
for record in self:
|
||||||
|
if record.state == 'send':
|
||||||
|
raise ValidationError(_('Cannot delete a sent transaction!'))
|
||||||
|
return super(InternalTransaction, self).unlink()
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def get_url(self):
|
def get_url(self):
|
||||||
url = u''
|
url = u''
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,13 @@
|
||||||
<field name="unit_location" attrs="{'invisible': [('type', 'not in', ['unit'])]}"/>
|
<field name="unit_location" attrs="{'invisible': [('type', 'not in', ['unit'])]}"/>
|
||||||
<field name="email"
|
<field name="email"
|
||||||
attrs="{'invisible': [('type','not in',['external'])]}"/>
|
attrs="{'invisible': [('type','not in',['external'])]}"/>
|
||||||
|
|
||||||
|
<field name="employee_id"
|
||||||
|
attrs="{'invisible': [('type','not in',['external'])]}"/>
|
||||||
|
|
||||||
|
<field name="company_name"
|
||||||
|
attrs="{'invisible': [('type','not in',['external'])]}"/>
|
||||||
|
|
||||||
<field name="sketch_attachment_id" widget="many2one_binary"
|
<field name="sketch_attachment_id" widget="many2one_binary"
|
||||||
attrs="{'invisible': [('type', 'not in', ['unit'])]}"/>
|
attrs="{'invisible': [('type', 'not in', ['unit'])]}"/>
|
||||||
<field name="person_id" attrs="{'invisible':[('type','not in',['employee'])]}"/>
|
<field name="person_id" attrs="{'invisible':[('type','not in',['employee'])]}"/>
|
||||||
|
|
|
||||||
|
|
@ -109,12 +109,12 @@
|
||||||
<group>
|
<group>
|
||||||
<field name="processing_ids"
|
<field name="processing_ids"
|
||||||
attrs="{'required':[('type','in',['reply','forward'])],'invisible':[('type','not in',['reply', 'forward'])],'readonly':[('state','not in',['draft'])]}">
|
attrs="{'required':[('type','in',['reply','forward'])],'invisible':[('type','not in',['reply', 'forward'])],'readonly':[('state','not in',['draft'])]}">
|
||||||
<tree name="">
|
<utsztree name="">
|
||||||
<field name="name"/>
|
<field name="name"/>
|
||||||
<field name="subject"/>
|
<field name="subject"/>
|
||||||
<field name="transaction_date"/>
|
<field name="transaction_date"/>
|
||||||
<field name="to_ids"/>
|
<field name="to_ids"/>
|
||||||
</tree>
|
</utsztree>
|
||||||
</field>
|
</field>
|
||||||
</group>
|
</group>
|
||||||
<group>
|
<group>
|
||||||
|
|
@ -124,7 +124,8 @@
|
||||||
<field name="entity_id" readonly="True"/>
|
<field name="entity_id" readonly="True"/>
|
||||||
<field name="date" readonly="True"/>
|
<field name="date" readonly="True"/>
|
||||||
<field name="description" required="False"/>
|
<field name="description" required="False"/>
|
||||||
<field name="file_save" filename="attachment_filename"/>
|
<field name="file_save" class="o_viewer_img o_viewer_text o_viewer_video"/>
|
||||||
|
<field name="external_drive_link" widget="url"/>
|
||||||
<field name="attachment_filename" invisible="True"/>
|
<field name="attachment_filename" invisible="True"/>
|
||||||
</tree>
|
</tree>
|
||||||
</field>
|
</field>
|
||||||
|
|
|
||||||
|
|
@ -7,9 +7,31 @@
|
||||||
<field name="interval_type">days</field>
|
<field name="interval_type">days</field>
|
||||||
<field name="numbercall">-1</field>
|
<field name="numbercall">-1</field>
|
||||||
<field name="doall" eval="False"/>
|
<field name="doall" eval="False"/>
|
||||||
<field name="model_id" ref="model_employee_leave" />
|
<field name="model_id" ref="model_employee_leave"/>
|
||||||
<field name="state">code</field>
|
<field name="state">code</field>
|
||||||
<field name="code">model.action_expired()</field>
|
<field name="code">model.action_expired()</field>
|
||||||
</record>
|
</record>
|
||||||
|
<record id="email_template_delegation_accepted" model="mail.template">
|
||||||
|
<field name="name">Delegation Accepted Notification</field>
|
||||||
|
<field name="model_id" ref="model_employee_leave"/>
|
||||||
|
<field name="subject">Delegation Accepted</field>
|
||||||
|
<field name="email_from">${(user.email or user.company_id.email) | safe}</field>
|
||||||
|
<field name="email_to">${object.employee_id.email}</field>
|
||||||
|
<field name="body_html">
|
||||||
|
<![CDATA[
|
||||||
|
<p>Hello ${object.employee_id.name},</p>
|
||||||
|
<p>Your delegation ${object.name} has been accepted.</p>
|
||||||
|
<p>Thank you.</p>
|
||||||
|
]]>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<record id="email_template_delegation_notification2" model="mail.template">
|
||||||
|
<field name="name">Delegation Users Notification</field>
|
||||||
|
<field name="model_id" ref="model_employee_leave"/>
|
||||||
|
<field name="subject">Delegation Notification</field>
|
||||||
|
<field name="email_from">${(user.email or user.company_id.email) | safe}</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
</data>
|
</data>
|
||||||
</odoo>
|
</odoo>
|
||||||
|
|
|
||||||
|
|
@ -48,16 +48,46 @@ class Leave(models.Model):
|
||||||
# Business methods
|
# Business methods
|
||||||
####################################################
|
####################################################
|
||||||
def action_request(self):
|
def action_request(self):
|
||||||
|
template_id = self.env.ref('exp_transaction_leave.email_template_delegation_notification2',False)
|
||||||
|
|
||||||
for rec in self:
|
for rec in self:
|
||||||
rec.state = 'request'
|
rec.state = 'request'
|
||||||
|
if rec.alternative_employee_ids:
|
||||||
|
for lin in rec.alternative_employee_ids:
|
||||||
|
emails = lin.employee_id.email
|
||||||
|
if emails:
|
||||||
|
body_html = f"""
|
||||||
|
<p>Hello {lin.employee_id.name},</p>
|
||||||
|
<p>You have been delegated a task.</p>
|
||||||
|
<p>Thank you.</p>
|
||||||
|
"""
|
||||||
|
email_template = template_id.write(
|
||||||
|
{'email_to': emails,'body_html': body_html,})
|
||||||
|
template_id.with_context(lang=self.env.user.lang).send_mail(rec.id, force_send=True, raise_exception=False)
|
||||||
|
if rec.alternative_manager_ids:
|
||||||
|
for lin in rec.alternative_employee_ids:
|
||||||
|
emails = lin.employee_id.email
|
||||||
|
if emails:
|
||||||
|
body_html = f"""
|
||||||
|
<p>Hello {lin.employee_id.name},</p>
|
||||||
|
<p>You have been delegated a task.</p>
|
||||||
|
<p>Thank you.</p>
|
||||||
|
"""
|
||||||
|
email_template = template_id.write(
|
||||||
|
{'email_to': emails,'body_html': body_html,})
|
||||||
|
template_id.with_context(lang=self.env.user.lang).send_mail(rec.id, force_send=True, raise_exception=False)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def action_refuse(self):
|
def action_refuse(self):
|
||||||
for rec in self:
|
for rec in self:
|
||||||
rec.state = 'refuse'
|
rec.state = 'refuse'
|
||||||
|
|
||||||
def action_approve(self):
|
def action_approve(self):
|
||||||
|
template_id = self.env.ref('exp_transaction_leave.email_template_delegation_accepted').id
|
||||||
for rec in self:
|
for rec in self:
|
||||||
rec.state = 'approve'
|
rec.state = 'approve'
|
||||||
|
self.env['mail.template'].browse(template_id).send_mail(rec.id, force_send=True)
|
||||||
|
|
||||||
def action_expired(self):
|
def action_expired(self):
|
||||||
date_now = date.today()
|
date_now = date.today()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue