Skip to content

Commit

Permalink
G2P-2416: Odoo payment batch tag server fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
dibik96 committed Jun 13, 2024
1 parent 2a89cf1 commit 736b241
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 19 deletions.
14 changes: 6 additions & 8 deletions g2p_program_registrant_info/static/src/js/g2p_additional_info.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,16 @@ export class G2PAdditionalInfoWidget extends TextField {
validateValue() {
const val = this.props.record.data.program_registrant_info;

if (val) {
if (typeof val === "string") {
if (!(val.charAt(0) === "{" && val.charAt(val.length - 1) === "}")) {
this.state.noValue = true;
} else {
this.state.noValue = false;
}
} else if (typeof val === "object") {
if (!val) {
this.state.noValue = true;
} else if (typeof val === "string") {
if (val.charAt(0) === "{" && val.charAt(val.length - 1) === "}") {
this.state.noValue = false;
} else {
this.state.noValue = true;
}
} else if (typeof val === "object") {
this.state.noValue = false;
} else {
this.state.noValue = true;
}
Expand Down
44 changes: 33 additions & 11 deletions g2p_programs/models/managers/payment_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,39 @@ class DefaultFilePaymentManager(models.Model):

@api.onchange("create_batch")
def on_change_create_batch(self):
self.batch_tag_ids = [
(5,),
(
0,
0,
{
"name": f"Default {self.program_id.name}",
"order": 1,
},
),
]
if self.create_batch:
existing_batch = (
self.env["g2p.payment.batch.tag"]
.sudo()
.search(
[
("name", "=", f"Default {self.program_id.name}"),
("order", "=", 1),
("max_batch_size", "=", 500),
],
limit=1,
)
)

if existing_batch:
batch_id = existing_batch
else:
batch_id = (
self.env["g2p.payment.batch.tag"]
.sudo()
.create(
{
"name": f"Default {self.program_id.name}",
"order": 1,
"domain": [],
"max_batch_size": 500,
}
)
)

self.batch_tag_ids = [(4, batch_id.id)]
else:
self.batch_tag_ids = [(5,)]

@api.constrains("batch_tag_ids")
def constrains_batch_tag_ids(self):
Expand Down

0 comments on commit 736b241

Please sign in to comment.