Skip to content

Commit

Permalink
[T0549] Improvements to communication revisions (#1852)
Browse files Browse the repository at this point in the history
* T0549 - Improvements to communication revisions

* Update partner_communication_revision/models/communication_revision.py

Co-authored-by: ecino <ecino@users.noreply.github.com>

---------

Co-authored-by: ecino <ecino@users.noreply.github.com>
  • Loading branch information
langjer and ecino authored Mar 7, 2024
1 parent d2fbe28 commit 9b49b41
Show file tree
Hide file tree
Showing 4 changed files with 269 additions and 240 deletions.
33 changes: 33 additions & 0 deletions partner_communication_revision/models/communication_revision.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,39 @@ def get_latest_revision(self):
limit=1,
)

def duplicate_revision(self):
"""
Duplicate the current revision by creating a new revision with an incremented revision number.
This function ensures that only one revision is duplicated at a time. It calculates the new revision number
by incrementing the current revision number by 1. It then checks if a revision with the same revision number
already exists. If so, it increments the revision number until a unique revision number is found.
After creating the new revision, it sets the active_revision_id of the current revision to the newly created
revision.
"""
self.ensure_one()

last_revision = self.env["partner.communication.revision.history"].search([
("linked_revision_id", "=", self.id),
], order="revision_number desc", limit=1)
new_revision_number = int(last_revision.revision_number) + 1

self.active_revision_id = (
self.env["partner.communication.revision.history"]
.create(
{
"revision_number": new_revision_number,
"revision_date": fields.Date.today(),
"subject": self.subject,
"body_html": self.body_html,
"linked_revision_id": self.id,
"proposition_text": self.proposition_text,
"raw_subject": self.raw_subject,
}
)
)

##########################################################################
# VIEW CALLBACKS #
##########################################################################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ def name_get(self):
names = []
for backup in self:
name = f"{round(backup.revision_number, 2):.2f}"
if self._context.get('show_revision_date'):
name += f" - {backup.revision_date}"
names.append((backup.id, name))
return names

Expand Down
184 changes: 97 additions & 87 deletions partner_communication_revision/views/communication_config_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,88 +3,98 @@
<field name="name">communication.config.revision.form</field>
<field name="model">partner.communication.config</field>
<field
name="inherit_id"
ref="partner_communication.communication_config_form"
/>
name="inherit_id"
ref="partner_communication.communication_config_form"
/>
<field name="arch" type="xml">
<xpath expr="//sheet" position="before">
<header>
<button
name="%(action_new_proposition)d"
type="action"
string="New revision"
class="oe_highlight"
/>
<field name="state" widget="statusbar" />
name="%(action_new_proposition)d"
type="action"
string="New revision"
class="oe_highlight"
/>
<field name="state" widget="statusbar"/>
</header>
</xpath>
<xpath expr="//div[@name='button_box']">
<button
class="oe_stat_button"
name="open_translation_view"
icon="fa-edit"
string="Edit raw translations"
type="object"
groups="base.group_system"
/>
class="oe_stat_button"
name="open_translation_view"
icon="fa-edit"
string="Edit raw translations"
type="object"
groups="base.group_system"
/>
</xpath>
<group name="general_config" position="after">
<group string="Revisions">
<group colspan="4">
<field name="revision_number" />
<field name="revision_date" />
<field
name="revision_ids"
context="{'default_config_id': id, 'form_view_ref': 'partner_communication_revision.revision_simplified_form'}"
>
<field name="revision_number"/>
<field name="revision_date"/>
<field name="revision_ids">
<tree
decoration-primary="state in ('pending','submit','corrected')"
decoration-success="state=='approved'"
decoration-muted="is_old_version"
>
<field name="is_old_version" invisible="1" />
<field name="config_id" invisible="1" />
<field name="lang" readonly="1" />
<field name="user_id" readonly="1" />
<field name="correction_user_id" readonly="1" />
decoration-primary="state in ('pending','submit','corrected')"
decoration-success="state=='approved'"
decoration-muted="is_old_version"
editable="bottom"
>
<field name="is_old_version" invisible="1"/>
<field name="config_id" invisible="1"/>
<field name="lang" widget="selection" options='{"editable":true}' readonly="False"/>
<field name="user_id" readonly="1"/>
<field name="correction_user_id" readonly="1"/>
<button
name="edit_proposition"
type="object"
icon="fa-file"
context="{'config_id': config_id}"
string="Show/Edit revision text"
/>
<field name="active_revision_id" />
<field name="revision_date" readonly="1" />
<field name="update_user_id" readonly="1" />
name="edit_proposition"
type="object"
icon="fa-file"
context="{'config_id': config_id}"
string="Show/Edit revision text"
/>
<field
name="active_revision_id"
widget="many2one"
options="{'editable': true}"
context="{'show_revision_date': True}"
readonly="False"
/>
<field name="revision_date" readonly="1"/>
<field name="update_user_id" readonly="1"/>
<button
name="show_revision"
type="object"
icon="fa-eye"
string="Show active text"
/>
name="show_revision"
type="object"
icon="fa-eye"
string="Show active text"
/>
<button
name="edit_revision"
type="object"
icon="fa-edit"
string="Correct active text"
attrs="{'invisible': [('is_old_version', '=', True)]}"
/>
name="edit_revision"
type="object"
icon="fa-edit"
string="Correct active text"
attrs="{'invisible': [('is_old_version', '=', True)]}"
/>
<button
name="new_revision"
type="object"
icon="fa-plus-square"
groups="base.group_erp_manager"
attrs="{'invisible': ['|', ('is_old_version', '=', True), ('state', '!=', 'approved')]}"
/>
<field name="state" readonly="1" />
name="new_revision"
type="object"
icon="fa-plus-square"
groups="base.group_erp_manager"
attrs="{'invisible': ['|', ('is_old_version', '=', True), ('state', '!=', 'approved')]}"
/>
<field name="state" readonly="1"/>
<button
name="save_current_revision"
type="object"
icon="fa-save"
string="Create backup of current revision"
attrs="{'invisible': ['|', ('state', '!=', 'active'), ('active_revision_id', '!=', False)]}"
/>
name="save_current_revision"
type="object"
icon="fa-save"
string="Create backup of current revision"
attrs="{'invisible': ['|', ('state', '!=', 'active'), ('active_revision_id', '!=', False)]}"
/>
<button
name="duplicate_revision"
string="Dupliquer révision"
type="object"
class="oe_highlight"
/>
</tree>
</field>
</group>
Expand All @@ -97,46 +107,46 @@
<field name="name">communication.config.revision.tree</field>
<field name="model">partner.communication.config</field>
<field
name="inherit_id"
ref="partner_communication.communication_config_tree"
/>
name="inherit_id"
ref="partner_communication.communication_config_tree"
/>
<field name="arch" type="xml">
<field name="report_id" position="after">
<field name="state" />
<field name="state"/>
</field>
<xpath expr="//tree" position="attributes">
<attribute name="decoration-info">state=='pending'</attribute>
</xpath>
</field>
</record>

<record model="ir.ui.view" id="communication_config_search">
<record model="ir.ui.view" id="communication_config_search">
<field name="name">communication.config.search</field>
<field name="model">partner.communication.config</field>
<field
name="inherit_id"
ref="partner_communication.communication_config_search"
/>
name="inherit_id"
ref="partner_communication.communication_config_search"
/>
<field name="arch" type="xml">
<field name="name" position="after">
<filter
name="need_action"
string="Need Action"
domain="['|', '&amp;', ('revision_ids.state', '=', 'pending'), ('revision_ids.user_id', '=', uid), '&amp;', ('revision_ids.state', '=', 'submit'), ('revision_ids.correction_user_id', '=', uid)]"
/>
<separator />
name="need_action"
string="Need Action"
domain="['|', '&amp;', ('revision_ids.state', '=', 'pending'), ('revision_ids.user_id', '=', uid), '&amp;', ('revision_ids.state', '=', 'submit'), ('revision_ids.correction_user_id', '=', uid)]"
/>
<separator/>
<filter
name="active"
string="Active"
domain="[('state', '=', 'active')]"
/>
name="active"
string="Active"
domain="[('state', '=', 'active')]"
/>
<filter
name="pending"
string="In Revision"
domain="[('state', '=', 'pending')]"
/>
<separator />
name="pending"
string="In Revision"
domain="[('state', '=', 'pending')]"
/>
<separator/>
</field>
</field>
</record>
</record>
</odoo>
Loading

0 comments on commit 9b49b41

Please sign in to comment.