|
| 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() |
0 commit comments