Skip to content

Commit 2f46c97

Browse files
committed
Merge PR #517 into 18.0
Signed-off-by Saran440
2 parents b35083e + 6704afb commit 2f46c97

File tree

6 files changed

+30
-6
lines changed

6 files changed

+30
-6
lines changed

budget_control_request_document/models/budget_period.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,22 @@ def _get_eligible_budget_period(self, date=False, doc_type=False):
4242
or (not bp.control_budget and bp.request_document)
4343
)
4444
return budget_period
45+
46+
@api.model
47+
def check_budget_precommit(self, doclines, doc_type="account"):
48+
"""Uncommit request document first before check budget"""
49+
budget_moves = False
50+
if (
51+
hasattr(doclines, "_doc_rel")
52+
and hasattr(doclines[doclines._doc_rel], "request_document_id")
53+
and doclines[doclines._doc_rel].request_document_id
54+
):
55+
budget_moves = (
56+
doclines[doclines._doc_rel]
57+
.request_document_id.with_context(reverse_precommit=1)
58+
.uncommit_request_budget(doclines)
59+
)
60+
res = super().check_budget_precommit(doclines, doc_type=doc_type)
61+
if budget_moves:
62+
budget_moves.unlink()
63+
return res

budget_control_request_document/models/request_document.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ def recompute_budget_move(self):
7878

7979
def close_budget_move(self):
8080
rounding = self.currency_id.rounding
81+
budget_moves = self.env["request.budget.move"]
8182
for rec in self:
8283
totals = rec.budget_move_ids.read(["debit", "credit"])
8384
debit = sum(x["debit"] for x in totals)
@@ -103,7 +104,9 @@ def close_budget_move(self):
103104
if line.id in line_amount_map
104105
else {}
105106
)
106-
line.with_context(**ctx).commit_budget(reverse=True)
107+
budget_move = line.with_context(**ctx).commit_budget(reverse=True)
108+
budget_moves += budget_move
109+
return budget_moves
107110

108111
def uncommit_request_budget(self, request_line):
109-
return
112+
return False

budget_control_request_document/models/request_order.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ def recompute_budget_move(self):
1717
self.mapped("line_ids").recompute_budget_move()
1818

1919
def close_budget_move(self):
20-
self.mapped("line_ids").close_budget_move()
20+
budget_moves = self.mapped("line_ids").close_budget_move()
21+
return budget_moves
2122

2223
def _clear_date_commit(self, doclines):
2324
clear_date_commit = {"date_commit": False}

budget_control_request_document/tests/request_document_tester.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ def uncommit_request_budget(self, request_line):
4646
and budget_move
4747
and request_line[request_line._doc_rel].state == "posted"
4848
):
49-
self.close_budget_move()
49+
budget_moves = self.close_budget_move()
50+
return budget_moves
5051
return res
5152

5253
def _create_tester(self):

budget_control_request_document/tests/test_budget_control_request_document.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414

1515
@tagged("post_install", "-at_install")
16-
class TestBudgetControlRequestDocument(get_budget_common_class()):
16+
class TestBudgetControlRequest(get_budget_common_class()):
1717
@classmethod
1818
@freeze_time("2001-02-01")
1919
def setUpClass(cls):

budget_control_request_document/views/request_order_view.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
name="budget_commit"
1212
invisible="not budget_move_ids"
1313
>
14-
<div class="oe_read_only oe_right" name="buttons">
14+
<div class="d-flex justify-content-end" name="buttons">
1515
<button
1616
type="object"
1717
name="recompute_budget_move"

0 commit comments

Comments
 (0)