Skip to content

Commit 2e4c4e9

Browse files
[FIX] hr_timesheet_purchase_order: fix minor bugs
Change field label Add validation for the setting product and add test for him Add groups to the view
1 parent 31a2d21 commit 2e4c4e9

6 files changed

+86
-1
lines changed

hr_timesheet_purchase_order/data/ir_actions_server.xml

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
<field name="name">Create Purchase Order</field>
99
<field name="model_id" ref="model_hr_timesheet_sheet" />
1010
<field name="binding_model_id" ref="model_hr_timesheet_sheet" />
11+
<field
12+
name="groups_id"
13+
eval="[(6, 0, [ref('hr_timesheet.group_timesheet_manager')])]"
14+
/>
1115
<field name="binding_view_types">list</field>
1216
<field name="state">code</field>
1317
<field name="code">

hr_timesheet_purchase_order/models/hr_timesheet_sheet.py

+16
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,22 @@ class HrTimesheetSheet(models.Model):
1313
related="employee_id.allow_generate_purchase_order"
1414
)
1515

16+
def action_timesheet_confirm(self):
17+
"""Confirm valid timesheets
18+
19+
Raises:
20+
UserError: You need to set a timesheet billing product
21+
in settings in order to create a PO
22+
"""
23+
if not self.company_id.timesheet_product_id:
24+
raise UserError(
25+
_(
26+
"You need to set a timesheet billing product"
27+
"in settings in order to create a PO"
28+
)
29+
)
30+
super().action_timesheet_confirm()
31+
1632
def action_create_purchase_order(self):
1733
"""
1834
Create Purchase Order

hr_timesheet_purchase_order/models/res_partner.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
class ResPartner(models.Model):
1212
_inherit = "res.partner"
1313

14-
is_auto_po_generate = fields.Boolean(string="Automatic PO generation")
14+
is_auto_po_generate = fields.Boolean(
15+
string="Automatic PO generation from timesheet sheets"
16+
)
1517
recurrence_id = fields.Many2one("hr.timesheet.recurrence", copy=False)
1618
employee_ids = fields.One2many(
1719
comodel_name="hr.employee",
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
from . import test_create_timesheet_po_recurrence_not_product
12
from . import test_create_timesheet_purchase_order
23
from . import test_create_timesheet_po_recurrence
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Copyright (C) 2024 Cetmix OÜ
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
3+
4+
from datetime import date
5+
6+
from freezegun import freeze_time
7+
8+
from odoo.exceptions import UserError
9+
from odoo.tests.common import Form
10+
11+
from .common_po_recurrence import TestTimesheetPOrecurrenceCommon
12+
13+
14+
class TestTimesheetPORecurrenceNotProduct(TestTimesheetPOrecurrenceCommon):
15+
@classmethod
16+
def setUpClass(cls):
17+
super().setUpClass()
18+
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))
19+
20+
config_obj = cls.env["res.config.settings"]
21+
config = config_obj.create({"timesheet_product_id": False})
22+
config.execute()
23+
24+
def test_recurrence_cron_repeat_until(self):
25+
with freeze_time("2020-01-01"):
26+
form = Form(self.outsourcing_company)
27+
form.is_auto_po_generate = True
28+
form.repeat_interval = 1
29+
form.repeat_unit = "month"
30+
form.repeat_type = "until"
31+
form.repeat_until = date(2020, 2, 20)
32+
form.repeat_on_month = "date"
33+
form.repeat_day = "15"
34+
35+
form.property_supplier_payment_term_id = self.account_payment_term_30days
36+
form.property_payment_method_id = self.account_payment_method_manual_out
37+
form.receipt_reminder_email = True
38+
form.reminder_date_before_receipt = 3
39+
40+
form.save()
41+
42+
sheet_form = Form(self.hr_timesheet_sheet_obj.with_user(self.user_1))
43+
with sheet_form.timesheet_ids.new() as timesheet:
44+
timesheet.name = "test until month"
45+
timesheet.project_id = self.project
46+
timesheet.unit_amount = 1.0
47+
sheet_1 = sheet_form.save()
48+
self.assertFalse(sheet_1.purchase_order_id, msg="Must be equal False")
49+
50+
# cannot create purchase order (sheet not approved)
51+
with self.assertRaises(UserError):
52+
sheet_1.action_create_purchase_order()
53+
54+
with self.assertRaises(
55+
UserError,
56+
msg=(
57+
"You need to set a timesheet billing product"
58+
"in settings in order to create a PO"
59+
),
60+
):
61+
sheet_1.action_timesheet_confirm()

hr_timesheet_purchase_order/views/hr_timesheet_sheet_view.xml

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
('state', '!=', 'done'),
2424
],
2525
}"
26+
groups="hr_timesheet.group_timesheet_manager"
2627
/>
2728
<button
2829
name="action_open_purchase_order"

0 commit comments

Comments
 (0)