[ADD]ADD new notes in transaction module

This commit is contained in:
zainab8585 2024-07-26 22:04:02 +02:00
parent 5a74818a73
commit b5b2b403ff
7 changed files with 85 additions and 8 deletions

View File

@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
from odoo import models, api, fields, _
import base64
from odoo.exceptions import ValidationError
TRACE_ACTIONS = [
('forward', _('Forwarded')),
('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',
store=True)
file_save = fields.Binary('Save File')
external_drive_link = fields.Char('External Drive Link')
attachment_filename = fields.Char(string="Attachment Filename")
incoming_transaction_id = fields.Many2one(comodel_name='incoming.transaction', string='Incoming 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)
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):
_name = 'cm.transaction.trace'

View File

@ -16,6 +16,8 @@ class Entity(models.Model):
_description = 'Transactions Contacts'
_order = 'name'
employee_id = fields.Many2one('hr.employee', string='Delivery Employee')
company_name = fields.Char('Delivery Company')
def _normalize_arabic_text(self, text):
translation_map = str.maketrans({
# Define a dictionary to replace different forms of characters

View File

@ -1,8 +1,7 @@
# -*- coding: utf-8 -*-
from datetime import datetime
from odoo import models, api, fields, _
from odoo.exceptions import ValidationError
class InternalTransaction(models.Model):
_name = 'internal.transaction'
_inherit = ['transaction.transaction', 'mail.thread']
@ -58,6 +57,12 @@ class InternalTransaction(models.Model):
new_args.append(arg)
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
def get_url(self):
url = u''

View File

@ -48,6 +48,13 @@
<field name="unit_location" attrs="{'invisible': [('type', 'not in', ['unit'])]}"/>
<field name="email"
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"
attrs="{'invisible': [('type', 'not in', ['unit'])]}"/>
<field name="person_id" attrs="{'invisible':[('type','not in',['employee'])]}"/>

View File

@ -109,12 +109,12 @@
<group>
<field name="processing_ids"
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="subject"/>
<field name="transaction_date"/>
<field name="to_ids"/>
</tree>
</utsztree>
</field>
</group>
<group>
@ -124,7 +124,8 @@
<field name="entity_id" readonly="True"/>
<field name="date" readonly="True"/>
<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"/>
</tree>
</field>

View File

@ -7,9 +7,31 @@
<field name="interval_type">days</field>
<field name="numbercall">-1</field>
<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="code">model.action_expired()</field>
</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>
</odoo>

View File

@ -48,16 +48,46 @@ class Leave(models.Model):
# Business methods
####################################################
def action_request(self):
template_id = self.env.ref('exp_transaction_leave.email_template_delegation_notification2',False)
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):
for rec in self:
rec.state = 'refuse'
def action_approve(self):
template_id = self.env.ref('exp_transaction_leave.email_template_delegation_accepted').id
for rec in self:
rec.state = 'approve'
self.env['mail.template'].browse(template_id).send_mail(rec.id, force_send=True)
def action_expired(self):
date_now = date.today()