Skip to content

Commit

Permalink
Fixing
Browse files Browse the repository at this point in the history
  • Loading branch information
herrygouw committed Jul 16, 2024
1 parent e32dc68 commit c2884bb
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 88 deletions.
1 change: 1 addition & 0 deletions payroll_account/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ Contributors

* Odoo SA <[email protected]>
* Saran Lim. <[email protected]>
* Herry/Panca. <https://solusiaglis.co.id>

Maintainers
~~~~~~~~~~~
Expand Down
184 changes: 97 additions & 87 deletions payroll_account/models/hr_payslip.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,97 +430,107 @@ def generate_journal_batch(self):
def action_payslip_done(self):
res = super(HrPayslip, self).action_payslip_done()

can_merge = False
for rec in self:
# not batch, run original core odoo (generate_journal_single, this will until post)
if not rec.payslip_run_id:
rec.generate_journal_single()
else:

# check all confirm except the current record
rec_done = self.env["hr.payslip"].search(
[("state", "=", "done"), ("payslip_run_id", "=", self.payslip_run_id.id)]
)
rec_all = self.env["hr.payslip"].search(
[("payslip_run_id", "=", self.payslip_run_id.id)]
)
# for batch, merge journal until draft

if len(rec_all) == len(rec_done):
can_merge = True

if can_merge:
merge_line_ids = []
journal_id = False
journal_date = False
batch_name = False
for rec in rec_done:
if rec.payslip_run_id:
rec.generate_journal_batch()
journal_id = rec.move_id.id
journal_date = rec.move_id.date
batch_name = rec.payslip_run_id.name
for move_rec in rec.move_id.line_ids:
move_line = (
0,
0,
{
"name": move_rec.name,
"partner_id": move_rec.partner_id.id
if move_rec.partner_id
else False,
"account_id": move_rec.account_id.id,
"analytic_account_id": move_rec.analytic_account_id.id
if move_rec.analytic_account_id
else False,
"journal_id": move_rec.journal_id.id,
"date": move_rec.date,
"debit": move_rec.debit,
"credit": move_rec.credit,
},
)
merge_line_ids.append(move_line)
can_merge = False

Check warning on line 441 in payroll_account/models/hr_payslip.py

View check run for this annotation

Codecov / codecov/patch

payroll_account/models/hr_payslip.py#L441

Added line #L441 was not covered by tests

# delete draft journal per payslip
rec.move_id.unlink()
rec.move_id = False
# check all confirm except the current record
rec_done = self.env["hr.payslip"].search(

Check warning on line 444 in payroll_account/models/hr_payslip.py

View check run for this annotation

Codecov / codecov/patch

payroll_account/models/hr_payslip.py#L444

Added line #L444 was not covered by tests
[
("state", "=", "done"),
("payslip_run_id", "=", self.payslip_run_id.id),
]
)
rec_all = self.env["hr.payslip"].search(

Check warning on line 450 in payroll_account/models/hr_payslip.py

View check run for this annotation

Codecov / codecov/patch

payroll_account/models/hr_payslip.py#L450

Added line #L450 was not covered by tests
[("payslip_run_id", "=", self.payslip_run_id.id)]
)

move_narration = _("Payslip Batch")
move_dict = {
"narration": move_narration,
"ref": batch_name,
"journal_id": journal_id,
"date": journal_date,
}
if len(rec_all) == len(rec_done):
can_merge = True

Check warning on line 455 in payroll_account/models/hr_payslip.py

View check run for this annotation

Codecov / codecov/patch

payroll_account/models/hr_payslip.py#L455

Added line #L455 was not covered by tests

if can_merge:
merge_line_ids = []
journal_id = False
journal_date = False
batch_name = False

Check warning on line 461 in payroll_account/models/hr_payslip.py

View check run for this annotation

Codecov / codecov/patch

payroll_account/models/hr_payslip.py#L458-L461

Added lines #L458 - L461 were not covered by tests
for rec in rec_done:
if rec.payslip_run_id:
rec.generate_journal_batch()
journal_id = rec.move_id.id
journal_date = rec.move_id.date
batch_name = rec.payslip_run_id.name

Check warning on line 467 in payroll_account/models/hr_payslip.py

View check run for this annotation

Codecov / codecov/patch

payroll_account/models/hr_payslip.py#L464-L467

Added lines #L464 - L467 were not covered by tests
for move_rec in rec.move_id.line_ids:
move_line = (

Check warning on line 469 in payroll_account/models/hr_payslip.py

View check run for this annotation

Codecov / codecov/patch

payroll_account/models/hr_payslip.py#L469

Added line #L469 was not covered by tests
0,
0,
{
"name": move_rec.name,
"partner_id": move_rec.partner_id.id
if move_rec.partner_id
else False,
"account_id": move_rec.account_id.id,
"analytic_account_id": move_rec.analytic_account_id.id
if move_rec.analytic_account_id
else False,
"journal_id": move_rec.journal_id.id,
"date": move_rec.date,
"debit": move_rec.debit,
"credit": move_rec.credit,
},
)
merge_line_ids.append(move_line)

Check warning on line 487 in payroll_account/models/hr_payslip.py

View check run for this annotation

Codecov / codecov/patch

payroll_account/models/hr_payslip.py#L487

Added line #L487 was not covered by tests

# delete draft journal per payslip
rec.move_id.unlink()
rec.move_id = False

Check warning on line 491 in payroll_account/models/hr_payslip.py

View check run for this annotation

Codecov / codecov/patch

payroll_account/models/hr_payslip.py#L490-L491

Added lines #L490 - L491 were not covered by tests

move_narration = _("Payslip Batch")
move_dict = {

Check warning on line 494 in payroll_account/models/hr_payslip.py

View check run for this annotation

Codecov / codecov/patch

payroll_account/models/hr_payslip.py#L493-L494

Added lines #L493 - L494 were not covered by tests
"narration": move_narration,
"ref": batch_name,
"journal_id": journal_id,
"date": journal_date,
}

final_merge_line_ids = []

Check warning on line 501 in payroll_account/models/hr_payslip.py

View check run for this annotation

Codecov / codecov/patch

payroll_account/models/hr_payslip.py#L501

Added line #L501 was not covered by tests
for line in merge_line_ids:
# search account_id and analytic_account_id
found_src = False
found_src_id = 0

Check warning on line 505 in payroll_account/models/hr_payslip.py

View check run for this annotation

Codecov / codecov/patch

payroll_account/models/hr_payslip.py#L504-L505

Added lines #L504 - L505 were not covered by tests
if len(final_merge_line_ids) > 0:
for src in final_merge_line_ids:
if (
src[2]["account_id"] == line[2]["account_id"]
and src[2]["analytic_account_id"]
== line[2]["analytic_account_id"]
and src[2]["partner_id"] == line[2]["partner_id"]
):
found_src = True
break

Check warning on line 515 in payroll_account/models/hr_payslip.py

View check run for this annotation

Codecov / codecov/patch

payroll_account/models/hr_payslip.py#L514-L515

Added lines #L514 - L515 were not covered by tests

found_src_id += 1

Check warning on line 517 in payroll_account/models/hr_payslip.py

View check run for this annotation

Codecov / codecov/patch

payroll_account/models/hr_payslip.py#L517

Added line #L517 was not covered by tests

if not found_src:
final_merge_line_ids.append(line)

Check warning on line 520 in payroll_account/models/hr_payslip.py

View check run for this annotation

Codecov / codecov/patch

payroll_account/models/hr_payslip.py#L520

Added line #L520 was not covered by tests
else:
final_merge_line_ids[found_src_id][2]["debit"] += line[2][

Check warning on line 522 in payroll_account/models/hr_payslip.py

View check run for this annotation

Codecov / codecov/patch

payroll_account/models/hr_payslip.py#L522

Added line #L522 was not covered by tests
"debit"
]
final_merge_line_ids[found_src_id][2]["credit"] += line[2][

Check warning on line 525 in payroll_account/models/hr_payslip.py

View check run for this annotation

Codecov / codecov/patch

payroll_account/models/hr_payslip.py#L525

Added line #L525 was not covered by tests
"credit"
]

final_merge_line_ids = []
for line in merge_line_ids:
# search account_id and analytic_account_id
found_src = False
found_src_id = 0
if len(final_merge_line_ids) > 0:
for src in final_merge_line_ids:
if (
src[2]["account_id"] == line[2]["account_id"]
and src[2]["analytic_account_id"]
== line[2]["analytic_account_id"]
and src[2]["partner_id"] == line[2]["partner_id"]
):
found_src = True
break

found_src_id += 1

if not found_src:
final_merge_line_ids.append(line)
else:
final_merge_line_ids[found_src_id][2]["debit"] += line[2]["debit"]
final_merge_line_ids[found_src_id][2]["credit"] += line[2]["credit"]

if final_merge_line_ids:
move_dict["line_ids"] = final_merge_line_ids
move = self.env["account.move"].create(move_dict)
# update all slip to this journal
for rec in rec_done:
rec.write({"move_id": move.id, "date": journal_date})

else:
for rec in self:
if not rec.payslip_run_id:
rec.generate_journal_single()
if final_merge_line_ids:
move_dict["line_ids"] = final_merge_line_ids
move = self.env["account.move"].create(move_dict)

Check warning on line 531 in payroll_account/models/hr_payslip.py

View check run for this annotation

Codecov / codecov/patch

payroll_account/models/hr_payslip.py#L530-L531

Added lines #L530 - L531 were not covered by tests
# update all slip to this journal
for rec in rec_done:
rec.write({"move_id": move.id, "date": journal_date})

Check warning on line 534 in payroll_account/models/hr_payslip.py

View check run for this annotation

Codecov / codecov/patch

payroll_account/models/hr_payslip.py#L534

Added line #L534 was not covered by tests

return res
2 changes: 1 addition & 1 deletion payroll_account/static/description/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
Expand Down Expand Up @@ -413,6 +412,7 @@ <h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
<ul class="simple">
<li>Odoo SA &lt;<a class="reference external" href="mailto:info&#64;odoo.com">info&#64;odoo.com</a>&gt;</li>
<li>Saran Lim. &lt;<a class="reference external" href="mailto:saranl&#64;ecosoft.co.th">saranl&#64;ecosoft.co.th</a>&gt;</li>
<li>Herry/Panca. &lt;<a class="reference external" href="https://solusiaglis.co.id">https://solusiaglis.co.id</a>&gt;</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand Down

0 comments on commit c2884bb

Please sign in to comment.