Skip to content

Commit

Permalink
[MIG] sign_oca: Migration to 17.0
Browse files Browse the repository at this point in the history
>
>
Co-authored-by: Bernat Puig <[email protected]>
  • Loading branch information
peluko00 committed Sep 18, 2024
1 parent ef43b4d commit fe8344e
Show file tree
Hide file tree
Showing 42 changed files with 462 additions and 340 deletions.
4 changes: 2 additions & 2 deletions sign_oca/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"name": "Sign Oca",
"summary": """
Allow to sign documents inside Odoo CE""",
"version": "16.0.2.0.0",
"version": "17.0.1.0.0",
"license": "AGPL-3",
"author": "Dixmit,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/sign",
Expand All @@ -14,6 +14,7 @@
"security/security.xml",
"views/menu.xml",
"data/data.xml",
"wizards/res_config_settings_views.xml",
"wizards/sign_oca_template_generate.xml",
"wizards/sign_oca_template_generate_multi.xml",
"views/res_partner_views.xml",
Expand Down Expand Up @@ -61,7 +62,6 @@
"sign_oca/static/src/components/sign_oca_pdf_portal/sign_oca_pdf_portal.esm.js",
"sign_oca/static/src/components/sign_oca_pdf_portal/sign_oca_pdf_portal.xml",
"sign_oca/static/src/scss/portal.scss",
"sign_oca/static/src/js/*.js",
"sign_oca/static/src/xml/*.xml",
],
"sign_oca.sign_assets": [
Expand Down
3 changes: 1 addition & 2 deletions sign_oca/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,4 @@ def get_sign_oca_sign_access(self, signer_id, access_token, items):
)
except (AccessError, MissingError):
return request.redirect("/my")
signer_sudo.action_sign(items, access_token=access_token)
return True
return signer_sudo.action_sign(items, access_token=access_token)

Check warning on line 104 in sign_oca/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

sign_oca/controllers/main.py#L102-L104

Added lines #L102 - L104 were not covered by tests
15 changes: 0 additions & 15 deletions sign_oca/migrations/16.0.1.1.1/pre-migration.py

This file was deleted.

1 change: 1 addition & 0 deletions sign_oca/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from . import res_company
from . import res_users
from . import res_partner
from . import sign_oca_template
Expand Down
14 changes: 14 additions & 0 deletions sign_oca/models/res_company.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright 2024 ForgeFlow S.L. (http://www.forgeflow.com)
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).

from odoo import fields, models


class ResCompany(models.Model):
_inherit = "res.company"

sign_oca_send_sign_request_copy = fields.Boolean(
string="Send signers a copy of the final signed document",
help="Once all signers have signed the request, a copy of "
"the final document will be sent to each of them.",
)
1 change: 1 addition & 0 deletions sign_oca/models/res_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def sign_oca_request_user_count(self):
"child_of",
[self.env.user.partner_id.commercial_partner_id.id],
),
("signed_on", "=", False),
]
signer_model = self.env["sign.oca.request.signer"]
signer_groups = signer_model.read_group(domain, ["model"], ["model"])

Check warning on line 23 in sign_oca/models/res_users.py

View check run for this annotation

Codecov / codecov/patch

sign_oca/models/res_users.py#L22-L23

Added lines #L22 - L23 were not covered by tests
Expand Down
86 changes: 54 additions & 32 deletions sign_oca/models/sign_oca_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,12 @@ class SignOcaRequest(models.Model):

name = fields.Char(required=True)
active = fields.Boolean(default=True)
template_id = fields.Many2one("sign.oca.template", readonly=True)
data = fields.Binary(
required=True, readonly=True, states={"draft": [("readonly", False)]}
)
template_id = fields.Many2one("sign.oca.template")
data = fields.Binary(required=True)
filename = fields.Char()
user_id = fields.Many2one(
comodel_name="res.users",
string="Responsible",
readonly=True,
states={"draft": [("readonly", False)]},
default=lambda self: self.env.user,
required=True,
)
Expand All @@ -45,17 +41,13 @@ class SignOcaRequest(models.Model):
)
],
string="Object",
readonly=True,
states={"draft": [("readonly", False)]},
)
signed = fields.Boolean(copy=False)
signer_ids = fields.One2many(
"sign.oca.request.signer",
inverse_name="request_id",
auto_join=True,
copy=True,
readonly=True,
states={"draft": [("readonly", False)]},
)
signer_id = fields.Many2one(
comodel_name="sign.oca.request.signer",
Expand All @@ -70,7 +62,6 @@ class SignOcaRequest(models.Model):
("cancel", "Cancelled"),
],
default="draft",
readonly=True,
required=True,
copy=False,
tracking=True,
Expand All @@ -80,16 +71,13 @@ class SignOcaRequest(models.Model):
to_sign = fields.Boolean(compute="_compute_to_sign")
signatory_data = fields.Serialized(
default=lambda r: {},
readonly=True,
copy=False,
)
current_hash = fields.Char(readonly=True, copy=False)
current_hash = fields.Char(copy=False)
company_id = fields.Many2one(
"res.company",
default=lambda r: r.env.company.id,
required=True,
readonly=True,
states={"draft": [("readonly", False)]},
)
next_item_id = fields.Integer(compute="_compute_next_item_id")

Expand Down Expand Up @@ -264,6 +252,40 @@ def action_send(self, sign_now=False, message=""):
email_layout_xmlid="mail.mail_notification_light",
)

def action_send_signed_request(self):
self.ensure_one()
if (
self.state != "signed"
or not self.env.company.sign_oca_send_sign_request_copy
):
return
for signer in self.signer_ids:
attachments = (

Check warning on line 263 in sign_oca/models/sign_oca_request.py

View check run for this annotation

Codecov / codecov/patch

sign_oca/models/sign_oca_request.py#L263

Added line #L263 was not covered by tests
self.env["ir.attachment"]
.sudo()
.search(
[
("res_model", "=", "sign.oca.request"),
("res_id", "=", self.id),
("res_field", "=", "data"),
]
)
)
# The message will not be linked to the record because we do not want
# it happen.
self.env["mail.thread"].message_notify(

Check warning on line 276 in sign_oca/models/sign_oca_request.py

View check run for this annotation

Codecov / codecov/patch

sign_oca/models/sign_oca_request.py#L276

Added line #L276 was not covered by tests
body=_(
"%(name)s (%(email)s) has sent the signed document.",
name=self.create_uid.name,
email=self.create_uid.email,
),
partner_ids=signer.partner_id.ids,
subject=_("Signed document"),
subtype_id=self.env.ref("mail.mt_comment").id,
mail_auto_delete=False,
attachment_ids=attachments.ids,
)

def _check_signed(self):
self.ensure_one()
if self.state != "sent":
Expand Down Expand Up @@ -310,8 +332,8 @@ class SignOcaRequestSigner(models.Model):
partner_name = fields.Char(related="partner_id.name")
partner_id = fields.Many2one("res.partner", required=True, ondelete="restrict")
role_id = fields.Many2one("sign.oca.role", required=True, ondelete="restrict")
signed_on = fields.Datetime(readonly=True)
signature_hash = fields.Char(readonly=True)
signed_on = fields.Datetime()
signature_hash = fields.Char()
model = fields.Char(compute="_compute_model", store=True)
res_id = fields.Integer(compute="_compute_res_id", store=True)
is_allow_signature = fields.Boolean(compute="_compute_is_allow_signature")
Expand Down Expand Up @@ -358,10 +380,10 @@ def get_info(self, access_token=False):
"items": self.request_id.signatory_data,
"to_sign": self.request_id.to_sign,
"partner": {
"id": self.env.user.partner_id.id,
"name": self.env.user.partner_id.name,
"email": self.env.user.partner_id.email,
"phone": self.env.user.partner_id.phone,
"id": self.partner_id.id,
"name": self.partner_id.name,
"email": self.partner_id.email,
"phone": self.partner_id.phone,
},
}

Expand Down Expand Up @@ -422,7 +444,11 @@ def action_sign(self, items, access_token=False):
self.signature_hash = final_hash
self.request_id._check_signed()
self._set_action_log("sign", access_token=access_token)
# TODO: Add a return
self.request_id.action_send_signed_request()
return {
"type": "ir.actions.act_url",
"url": self.access_url,
}

def _check_signable(self, item):
if not item["required"]:
Expand Down Expand Up @@ -510,9 +536,9 @@ def _set_action_log(self, action, **kwargs):
self.ensure_one()
return self.request_id._set_action_log(action, signer_id=self.id, **kwargs)

def name_get(self):
result = [(signer.id, (signer.partner_id.display_name)) for signer in self]
return result
def _compute_display_name(self):
for signer in self:
signer.display_name = signer.partner_id.display_name

Check warning on line 541 in sign_oca/models/sign_oca_request.py

View check run for this annotation

Codecov / codecov/patch

sign_oca/models/sign_oca_request.py#L541

Added line #L541 was not covered by tests


class SignRequestLog(models.Model):
Expand All @@ -524,13 +550,10 @@ class SignRequestLog(models.Model):
uid = fields.Many2one(
"res.users",
required=True,
readonly=True,
ondelete="cascade",
default=lambda r: r.env.user.id,
)
date = fields.Datetime(
required=True, readonly=True, default=lambda r: fields.Datetime.now()
)
date = fields.Datetime(required=True, default=lambda r: fields.Datetime.now())
partner_id = fields.Many2one(
"res.partner", required=True, default=lambda r: r.env.user.partner_id.id
)
Expand All @@ -549,7 +572,6 @@ class SignRequestLog(models.Model):
("configure", "Configure"),
],
required=True,
readonly=True,
)
access_token = fields.Char(readonly=True)
ip = fields.Char(readonly=True)
access_token = fields.Char()
ip = fields.Char()
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
/** @odoo-module **/
/** @odoo-module QWeb **/

import {ComponentWrapper} from "web.OwlCompatibility";
import AbstractAction from "web.AbstractAction";
import Dialog from "web.Dialog";
import core from "web.core";
import ControlPanel from "web.ControlPanel";
import {Component} from "@odoo/owl";
import {ControlPanel} from "@web/search/control_panel/control_panel";
import {Dialog} from "@web/core/dialog/dialog";
import {FormRenderer} from "@web/views/form/form_renderer";
import SignOcaPdfCommon from "../sign_oca_pdf_common/sign_oca_pdf_common.esm.js";
const _t = core._t;
import {_t} from "@web/core/l10n/translation";
import {registry} from "@web/core/registry";
import {renderToString} from "@web/core/utils/render";

export class SignOcaConfigureControlPanel extends ControlPanel {}
SignOcaConfigureControlPanel.template = "sign_oca.SignOcaConfigureControlPanel";
export class SignOcaConfigure extends SignOcaPdfCommon {
Expand Down Expand Up @@ -35,7 +37,7 @@ export class SignOcaConfigure extends SignOcaPdfCommon {
}
var position = page.getBoundingClientRect();
this.contextMenu = $(
core.qweb.render("sign_oca.sign_iframe_contextmenu", {
renderToString("sign_oca.sign_iframe_contextmenu", {
page,
e,
left: ((e.pageX - position.x) * 100) / position.width + "%",
Expand Down Expand Up @@ -111,7 +113,7 @@ export class SignOcaConfigure extends SignOcaPdfCommon {
var dialog = new Dialog(this, {
title: _t("Edit field"),
$content: $(
core.qweb.render("sign_oca.sign_oca_field_edition", {
renderToString("sign_oca.sign_oca_field_edition", {
item,
info: this.info,
})
Expand Down Expand Up @@ -367,34 +369,33 @@ export class SignOcaConfigure extends SignOcaPdfCommon {
}
}

export const SignOcaConfigureAction = AbstractAction.extend({
hasControlPanel: true,
init: function (parent, action) {
export class SignOcaConfigureAction extends Component {
init(parent, action) {
this._super.apply(this, arguments);
this.model =
(action.params.res_model !== undefined && action.params.res_model) ||
action.context.params.res_model;
this.res_id =
(action.params.res_id !== undefined && action.params.res_id) ||
action.context.params.id;
},
}
async start() {
await this._super(...arguments);
this.component = new ComponentWrapper(this, SignOcaConfigure, {
this.component = new FormRenderer(this, SignOcaConfigure, {
model: this.model,
res_id: this.res_id,
});
this.$el.addClass("o_sign_oca_action");
return this.component.mount(this.$(".o_content")[0]);
},
getState: function () {
}
getState() {
var result = this._super(...arguments);
result = _.extend({}, result, {
res_model: this.model,
res_id: this.res_id,
});
return result;
},
});
core.action_registry.add("sign_oca_configure", SignOcaConfigureAction);
}
}
SignOcaConfigure.template = "sign_oca.SignOcaConfigure";
registry.category("actions").add("sign_oca_configure", SignOcaConfigureAction);
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@
t-name="sign_oca.SignOcaConfigure"
t-inherit="sign_oca.SignOcaPdfCommon"
t-inherit-mode="primary"
owl="1"
>
<xpath expr="//iframe" position="before">
<div
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/** @odoo-module **/
/** @odoo-module Qweb **/

import SignOcaPdfCommon from "../sign_oca_pdf_common/sign_oca_pdf_common.esm.js";
import core from "web.core";
import {registry} from "@web/core/registry";
const SignRegistry = registry.category("sign_oca");
import {renderToString} from "@web/core/utils/render";

export default class SignOcaPdf extends SignOcaPdfCommon {
setup() {
super.setup(...arguments);
Expand All @@ -23,7 +24,7 @@ export default class SignOcaPdf extends SignOcaPdfCommon {
}
renderButtons(to_sign) {
var $buttons = $(
core.qweb.render("oca_sign_oca.SignatureButtons", {
renderToString("oca_sign_oca.SignatureButtons", {
to_sign: to_sign,
})
);
Expand Down Expand Up @@ -86,7 +87,7 @@ export default class SignOcaPdf extends SignOcaPdfCommon {
_.filter(this.info.items, (item) => {
return (
item.required &&
item.role === this.info.role &&
item.role_id === this.info.role_id &&
!SignRegistry.get(item.field_type).check(item)
);
}).length === 0;
Expand Down
Loading

0 comments on commit fe8344e

Please sign in to comment.