Skip to content

Commit

Permalink
[MIG] fieldservice_recurring: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kaynnan committed Jul 10, 2023
1 parent 4929b43 commit a588d98
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 35 deletions.
2 changes: 1 addition & 1 deletion fieldservice_recurring/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
"name": "Field Service Recurring Work Orders",
"summary": "Manage recurring Field Service orders",
"version": "15.0.1.0.0",
"version": "16.0.1.0.0",
"category": "Field Service",
"author": "Brian McMaster, "
"Open Source Integrators, "
Expand Down
29 changes: 15 additions & 14 deletions fieldservice_recurring/models/fsm_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,21 @@ class FSMOrder(models.Model):
"fsm.recurring", "Recurring Order", readonly=True
)

@api.model
def create(self, vals):
if vals.get("fsm_recurring_id", False) and vals.get(
"scheduled_date_start", False
):
days_late = (
self.env["fsm.recurring"]
.browse(vals["fsm_recurring_id"])
.fsm_frequency_set_id.buffer_late
)
vals["request_late"] = vals["scheduled_date_start"] + timedelta(
days=days_late
)
return super().create(vals)
@api.model_create_multi
def create(self, vals_list):
for vals in vals_list:
if vals.get("fsm_recurring_id", False) and vals.get(
"scheduled_date_start", False
):
days_late = (
self.env["fsm.recurring"]
.browse(vals["fsm_recurring_id"])
.fsm_frequency_set_id.buffer_late
)
vals["request_late"] = vals["scheduled_date_start"] + timedelta(
days=days_late
)
return super().create(vals_list)

def action_view_fsm_recurring(self):
action = self.env.ref("fieldservice_recurring.action_fsm_recurring").read()[0]
Expand Down
15 changes: 8 additions & 7 deletions fieldservice_recurring/models/fsm_recurring.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,14 @@ def populate_from_template(self, template=False):
"company_id": template.company_id,
}

@api.model
def create(self, vals):
if vals.get("name", _("New")) == _("New"):
vals["name"] = self.env["ir.sequence"].next_by_code("fsm.recurring") or _(
"New"
)
return super(FSMRecurringOrder, self).create(vals)
@api.model_create_multi
def create(self, vals_list):
for vals in vals_list:
if vals.get("name", _("New")) == _("New"):
vals["name"] = self.env["ir.sequence"].next_by_code(
"fsm.recurring"
) or _("New")
return super(FSMRecurringOrder, self).create(vals_list)

def action_start(self):
for rec in self:
Expand Down
27 changes: 14 additions & 13 deletions fieldservice_recurring/tests/test_fsm_recurring.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,27 @@


class FSMRecurringCase(TransactionCase):
def setUp(self):
super(FSMRecurringCase, self).setUp()
self.Recurring = self.env["fsm.recurring"]
self.Frequency = self.env["fsm.frequency"]
self.FrequencySet = self.env["fsm.frequency.set"]
@classmethod
def setUpClass(cls):
super(FSMRecurringCase, cls).setUpClass()
cls.Recurring = cls.env["fsm.recurring"]
cls.Frequency = cls.env["fsm.frequency"]
cls.FrequencySet = cls.env["fsm.frequency.set"]
# create a Partner to be converted to FSM Location/Person
self.test_loc_partner = self.env["res.partner"].create(
cls.test_loc_partner = cls.env["res.partner"].create(
{"name": "Test Loc Partner", "phone": "ABC", "email": "tlp@email.com"}
)
# create expected FSM Location to compare to converted FSM Location
self.test_location = self.env["fsm.location"].create(
cls.test_location = cls.env["fsm.location"].create(
{
"name": "Test Location",
"phone": "123",
"email": "tp@email.com",
"partner_id": self.test_loc_partner.id,
"owner_id": self.test_loc_partner.id,
"partner_id": cls.test_loc_partner.id,
"owner_id": cls.test_loc_partner.id,
}
)
self.rule = self.Frequency.create(
cls.rule = cls.Frequency.create(
{
"name": "All weekdays",
"interval_type": "monthly",
Expand All @@ -43,14 +44,14 @@ def setUp(self):
"fr": True,
}
)
self.fr_set = self.FrequencySet.create(
cls.fr_set = cls.FrequencySet.create(
{
"name": "31th only",
"schedule_days": 365,
"fsm_frequency_ids": [(6, 0, self.rule.ids)],
"fsm_frequency_ids": [(6, 0, cls.rule.ids)],
}
)
self.fsm_recurring_template = self.env["fsm.recurring.template"].create(
cls.fsm_recurring_template = cls.env["fsm.recurring.template"].create(
{"name": "Test Template"}
)

Expand Down

0 comments on commit a588d98

Please sign in to comment.