diff --git a/fieldservice_recurring/__manifest__.py b/fieldservice_recurring/__manifest__.py index 8474cc3eb9..3ced537919 100644 --- a/fieldservice_recurring/__manifest__.py +++ b/fieldservice_recurring/__manifest__.py @@ -4,7 +4,7 @@ { "name": "Field Service Recurring Work Orders", "summary": "Manage recurring Field Service orders", - "version": "16.0.1.0.1", + "version": "16.0.2.0.0", "category": "Field Service", "author": "Brian McMaster, " "Open Source Integrators, " diff --git a/fieldservice_recurring/migrations/16.0.2.0.0/pre-migration.py b/fieldservice_recurring/migrations/16.0.2.0.0/pre-migration.py new file mode 100644 index 0000000000..9c3f2510f3 --- /dev/null +++ b/fieldservice_recurring/migrations/16.0.2.0.0/pre-migration.py @@ -0,0 +1,7 @@ +# Copyright (C) 2022 Raphaƫl Reverdy +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + + +def migrate(env, version): + env.execute("UPDATE fsm_recurring SET state = 'close' WHERE state = 'cancel';") + env.execute("UPDATE fsm_recurring SET state = 'progress' WHERE state = 'pending';") diff --git a/fieldservice_recurring/models/fsm_recurring.py b/fieldservice_recurring/models/fsm_recurring.py index 6cb42dc3f6..5d0f7d467a 100644 --- a/fieldservice_recurring/models/fsm_recurring.py +++ b/fieldservice_recurring/models/fsm_recurring.py @@ -31,9 +31,8 @@ def _default_team_id(self): [ ("draft", "Draft"), ("progress", "In Progress"), - ("pending", "To Renew"), + ("suspend", "Suspended"), ("close", "Closed"), - ("cancel", "Cancelled"), ], readonly=True, default="draft", @@ -66,7 +65,7 @@ def _default_team_id(self): help="This is the order template that will be recurring", ) company_id = fields.Many2one( - "res.company", "Company", default=lambda self: self.env.company + "res.company", "Company", default=lambda self: self.env.user.company_id ) fsm_order_ids = fields.One2many( "fsm.order", "fsm_recurring_id", string="Orders", copy=False @@ -135,15 +134,12 @@ def action_start(self): rec.write({"state": "progress"}) rec._generate_orders() - def action_renew(self): - return self.action_start() - - def action_cancel(self): + def action_suspend(self): for order in self.fsm_order_ids.filtered( lambda o: o.stage_id.is_closed is False ): order.action_cancel() - return self.write({"state": "cancel"}) + return self.write({"state": "suspend"}) def _get_rruleset(self): self.ensure_one() @@ -172,7 +168,7 @@ def _get_rruleset(self): thru_date = request_thru_date # use variables to calulate and return the rruleset object ruleset = self.fsm_frequency_set_id._get_rruleset( - dtstart=next_date, until=thru_date, tz=self.location_id.tz + dtstart=next_date, until=thru_date ) return ruleset @@ -238,44 +234,26 @@ def _cron_generate_orders(self): """ return ( self.env["fsm.recurring"] - .search([("state", "in", ("progress", "pending"))]) + .search([("state", "=", "progress")]) ._generate_orders() ) @api.model def _cron_manage_expiration(self): """ - Executed by Cron task to put all 'pending' recurring orders into + Executed by Cron task to put all 'in progress' recurring orders into 'close' stage if it is after their end date or the max orders have - been generated. Next, the 'progress' recurring orders are put in - 'pending' stage by first checking if the end date is within the next - 30 days and then checking if the max number of orders will be created - within the next 30 days + been generated. """ to_close = self.env["fsm.recurring"] - pending_rec = self.env["fsm.recurring"].search([("state", "=", "pending")]) - for rec in pending_rec: + open_rec = self.env["fsm.recurring"].search([("state", "=", "progress")]) + for rec in open_rec: if rec.end_date and rec.end_date <= datetime.today(): to_close += rec continue if rec.max_orders > 0 and rec.fsm_order_count >= rec.max_orders: to_close += rec to_close.write({"state": "close"}) - to_renew = self.env["fsm.recurring"] - expire_date = datetime.today() + relativedelta(days=+30) - open_rec = self.env["fsm.recurring"].search([("state", "=", "progress")]) - for rec in open_rec: - if rec.end_date and rec.end_date <= expire_date: - to_renew += rec - continue - if rec.max_orders > 0: - orders_in_30 = rec.fsm_order_count - orders_in_30 += rec.fsm_frequency_set_id._get_rruleset( - until=expire_date, tz=rec.location_id.tz - ).count() - if orders_in_30 >= rec.max_orders: - to_renew += rec - to_renew.write({"state": "pending"}) @api.model def _cron_scheduled_task(self): diff --git a/fieldservice_recurring/tests/test_fsm_recurring.py b/fieldservice_recurring/tests/test_fsm_recurring.py index 89a8211bca..7432d8be9b 100644 --- a/fieldservice_recurring/tests/test_fsm_recurring.py +++ b/fieldservice_recurring/tests/test_fsm_recurring.py @@ -114,7 +114,6 @@ def test_cron_generate_orders_rule1(self): ) recurring.action_start() test_recurring.action_start() - test_recurring.action_renew() # Run schedule job now, to compute the future work orders recurring._cron_scheduled_task() recurring.onchange_recurring_template_id() @@ -295,4 +294,3 @@ def test_fsm_order(self): fsm_order = self.env["fsm.order"].create(order_vals) self.env["fsm.order"].create(order_vals2) fsm_order.action_view_fsm_recurring() - recurring.action_cancel() diff --git a/fieldservice_recurring/views/fsm_recurring.xml b/fieldservice_recurring/views/fsm_recurring.xml index 77e4928606..3b559ce01d 100644 --- a/fieldservice_recurring/views/fsm_recurring.xml +++ b/fieldservice_recurring/views/fsm_recurring.xml @@ -27,28 +27,19 @@