[UPD] exp_transation_letters: add improvements on letters & restrictions

This commit is contained in:
Samir Ladoui 2025-02-16 10:10:36 +01:00
parent ca40ba87e2
commit dbe45822f3
6 changed files with 168 additions and 28 deletions

View File

@ -24,7 +24,8 @@ Letters Managment
'views/letters_view.xml',
'reports/letter_template.xml',
'reports/formal_letter.xml',
'views/editor.xml'
'views/editor.xml',
'views/transaction_views.xml'
],
'qweb' : [
],

View File

@ -56,6 +56,11 @@ msgstr "<span>رقم المعاملة:</span>"
msgid "Add As Attachment to Transaction"
msgstr "إضافة كمرفق إلى المعاملة"
#. module: exp_transation_letters
#: model:ir.model.fields.selection,name:exp_transation_letters.selection__letters_letters__state__attached
msgid "Attached"
msgstr "تم الإرفاق"
#. module: exp_transation_letters
#: model:ir.model.fields,field_description:exp_transation_letters.field_res_users__attachment_id
msgid "Attachment"
@ -106,6 +111,11 @@ msgstr "التاريخ"
msgid "Display Name"
msgstr "اسم العرض"
#. module: exp_transation_letters
#: model:ir.model.fields.selection,name:exp_transation_letters.selection__letters_letters__state__draft
msgid "Draft"
msgstr "مسودة"
#. module: exp_transation_letters
#: model:ir.model.fields,field_description:exp_transation_letters.field_letters_template__is_favorite
#: model:ir.model.fields.selection,name:exp_transation_letters.selection__letters_template__is_favorite__1
@ -126,7 +136,7 @@ msgstr "المعرف"
#. module: exp_transation_letters
#: model:ir.model.fields.selection,name:exp_transation_letters.selection__letters_letters__transaction_type__incoming
msgid "Incoming"
msgstr "وارد"
msgstr "خارجية واردة"
#. module: exp_transation_letters
#: model:ir.model.fields,field_description:exp_transation_letters.field_letters_letters__incoming_transaction_id
@ -216,7 +226,7 @@ msgstr "الاسم"
#. module: exp_transation_letters
#: model:ir.model.fields.selection,name:exp_transation_letters.selection__letters_letters__transaction_type__outgoing
msgid "Outgoing"
msgstr "خارجية"
msgstr "خارجية صادرة"
#. module: exp_transation_letters
#: model:ir.model.fields,field_description:exp_transation_letters.field_letters_letters__outgoing_transaction_id
@ -233,6 +243,11 @@ msgstr "طباعة الخطاب على ورق رسمي"
msgid "Print letters"
msgstr "طباعة الخطاب"
#. module: exp_transation_letters
#: model_terms:ir.ui.view,arch_db:exp_transation_letters.view_transaction_letters_form
msgid "Reset to Draft"
msgstr "ارجاع الى مسودة"
#. module: exp_transation_letters
#: model:ir.model.fields,field_description:exp_transation_letters.field_letters_letters__new_signature
#: model:ir.model.fields,field_description:exp_transation_letters.field_letters_letters__signature
@ -270,6 +285,12 @@ msgstr "وحدة"
msgid "Users"
msgstr "المستخدمون"
#. module: exp_transation_letters
#: code:addons/exp_transation_letters/models/letter.py:0
#, python-format
msgid "You cannot delete a letter in the Attached state."
msgstr "لا يمكنك حذف خطاب تم إرفاقه."
#. module: exp_transation_letters
#: model:ir.model,name:exp_transation_letters.model_letters_letters
msgid "letters.letters"

View File

@ -1,29 +1,55 @@
# -*- coding: utf-8 -*-
import base64
from odoo import api, fields, models
from odoo import api, fields, models, _
from odoo.exceptions import UserError
from hijri_converter import convert
import datetime
class Letters(models.Model):
_name = "letters.letters"
_inherit = 'mail.thread'
name = fields.Char(string="Name")
unite = fields.Many2one('cm.entity', string="Unite")
letter_template = fields.Many2one('letters.template', string='Template')
date = fields.Date(string="Date")
name = fields.Char(string="Name", tracking=True)
unite = fields.Many2one('cm.entity', string="Unite", tracking=True)
letter_template = fields.Many2one('letters.template', string='Template', tracking=True)
date = fields.Date(string="Date", tracking=True)
hijir_date = fields.Char(string="Hijir Date", compute='compute_hijri')
content = fields.Html(string="Content")
content = fields.Html(string="Content", tracking=True)
signature = fields.Binary("Signature image",compute='compute_img',store=True)
is_sign = fields.Boolean(string='Is Sign',readonly=True)
new_signature = fields.Binary("Signature image",readonly=True)
transaction_type = fields.Selection([('internal', 'Internal'), ('outgoing', 'Outgoing'),
('incoming', 'Incoming')], default='internal', string='Transaction Type')
incoming_transaction_id = fields.Many2one(comodel_name='incoming.transaction', string='Incoming Transaction')
internal_transaction_id = fields.Many2one(comodel_name='internal.transaction', string='Internal Transaction')
outgoing_transaction_id = fields.Many2one(comodel_name='outgoing.transaction', string='Outgoing Transaction')
attachment_generated = fields.Boolean()
('incoming', 'Incoming')], default='internal', string='Transaction Type', tracking=True)
incoming_transaction_id = fields.Many2one(
comodel_name='incoming.transaction',
string='Incoming Transaction',
domain="[('state', 'not in', ['closed', 'canceled'])]",
tracking=True
)
internal_transaction_id = fields.Many2one(
comodel_name='internal.transaction',
string='Internal Transaction',
domain="[('state', 'not in', ['closed', 'canceled'])]",
tracking=True
)
outgoing_transaction_id = fields.Many2one(
comodel_name='outgoing.transaction',
string='Outgoing Transaction',
domain="[('state', 'not in', ['closed', 'canceled'])]",
tracking=True
)
# attachment_generated = fields.Boolean()
signed_user_id = fields.Many2one('res.users')
state = fields.Selection(
[
('draft', 'Draft'),
('attached', 'Attached')
],
default='draft',
readonly=True,
tracking=True
)
@api.depends('transaction_type','name')
@ -102,7 +128,8 @@ class Letters(models.Model):
'store_fname': ATTACHMENT_NAME,
'mimetype': 'application/pdf'
})
self.attachment_generated = True
# self.attachment_generated = True
self.state = 'attached'
return self.env['cm.attachment.rule'].sudo().create({
'employee_id': self.unite.id,
'entity_id': self.unite.id,
@ -120,6 +147,16 @@ class Letters(models.Model):
final_content = values.get('content')
values['content'] = final_content.replace('line-height', '')
return super(Letters, self).write(values)
def unlink(self):
for record in self:
if record.state == 'attached':
raise UserError(_("You cannot delete a letter in the Attached state."))
return super(Letters, self).unlink()
def action_draft(self):
self.ensure_one()
self.state = 'draft'
class LettersTemp(models.Model):

View File

@ -1,3 +1,4 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
letter_employee,employee_letter,exp_transation_letters.model_letters_letters,exp_transation_letters.group_cm_user_letter,1,1,1,1
letter_employee,employee_letter,exp_transation_letters.model_letters_letters,exp_transation_letters.group_cm_user_letter,1,1,1,0
letter_employee__temp,employee_letter,exp_transation_letters.model_letters_template,exp_transation_letters.group_cm_user_letter,1,1,1,1
letter_manager_employee,manager_employee_letter,exp_transation_letters.model_letters_letters,exp_transaction_documents.group_transaction_manager,1,1,1,1
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
2 letter_employee employee_letter exp_transation_letters.model_letters_letters exp_transation_letters.group_cm_user_letter 1 1 1 1 0
3 letter_employee__temp employee_letter exp_transation_letters.model_letters_template exp_transation_letters.group_cm_user_letter 1 1 1 1
4 letter_manager_employee manager_employee_letter exp_transation_letters.model_letters_letters exp_transaction_documents.group_transaction_manager 1 1 1 1

View File

@ -19,35 +19,49 @@
<field name="arch" type="xml">
<form string="Letters">
<header>
<button name="action_generate_attachment" string="Add As Attachment to Transaction" class="oe_highlight" type="object"
attrs="{'invisible': [('new_signature','!=', False)]}"/>
<button name="action_generate_attachment"
string="Add As Attachment to Transaction"
class="oe_highlight"
type="object"
states="draft"
/>
<button name="action_draft"
string="Reset to Draft"
type="object"
states="attached"
groups="exp_transaction_documents.group_transaction_manager"
/>
<field name="state" widget="statusbar"/>
</header>
<sheet>
<group>
<group>
<field name="name" required="1"/>
<field name="unite" required="1"/>
<field name="letter_template" options="{'no_create':True,'no_open':True}"/>
<field name="attachment_generated" invisible="1"/>
<field name="name" required="1" attrs="{'readonly': [('state', '!=', 'draft')]}"/>
<field name="unite" required="1" attrs="{'readonly': [('state', '!=', 'draft')]}"/>
<field name="letter_template" options="{'no_create':True,'no_open':True}" attrs="{'readonly': [('state', '!=', 'draft')]}"/>
<!-- <field name="attachment_generated" invisible="1"/> -->
<field name="signed_user_id" invisible="1"/>
</group>
<group>
<field name="date" required="1"/>
<field name="date" required="1" attrs="{'readonly': [('state', '!=', 'draft')]}"/>
<field name="hijir_date"/>
<field name="transaction_type"/>
<field name="incoming_transaction_id" attrs="{'invisible': [('transaction_type','!=','incoming')]}"/>
<field name="internal_transaction_id" attrs="{'invisible': [('transaction_type','!=','internal')]}"/>
<field name="outgoing_transaction_id" attrs="{'invisible': [('transaction_type','!=','outgoing')]}"/>
<field name="transaction_type" attrs="{'readonly': [('state', '!=', 'draft')]}"/>
<field name="incoming_transaction_id" attrs="{'invisible': [('transaction_type','!=','incoming')], 'readonly': [('state', '!=', 'draft')]}"/>
<field name="internal_transaction_id" attrs="{'invisible': [('transaction_type','!=','internal')], 'readonly': [('state', '!=', 'draft')]}"/>
<field name="outgoing_transaction_id" attrs="{'invisible': [('transaction_type','!=','outgoing')], 'readonly': [('state', '!=', 'draft')]}"/>
</group>
</group>
<group>
<field name="content"/>
<field name="content" attrs="{'readonly': [('state', '!=', 'draft')]}"/>
</group>
<group>
<field name="signature" widget="image" invisible="1"/>
<field name="new_signature" widget="image"/>
</group>
</sheet>
<div class="oe_chatter">
<field name="message_ids" widget="mail_thread"/>
</div>
</form>
</field>
</record>

View File

@ -0,0 +1,66 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="view_incoming_transaction_filter_exp_transaction_documents" model="ir.ui.view">
<field name="name">incoming.transaction.view.form.inherit</field>
<field name="model">incoming.transaction</field>
<field name="inherit_id" ref="exp_transaction_documents.view_incoming_transaction_filter"/>
<field name="arch" type="xml">
<xpath expr="//search/field[@name='subject']" position="attributes">
<attribute name="groups">exp_transaction_documents.group_transaction_manager</attribute>
</xpath>
</field>
</record>
<record id="common_transaction_external_tree_exp_transaction_documents" model="ir.ui.view">
<field name="name">incoming.transaction.view.form.inherit</field>
<field name="model">incoming.transaction</field>
<field name="inherit_id" ref="exp_transaction_documents.common_transaction_external_tree"/>
<field name="arch" type="xml">
<xpath expr="//tree/field[@name='subject']" position="attributes">
<attribute name="groups">exp_transaction_documents.group_transaction_manager</attribute>
</xpath>
</field>
</record>
<record id="view_internal_transaction_filter_exp_transaction_documents" model="ir.ui.view">
<field name="name">internal.transaction.view.form.inherit</field>
<field name="model">internal.transaction</field>
<field name="inherit_id" ref="exp_transaction_documents.view_internal_transaction_filter"/>
<field name="arch" type="xml">
<xpath expr="//search/field[@name='subject']" position="attributes">
<attribute name="groups">exp_transaction_documents.group_transaction_manager</attribute>
</xpath>
</field>
</record>
<record id="common_transaction_internal_tree_exp_transaction_documents" model="ir.ui.view">
<field name="name">internal.transaction.view.form.inherit</field>
<field name="model">internal.transaction</field>
<field name="inherit_id" ref="exp_transaction_documents.common_transaction_internal_tree"/>
<field name="arch" type="xml">
<xpath expr="//tree/field[@name='subject']" position="attributes">
<attribute name="groups">exp_transaction_documents.group_transaction_manager</attribute>
</xpath>
</field>
</record>
<record id="view_outgoing_transaction_filter_exp_transaction_documents" model="ir.ui.view">
<field name="name">outgoing.transaction.view.form.inherit</field>
<field name="model">outgoing.transaction</field>
<field name="inherit_id" ref="exp_transaction_documents.view_outgoing_transaction_filter"/>
<field name="arch" type="xml">
<xpath expr="//search/field[@name='subject']" position="attributes">
<attribute name="groups">exp_transaction_documents.group_transaction_manager</attribute>
</xpath>
</field>
</record>
<record id="common_outgoing_transaction_external_tree_exp_transaction_documents" model="ir.ui.view">
<field name="name">outgoing.transaction.view.form.inherit</field>
<field name="model">outgoing.transaction</field>
<field name="inherit_id" ref="exp_transaction_documents.common_outgoing_transaction_external_tree"/>
<field name="arch" type="xml">
<xpath expr="//tree/field[@name='subject']" position="attributes">
<attribute name="groups">exp_transaction_documents.group_transaction_manager</attribute>
</xpath>
</field>
</record>
</odoo>