Skip to content

Commit 1744d6f

Browse files
Merge pull request #70 from hbrunn/14.0-528-klippa-expense-ou
[IMP] #528 ps_klippa: set expense OU from employee's default OU
2 parents 1f05859 + 9207133 commit 1744d6f

File tree

7 files changed

+50
-17
lines changed

7 files changed

+50
-17
lines changed

ps_expense/models/hr_expense.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ def action_move_create(self):
2626

2727
def _create_sheet_from_expenses(self):
2828
"""Allow creating expense sheet from expenses without product"""
29+
self = self.with_context(
30+
default_operating_unit_id=self.mapped("operating_unit_id")[:1].id
31+
)
2932
result = super()._create_sheet_from_expenses()
30-
if not result.operating_unit_id:
31-
result.operating_unit_id = self.mapped("operating_unit_id")[:1]
3233
return result
3334

3435
def action_view_sheet(self):

ps_klippa/models/hr_expense.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class HrExpense(models.Model):
1010
@api.model
1111
def _klippa_update_expenses(self):
1212
user = self.env.ref("ps_klippa.user_klippa")
13+
1314
for this in self.search(
1415
[
1516
("create_uid", "=", user.id),
@@ -18,7 +19,8 @@ def _klippa_update_expenses(self):
1819
("analytic_account_id", "!=", False),
1920
]
2021
):
21-
this.operating_unit_id = this.analytic_account_id.operating_unit_ids.ids[:1]
22+
this.operating_unit_id = this.analytic_account_id.operating_unit_ids[:1]
23+
2224
for row in self.read_group(
2325
[
2426
("create_uid", "=", user.id),
@@ -30,6 +32,15 @@ def _klippa_update_expenses(self):
3032
lazy=False,
3133
):
3234
expenses = self.search(row["__domain"])
35+
expense_user = expenses.employee_id.user_id
36+
ou = expense_user.with_company(
37+
expense_user.company_id
38+
).operating_unit_default_get(expense_user.id)
39+
expenses.write(
40+
{
41+
"operating_unit_id": ou.id,
42+
}
43+
)
3344
sheet = expenses._create_sheet_from_expenses()
3445
sheet.name = expenses[0].name
3546
sheet.action_submit_sheet()

ps_klippa/tests/test_ps_klippa.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ def test_ps_klippa(self):
77
demo_expenses = self.env.ref("ps_klippa.expense_demo1") + self.env.ref(
88
"ps_klippa.expense_demo2"
99
)
10+
demo_ou = self.env.ref("operating_unit.b2c_operating_unit")
11+
self.env.ref("base.user_demo").default_operating_unit_id = demo_ou
1012
demo_expenses_other = self.env.ref("ps_klippa.expense_demo3")
1113
chs_expense = self.env.ref("ps_klippa.expense_chs")
1214
all_expenses = demo_expenses + demo_expenses_other + chs_expense
@@ -20,6 +22,7 @@ def test_ps_klippa(self):
2022
self.assertEqual(len(sheets), 3)
2123
self.assertEqual(demo_expenses[0].name, demo_expenses[1].sheet_id.name)
2224
self.assertEqual(set(sheets.mapped("state")), {"submit"})
25+
self.assertIn(demo_ou, sheets.operating_unit_id)
2326
new_expenses = sum(
2427
(expense.copy() for expense in demo_expenses), self.env["hr.expense"]
2528
)

ps_landing_page/models/hr_employee_landing_page.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ def _compute_all(self):
2323
AND type_id = (SELECT id FROM date_range_type WHERE calender_week = true)
2424
LIMIT 1"""
2525
)
26-
current_week_id = self.env.cr.fetchone()[0]
26+
try:
27+
current_week_id = self.env.cr.fetchone()[0]
28+
except TypeError:
29+
current_week_id = 0
2730

2831
next_week_id = self.get_upcoming_week()
2932
if current_week_id == next_week_id.id or current_week_id < next_week_id.id:

ps_planning/wizards/ps_planning_report_wizard.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ def action_open_report(self):
3131
_get_work_days = ContractedLine._get_work_days_dates
3232
mtd_fraction = _get_work_days(
3333
self.reference_date.replace(day=1), self.reference_date
34-
) / _get_work_days(month.date_start, month.date_end)
34+
) / _get_work_days(
35+
month.date_start or self.reference_date.replace(day=1),
36+
month.date_end or self.reference_date,
37+
)
3538
for project in self.env["project.project"].search(
3639
[("ps_contracted_line_ids", "!=", False)]
3740
):
@@ -75,8 +78,14 @@ def action_open_report(self):
7578
TimeLine.search(
7679
[
7780
("task_id.project_id", "=", project.id),
78-
("date", ">=", month.date_start.replace(month=1, day=1)),
79-
("date", "<", month.date_start),
81+
(
82+
"date",
83+
">=",
84+
(month.date_start or self.reference_date).replace(
85+
month=1, day=1
86+
),
87+
),
88+
("date", "<", month.date_start or self.reference_date),
8089
("product_uom_id", "=", uom_hours.id),
8190
]
8291
).mapped(lambda x: x.unit_amount / 8)
@@ -87,9 +96,15 @@ def action_open_report(self):
8796
(
8897
"range_id.date_start",
8998
">=",
90-
month.date_start.replace(month=1, day=1),
99+
(month.date_start or self.reference_date).replace(
100+
month=1, day=1
101+
),
102+
),
103+
(
104+
"range_id.date_end",
105+
"<",
106+
month.date_start or self.reference_date,
91107
),
92-
("range_id.date_end", "<", month.date_start),
93108
("task_id.project_id", "=", project.id),
94109
("line_type", "=", "contracted"),
95110
]

ps_planning/wizards/ps_planning_wizard.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,8 @@ class PsPlanningWizardLine(models.TransientModel):
234234
y_axis_display = fields.Char()
235235
range_id = fields.Many2one("date.range")
236236
days = fields.Float()
237-
planning_line_id = fields.Many2one("ps.planning.line")
238-
contracted_line_id = fields.Many2one("ps.contracted.line")
237+
planning_line_id = fields.Many2one("ps.planning.line", ondelete="cascade")
238+
contracted_line_id = fields.Many2one("ps.contracted.line", ondelete="cascade")
239239
line_type = fields.Char()
240240
state = fields.Char()
241241
task_id = fields.Many2one("project.task")

ps_timesheet_invoicing/demo/date_range.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
name="create"
77
eval="[{
88
'type_id': ref('ps_date_range_week.date_range_calender_week'),
9-
'date_start': datetime.now().date() + relativedelta(years=-1, month=1, day=1),
10-
'date_end': datetime.now().date() + relativedelta(month=12, day=31),
9+
'date_start': '2023-01-01',
10+
'date_end': '2024-12-31',
1111
'unit_of_time': '2',
1212
'duration_count': 1,
1313
'count': 104,
@@ -21,8 +21,8 @@
2121
name="create"
2222
eval="[{
2323
'type_id': ref('account_fiscal_month.date_range_fiscal_month'),
24-
'date_start': datetime.now().date() + relativedelta(years=-1, month=1, day=1),
25-
'date_end': datetime.now().date() + relativedelta(month=12, day=31),
24+
'date_start': '2023-01-01',
25+
'date_end': '2024-12-31',
2626
'unit_of_time': '1',
2727
'duration_count': 1,
2828
'count': 24,
@@ -36,8 +36,8 @@
3636
name="create"
3737
eval="[{
3838
'type_id': ref('ps_timesheet_invoicing.date_range_quarter'),
39-
'date_start': datetime.now().date() + relativedelta(years=-1, month=1, day=1),
40-
'date_end': datetime.now().date() + relativedelta(month=12, day=31),
39+
'date_start': '2023-01-01',
40+
'date_end': '2024-12-31',
4141
'unit_of_time': '1',
4242
'duration_count': 3,
4343
'count': 8,

0 commit comments

Comments
 (0)