Skip to content

Commit

Permalink
Merge pull request #162 from RamakrishnaVellala/15.0-develop-main
Browse files Browse the repository at this point in the history
G2P-1360-Buttons to follow logical flow - Approve Entitlements button should not be shown until Entitlements are prepared
  • Loading branch information
shibu-narayanan authored Dec 8, 2023
2 parents 697e64f + 38942cc commit 5ad2d4a
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 27 deletions.
4 changes: 4 additions & 0 deletions g2p_program_assessment/models/assessment.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ class G2PProgramAssessment(models.Model):
program_membership_id = fields.Many2one("g2p.program_membership")

entitlement_id = fields.Many2one("g2p.entitlement")
is_comment = fields.Boolean(default=False)

@api.model
def post_assessment(
self,
body,
res_model,
res_ids,
is_comment=False,
subject=None,
message_type="comment",
subtype_id=None,
Expand Down Expand Up @@ -72,6 +74,7 @@ def post_assessment(
"name": message.subject,
"remarks_id": message.id,
self.get_res_field_name(res_model): res_ids[i],
"is_comment": is_comment,
}
for i, message in enumerate(messages)
]
Expand Down Expand Up @@ -162,6 +165,7 @@ def get_rendering_context(self, res_model, res_id):
"author_id": assess.author_id.id,
"assessment_date": assess.assessment_date,
"body": assess.remarks_id.body,
"is_comment": assess.is_comment,
}
for assess in self.search(
[(self.get_res_field_name(res_model), "=", res_id)],
Expand Down
28 changes: 20 additions & 8 deletions g2p_program_assessment/static/src/js/g2p_assessment.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ var G2PAssessmentWizardWidget = AbstractField.extend({
tagName: "div",
events: {
"click button.o_ChatterTopbar_buttonAddAssess": "triggerAddAssessment",
"click button.o_ChatterTopbar_buttonAddComment": "triggerAddComment",
"click button.o_Composer_buttonCancel": "triggerAddAssessment",
"click button.o_Composer_buttonSubmit": "submitAssessment",
// "click button.o_Composer_buttonSubmit": "submitComment",
"keyup textarea.o_ComposerTextInput_textarea": "triggerButtonSubmitEnable",
},
init: function () {
Expand All @@ -32,41 +34,49 @@ var G2PAssessmentWizardWidget = AbstractField.extend({
} else if (this.nodeOptions.not_readonly_field) {
this.readonly = !this.recordData[this.nodeOptions.not_readonly_field];
}
this.showAddCommentsButton = this.nodeOptions.show_add_comments_button != false;
this.showAddAssessmentsButton = this.nodeOptions.show_add_assessments_button != false;
console.log(this);
this.assessmentAddMode = 0;
this.assessmentAddModeStarted = 0;
},
_render: async function () {
return this.$el.html(qweb.render("g2p_assessments_list", await this._getRenderingContext()));
},
triggerAddAssessment: function () {
triggerAddComment: function (e) {
return this.triggerAddAssessment(e, true);
},
triggerAddAssessment: function (e, is_comment = false) {
if (this.assessmentAddModeStarted === 0) {
this.assessmentAddMode = 1;
this.assessmentAddModeStarted = 1;
this.$(".o_ChatterTopbar_buttonAddAssess").addClass("o_invisible_modifier");
this.$(".o_Composer_header_buttons").addClass("o_invisible_modifier");
this.$(".o_Composer").replaceWith(
qweb.render("g2p_assessments_add", {author_partner_id: session.partner_id})
);
return;
}
if (this.assessmentAddMode === 0) {
} else if (this.assessmentAddMode === 0) {
this.assessmentAddMode = 1;
this.$(".o_Composer_Assessment").removeClass("o_invisible_modifier");
this.$(".o_ChatterTopbar_buttonAddAssess").addClass("o_invisible_modifier");
this.$(".o_Composer_header_buttons").addClass("o_invisible_modifier");
} else {
this.assessmentAddMode = 0;
this.$(".o_Composer_Assessment").addClass("o_invisible_modifier");
this.$(".o_ChatterTopbar_buttonAddAssess").removeClass("o_invisible_modifier");
this.$(".o_Composer_header_buttons").removeClass("o_invisible_modifier");
}
console.log("trigger ", is_comment);
if (is_comment) this.$(".o_Composer_Assessment").addClass("o_Composer_Comment");
else this.$(".o_Composer_Assessment").removeClass("o_Composer_Comment");
},
submitAssessment: function () {
var self = this;
const is_comment = this.$(".o_Composer_Assessment").hasClass("o_Composer_Comment");
console.log(is_comment);
let textareaBody = this.$("textarea.o_ComposerTextInput_textarea")[0].value;
textareaBody = textareaBody.replace(/(?:\r\n|\r|\n)/g, "<br />");
this._rpc({
model: "g2p.program.assessment",
method: "post_assessment",
args: [textareaBody, this.resModel, this.resId],
args: [textareaBody, this.resModel, this.resId, is_comment],
}).then(function () {
self.assessmentAddMode = 0;
self.assessmentAddModeStarted = 0;
Expand All @@ -91,6 +101,8 @@ var G2PAssessmentWizardWidget = AbstractField.extend({
});
res.readonly = this.readonly;
res.resModel = this.resModel;
res.showAddCommentsButton = this.showAddCommentsButton;
res.showAddAssessmentsButton = this.showAddAssessmentsButton;
return res;
},
});
Expand Down
15 changes: 14 additions & 1 deletion g2p_program_assessment/static/src/scss/g2p_assessment.scss
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
margin-bottom: 0.4%;
}

.o_Message.o_Message_Assessment.o_message_highlight {
background: #ffffff 0% 0% no-repeat padding-box;
}
.o_ChatterTopbar_buttonAddAssess {
border-radius: 10px;
border: 1px solid #0000001a;
Expand All @@ -33,12 +36,15 @@
}

.o_Composer_Assessment {
background: #ffffff 0% 0% no-repeat padding-box;
background: #f8f9fa 0% 0% no-repeat padding-box;
box-shadow: 0px 2px 5px #0000001a;
border-radius: 10px;
border: 1px solid #0000001a;
padding: 2% 1% 2% 1%;
}
.o_Composer_Assessment.o_Composer_Comment {
background: #ffffff 0% 0% no-repeat padding-box;
}

.o_Composer_Assessment .o_Message_sidebar {
margin-right: 1%;
Expand Down Expand Up @@ -75,3 +81,10 @@
.o_Composer_buttonCancelText {
color: #e27d21;
}
.o_ChatterTopbar_buttonAddComment {
border-radius: 10px;
border: 1px solid #e27d21;
}
.o_ChatterTopbar_buttonAddCommentText {
color: #e27d21;
}
26 changes: 19 additions & 7 deletions g2p_program_assessment/static/src/xml/g2p_assessment_templates.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,22 @@
<div class="o_Chatter">
<t t-if="readonly != true">
<div class="o_Chatter_fixedPanel">
<button class="btn o_ChatterTopbar_buttonAddAssess">
<span class="o_ChatterTopbar_buttonAddAssessText"><i class="fa fa-plus" />
<t t-if="resModel == 'g2p.entitlement'">Add Comments</t>
<t t-else="">Add Assessment</t>
</span>
</button>
<div class='o_Composer_header_buttons'>
<t t-if="showAddAssessmentsButton">
<button class="btn o_ChatterTopbar_buttonAddAssess">
<span class="o_ChatterTopbar_buttonAddAssessText"><i class="fa fa-plus" />
Add Assessment
</span>
</button>
</t>
<t t-if="showAddCommentsButton">
<button class="btn o_ChatterTopbar_buttonAddComment">
<span class="o_ChatterTopbar_buttonAddCommentText"><i class="fa fa-plus" />
Add Comment
</span>
</button>
</t>
</div>
<!-- The following o_Composer will be replaced by above template -->
<div class="o_Composer" />
</div>
Expand All @@ -53,7 +63,9 @@
<div class="o_ThreadView_core d-flex flex-column flex-grow-1">
<div class="o_MessageList o_ThreadView_messageList">
<t t-foreach="assessments" t-as="assess">
<div class="o_Message o_Message_Assessment o-not-discussion mt-3">
<div
t-att-class="'o_Message o_Message_Assessment o-not-discussion mt-3'+(assess.is_comment?' o_message_highlight':'')"
>
<div class="d-flex flex-shrink-0">
<div class="o_Message_sidebar">
<div
Expand Down
18 changes: 10 additions & 8 deletions g2p_program_assessment/views/entitlement_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ Part of OpenG2P. See LICENSE file for full copyright and licensing details.
<field name="priority" eval="170" />
<field name="arch" type="xml">
<xpath expr="//field[@name='date_approved']/../.." position="after">
<group string="Comments">
<field
name="assessment_ids"
nolabel="1"
widget="g2p_assess_widget"
options="{'res_model': 'g2p.entitlement', 'res_id_field': 'id'}"
colspan="4"
/>
<group string="Assessments">
<t t-if="len(assessment_ids)">
<field
name="assessment_ids"
nolabel="1"
widget="g2p_assess_widget"
options="{'res_model': 'g2p.entitlement', 'res_id_field': 'id', 'show_add_assessments_button':false}"
colspan="4"
/>
</t>
</group>
</xpath>
</field>
Expand Down
6 changes: 6 additions & 0 deletions g2p_program_documents/models/entitlement.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ class G2PEntitlement(models.Model):
_inherit = "g2p.entitlement"

supporting_document_ids = fields.One2many("storage.file", "entitlement_id")
document_count = fields.Integer(compute="_compute_document_count")

@api.depends("supporting_document_ids")
def _compute_document_count(self):
for record in self:
record.document_count = len(record.supporting_document_ids)

def copy_documents_from_beneficiary(self):
for rec in self:
Expand Down
3 changes: 2 additions & 1 deletion g2p_program_documents/views/entitlement_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
<field name="priority" eval="160" />
<field name="arch" type="xml">
<xpath expr="//field[@name='date_approved']/../.." position="after">
<group string="Supporting Documents">
<field name="document_count" invisible='1' />
<group string="Supporting Documents" attrs="{ 'invisible':[('document_count','=',0)] }">
<field name="supporting_document_ids" readonly="1" nolabel="1">
<tree default_order="id desc">
<field name="tags_ids" widget="many2many_tags" />
Expand Down
5 changes: 4 additions & 1 deletion g2p_programs/models/managers/payment_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,10 @@ def prepare_payments(self, cycle, entitlements=None):
payments, batches = self._prepare_payments(cycle, entitlements)
if payments:
kind = "success"
message = _("%s new payments was issued.", len(payments))
message = _(
"Payment batch successfully created for %s beneficiaries.",
len(payments),
)
sticky = False
else:
kind = "danger"
Expand Down
3 changes: 2 additions & 1 deletion g2p_programs/views/cycle_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Part of OpenG2P. See LICENSE file for full copyright and licensing details.
name="send_payment"
states="approved"
string="Send Payments"
invisible="context.get('hide_cash')"
attrs="{'invisible':['|',('payments_count','=',0)]}"
/>
<button
type="object"
Expand All @@ -100,6 +100,7 @@ Part of OpenG2P. See LICENSE file for full copyright and licensing details.
name="to_approve"
string="To Approve"
states="draft"
attrs="{'invisible': ['|',('entitlements_count', '=', 0)]}"
/>
<button
type="object"
Expand Down

0 comments on commit 5ad2d4a

Please sign in to comment.