Skip to content

Commit

Permalink
fieldservice_recurring: adapt to RFC OCA#735
Browse files Browse the repository at this point in the history
add scheduled_duration to recurring order.

Scheduled_duration, when filled directly on the recurring
order overrides the value from the template
  • Loading branch information
hparfr committed Dec 28, 2021
1 parent 7cd9cd2 commit 158fe81
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 13 deletions.
4 changes: 1 addition & 3 deletions fieldservice_recurring/models/fsm_frequency.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ class FSMFrequency(models.Model):
help="""Checking this box will make this an exclusive rule. Exclusive
rules prevent the configured days from being a schedule option""",
)
company_id = fields.Many2one(
"res.company", "Company", default=lambda self: self.env.user.company_id
)
company_id = fields.Many2one("res.company", "Company")
use_bymonthday = fields.Boolean(
string="Use Day of Month",
help="""When selected you will be able to specify which calendar day
Expand Down
15 changes: 12 additions & 3 deletions fieldservice_recurring/models/fsm_recurring.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,13 @@ def _default_team_id(self):
)
description = fields.Text(string="Description")
fsm_frequency_set_id = fields.Many2one(
"fsm.frequency.set", "Frequency Set", required=True
"fsm.frequency.set",
"Frequency Set",
)
scheduled_duration = fields.Float(
string="Scheduled duration", help="Scheduled duration of the work in hours"
)

start_date = fields.Datetime(string="Start Date")
end_date = fields.Datetime(
string="End Date", help="Recurring orders will not be made after this date"
Expand Down Expand Up @@ -111,6 +116,7 @@ def populate_from_template(self, template=False):
"max_orders": template.max_orders,
"description": template.description,
"fsm_order_template_id": template.fsm_order_template_id,
"scheduled_duration": template.fsm_order_template_id.duration,
"company_id": template.company_id,
}
return vals
Expand Down Expand Up @@ -143,7 +149,7 @@ def action_cancel(self):
def _get_rruleset(self):
self.ensure_one()
ruleset = rruleset()
if self.state != "progress":
if self.state != "progress" or not self.fsm_frequency_set_id:
return ruleset
# set next_date which is used as the rrule 'dtstart' parameter
next_date = self.start_date
Expand Down Expand Up @@ -176,6 +182,9 @@ def _prepare_order_values(self, date=None):
schedule_date = date if date else datetime.now()
days_early = self.fsm_frequency_set_id.buffer_early
earliest_date = schedule_date + relativedelta(days=-days_early)
scheduled_duration = (
self.scheduled_duration or self.fsm_order_template_id.duration
)
return {
"fsm_recurring_id": self.id,
"location_id": self.location_id.id,
Expand All @@ -184,7 +193,7 @@ def _prepare_order_values(self, date=None):
"request_early": str(earliest_date),
"description": self.description,
"template_id": self.fsm_order_template_id.id,
"scheduled_duration": self.fsm_order_template_id.duration,
"scheduled_duration": scheduled_duration,
"category_ids": [(6, False, self.fsm_order_template_id.category_ids.ids)],
"company_id": self.company_id.id,
"person_id": self.person_id.id,
Expand Down
8 changes: 2 additions & 6 deletions fieldservice_recurring/models/fsm_recurring_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ class FSMRecurringTemplate(models.Model):
name = fields.Char(string="Name", required=True)
active = fields.Boolean(default=True)
description = fields.Text(string="Description")
fsm_frequency_set_id = fields.Many2one(
"fsm.frequency.set", "Frequency Set", required=True
)
fsm_frequency_set_id = fields.Many2one("fsm.frequency.set", "Frequency Set")
max_orders = fields.Integer(
string="Maximum Orders", help="Maximium number of orders that will be created"
)
Expand All @@ -23,6 +21,4 @@ class FSMRecurringTemplate(models.Model):
string="Order Template",
help="This is the order template that will be recurring",
)
company_id = fields.Many2one(
"res.company", "Company", default=lambda self: self.env.user.company_id
)
company_id = fields.Many2one("res.company", "Company")
2 changes: 1 addition & 1 deletion fieldservice_recurring/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
* Brian McMaster <brian@mcmpest.com>
* Kitti Upariphutthiphone <kittiu@ecosoft.co.th>
* Rapha??l Reverdy <raphael.reverdy@akretion.com>
* Raphaël Reverdy <raphael.reverdy@akretion.com>
1 change: 1 addition & 0 deletions fieldservice_recurring/views/fsm_recurring.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
groups="fieldservice.group_fsm_template"
/>
<field name="fsm_frequency_set_id" />
<field name="scheduled_duration" />
<field name="start_date" />
<field name="end_date" />
<field name="max_orders" />
Expand Down

0 comments on commit 158fe81

Please sign in to comment.