Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
majouda committed Apr 9, 2024
1 parent 6b0bdde commit 5aefa7c
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 68 deletions.
2 changes: 1 addition & 1 deletion .docker_files/main/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
"project_wip_material",
# "project_wip_outsourcing",
# "project_wip_supply_cost",
# "project_wip_timesheet",
"project_wip_timesheet",
"timesheet_task_project_no_change",
],
"installable": True,
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ COPY project_wip /mnt/extra-addons/project_wip
COPY project_wip_material /mnt/extra-addons/project_wip_material
#COPY project_wip_outsourcing /mnt/extra-addons/project_wip_outsourcing
#COPY project_wip_supply_cost /mnt/extra-addons/project_wip_supply_cost
#COPY project_wip_timesheet /mnt/extra-addons/project_wip_timesheet
COPY project_wip_timesheet /mnt/extra-addons/project_wip_timesheet
COPY stock_location_production /mnt/extra-addons/stock_location_production
COPY timesheet_task_project_no_change /mnt/extra-addons/timesheet_task_project_no_change

Expand Down
62 changes: 3 additions & 59 deletions project_wip_timesheet/models/account_analytic_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ def _update_salary_account_move(self):
)
)

self.salary_account_move_id.button_draft()
self.salary_account_move_id.name = ""
self.salary_account_move_id.state = "draft"
vals = self._get_salary_account_move_vals()
self.salary_account_move_id.write(vals)
self.salary_account_move_id.post()
Expand All @@ -112,16 +111,7 @@ def _reverse_salary_account_move_for_updated_timesheet(self):
move_name=self.salary_account_move_id.name,
)
)
reversed_move = self.salary_account_move_id._reverse_moves()
reversed_move.action_post()

# get the reversed move line and reconcile it with the salary move line
reversed_move_line, move_line = self._get_line_reconciliation_data(
self.salary_account_move_id, reversed_move
)

# reconcile the move lines
self._reconcile_move_lines(move_line, reversed_move_line)
self.salary_account_move_id._reverse_moves()

self.salary_account_move_id = False

Expand All @@ -138,53 +128,7 @@ def _reverse_salary_account_move_for_deleted_timesheet(self):
move_name=self.salary_account_move_id.name,
)
)
# reverse the move and post it to allow the reconciliation of the move lines
reversed_move = self.salary_account_move_id._reverse_moves()
reversed_move.action_post()

# get the reversed move line and reconcile it with the salary move line
reversed_move_line, move_line = self._get_line_reconciliation_data(
self.salary_account_move_id, reversed_move
)

# reconcile the move lines
self._reconcile_move_lines(move_line, reversed_move_line)

def _get_line_reconciliation_data(self, move, reversed_move):
"""Get the reconciled move line and the original move line.
In case, we changed project in timesheet, and project has no type to select wip
account, we identify the account move line by task_id linked, that only on wip
account.
:rtype: tuple
"""
move_line = move.line_ids.filtered(
lambda line: (line.account_id == self._get_wip_account()) or line.task_id
)
reversed_move_line = reversed_move.line_ids.filtered(
lambda line: (line.account_id == self._get_wip_account()) or line.task_id
)
return reversed_move_line, move_line

def _reconcile_move_lines(self, move_line, reversal_line):
"""Reconcile the move lines."""
data = [
{
"id": None,
"mv_line_ids": [move_line.id, reversal_line.id],
"new_mv_line_dicts": [],
"type": None,
}
]
self.env["account.reconciliation.widget"].process_move_lines(data)

if move_line.matching_number == "P":
raise ValidationError(
_(
"The entry {move_line} ({amount}) could not be reconciled."
"You should verify if the Salary entry is partially reconciled."
).format(wip_line=move_line.display_name, amount=move_line.balance)
)
self.salary_account_move_id._reverse_moves()

def _is_salary_account_move_reconciled(self):
return any(line.reconciled for line in self.salary_account_move_id.line_ids)
Expand Down
1 change: 1 addition & 0 deletions project_wip_timesheet/models/project_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class ProjectType(models.Model):

@api.constrains("salary_account_id", "salary_journal_id", "wip_account_id")
def _check_required_fields_for_salary_entries(self):
self = self.with_context(force_company=self.env.user.company_id.id)
project_types_with_salary_account = self.filtered(lambda t: t.salary_account_id)
for project_type in project_types_with_salary_account:
if not project_type.wip_account_id:
Expand Down
10 changes: 3 additions & 7 deletions project_wip_timesheet/tests/test_wip_journal_entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def setUpClass(cls):
{
"name": "Work in Progress",
"code": "WIP",
# "update_posted": True,
"restrict_mode_hash_table": True,
"type": "general",
"company_id": cls.company.id,
}
Expand Down Expand Up @@ -99,10 +99,6 @@ def setUpClass(cls):

cls.env = cls.env(user=cls.manager, context={"force_company": cls.company.id})

cls.env["project.project"].create(
{"name": "Job 123", "company_id": cls.company.id}
)

cls.project_type = cls.env["project.type"].create(
{
"name": "Trailer Refurb",
Expand Down Expand Up @@ -181,12 +177,12 @@ def test_account_move_has_no_analytic_lines(self):

def _get_wip_move_line(self, timesheet_line):
return timesheet_line.salary_account_move_id.line_ids.filtered(
lambda l: l.account_id == self.wip_account
lambda line: line.account_id == self.wip_account
)

def _get_salary_move_line(self, timesheet_line):
return timesheet_line.salary_account_move_id.line_ids.filtered(
lambda l: l.account_id == self.salary_account
lambda line: line.account_id == self.salary_account
)

def test_wip_move_line_analytic_account_is_project(self):
Expand Down

0 comments on commit 5aefa7c

Please sign in to comment.