size
int64
0
304k
ext
stringclasses
1 value
lang
stringclasses
1 value
branch
stringclasses
1 value
content
stringlengths
0
304k
avg_line_length
float64
0
238
max_line_length
int64
0
304k
2,263
py
PYTHON
15.0
# Copyright (C) 2019 Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import fields, models class FSMLocationBuilderWizard(models.TransientModel): _name = "fsm.location.builder.wizard" _description = "FSM Location Builder Wizard" level_ids = fields.One2many("fsm.location.level", "wizard_id", string="Level ID's") def create_sub_locations(self): levels = len(self.level_ids) - 1 location = self.env["fsm.location"].browse(self.env.context.get("active_id")) def build_location(parent, num): if self.level_ids[num].spacer: spacer = " " + self.level_ids[num].spacer + " " else: spacer = " " for lev_id in range( self.level_ids[num].start_number, self.level_ids[num].end_number + 1 ): vals = self.prepare_fsm_location_values( location, parent, spacer, lev_id, num ) new_location = self.env["fsm.location"].create(vals) if num < levels: build_location(new_location, num + 1) build_location(location, 0) def prepare_fsm_location_values(self, location, parent, spacer, lev_id, num): tags = self.level_ids[num].tag_ids.ids vals = { "name": self.level_ids[num].name + spacer + str(lev_id), "owner_id": location.owner_id.id, "fsm_parent_id": parent.id, "street": location.street, "street2": self.level_ids[num].name + spacer + str(lev_id), "city": location.city, "zip": location.zip, } if hasattr(location, "customer_id"): vals.update({"customer_id": location.customer_id.id}) if tags: vals.update({"category_id": [(6, 0, tags)]}) if location.state_id: vals.update([("state_id", location.state_id.id)]) if location.country_id: vals.update([("country_id", location.country_id.id)]) if location.territory_id: vals.update([("territory_id", location.territory_id.id)]) if location.tz: vals.update([("tz", location.tz)]) return vals
39.701754
2,263
1,122
py
PYTHON
15.0
# Copyright (C) 2019 Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import api, fields, models class FSMLocationLevel(models.TransientModel): _name = "fsm.location.level" _description = "Level in the FSM location tree structure" sequence = fields.Integer() name = fields.Char(required=True) spacer = fields.Char() start_number = fields.Integer() end_number = fields.Integer() total_number = fields.Integer("Total", compute="_compute_total_number") tag_ids = fields.Many2many("res.partner.category", string="Tags", readonly=False) wizard_id = fields.Many2one("fsm.location.builder.wizard") @api.depends("start_number", "end_number") def _compute_total_number(self): for level_id in self: level_id.total_number = 0 if ( level_id.start_number is not None and level_id.end_number is not None and level_id.start_number < level_id.end_number ): level_id.total_number = level_id.end_number - level_id.start_number + 1
40.071429
1,122
1,134
py
PYTHON
15.0
# Copyright (C) 2019 Brian McMaster, Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { "name": "Field Service Recurring Work Orders", "summary": "Manage recurring Field Service orders", "version": "15.0.1.0.0", "category": "Field Service", "author": "Brian McMaster, " "Open Source Integrators, " "Odoo Community Association (OCA)", "website": "https://github.com/OCA/field-service", "depends": ["fieldservice"], "data": [ "data/ir_sequence.xml", "security/res_groups.xml", "security/ir.model.access.csv", "security/recurring_security.xml", "views/fsm_frequency.xml", "views/fsm_frequency_set.xml", "views/fsm_order.xml", "views/fsm_recurring_template.xml", "views/fsm_recurring.xml", "data/recurring_cron.xml", ], "demo": [ "demo/frequency_demo.xml", "demo/frequency_set_demo.xml", "demo/recur_template_demo.xml", ], "license": "AGPL-3", "development_status": "Beta", "maintainers": ["wolfhall", "max3903", "brian10048"], }
33.352941
1,134
10,679
py
PYTHON
15.0
# Copyright 2019 Ecosoft Co., Ltd (http://ecosoft.co.th/) # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html) from datetime import datetime from dateutil.relativedelta import relativedelta from dateutil.rrule import WEEKLY, rrule from odoo import fields from odoo.exceptions import UserError from odoo.tests.common import TransactionCase 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"] # create a Partner to be converted to FSM Location/Person self.test_loc_partner = self.env["res.partner"].create( {"name": "Test Loc Partner", "phone": "ABC", "email": "[email protected]"} ) # create expected FSM Location to compare to converted FSM Location self.test_location = self.env["fsm.location"].create( { "name": "Test Location", "phone": "123", "email": "[email protected]", "partner_id": self.test_loc_partner.id, "owner_id": self.test_loc_partner.id, } ) self.rule = self.Frequency.create( { "name": "All weekdays", "interval_type": "monthly", "use_byweekday": True, "mo": True, "tu": True, "we": True, "th": True, "fr": True, } ) self.fr_set = self.FrequencySet.create( { "name": "31th only", "schedule_days": 365, "fsm_frequency_ids": [(6, 0, self.rule.ids)], } ) self.fsm_recurring_template = self.env["fsm.recurring.template"].create( {"name": "Test Template"} ) def test_cron_generate_orders_rule1(self): """Test recurring order with following rule, - Work order Monday to Friday, exclude odd week Wednesday """ rules = self.Frequency # Frequency Rule for rules += self.Frequency.create( { "name": "All weekdays", "interval_type": "monthly", "use_byweekday": True, "mo": True, "tu": True, "we": True, "th": True, "fr": True, } ) # Exclusive Rule for odd Wednesday for ex in [1, 3, 5]: rules += self.Frequency.create( { "name": "Exclude Wed-%s" % ex, "is_exclusive": True, "interval_type": "monthly", "use_byweekday": True, "we": True, "use_setpos": True, "set_pos": ex, } ) # Frequency Rule Set fr_set = self.FrequencySet.create( { "name": "Monday to Friday, exclude odd Wednesday", "schedule_days": 30, "fsm_frequency_ids": [(6, 0, rules.ids)], } ) # Create Recurring Order link to this rule set recurring = self.Recurring.create( { "fsm_frequency_set_id": fr_set.id, "location_id": self.test_location.id, "start_date": fields.Datetime.today(), } ) test_recurring = self.Recurring.create( { "fsm_frequency_set_id": fr_set.id, "location_id": self.test_location.id, "fsm_recurring_template_id": self.fsm_recurring_template.id, } ) 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() test_recurring.onchange_recurring_template_id() recurring.populate_from_template() test_recurring.populate_from_template() # Test none of the scheduled date (except on recurring start date), # are on weekend or odd wednesday all_dates = recurring.fsm_order_ids.filtered( lambda l: l.scheduled_date_start != recurring.start_date ).mapped("scheduled_date_start") days = {x.weekday() for x in all_dates} mon_to_fri = {0, 1, 2, 3, 4} self.assertTrue(days <= mon_to_fri) wednesdays = [x for x in all_dates if x.weekday() == 2] first_dom = all_dates[0].replace(day=1) odd_wednesdays = list(rrule(WEEKLY, interval=2, dtstart=first_dom, count=3)) self.assertTrue(wednesdays not in odd_wednesdays) def test_cron_generate_orders_rule2(self): """Test recurring order with following rule, - Work Order every 3 weeks """ rules = self.Frequency # Test Rule with self.assertRaises(UserError): self.Frequency.create( { "name": "Every 3 weeks", "interval": 3, "interval_type": "weekly", "use_bymonthday": True, "month_day": 32, } ) with self.assertRaises(UserError): self.Frequency.create( { "name": "Every 3 weeks", "interval": 3, "interval_type": "weekly", "use_setpos": True, "set_pos": 467, } ) # Frequency Rule rules += self.Frequency.create( {"name": "Every 3 weeks", "interval": 3, "interval_type": "weekly"} ) # Frequency Rule Set fr_set = self.FrequencySet.create( { "name": "Every 3 weeks", "schedule_days": 100, "fsm_frequency_ids": [(6, 0, rules.ids)], } ) # Create Recurring Order link to this rule set expire_date = datetime.today() + relativedelta(days=-22) expire_date1 = datetime.today() + relativedelta(days=+22) recurring = self.Recurring.create( { "fsm_frequency_set_id": fr_set.id, "location_id": self.test_location.id, "start_date": fields.Datetime.today(), "end_date": expire_date1, } ) test_recurring = self.Recurring.create( { "fsm_frequency_set_id": fr_set.id, "location_id": self.test_location.id, "start_date": fields.Datetime.today(), "max_orders": 1, } ) test_recurring1 = self.Recurring.create( { "fsm_frequency_set_id": fr_set.id, "location_id": self.test_location.id, "start_date": fields.Datetime.today(), "max_orders": 1, } ) test_recurring1.end_date = expire_date recurring.action_start() test_recurring.action_start() test_recurring1.action_start() # Run schedule job now, to compute the future work orders recurring._cron_scheduled_task() test_recurring._cron_scheduled_task() test_recurring1._cron_scheduled_task() # Test date are 3 weeks apart (21 days) all_dates = recurring.fsm_order_ids.mapped("scheduled_date_start") x = False for d in all_dates: if x: diff_days = (d - x).days self.assertEqual(diff_days, 21) x = d def test_cron_generate_orders_rule3(self): """Test recurring order with following rule, - Work Order every last day of the month only ending by 31th """ rules = self.Frequency test = rules.create( { "name": "31th only", "interval": 1, "interval_type": "monthly", "use_bymonth": True, "month_day": 31, } ) test._get_rrule() # Frequency Rule rules += self.Frequency.create( { "name": "31th only", "interval": 1, "interval_type": "monthly", "use_bymonthday": True, "month_day": 31, } ) # Frequency Rule Set fr_set = self.FrequencySet.create( { "name": "31th only", "schedule_days": 365, "fsm_frequency_ids": [(6, 0, rules.ids)], } ) # Create Recurring Order link to this rule set recurring = self.Recurring.create( { "fsm_frequency_set_id": fr_set.id, "location_id": self.test_location.id, "start_date": fields.Datetime.today(), } ) recurring.action_start() # Run schedule job now, to compute the future work orders recurring._cron_scheduled_task() # Test date are 31st all_dates = recurring.fsm_order_ids.filtered( lambda l: l.scheduled_date_start != recurring.start_date ).mapped("scheduled_date_start") for d in all_dates: self.assertEqual(d.day, 31) def test_fsm_order(self): self.test_location = self.env.ref("fieldservice.test_location") recurring = self.Recurring.create( { "fsm_frequency_set_id": self.fr_set.id, "location_id": self.test_location.id, "start_date": fields.Datetime.today(), } ) order_vals = { "request_early": fields.Datetime.today(), "location_id": self.test_location.id, "scheduled_date_start": fields.Datetime.today().replace( hour=0, minute=0, second=0 ), "fsm_recurring_id": recurring.id, } order_vals2 = { "request_early": fields.Datetime.today(), "location_id": self.test_location.id, "scheduled_date_start": fields.Datetime.today().replace( hour=0, minute=0, second=0 ), } 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()
36.323129
10,679
1,186
py
PYTHON
15.0
# Copyright (C) 2019 Brian McMaster, Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from datetime import timedelta from odoo import api, fields, models class FSMOrder(models.Model): _inherit = "fsm.order" fsm_recurring_id = fields.Many2one( "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) def action_view_fsm_recurring(self): action = self.env.ref("fieldservice_recurring.action_fsm_recurring").read()[0] action["views"] = [ (self.env.ref("fieldservice_recurring.fsm_recurring_form_view").id, "form") ] action["res_id"] = self.fsm_recurring_id.id return action
32.054054
1,186
881
py
PYTHON
15.0
# Copyright (C) 2019 Brian McMaster, Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import fields, models class FSMRecurringTemplate(models.Model): _name = "fsm.recurring.template" _description = "Recurring Field Service Order Template" _inherit = "mail.thread" name = fields.Char(required=True) active = fields.Boolean(default=True) description = fields.Text() 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" ) fsm_order_template_id = fields.Many2one( "fsm.template", string="Order Template", help="This is the order template that will be recurring", ) company_id = fields.Many2one("res.company", "Company")
36.708333
881
5,453
py
PYTHON
15.0
# Copyright (C) 2019 Brian McMaster, Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from dateutil.rrule import ( DAILY, FR, MO, MONTHLY, SA, SU, TH, TU, WE, WEEKLY, YEARLY, rrule, ) from odoo import _, api, fields, models from odoo.exceptions import UserError WEEKDAYS = {"mo": MO, "tu": TU, "we": WE, "th": TH, "fr": FR, "sa": SA, "su": SU} FREQUENCIES = {"yearly": YEARLY, "monthly": MONTHLY, "weekly": WEEKLY, "daily": DAILY} FREQUENCY_SELECT = [ ("yearly", "Yearly"), ("monthly", "Monthly"), ("weekly", "Weekly"), ("daily", "Daily"), ] class FSMFrequency(models.Model): _name = "fsm.frequency" _description = "Frequency Rule for Field Service Orders" _inherit = ["mail.thread"] name = fields.Char(required=True) active = fields.Boolean(default=True) interval = fields.Integer( string="Repeat Every", help="The number of intervals between events", default=1, required=True, tracking=True, ) interval_type = fields.Selection( FREQUENCY_SELECT, required=True, tracking=True, ) is_exclusive = fields.Boolean( string="Exclusive Rule?", 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") use_bymonthday = fields.Boolean( string="Use Day of Month", help="""When selected you will be able to specify which calendar day of the month the event occurs on""", ) month_day = fields.Integer(string="Day of Month", tracking=True) use_byweekday = fields.Boolean( string="Use Days of Week", help="""When selected you will be able to choose which days of the week the scheduler will include (or exclude if Exclusive rule)""", ) mo = fields.Boolean("Monday") tu = fields.Boolean("Tuesday") we = fields.Boolean("Wednesday") th = fields.Boolean("Thursday") fr = fields.Boolean("Friday") sa = fields.Boolean("Saturday") su = fields.Boolean("Sunday") use_bymonth = fields.Boolean(string="Use Months") jan = fields.Boolean("January") feb = fields.Boolean("February") mar = fields.Boolean("March") apr = fields.Boolean("April") may = fields.Boolean() jun = fields.Boolean("June") jul = fields.Boolean("July") aug = fields.Boolean("August") sep = fields.Boolean("September") oct = fields.Boolean("October") nov = fields.Boolean("November") dec = fields.Boolean("December") use_setpos = fields.Boolean(string="Use Position") set_pos = fields.Integer( string="By Position", help="""Specify an occurrence number, positive or negative, corresponding to the nth occurrence of the rule inside the frequency period. For example, -1 if combined with a 'Monthly' frequency, and a weekday of (MO, TU, WE, TH, FR), will result in the last work day of every month.""", ) @api.constrains("set_pos") def _check_set_pos(self): for rec in self: if rec.use_setpos: if not (-366 < rec.set_pos < 366): raise UserError(_("Position must be between -366 and 366")) @api.constrains("month_day") def _check_month_day(self): for rec in self: if rec.use_bymonthday: if not (1 <= rec.month_day <= 31): raise UserError(_("'Day of Month must be between 1 and 31")) def _get_rrule(self, dtstart=None, until=None): self.ensure_one() freq = FREQUENCIES[self.interval_type] return rrule( freq, interval=self.interval, dtstart=dtstart, until=until, byweekday=self._byweekday(), bymonth=self._bymonth(), bymonthday=self._bymonthday(), bysetpos=self._bysetpos(), ) def _byweekday(self): """ Checks day of week booleans and builds the value for rrule parameter @returns: {list} byweekday: list of WEEKDAY values used for rrule """ self.ensure_one() if not self.use_byweekday: return None weekdays = ["mo", "tu", "we", "th", "fr", "sa", "su"] byweekday = [WEEKDAYS[field] for field in weekdays if self[field]] return byweekday def _bymonth(self): """ Checks month booleans and builds the value for rrule parameter @returns: {list} bymonth: list of integers used for rrule """ self.ensure_one() if not self.use_bymonth: return None months = [ "jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec", ] return [months.index(field) + 1 for field in months if self[field]] def _bymonthday(self): self.ensure_one() if not self.use_bymonthday: return None return self.month_day def _bysetpos(self): self.ensure_one() if not self.use_setpos or self.set_pos == 0: return None return self.set_pos
30.80791
5,453
1,566
py
PYTHON
15.0
# Copyright (C) 2019 Brian McMaster, Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from dateutil.rrule import rruleset from odoo import fields, models class FSMFrequencySet(models.Model): _name = "fsm.frequency.set" _description = "Frequency Rule Set for Field Service Orders" _inherit = ["mail.thread"] name = fields.Char(required=True) active = fields.Boolean(default=True) fsm_frequency_ids = fields.Many2many( "fsm.frequency", tracking=True, string="Frequency Rules" ) schedule_days = fields.Integer( string="Days Ahead to Schedule", default="30", help="""The number of days from today that the scheduler will generate orders for this rule""", tracking=True, ) buffer_early = fields.Integer( string="Early Buffer", tracking=True, help="""The allowed number of days before the computed schedule date that an event can be done""", ) buffer_late = fields.Integer( string="Late Buffer", tracking=True, help="""The allowed number of days after the computed schedule date that an event can be done""", ) def _get_rruleset(self, dtstart=None, until=None): self.ensure_one() rset = rruleset() for rule in self.fsm_frequency_ids: if not rule.is_exclusive: rset.rrule(rule._get_rrule(dtstart, until)) else: rset.exrule(rule._get_rrule(dtstart)) return rset
33.319149
1,566
10,262
py
PYTHON
15.0
# Copyright (C) 2019 Brian McMaster, Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from datetime import datetime from dateutil.relativedelta import relativedelta from dateutil.rrule import rruleset from odoo import _, api, fields, models class FSMRecurringOrder(models.Model): _name = "fsm.recurring" _description = "Recurring Field Service Order" _inherit = ["mail.thread", "mail.activity.mixin"] def _default_team_id(self): return self.env.ref("fieldservice.fsm_team_default") name = fields.Char( required=True, index=True, copy=False, default=lambda self: _("New"), ) state = fields.Selection( [ ("draft", "Draft"), ("progress", "In Progress"), ("pending", "To Renew"), ("close", "Closed"), ("cancel", "Cancelled"), ], readonly=True, default="draft", tracking=True, ) fsm_recurring_template_id = fields.Many2one( "fsm.recurring.template", "Recurring Template", readonly=True, states={"draft": [("readonly", False)]}, ) location_id = fields.Many2one( "fsm.location", string="Location", index=True, required=True ) description = fields.Text() fsm_frequency_set_id = fields.Many2one( "fsm.frequency.set", "Frequency Set", ) scheduled_duration = fields.Float(help="Scheduled duration of the work in hours") start_date = fields.Datetime() end_date = fields.Datetime(help="Recurring orders will not be made after this date") max_orders = fields.Integer( string="Maximum Orders", help="Maximium number of orders that will be created" ) fsm_order_template_id = fields.Many2one( "fsm.template", 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 ) fsm_order_ids = fields.One2many( "fsm.order", "fsm_recurring_id", string="Orders", copy=False ) fsm_order_count = fields.Integer("Orders Count", compute="_compute_order_count") team_id = fields.Many2one( "fsm.team", string="Team", default=lambda self: self._default_team_id(), index=True, required=True, tracking=True, ) person_id = fields.Many2one( "fsm.person", string="Assigned To", index=True, tracking=True ) @api.depends("fsm_order_ids") def _compute_order_count(self): data = self.env["fsm.order"].read_group( [ ("fsm_recurring_id", "in", self.ids), ("stage_id", "!=", self.env.ref("fieldservice.fsm_stage_cancelled").id), ], ["fsm_recurring_id"], ["fsm_recurring_id"], ) count_data = { item["fsm_recurring_id"][0]: item["fsm_recurring_id_count"] for item in data } for recurring in self: recurring.fsm_order_count = count_data.get(recurring.id, 0) @api.onchange("fsm_recurring_template_id") def onchange_recurring_template_id(self): if not self.fsm_recurring_template_id: return self.update(self.populate_from_template()) def populate_from_template(self, template=False): if not template: template = self.fsm_recurring_template_id return { "fsm_frequency_set_id": template.fsm_frequency_set_id, "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, } @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) def action_start(self): for rec in self: if not rec.start_date: rec.start_date = datetime.now() rec.write({"state": "progress"}) rec._generate_orders() def action_renew(self): return self.action_start() def action_cancel(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"}) def _get_rruleset(self): self.ensure_one() ruleset = rruleset() 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 last_order = self.env["fsm.order"].search( [ ("fsm_recurring_id", "=", self.id), ("stage_id", "!=", self.env.ref("fieldservice.fsm_stage_cancelled").id), ], offset=0, limit=1, order="scheduled_date_start desc", ) if last_order: next_date = last_order.scheduled_date_start # set thru_date to use as rrule 'until' parameter days_ahead = self.fsm_frequency_set_id.schedule_days request_thru_date = datetime.now() + relativedelta(days=+days_ahead) if self.end_date and (self.end_date < request_thru_date): thru_date = self.end_date else: 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 ) return ruleset def _prepare_order_values(self, date=None): self.ensure_one() 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, "team_id": self.team_id.id, "scheduled_date_start": schedule_date, "request_early": str(earliest_date), "description": self.description, "template_id": self.fsm_order_template_id.id, "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, } def _create_order(self, date): self.ensure_one() vals = self._prepare_order_values(date) order = self.env["fsm.order"].create(vals) order._onchange_template_id() return order def _generate_orders(self): """ create field service orders from self up to the max orders allowed by the recurring order @return {recordset} orders: all the order objects created """ orders = self.env["fsm.order"] for rec in self: order_dates = [] for order in rec.fsm_order_ids: if order.scheduled_date_start: order_dates.append(order.scheduled_date_start.date()) max_orders = rec.max_orders if rec.max_orders > 0 else False order_count = rec.fsm_order_count for date in rec._get_rruleset(): if date.date() in order_dates: continue if max_orders > order_count or not max_orders: orders |= rec._create_order(date=date) order_count += 1 return orders @api.model def _cron_generate_orders(self): """ Executed by Cron task to create field service orders from any recurring orders which are in progress, or to renew, and up to the max orders allowed by the recurring order @return {recordset} orders: all the order objects created """ return ( self.env["fsm.recurring"] .search([("state", "in", ("progress", "pending"))]) ._generate_orders() ) @api.model def _cron_manage_expiration(self): """ Executed by Cron task to put all 'pending' 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 """ to_close = self.env["fsm.recurring"] pending_rec = self.env["fsm.recurring"].search([("state", "=", "pending")]) for rec in pending_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 ).count() if orders_in_30 >= rec.max_orders: to_renew += rec to_renew.write({"state": "pending"}) @api.model def _cron_scheduled_task(self): self._cron_generate_orders() self._cron_manage_expiration()
37.181159
10,262
713
py
PYTHON
15.0
# Copyright (C) 2018 Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { "name": "Field Service - Accounting", "summary": "Track invoices linked to Field Service orders", "version": "15.0.1.0.0", "category": "Field Service", "author": "Open Source Integrators, Odoo Community Association (OCA)", "website": "https://github.com/OCA/field-service", "depends": ["fieldservice", "account"], "data": [ "security/ir.model.access.csv", "views/account_move.xml", "views/fsm_order.xml", ], "license": "AGPL-3", "development_status": "Production/Stable", "maintainers": ["osimallen", "brian10048", "bodedra"], }
35.65
713
7,030
py
PYTHON
15.0
# Copyright 2019 Ecosoft Co., Ltd (http://ecosoft.co.th/) # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html) from datetime import datetime, timedelta from odoo.tests.common import TransactionCase class FSMAccountCase(TransactionCase): def setUp(self): super(FSMAccountCase, self).setUp() self.Wizard = self.env["fsm.wizard"] self.WorkOrder = self.env["fsm.order"] self.AccountInvoice = self.env["account.move"] self.AccountInvoiceLine = self.env["account.move.line"] # create a Res Partner self.test_partner = self.env["res.partner"].create( {"name": "Test Partner", "phone": "123", "email": "[email protected]"} ) # create a Res Partner to be converted to FSM Location/Person self.test_loc_partner = self.env["res.partner"].create( {"name": "Test Loc Partner", "phone": "ABC", "email": "[email protected]"} ) self.test_loc_partner2 = self.env["res.partner"].create( {"name": "Test Loc Partner 2", "phone": "123", "email": "[email protected]"} ) # create expected FSM Location to compare to converted FSM Location self.test_location = self.env["fsm.location"].create( { "name": "Test Location", "phone": "123", "email": "[email protected]", "partner_id": self.test_loc_partner.id, "owner_id": self.test_loc_partner.id, } ) self.test_order = self.env["fsm.order"].create( { "location_id": self.test_location.id, "date_start": datetime.today(), "date_end": datetime.today() + timedelta(hours=2), "request_early": datetime.today(), } ) self.test_order2 = self.env["fsm.order"].create( { "location_id": self.test_location.id, "date_start": datetime.today(), "date_end": datetime.today() + timedelta(hours=2), "request_early": datetime.today(), } ) self.default_account_revenue = self.env["account.account"].search( [ ("company_id", "=", self.env.user.company_id.id), ( "user_type_id", "=", self.env.ref("account.data_account_type_revenue").id, ), ], limit=1, ) self.test_invoice = self.env["account.move"].create( { "partner_id": self.test_partner.id, "move_type": "out_invoice", "invoice_date": datetime.today().date(), "invoice_line_ids": [ ( 0, 0, { "name": "Test", "quantity": 1.00, "price_unit": 100.00, }, ) ], "line_ids": [ ( 0, 0, { "name": "line_debit", "account_id": self.default_account_revenue.id, }, ), ( 0, 0, { "name": "line_credit", "account_id": self.default_account_revenue.id, }, ), ], } ) self.test_invoice2 = self.env["account.move"].create( { "partner_id": self.test_partner.id, "move_type": "out_invoice", "invoice_date": datetime.today().date(), "invoice_line_ids": [ ( 0, 0, { "name": "Test1", "quantity": 1.00, "price_unit": 100.00, }, ) ], "line_ids": [ ( 0, 0, { "name": "line_debit", "account_id": self.default_account_revenue.id, }, ), ( 0, 0, { "name": "line_credit", "account_id": self.default_account_revenue.id, }, ), ], } ) def test_fsm_account(self): # Set invoice lines on Test Order 1 self.test_order.invoice_lines = [(6, 0, self.test_invoice.line_ids.ids)] # Verify invoice is correctly linked to FSM Order self.test_order._compute_get_invoiced() self.assertEqual(self.test_order.invoice_count, 1) self.assertEqual(self.test_invoice.id, self.test_order.invoice_ids.ids[0]) # Verify FSM Order is correctly linked to invoice self.test_invoice._compute_fsm_order_ids() self.assertEqual(self.test_invoice.fsm_order_count, 1) self.assertEqual(self.test_order.id, self.test_invoice.fsm_order_ids.ids[0]) # Verify action result to view one invoice from order action_view_inv = self.test_order.action_view_invoices() self.assertEqual(action_view_inv.get("res_id"), self.test_invoice.id) # Verify action result to view one FSM Order from invoice action_view_order = self.test_invoice.action_view_fsm_orders() self.assertEqual(action_view_order.get("res_id"), self.test_order.id) # Set invoice lines on Test Order 2 self.test_order2.invoice_lines = [(6, 0, self.test_invoice.line_ids.ids)] # Verify 2 FSM Orders are now linked to the invoice self.test_invoice._compute_fsm_order_ids() self.assertEqual(self.test_invoice.fsm_order_count, 2) # Verify action result to view two orders from invoice view_order_action = self.test_invoice.action_view_fsm_orders() self.assertTrue(view_order_action.get("domain")) # Add a second set of invoice lines to Test Order 1 lines = self.test_invoice.line_ids.ids + self.test_invoice2.line_ids.ids self.test_order.invoice_lines = [(6, 0, lines)] # Verify 2 invoices are linked to the FSM Order self.test_order._compute_get_invoiced() self.assertEqual(self.test_order.invoice_count, 2) # Verify action result to view two invoices from order action_view_inv = self.test_order.action_view_invoices() self.assertTrue(action_view_inv.get("domain"))
41.352941
7,030
1,298
py
PYTHON
15.0
# Copyright (C) 2018, Open Source Integrators # Copyright 2019 Akretion <[email protected]> # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import api, fields, models class AccountMove(models.Model): _inherit = "account.move" fsm_order_ids = fields.Many2many( "fsm.order", compute="_compute_fsm_order_ids", string="Field Service orders associated to this invoice", ) fsm_order_count = fields.Integer( string="FSM Orders", compute="_compute_fsm_order_ids" ) @api.depends("line_ids") def _compute_fsm_order_ids(self): for order in self: orders = self.env["fsm.order"].search( [("invoice_lines", "in", order.line_ids.ids)] ) order.fsm_order_ids = orders order.fsm_order_count = len(order.fsm_order_ids) def action_view_fsm_orders(self): action = self.env.ref("fieldservice.action_fsm_dash_order").read()[0] if self.fsm_order_count > 1: action["domain"] = [("id", "in", self.fsm_order_ids.ids)] elif self.fsm_order_ids: action["views"] = [(self.env.ref("fieldservice.fsm_order_form").id, "form")] action["res_id"] = self.fsm_order_ids[0].id return action
36.055556
1,298
1,476
py
PYTHON
15.0
# Copyright (C) 2018 Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import api, fields, models class FSMOrder(models.Model): _inherit = "fsm.order" invoice_lines = fields.Many2many( "account.move.line", "fsm_order_account_move_line_rel", "fsm_order_id", "account_move_line_id", copy=False, ) invoice_ids = fields.Many2many( "account.move", string="Invoices", compute="_compute_get_invoiced", readonly=True, copy=False, ) invoice_count = fields.Integer( compute="_compute_get_invoiced", readonly=True, copy=False, ) @api.depends("invoice_lines") def _compute_get_invoiced(self): for order in self: invoices = order.invoice_lines.mapped("move_id").filtered( lambda r: r.move_type in ("out_invoice", "out_refund") ) order.invoice_ids = invoices order.invoice_count = len(invoices) def action_view_invoices(self): action = self.env.ref("account.action_move_out_invoice_type").read()[0] invoices = self.mapped("invoice_ids") if len(invoices) > 1: action["domain"] = [("id", "in", invoices.ids)] elif invoices: action["views"] = [(self.env.ref("account.view_move_form").id, "form")] action["res_id"] = invoices.ids[0] return action
30.75
1,476
465
py
PYTHON
15.0
# Copyright 2019 Akretion <[email protected]> # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import fields, models class AccountMoveLine(models.Model): _inherit = "account.move.line" fsm_order_ids = fields.Many2many( "fsm.order", "fsm_order_account_move_line_rel", "account_move_line_id", "fsm_order_id", string="FSM Orders", readonly=True, copy=False, )
25.833333
465
675
py
PYTHON
15.0
# Copyright (C) 2021 - Akretion # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { "name": "Field Service - Flow for ISP", "summary": "Field Service workflow for Internet Service Providers", "version": "15.0.1.0.0", "category": "Field Service", "author": "Open Source Integrators, " "Akretion, Odoo Community Association (OCA)", "website": "https://github.com/OCA/field-service", "depends": [ "fieldservice", ], "data": [ "data/fsm_stage.xml", "views/fsm_order.xml", ], "application": False, "license": "AGPL-3", "development_status": "Beta", "maintainers": ["osi-scampbell"], }
30.681818
675
4,462
py
PYTHON
15.0
# Copyright (C) 2021 - TODAY, Open Source Integrators # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html) from datetime import timedelta from odoo import fields from odoo.exceptions import ValidationError from odoo.tests.common import Form, TransactionCase class FSMIspFlowCase(TransactionCase): def setUp(self): super(FSMIspFlowCase, self).setUp() self.WorkOrder = self.env["fsm.order"] self.Worker = self.env["fsm.person"] view_id = "fieldservice.fsm_person_form" with Form(self.Worker, view=view_id) as f: f.name = "Worker A" self.worker = f.save() self.test_partner = self.env["res.partner"].create( {"name": "Test Partner", "phone": "123", "email": "[email protected]"} ) # create a Res Partner to be converted to FSM Location/Person self.test_loc_partner = self.env["res.partner"].create( {"name": "Test Loc Partner", "phone": "ABC", "email": "[email protected]"} ) self.test_location = self.env.ref("fieldservice.test_location") self.init_values = { "stage_id": self.env.ref("fieldservice_isp_flow.fsm_stage_confirmed").id } self.stage1 = self.env.ref("fieldservice_isp_flow.fsm_stage_confirmed") self.stage2 = self.env.ref("fieldservice_isp_flow.fsm_stage_scheduled") self.stage3 = self.env.ref("fieldservice_isp_flow.fsm_stage_assigned") self.stage4 = self.env.ref("fieldservice_isp_flow.fsm_stage_enroute") self.stage5 = self.env.ref("fieldservice_isp_flow.fsm_stage_started") def test_fsm_orders(self): """Test creating new workorders, and test following functions.""" # Create an Orders hours_diff = 100 date_start = fields.Datetime.today() order = self.WorkOrder.create( { "location_id": self.test_location.id, "date_start": date_start, "date_end": date_start + timedelta(hours=hours_diff), "request_early": fields.Datetime.today(), } ) order2 = self.WorkOrder.create( { "location_id": self.test_location.id, "request_early": fields.Datetime.today(), "person_id": self.worker.id, "date_end": date_start + timedelta(hours=hours_diff), "scheduled_date_start": date_start, } ) order3 = self.WorkOrder.create( { "location_id": self.test_location.id, "stage_id": self.stage1.id, } ) order4 = self.WorkOrder.create( { "location_id": self.test_location.id, "stage_id": self.stage2.id, } ) order5 = self.WorkOrder.create( { "location_id": self.test_location.id, "stage_id": self.stage3.id, } ) order6 = self.WorkOrder.create( { "location_id": self.test_location.id, "stage_id": self.stage4.id, } ) order7 = self.WorkOrder.create( { "location_id": self.test_location.id, "stage_id": self.stage5.id, } ) order.action_confirm() order.action_enroute() order.action_start() order2.action_assign() order2.action_schedule() order3._track_subtype(self.init_values) order4._track_subtype(self.init_values) order5._track_subtype(self.init_values) order6._track_subtype(self.init_values) order7._track_subtype(self.init_values) order._track_subtype(self.init_values) order._track_subtype(self.init_values) data_dict = order2.action_schedule() self.assertEqual(data_dict, True) with self.assertRaises(ValidationError): order2.action_complete() with self.assertRaises(ValidationError): order.action_request() with self.assertRaises(ValidationError): order.action_assign() with self.assertRaises(ValidationError): order.action_schedule() with self.assertRaises(ValidationError): order.date_end = False order.action_complete() with self.assertRaises(ValidationError): order2.action_start()
38.465517
4,462
3,774
py
PYTHON
15.0
# Copyright (C) 2021 - TODAY, Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import _, models from odoo.exceptions import ValidationError class FSMOrder(models.Model): _inherit = "fsm.order" def action_confirm(self): return self.write( {"stage_id": self.env.ref("fieldservice_isp_flow.fsm_stage_confirmed").id} ) def action_request(self): if not self.person_ids: raise ValidationError( _("Cannot move to Requested " + "until 'Request Workers' is filled in") ) return self.write( {"stage_id": self.env.ref("fieldservice_isp_flow.fsm_stage_requested").id} ) def action_assign(self): if self.person_id: return self.write( { "stage_id": self.env.ref( "fieldservice_isp_flow.fsm_stage_assigned" ).id } ) raise ValidationError( _("Cannot move to Assigned " + "until 'Assigned To' is filled in") ) def action_schedule(self): if self.scheduled_date_start and self.person_id: return self.write( { "stage_id": self.env.ref( "fieldservice_isp_flow.fsm_stage_scheduled" ).id } ) raise ValidationError( _( "Cannot move to Scheduled " + "until both 'Assigned To' and " + "'Scheduled Start Date' are filled in" ) ) def action_enroute(self): return self.write( {"stage_id": self.env.ref("fieldservice_isp_flow.fsm_stage_enroute").id} ) def action_start(self): if not self.date_start: raise ValidationError( _("Cannot move to Start " + "until 'Actual Start' is filled in") ) return self.write( {"stage_id": self.env.ref("fieldservice_isp_flow.fsm_stage_started").id} ) def action_complete(self): if not self.date_end: raise ValidationError( _("Cannot move to Complete " + "until 'Actual End' is filled in") ) if not self.resolution: raise ValidationError( _("Cannot move to Complete " + "until 'Resolution' is filled in") ) return super(FSMOrder, self).action_complete() def _track_subtype(self, init_values): self.ensure_one() if "stage_id" in init_values: if ( self.stage_id.id == self.env.ref("fieldservice_isp_flow.fsm_stage_confirmed").id ): return self.env.ref("fieldservice.mt_order_confirmed") if ( self.stage_id.id == self.env.ref("fieldservice_isp_flow.fsm_stage_scheduled").id ): return self.env.ref("fieldservice.mt_order_scheduled") if ( self.stage_id.id == self.env.ref("fieldservice_isp_flow.fsm_stage_assigned").id ): return self.env.ref("fieldservice.mt_order_assigned") if ( self.stage_id.id == self.env.ref("fieldservice_isp_flow.fsm_stage_enroute").id ): return self.env.ref("fieldservice.mt_order_enroute") if ( self.stage_id.id == self.env.ref("fieldservice_isp_flow.fsm_stage_started").id ): return self.env.ref("fieldservice.mt_order_started") return super(FSMOrder, self)._track_subtype(init_values)
34.944444
3,774
100
py
PYTHON
15.0
import setuptools setuptools.setup( setup_requires=['setuptools-odoo'], odoo_addon=True, )
16.666667
100
100
py
PYTHON
15.0
import setuptools setuptools.setup( setup_requires=['setuptools-odoo'], odoo_addon=True, )
16.666667
100
2,295
py
PYTHON
15.0
import setuptools with open('VERSION.txt', 'r') as f: version = f.read().strip() setuptools.setup( name="odoo-addons-oca-field-service", description="Meta package for oca-field-service Odoo addons", version=version, install_requires=[ 'odoo-addon-base_territory>=15.0dev,<15.1dev', 'odoo-addon-fieldservice>=15.0dev,<15.1dev', 'odoo-addon-fieldservice_account>=15.0dev,<15.1dev', 'odoo-addon-fieldservice_account_analytic>=15.0dev,<15.1dev', 'odoo-addon-fieldservice_account_payment>=15.0dev,<15.1dev', 'odoo-addon-fieldservice_activity>=15.0dev,<15.1dev', 'odoo-addon-fieldservice_calendar>=15.0dev,<15.1dev', 'odoo-addon-fieldservice_crm>=15.0dev,<15.1dev', 'odoo-addon-fieldservice_delivery>=15.0dev,<15.1dev', 'odoo-addon-fieldservice_distribution>=15.0dev,<15.1dev', 'odoo-addon-fieldservice_equipment_stock>=15.0dev,<15.1dev', 'odoo-addon-fieldservice_isp_account>=15.0dev,<15.1dev', 'odoo-addon-fieldservice_isp_flow>=15.0dev,<15.1dev', 'odoo-addon-fieldservice_location_builder>=15.0dev,<15.1dev', 'odoo-addon-fieldservice_partner_multi_relation>=15.0dev,<15.1dev', 'odoo-addon-fieldservice_project>=15.0dev,<15.1dev', 'odoo-addon-fieldservice_purchase>=15.0dev,<15.1dev', 'odoo-addon-fieldservice_recurring>=15.0dev,<15.1dev', 'odoo-addon-fieldservice_repair>=15.0dev,<15.1dev', 'odoo-addon-fieldservice_route>=15.0dev,<15.1dev', 'odoo-addon-fieldservice_sale>=15.0dev,<15.1dev', 'odoo-addon-fieldservice_sale_recurring>=15.0dev,<15.1dev', 'odoo-addon-fieldservice_sale_stock>=15.0dev,<15.1dev', 'odoo-addon-fieldservice_size>=15.0dev,<15.1dev', 'odoo-addon-fieldservice_skill>=15.0dev,<15.1dev', 'odoo-addon-fieldservice_stage_server_action>=15.0dev,<15.1dev', 'odoo-addon-fieldservice_stage_validation>=15.0dev,<15.1dev', 'odoo-addon-fieldservice_stock>=15.0dev,<15.1dev', 'odoo-addon-fieldservice_substatus>=15.0dev,<15.1dev', 'odoo-addon-fieldservice_vehicle>=15.0dev,<15.1dev', ], classifiers=[ 'Programming Language :: Python', 'Framework :: Odoo', 'Framework :: Odoo :: 15.0', ] )
48.829787
2,295
100
py
PYTHON
15.0
import setuptools setuptools.setup( setup_requires=['setuptools-odoo'], odoo_addon=True, )
16.666667
100
100
py
PYTHON
15.0
import setuptools setuptools.setup( setup_requires=['setuptools-odoo'], odoo_addon=True, )
16.666667
100
100
py
PYTHON
15.0
import setuptools setuptools.setup( setup_requires=['setuptools-odoo'], odoo_addon=True, )
16.666667
100
100
py
PYTHON
15.0
import setuptools setuptools.setup( setup_requires=['setuptools-odoo'], odoo_addon=True, )
16.666667
100
100
py
PYTHON
15.0
import setuptools setuptools.setup( setup_requires=['setuptools-odoo'], odoo_addon=True, )
16.666667
100
100
py
PYTHON
15.0
import setuptools setuptools.setup( setup_requires=['setuptools-odoo'], odoo_addon=True, )
16.666667
100
100
py
PYTHON
15.0
import setuptools setuptools.setup( setup_requires=['setuptools-odoo'], odoo_addon=True, )
16.666667
100
100
py
PYTHON
15.0
import setuptools setuptools.setup( setup_requires=['setuptools-odoo'], odoo_addon=True, )
16.666667
100
100
py
PYTHON
15.0
import setuptools setuptools.setup( setup_requires=['setuptools-odoo'], odoo_addon=True, )
16.666667
100
100
py
PYTHON
15.0
import setuptools setuptools.setup( setup_requires=['setuptools-odoo'], odoo_addon=True, )
16.666667
100
100
py
PYTHON
15.0
import setuptools setuptools.setup( setup_requires=['setuptools-odoo'], odoo_addon=True, )
16.666667
100
100
py
PYTHON
15.0
import setuptools setuptools.setup( setup_requires=['setuptools-odoo'], odoo_addon=True, )
16.666667
100
100
py
PYTHON
15.0
import setuptools setuptools.setup( setup_requires=['setuptools-odoo'], odoo_addon=True, )
16.666667
100
100
py
PYTHON
15.0
import setuptools setuptools.setup( setup_requires=['setuptools-odoo'], odoo_addon=True, )
16.666667
100
100
py
PYTHON
15.0
import setuptools setuptools.setup( setup_requires=['setuptools-odoo'], odoo_addon=True, )
16.666667
100
100
py
PYTHON
15.0
import setuptools setuptools.setup( setup_requires=['setuptools-odoo'], odoo_addon=True, )
16.666667
100
100
py
PYTHON
15.0
import setuptools setuptools.setup( setup_requires=['setuptools-odoo'], odoo_addon=True, )
16.666667
100
100
py
PYTHON
15.0
import setuptools setuptools.setup( setup_requires=['setuptools-odoo'], odoo_addon=True, )
16.666667
100
100
py
PYTHON
15.0
import setuptools setuptools.setup( setup_requires=['setuptools-odoo'], odoo_addon=True, )
16.666667
100
100
py
PYTHON
15.0
import setuptools setuptools.setup( setup_requires=['setuptools-odoo'], odoo_addon=True, )
16.666667
100
100
py
PYTHON
15.0
import setuptools setuptools.setup( setup_requires=['setuptools-odoo'], odoo_addon=True, )
16.666667
100
100
py
PYTHON
15.0
import setuptools setuptools.setup( setup_requires=['setuptools-odoo'], odoo_addon=True, )
16.666667
100
100
py
PYTHON
15.0
import setuptools setuptools.setup( setup_requires=['setuptools-odoo'], odoo_addon=True, )
16.666667
100
100
py
PYTHON
15.0
import setuptools setuptools.setup( setup_requires=['setuptools-odoo'], odoo_addon=True, )
16.666667
100
100
py
PYTHON
15.0
import setuptools setuptools.setup( setup_requires=['setuptools-odoo'], odoo_addon=True, )
16.666667
100
100
py
PYTHON
15.0
import setuptools setuptools.setup( setup_requires=['setuptools-odoo'], odoo_addon=True, )
16.666667
100
100
py
PYTHON
15.0
import setuptools setuptools.setup( setup_requires=['setuptools-odoo'], odoo_addon=True, )
16.666667
100
100
py
PYTHON
15.0
import setuptools setuptools.setup( setup_requires=['setuptools-odoo'], odoo_addon=True, )
16.666667
100
851
py
PYTHON
15.0
# Copyright (C) 2018 - TODAY, Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { "name": "Field Service - Skills", "summary": "Manage your Field Service workers skills", "version": "15.0.1.0.0", "category": "Field Service", "license": "AGPL-3", "author": "Open Source Integrators, Odoo Community Association (OCA)", "website": "https://github.com/OCA/field-service", "depends": ["hr_skills", "fieldservice"], "data": [ "security/ir.model.access.csv", "views/fsm_person.xml", "views/fsm_category.xml", "views/fsm_person_skill.xml", "views/fsm_order.xml", "views/hr_skill.xml", "views/fsm_template.xml", ], "development_status": "Beta", "maintainers": ["osi-scampbell", "max3903"], "installable": True, }
34.04
851
8,638
py
PYTHON
15.0
# Copyright 2020, Brian McMaster <[email protected]> # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html) from odoo.exceptions import ValidationError from odoo.tests.common import TransactionCase class TestFSMSkill(TransactionCase): def setUp(self): super(TestFSMSkill, self).setUp() self.skill = self.env["hr.skill"] self.skill_level = self.env["hr.skill.level"] self.skill_type = self.env["hr.skill.type"] self.fsm_person = self.env["fsm.person"] self.fsm_person_skill = self.env["fsm.person.skill"] self.fsm_order = self.env["fsm.order"] self.fsm_location = self.env["fsm.location"] self.fsm_template = self.env["fsm.template"] self.fsm_category = self.env["fsm.category"] self.skill_type_01 = self.skill_type.create({"name": "Field Service Skills"}) self.skill_type_03 = self.skill_type.create({"name": "Field Service Skills 3"}) # Create some great skills self.skill_01 = self.skill.create( {"name": "Nunchuck Skills", "skill_type_id": self.skill_type_01.id} ) self.skill_02 = self.skill.create( {"name": "Bow Hunting Skills", "skill_type_id": self.skill_type_01.id} ) self.skill_03 = self.skill.create( {"name": "Computer Hacking Skills", "skill_type_id": self.skill_type_01.id} ) self.skill_04 = self.skill.create( {"name": "Sweet Bike Owning Skills", "skill_type_id": self.skill_type_01.id} ) self.skill_05 = self.skill.create( { "name": "Hooking Up with Chicks Skills", "skill_type_id": self.skill_type_01.id, } ) self.skill_06 = self.skill.create( {"name": "Moustache Growing Skills", "skill_type_id": self.skill_type_01.id} ) self.skill_07 = self.skill.create( {"name": "Growing Skills", "skill_type_id": self.skill_type_01.id} ) self.skill_08 = self.skill.create( {"name": "Computer Growing Skills", "skill_type_id": self.skill_type_01.id} ) self.skill_level_100 = self.skill_level.create( { "name": "Great", "skill_type_id": self.skill_type_01.id, "level_progress": 100, } ) self.skill_level_101 = self.skill_level.create( { "name": "Great", "skill_type_id": self.skill_type_01.id, "level_progress": 100, } ) # Create some great workers with their own great skills # Our first worker, Napoleon, has nunchuck skills and bow hunting # skills, which he learned while in Alaska hunting wolverines with his # uncle. self.person_01 = self.fsm_person.create({"name": "Napoleon"}) self.person_01_skill_01 = self.fsm_person_skill.create( { "person_id": self.person_01.id, "skill_id": self.skill_01.id, "skill_level_id": self.skill_level_100.id, "skill_type_id": self.skill_type_01.id, } ) self.person_01_skill_02 = self.fsm_person_skill.create( { "person_id": self.person_01.id, "skill_id": self.skill_02.id, "skill_level_id": self.skill_level_100.id, "skill_type_id": self.skill_type_01.id, } ) # Our second worker, Pedro, has a lot of really good skills which he # learned from his cousins that have all the sweet hookups self.person_02 = self.fsm_person.create({"name": "Pedro"}) self.person_02_skill_04 = self.fsm_person_skill.create( { "person_id": self.person_02.id, "skill_id": self.skill_04.id, "skill_level_id": self.skill_level_100.id, "skill_type_id": self.skill_type_01.id, } ) self.person_02_skill_05 = self.fsm_person_skill.create( { "person_id": self.person_02.id, "skill_id": self.skill_05.id, "skill_level_id": self.skill_level_100.id, "skill_type_id": self.skill_type_01.id, } ) self.person_02_skill_06 = self.fsm_person_skill.create( { "person_id": self.person_02.id, "skill_id": self.skill_06.id, "skill_level_id": self.skill_level_100.id, "skill_type_id": self.skill_type_01.id, } ) # Create a location for an order self.location_01 = self.fsm_location.create( { "name": "Summer's House", "owner_id": self.env["res.partner"] .create({"name": "Summer's Parents"}) .id, } ) # Create a category that requires great skills self.category_01_skills = [self.skill_04.id, self.skill_05.id, self.skill_06.id] self.category_01 = self.fsm_category.create( {"name": "Sales", "skill_ids": [(6, 0, self.category_01_skills)]} ) self.category_02_skills = [self.skill_05.id, self.skill_06.id, self.skill_07.id] self.category_02 = self.fsm_category.create( {"name": "Sales1", "skill_ids": [(6, 0, self.category_02_skills)]} ) self.skill_type_02 = self.skill_type.create( { "name": "Field Service Skills 2", "skill_ids": [(6, 0, self.category_02_skills)], } ) # Create a template that requires great skills self.template_01_skills = [self.skill_01.id, self.skill_02.id] self.template_01 = self.fsm_template.create( {"name": "Template Name", "skill_ids": [(6, 0, self.template_01_skills)]} ) # Create an order that requires no skills self.order_no_skills = self.fsm_order.create( {"location_id": self.location_01.id} ) # Create an order with a category self.order_category_skills = self.fsm_order.create( { "location_id": self.location_01.id, "category_ids": [(6, 0, [self.category_01.id])], } ) # Create an order with a template self.order_template_skills = self.fsm_order.create( {"location_id": self.location_01.id, "template_id": self.template_01.id} ) def test_fsm_skills(self): # Validate the order without skills can be done by all workers self.assertEqual( self.order_no_skills.skill_worker_ids.ids, self.fsm_person.search([]).ids, "FSM Order without skills should allow all workers", ) # Trigger the category onchange and validate skill_ids get set self.order_category_skills._onchange_category_ids() self.assertEqual( self.order_category_skills.skill_ids.ids, self.category_01_skills, "The order should have skills based on the category", ) # Trigger the template onchange and validate skill_ids get set self.order_template_skills._onchange_template_id() self.assertEqual( self.order_template_skills.skill_ids.ids, self.template_01_skills, "The order should have skills based on the template", ) # Validate the skilled order can be done by Pedro who has the skills self.assertEqual( self.order_category_skills.skill_worker_ids, self.person_02, "FSM Order should only allow workers with all skills required", ) def test_constrains_skill_01(self): with self.assertRaises(ValidationError): self.fsm_person_skill.create( { "person_id": self.person_01.id, "skill_id": self.skill_07.id, "skill_level_id": self.skill_level_100.id, "skill_type_id": self.skill_type_01.id, } ) def test_constrains_skill_level_100(self): with self.assertRaises(ValidationError): self.fsm_person_skill.create( { "person_id": self.person_01.id, "skill_id": self.skill_08.id, "skill_level_id": self.skill_level_101.id, "skill_type_id": self.skill_type_03.id, } )
39.085973
8,638
287
py
PYTHON
15.0
# Copyright (C) 2018, Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import fields, models class FSMPerson(models.Model): _inherit = "fsm.person" skill_ids = fields.One2many("fsm.person.skill", "person_id", string="Skills")
28.7
287
280
py
PYTHON
15.0
# Copyright (C) 2018, Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import fields, models class FSMTemplate(models.Model): _inherit = "fsm.template" skill_ids = fields.Many2many("hr.skill", string="Required Skills")
28
280
2,038
py
PYTHON
15.0
# Copyright (C) 2018, Open Source Integrators # Copyright (C) 2020, Brian McMaster # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import _, api, fields, models from odoo.exceptions import ValidationError class FSMPersonSkill(models.Model): _name = "fsm.person.skill" _rec_name = "skill_id" _description = "Field Service Worker Skill" person_id = fields.Many2one( "fsm.person", string="Field Service Worker", required=True ) skill_id = fields.Many2one("hr.skill", string="Skill", required=True) skill_level_id = fields.Many2one("hr.skill.level", required=True) skill_type_id = fields.Many2one("hr.skill.type", required=True) level_progress = fields.Integer(related="skill_level_id.level_progress", store=True) _sql_constraints = [ ( "person_skill_uniq", "unique(person_id, skill_id)", "This person already has that skill!", ), ] @api.constrains("skill_id", "skill_type_id") def _check_skill_type(self): for record in self: if record.skill_id not in record.skill_type_id.skill_ids: raise ValidationError( _( "The skill '%(skill)s' \ and skill type '%(skilltype)s' doesn't match", skill=record.skill_id.name, skilltype=record.skill_type_id.name, ) ) @api.constrains("skill_type_id", "skill_level_id") def _check_skill_level(self): for record in self: if record.skill_level_id not in record.skill_type_id.skill_level_ids: raise ValidationError( _( "The skill level '%(skilllevel)s' \ is not valid for skill type: '%(skilltype)s' ", skilllevel=record.skill_level_id.name, skilltype=record.skill_type_id.name, ) )
37.740741
2,038
1,897
py
PYTHON
15.0
# Copyright (C) 2018, Open Source Integrators # Copyright (C) 2020, Brian McMaster # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). import logging from odoo import api, fields, models _logger = logging.getLogger(__name__) class FSMOrder(models.Model): _inherit = "fsm.order" skill_ids = fields.Many2many("hr.skill", string="Required Skills") skill_worker_ids = fields.Many2many( "fsm.person", "fsm_order_skill_workers_rel", compute="_compute_skill_workers", help="Available workers based on skill requirements", ) @api.onchange("category_ids") def _onchange_category_ids(self): if not self.template_id: skill_ids = [] for category in self.category_ids: skill_ids.extend([skill.id for skill in category.skill_ids]) self.skill_ids = [(6, 0, skill_ids)] @api.onchange("template_id") def _onchange_template_id(self): res = False if self.template_id: res = super(FSMOrder, self)._onchange_template_id() self.skill_ids = self.template_id.skill_ids return res @api.depends("skill_ids") def _compute_skill_workers(self): worker_ids = [] req_skills = self.skill_ids.ids if not self.skill_ids: worker_ids = self.env["fsm.person"].search([]).ids else: FPS = self.env["fsm.person.skill"] potential_workers = FPS.search( [("skill_id", "in", self.skill_ids.ids)] ).mapped("person_id") for w in potential_workers: worker_skills = FPS.search([("person_id", "=", w.id)]).mapped( "skill_id" ) if set(worker_skills.ids) >= set(req_skills): worker_ids.append(w.id) self.skill_worker_ids = [(6, 0, worker_ids)]
34.490909
1,897
280
py
PYTHON
15.0
# Copyright (C) 2018, Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import fields, models class FSMCategory(models.Model): _inherit = "fsm.category" skill_ids = fields.Many2many("hr.skill", string="Required Skills")
28
280
276
py
PYTHON
15.0
# Copyright (C) 2020, Brian McMaster # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import fields, models class HRSkill(models.Model): _inherit = "hr.skill" color = fields.Integer( string="Color Index", default=10, )
21.230769
276
895
py
PYTHON
15.0
# Copyright (C) 2020, Brian McMaster # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { "name": "Field Service - Stock Equipment", "summary": "Integrate stock operations with your field service equipments", "version": "15.0.1.0.0", "category": "Field Service", "author": "Open Source Integrators, " "Brian McMaster, " "Odoo Community Association (OCA)", "website": "https://github.com/OCA/field-service", "depends": [ "fieldservice_stock", ], "data": [ "security/ir.model.access.csv", "views/fsm_equipment.xml", "views/product_template.xml", "views/stock_picking_type.xml", "views/stock_production_lot.xml", ], "license": "AGPL-3", "development_status": "Beta", "maintainers": [ "brian10048", "wolfhall", "max3903", "smangukiya", ], }
28.870968
895
1,837
py
PYTHON
15.0
# Copyright (C) 2021 Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo.tests.common import TransactionCase class TestStockMove(TransactionCase): def setUp(self): super(TestStockMove, self).setUp() self.Move = self.env["stock.move"] self.stock_location = self.env.ref("stock.stock_location_customers") self.supplier_location = self.env.ref("stock.stock_location_suppliers") self.stock_location = self.env.ref("stock.stock_location_stock") self.uom_unit = self.env.ref("uom.product_uom_unit") def test_action_done(self): # Create product template templateAB = self.env["product.template"].create( {"name": "templAB", "uom_id": self.uom_unit.id} ) # Create product A and B productA = self.env["product.product"].create( { "name": "product A", "standard_price": 1, "type": "product", "uom_id": self.uom_unit.id, "default_code": "A", "product_tmpl_id": templateAB.id, } ) # Create a stock move from INCOMING to STOCK stockMoveInA = self.env["stock.move"].create( { "location_id": self.supplier_location.id, "location_dest_id": self.stock_location.id, "name": "MOVE INCOMING -> STOCK ", "product_id": productA.id, "product_uom": productA.uom_id.id, "product_uom_qty": 2, } ) stockMoveInA.quantity_done = stockMoveInA.product_uom_qty stockMoveInA._action_confirm() stockMoveInA._action_assign() stockMoveInA._action_done() self.assertEqual("done", stockMoveInA.state)
36.019608
1,837
2,918
py
PYTHON
15.0
# Copyright (C) 2020 - TODAY, Marcel Savegnago (Escodoo) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo.tests.common import Form, TransactionCase class TestFSMEquipment(TransactionCase): def setUp(self): super(TestFSMEquipment, self).setUp() self.Equipment = self.env["fsm.equipment"] self.stock_location = self.env.ref("stock.stock_location_customers") self.current_location = self.env.ref("fieldservice.location_1") self.test_location = self.env.ref("fieldservice.test_location") currency = self.env["res.currency"].create( { "name": "Currency 1", "symbol": "$", } ) partner = self.env["res.partner"].create( { "name": "Partner 1", } ) self.company1 = self.env["res.company"].create( { "name": "Company 1", "currency_id": currency.id, "partner_id": partner.id, } ) self.product1 = self.env["product.product"].create( { "name": "Product A", "type": "product", "tracking": "serial", } ) self.lot1 = self.env["stock.production.lot"].create( { "name": "serial1", "product_id": self.product1.id, "company_id": self.company1.id, } ) self.env["stock.quant"].create( { "product_id": self.product1.id, "location_id": self.stock_location.id, "quantity": 1.0, "lot_id": self.lot1.id, } ) self.equipment = self.Equipment.create( { "name": "Equipment 1", "product_id": self.product1.id, "lot_id": self.lot1.id, "current_stock_location_id": self.stock_location.id, } ) def test_onchange_product(self): equipment = self.equipment equipment._onchange_product() self.assertFalse(equipment.current_stock_location_id) def test_compute_current_stock_loc_id(self): equipment = self.equipment equipment._compute_current_stock_loc_id() self.assertTrue(equipment.current_stock_location_id == self.stock_location) def test_fsm_equipment(self): # Create an equipment view_id = "fieldservice.fsm_equipment_form_view" with Form(self.Equipment, view=view_id) as f: f.name = "Test Equipment 1" f.current_location_id = self.current_location f.location_id = self.test_location f.lot_id = self.lot1 f.product_id = self.product1 equipment = f.save() self.assertEqual(f.id, equipment.lot_id.fsm_equipment_id.id)
34.329412
2,918
301
py
PYTHON
15.0
# Copyright (C) 2018 - TODAY, Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import fields, models class ProductTemplate(models.Model): _inherit = "product.template" create_fsm_equipment = fields.Boolean(string="Creates a FSM Equipment")
30.1
301
446
py
PYTHON
15.0
# Copyright (C) 2020 Open Source Integrators, Daniel Reis # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import fields, models class StockPickingType(models.Model): _inherit = "stock.picking.type" create_fsm_equipment = fields.Boolean( name="Create FSM Equipment", help="Products with the 'Creates a FSM Equipment' flag " "will automatically be converted to an FSM Equipment.", )
34.307692
446
1,313
py
PYTHON
15.0
# Copyright (C) 2018 Brian McMaster # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import models class StockMove(models.Model): _inherit = "stock.move" def prepare_equipment_values(self, move_line): move = move_line.move_id return { "name": "%s (%s)" % (move_line.product_id.name, move_line.lot_id.name), "product_id": move_line.product_id.id, "lot_id": move_line.lot_id.id, "location_id": move.stock_request_ids.fsm_order_id.location_id.id, "current_location_id": move.stock_request_ids.fsm_order_id.location_id.id, "current_stock_location_id": move_line.location_dest_id.id, } def _action_done(self, cancel_backorder=False): res = super()._action_done(cancel_backorder) fsm_equipment_obj = self.env["fsm.equipment"] for rec in self: if ( rec.state == "done" and rec.picking_type_id.create_fsm_equipment and rec.product_tmpl_id.create_fsm_equipment ): for line in rec.move_line_ids: line.lot_id.fsm_equipment_id = fsm_equipment_obj.create( self.prepare_equipment_values(line) ) return res
39.787879
1,313
337
py
PYTHON
15.0
# Copyright (C) 2018 - TODAY, Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import fields, models class StockProductionLot(models.Model): _inherit = "stock.production.lot" fsm_equipment_id = fields.Many2one( "fsm.equipment", string="Equipment", readonly=True )
28.083333
337
1,550
py
PYTHON
15.0
# Copyright (C) 2018 - TODAY, Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import api, fields, models class FSMEquipment(models.Model): _inherit = "fsm.equipment" product_id = fields.Many2one("product.product", string="Product", required=True) lot_id = fields.Many2one("stock.production.lot", string="Serial #", required=True) current_stock_location_id = fields.Many2one( "stock.location", string="Current Inventory Location", compute="_compute_current_stock_loc_id", ) @api.depends("product_id", "lot_id") def _compute_current_stock_loc_id(self): stock_quant_obj = self.env["stock.quant"] for equipment in self: quants = stock_quant_obj.search( [("lot_id", "=", equipment.lot_id.id)], order="id desc", limit=1 ) equipment.current_stock_location_id = ( quants.location_id and quants.location_id.id or False ) @api.onchange("product_id") def _onchange_product(self): self.current_stock_location_id = False @api.model def create(self, vals): res = super(FSMEquipment, self).create(vals) if "lot_id" in vals: res.lot_id.fsm_equipment_id = res.id return res def write(self, vals): res = super(FSMEquipment, self).write(vals) for equipment in self: if "lot_id" in vals: equipment.lot_id.fsm_equipment_id = equipment.id return res
34.444444
1,550
748
py
PYTHON
15.0
# Copyright (C) 2019 Open Source Integrators # Copyright (C) 2019 Serpent Consulting Services # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { "name": "Field Service - Accounting Payment", "summary": "Allow workers to collect payments from the order.", "version": "15.0.1.0.0", "category": "Field Service", "author": "Open Source Integrators, Odoo Community Association (OCA)", "website": "https://github.com/OCA/field-service", "depends": [ "fieldservice_account", ], "data": [ "security/ir.model.access.csv", "views/fsm_order.xml", "views/account_payment.xml", ], "license": "AGPL-3", "development_status": "Beta", "maintainers": ["max3903"], }
34
748
5,714
py
PYTHON
15.0
# Copyright (C) 2019 Open Source Integrators # Copyright (C) 2019 Serpent consulting Services # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html) from datetime import datetime, timedelta from odoo.tests.common import TransactionCase class FSMAccountPaymentCase(TransactionCase): def setUp(self): super(FSMAccountPaymentCase, self).setUp() self.register_payments_model = self.env[ "account.payment.register" ].with_context(active_model="account.move") self.company = self.env.user.company_id self.default_journal_bank = self.env["account.journal"].search( [("company_id", "=", self.company.id), ("type", "=", "bank")], limit=1 ) self.inbound_payment_method_line = ( self.default_journal_bank.inbound_payment_method_line_ids[0] ) self.payment_model = self.env["account.payment"] self.test_analytic = self.env.ref("analytic.analytic_administratif") # create a Res Partner self.test_partner = self.env["res.partner"].create( {"name": "Test Partner", "phone": "123", "email": "[email protected]"} ) # create a Res Partner to be converted to FSM Location/Person self.test_loc_partner = self.env["res.partner"].create( {"name": "Test Loc Partner", "phone": "ABC", "email": "[email protected]"} ) self.test_loc_partner2 = self.env["res.partner"].create( {"name": "Test Loc Partner 2", "phone": "123", "email": "[email protected]"} ) # create expected FSM Location to compare to converted FSM Location self.test_location = self.env["fsm.location"].create( { "name": "Test Location", "phone": "123", "email": "[email protected]", "partner_id": self.test_loc_partner.id, "owner_id": self.test_loc_partner.id, "customer_id": self.test_partner.id, } ) self.account_income = self.env["account.account"].create( { "code": "X1112", "name": "Sale - Test Account", "user_type_id": self.env.ref( "account.data_account_type_direct_costs" ).id, } ) # Create a FSM order self.test_order = self.env["fsm.order"].create( { "location_id": self.test_location.id, "date_start": datetime.today(), "date_end": datetime.today() + timedelta(hours=2), "request_early": datetime.today(), } ) self.test_order2 = self.env["fsm.order"].create( { "location_id": self.test_location.id, "date_start": datetime.today(), "date_end": datetime.today() + timedelta(hours=2), "request_early": datetime.today(), } ) # Create an invoice self.test_invoice = self.env["account.move"].create( { "partner_id": self.test_partner.id, "move_type": "out_invoice", "invoice_date": datetime.today().date(), "invoice_line_ids": [ ( 0, 0, { "name": "Test", "quantity": 1.00, "price_unit": 100.00, }, ) ], "fsm_order_ids": [(6, 0, [self.test_order.id])], } ) # Create a payment method self.bank_journal = self.env["account.journal"].create( {"name": "Bank", "type": "bank", "code": "BNK99"} ) self.test_invoice.action_post() def test_fsm_account_payment(self): ctx = { "active_model": "account.move", "active_id": self.test_invoice.id, "active_ids": self.test_invoice.ids, } register_payments = self.register_payments_model.with_context(**ctx).create( { "payment_date": datetime.today(), "journal_id": self.bank_journal.id, "payment_method_line_id": self.inbound_payment_method_line.id, } ) order = self.test_order register_payment_action = register_payments.action_create_payments() payment = self.payment_model.browse(register_payment_action.get("res_id")) test_order = self.test_order.id payment.fsm_order_ids = [(6, 0, [test_order])] self.test_invoice.fsm_order_ids = [(6, 0, [test_order])] order.payment_ids = [(6, 0, [payment.id])] self.test_order._compute_account_payment_count() payment._compute_fsm_order_ids() payment.action_view_fsm_orders() order.action_view_payments() self.assertAlmostEqual(payment.amount, 100) self.assertEqual(payment.state, "posted") self.assertEqual(self.test_invoice.state, "posted") self.assertEqual(self.test_invoice.fsm_order_ids, payment.fsm_order_ids) res = self.env["fsm.order"].search([("payment_ids", "in", payment.id)]) self.assertEqual(len(res), 1) payment.fsm_order_ids = [(6, 0, [test_order, self.test_order2.id])] payment.action_view_fsm_orders() register_payment_action2 = register_payments.action_create_payments() payment2 = self.payment_model.browse(register_payment_action2.get("res_id")) order.payment_ids = [(6, 0, [payment.id, payment2.id])] order.action_view_payments()
42.641791
5,714
1,150
py
PYTHON
15.0
# Copyright (C) 2019 Open Source Integrators # Copyright (C) 2019 Serpent Consulting Services # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import api, fields, models class FSMOrder(models.Model): _inherit = "fsm.order" payment_ids = fields.Many2many( "account.payment", "fsm_order_account_payment", "fsm_order_id", "payment_id", string="Payments", ) payment_count = fields.Integer( compute="_compute_account_payment_count", readonly=True ) @api.depends("payment_ids") def _compute_account_payment_count(self): for order in self: order.payment_count = len(order.payment_ids) def action_view_payments(self): action = self.env.ref("account.action_account_payments").read()[0] if self.payment_count > 1: action["domain"] = [("id", "in", self.payment_ids.ids)] elif self.payment_ids: action["views"] = [ (self.env.ref("account.view_account_payment_form").id, "form") ] action["res_id"] = self.payment_ids[0].id return action
32.857143
1,150
1,635
py
PYTHON
15.0
# Copyright (C) 2019 Open Source Integrators # Copyright (C) 2019 Serpent Consulting Services # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import api, fields, models class AccountPayment(models.Model): _inherit = "account.payment" fsm_order_ids = fields.Many2many( "fsm.order", "fsm_order_account_payment", "payment_id", "fsm_order_id", string="FSM Orders", compute="_compute_fsm_order_ids", store=True, index=True, copy=False, ) fsm_order_count = fields.Integer( string="FSM Order Count", compute="_compute_fsm_order_count", readonly=True ) @api.depends("fsm_order_ids") def _compute_fsm_order_count(self): for payment in self: payment.fsm_order_count = ( len(payment.fsm_order_ids) if payment.fsm_order_ids else 0 ) def action_view_fsm_orders(self): action = self.env.ref("fieldservice.action_fsm_operation_order").read()[0] if self.fsm_order_count > 1: action["domain"] = [("id", "in", self.fsm_order_ids)] elif self.fsm_order_ids: action["views"] = [(self.env.ref("fieldservice.fsm_order_form").id, "form")] action["res_id"] = self.fsm_order_ids[0].id return action def _compute_fsm_order_ids(self): fsm_order_ids = [] for invoice in self.reconciled_invoice_ids: if invoice.fsm_order_ids: fsm_order_ids.extend(invoice.fsm_order_ids.ids) if fsm_order_ids: self.fsm_order_ids = [(6, 0, fsm_order_ids)]
34.787234
1,635
935
py
PYTHON
15.0
# Copyright (C) 2019 Open Source Integrators # Copyright (C) 2019 Serpent consulting Services # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). { "name": "Field Service Route", "summary": "Organize the routes of each day.", "version": "15.0.1.0.0", "category": "Field Service", "license": "AGPL-3", "author": "Open Source Integrators, Odoo Community Association (OCA)", "website": "https://github.com/OCA/field-service", "depends": ["fieldservice"], "data": [ "data/ir_sequence.xml", "data/fsm_route_day_data.xml", "data/fsm_stage_data.xml", "security/ir.model.access.csv", "views/fsm_route_day.xml", "views/fsm_route.xml", "views/fsm_location.xml", "views/fsm_route_dayroute.xml", "views/fsm_order.xml", "views/menu.xml", ], "development_status": "Beta", "maintainers": ["max3903"], }
33.392857
935
2,164
py
PYTHON
15.0
# Copyright (C) 2019 Open Source Integrators # Copyright (C) 2019 Serpent consulting Services # Copyright 2022 Tecnativa - Víctor Martínez # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). from datetime import datetime from odoo.tests import Form, common class FSMOrderRouteCase(common.TransactionCase): def setUp(self): super().setUp() self.fsm_stage_obj = self.env["fsm.stage"] self.fsm_order_obj = self.env["fsm.order"] self.fsm_route_obj = self.env["fsm.route"] self.test_person = self.env.ref("fieldservice.test_person") self.test_location = self.env.ref("fieldservice.test_location") date = datetime.now() self.date = date.replace(microsecond=0) self.days = [ self.env.ref("fieldservice_route.fsm_route_day_0").id, self.env.ref("fieldservice_route.fsm_route_day_1").id, self.env.ref("fieldservice_route.fsm_route_day_2").id, self.env.ref("fieldservice_route.fsm_route_day_3").id, self.env.ref("fieldservice_route.fsm_route_day_4").id, self.env.ref("fieldservice_route.fsm_route_day_5").id, self.env.ref("fieldservice_route.fsm_route_day_6").id, ] self.fsm_route_id = self.fsm_route_obj.create( { "name": "Demo Route", "max_order": 10, "fsm_person_id": self.test_person.id, "day_ids": [(6, 0, self.days)], } ) self.test_location.fsm_route_id = self.fsm_route_id.id def test_create_day_route(self): order_form = Form(self.fsm_order_obj) order_form.location_id = self.test_location order_form.scheduled_date_start = self.date order = order_form.save() self.assertEqual(order.person_id, self.test_person) self.assertEqual(order.fsm_route_id, self.test_location.fsm_route_id) self.assertEqual(order.dayroute_id.person_id, order.person_id) self.assertEqual(order.dayroute_id.date, order.scheduled_date_start.date()) self.assertEqual(order.dayroute_id.route_id, order.fsm_route_id)
44.122449
2,162
340
py
PYTHON
15.0
# Copyright (C) 2019 Open Source Integrators # Copyright (C) 2019 Serpent consulting Services # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). from odoo import fields, models class FSMLocation(models.Model): _inherit = "fsm.location" fsm_route_id = fields.Many2one(comodel_name="fsm.route", string="Route")
30.909091
340
612
py
PYTHON
15.0
# Copyright (C) 2019 Open Source Integrators # Copyright (C) 2019 Serpent consulting Services # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). from odoo import fields, models class FSMRouteDay(models.Model): _name = "fsm.route.day" _description = "Route Day" name = fields.Selection( selection=[ ("Monday", "Monday"), ("Tuesday", "Tuesday"), ("Wednesday", "Wednesday"), ("Thursday", "Thursday"), ("Friday", "Friday"), ("Saturday", "Saturday"), ("Sunday", "Sunday"), ], )
27.818182
612
963
py
PYTHON
15.0
# Copyright (C) 2019 Open Source Integrators # Copyright (C) 2019 Serpent consulting Services # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). from odoo import fields, models class FSMRoute(models.Model): _name = "fsm.route" _description = "Field Service Route" name = fields.Char(required=True) fsm_person_id = fields.Many2one(comodel_name="fsm.person", string="Person") day_ids = fields.Many2many(comodel_name="fsm.route.day", string="Days") max_order = fields.Integer( string="Maximum Orders", default=0, help="Maximum number of orders per day route.", ) def run_on(self, date): """ :param date: date :return: True if the route runs on the date, False otherwise. """ if date: day_index = date.weekday() day = self.env.ref("fieldservice_route.fsm_route_day_" + str(day_index)) return day in self.day_ids
34.392857
963
3,896
py
PYTHON
15.0
# Copyright (C) 2019 Open Source Integrators # Copyright (C) 2019 Serpent consulting Services # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). from datetime import datetime from odoo import api, fields, models from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT class FSMOrder(models.Model): _inherit = "fsm.order" dayroute_id = fields.Many2one( comodel_name="fsm.route.dayroute", string="Day Route", index=True ) fsm_route_id = fields.Many2one(related="location_id.fsm_route_id", string="Route") person_id = fields.Many2one( comodel_name="fsm.person", string="Assigned To", index=True, compute="_compute_person_id", store=True, readonly=False, ) @api.depends("fsm_route_id") def _compute_person_id(self): for item in self.filtered("fsm_route_id"): item.person_id = item.fsm_route_id.fsm_person_id def prepare_dayroute_values(self, values): return { "person_id": values["person_id"], "date": values["date"], "route_id": values["route_id"], } def _get_dayroute_values(self, vals): date = False if vals.get("scheduled_date_start"): if type(vals.get("scheduled_date_start")) == str: date = datetime.strptime( vals.get("scheduled_date_start"), DEFAULT_SERVER_DATETIME_FORMAT ).date() elif isinstance(vals.get("scheduled_date_start"), datetime): date = vals.get("scheduled_date_start").date() return { "person_id": vals.get("person_id") or self.person_id.id or self.fsm_route_id.fsm_person_id.id, "date": date or self.scheduled_date_start.date(), "route_id": vals.get("fsm_route_id") or self.fsm_route_id.id, } def _get_dayroute_domain(self, values): return [ ("person_id", "=", values["person_id"]), ("date", "=", values["date"]), ("order_remaining", ">", 0), ] def _can_create_dayroute(self, values): return values["person_id"] and values["date"] def _manage_fsm_route(self, vals): dayroute_obj = self.env["fsm.route.dayroute"] values = self._get_dayroute_values(vals) domain = self._get_dayroute_domain(values) dayroute = dayroute_obj.search(domain, limit=1) if dayroute: vals.update({"dayroute_id": dayroute.id}) else: if self._can_create_dayroute(values): dayroute = dayroute_obj.create(self.prepare_dayroute_values(values)) vals.update({"dayroute_id": dayroute.id}) # If this was the last order of the dayroute, # delete the dayroute if self.dayroute_id and not self.dayroute_id.order_ids: self.dayroute_id.unlink() return vals @api.model def create(self, vals): location = self.env["fsm.location"].browse(vals.get("location_id")) if not vals.get("fsm_route_id"): vals.update({"fsm_route_id": location.fsm_route_id.id}) if vals.get("person_id") and vals.get("scheduled_date_start"): vals = self._manage_fsm_route(vals) return super().create(vals) def write(self, vals): for rec in self: if vals.get("route_id", False): route = self.env["fsm.route"].browse(vals.get("route_id")) vals.update( { "scheduled_date_start": route.date, } ) if (vals.get("person_id", False) or rec.person_id) and ( vals.get("scheduled_date_start", False) or rec.scheduled_date_start ): vals = rec._manage_fsm_route(vals) return super().write(vals)
37.104762
3,896
5,339
py
PYTHON
15.0
# Copyright (C) 2019 Open Source Integrators # Copyright (C) 2019 Serpent consulting Services # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). from datetime import datetime from odoo import _, api, fields, models from odoo.exceptions import ValidationError from odoo.tools import DEFAULT_SERVER_DATE_FORMAT class FSMRouteDayRoute(models.Model): _name = "fsm.route.dayroute" _description = "Field Service Route Dayroute" name = fields.Char(required=True, copy=False, default=lambda self: _("New")) person_id = fields.Many2one(comodel_name="fsm.person", string="Person") route_id = fields.Many2one(comodel_name="fsm.route", string="Route") date = fields.Date(required=True) team_id = fields.Many2one( comodel_name="fsm.team", string="Team", default=lambda self: self._default_team_id(), ) stage_id = fields.Many2one( comodel_name="fsm.stage", string="Stage", domain="[('stage_type', '=', 'route')]", index=True, copy=False, default=lambda self: self._default_stage_id(), ) longitude = fields.Float() latitude = fields.Float() last_location_id = fields.Many2one( comodel_name="fsm.location", string="Last Location" ) date_start_planned = fields.Datetime(string="Planned Start Time") start_location_id = fields.Many2one( comodel_name="fsm.location", string="Start Location" ) end_location_id = fields.Many2one( comodel_name="fsm.location", string="End Location" ) work_time = fields.Float(string="Time before overtime (in hours)", default=8.0) max_allow_time = fields.Float( string="Maximal Allowable Time (in hours)", default=10.0 ) order_ids = fields.One2many( comodel_name="fsm.order", inverse_name="dayroute_id", string="Orders" ) order_count = fields.Integer( compute="_compute_order_count", string="Number of Orders", store=True ) order_remaining = fields.Integer( compute="_compute_order_count", string="Available Capacity", store=True ) max_order = fields.Integer( related="route_id.max_order", string="Maximum Capacity", store=True, help="Maximum numbers of orders that can be added to this day route.", ) def _default_team_id(self): teams = self.env["fsm.team"].search( [("company_id", "in", (self.env.user.company_id.id, False))], order="sequence asc", limit=1, ) if teams: return teams else: raise ValidationError(_("You must create a FSM team first.")) def _default_stage_id(self): return self.env["fsm.stage"].search( [("stage_type", "=", "route"), ("is_default", "=", True)], limit=1 ) @api.depends("route_id", "order_ids") def _compute_order_count(self): for rec in self: rec.order_count = len(rec.order_ids) rec.order_remaining = rec.max_order - rec.order_count @api.onchange("route_id") def _onchange_person(self): self.person_id = self.route_id.fsm_person_id.id @api.onchange("date") def _onchange_date(self): if self.date: # TODO: Use the worker timezone and working schedule self.date_start_planned = datetime.combine( self.date, datetime.strptime("8:00:00", "%H:%M:%S").time() ) @api.model def create(self, vals): if vals.get("name", _("New")) == _("New"): vals["name"] = self.env["ir.sequence"].next_by_code( "fsm.route.dayroute" ) or _("New") if not vals.get("date_start_planned", False) and vals.get("date", False): # TODO: Use the worker timezone and working schedule date = vals.get("date") if type(vals.get("date")) == str: date = datetime.strptime( vals.get("date"), DEFAULT_SERVER_DATE_FORMAT ).date() vals.update( { "date_start_planned": datetime.combine( date, datetime.strptime("8:00:00", "%H:%M:%S").time() ) } ) return super().create(vals) @api.constrains("date", "route_id") def check_day(self): for rec in self: if rec.date and rec.route_id: # Get the day of the week: Monday -> 0, Sunday -> 6 day_index = rec.date.weekday() day = self.env.ref("fieldservice_route.fsm_route_day_" + str(day_index)) if day.id not in rec.route_id.day_ids.ids: raise ValidationError( _("The route %(route_name)s does not run on %(name)s!") % {"route_name": rec.route_id.name, "name": day.name} ) @api.constrains("route_id", "max_order", "order_count") def check_capacity(self): for rec in self: if rec.route_id and rec.order_count > rec.max_order: raise ValidationError( _( "The day route is exceeding the maximum number of " "orders of the route." ) )
37.598592
5,339
372
py
PYTHON
15.0
# Copyright (C) 2019 Open Source Integrators # Copyright (C) 2019 Serpent consulting Services # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). from odoo import fields, models class FSMStage(models.Model): _inherit = "fsm.stage" stage_type = fields.Selection( selection_add=[("route", "Route")], ondelete={"route": "cascade"} )
28.615385
372
896
py
PYTHON
15.0
# Copyright (C) 2018 Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { "name": "Field Service - Sales", "version": "15.0.2.0.2", "summary": "Sell field services.", "category": "Field Service", "author": "Open Source Integrators, Odoo Community Association (OCA)", "website": "https://github.com/OCA/field-service", "depends": [ "fieldservice", "sale_management", "fieldservice_account", ], "data": [ "security/ir.model.access.csv", "views/fsm_location.xml", "views/fsm_order.xml", "views/product_template.xml", "views/sale_order.xml", "data/fsm_template_group.xml", ], "license": "AGPL-3", "development_status": "Beta", "maintainers": [ "wolfhall", "max3903", "brian10048", ], "installable": True, }
28.903226
896
319
py
PYTHON
15.0
# Copyright (C) 2021, Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). def migrate(env, version): if not version: return env.execute( "UPDATE product_template SET field_service_tracking = 'sale' " "WHERE field_service_tracking = 'order';" )
26.583333
319
5,084
py
PYTHON
15.0
# Copyright (C) 2019 Brian McMaster <[email protected]> # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo.addons.sale.tests.common import TestSaleCommonBase class TestFSMSale(TestSaleCommonBase): @classmethod def setUpClass(cls): super(TestFSMSale, cls).setUpClass() @classmethod def setUpFSMTemplates(cls): # Create some templates to use on the FSM products FSMTemplate = cls.env["fsm.template"] # Template 1 cls.fsm_template_1 = FSMTemplate.create( { "name": "Test FSM Template #1", "instructions": "These are the instructions for Template #1", "duration": 2.25, } ) # Template 2 cls.fsm_template_2 = FSMTemplate.create( { "name": "Test FSM Template #2", "instructions": "Template #2 requires a lot of work", "duration": 4.5, } ) # Template 3 cls.fsm_template_3 = FSMTemplate.create( { "name": "Test FSM Template #3", "instructions": "Complete the steps outlined for Template #3", "duration": 0.75, } ) # Template 4 cls.fsm_template_4 = FSMTemplate.create( { "name": "Test FSM Template #4", "instructions": "These notes apply to Template #4", "duration": 0.75, } ) @classmethod def setUpFSMProducts(cls): cls.setUpFSMTemplates() # Product 1 that creates one FSM Order per SO cls.fsm_per_order_1 = cls.env["product.product"].create( { "name": "FSM Order per Sale Order #1", "categ_id": cls.env.ref("product.product_category_3").id, "standard_price": 85.0, "list_price": 90.0, "type": "service", "uom_id": cls.env.ref("uom.product_uom_unit").id, "uom_po_id": cls.env.ref("uom.product_uom_unit").id, "invoice_policy": "order", "field_service_tracking": "sale", "fsm_order_template_id": cls.fsm_template_1.id, } ) # Product 2 that creates one FSM Order per SO cls.fsm_per_order_2 = cls.env["product.product"].create( { "name": "FSM Order per Sale Order #2", "categ_id": cls.env.ref("product.product_category_3").id, "standard_price": 125.0, "list_price": 140.0, "type": "service", "uom_id": cls.env.ref("uom.product_uom_unit").id, "uom_po_id": cls.env.ref("uom.product_uom_unit").id, "invoice_policy": "order", "field_service_tracking": "sale", "fsm_order_template_id": cls.fsm_template_2.id, } ) # Product 1 that creates one FSM Order per SO Line cls.fsm_per_line_1 = cls.env["product.product"].create( { "name": "FSM Order per SO Line #1", "categ_id": cls.env.ref("product.product_category_3").id, "standard_price": 75.0, "list_price": 80.0, "type": "service", "uom_id": cls.env.ref("uom.product_uom_unit").id, "uom_po_id": cls.env.ref("uom.product_uom_unit").id, "invoice_policy": "delivery", "field_service_tracking": "line", "fsm_order_template_id": cls.fsm_template_3.id, } ) # Product 2 that creates one FSM Order per SO Line cls.fsm_per_line_2 = cls.env["product.product"].create( { "name": "FSM Order per SO Line #2", "categ_id": cls.env.ref("product.product_category_3").id, "standard_price": 75.0, "list_price": 80.0, "type": "service", "uom_id": cls.env.ref("uom.product_uom_unit").id, "uom_po_id": cls.env.ref("uom.product_uom_unit").id, "invoice_policy": "delivery", "field_service_tracking": "line", "fsm_order_template_id": cls.fsm_template_4.id, } ) # Normal Product cls.product_line = cls.env["product.template"].create( { "name": "FSM Order per SO Line #2", "categ_id": cls.env.ref("product.product_category_3").id, "standard_price": 75.0, "list_price": 80.0, "type": "service", "uom_id": cls.env.ref("uom.product_uom_unit").id, "uom_po_id": cls.env.ref("uom.product_uom_unit").id, "invoice_policy": "delivery", "field_service_tracking": "no", "fsm_order_template_id": cls.fsm_template_4.id, } ) cls.product_line._onchange_field_service_tracking()
39.410853
5,084
20,184
py
PYTHON
15.0
# Copyright (C) 2019 Brian McMaster <[email protected]> # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import fields from odoo.exceptions import ValidationError from .test_fsm_sale_common import TestFSMSale class TestFSMSaleOrder(TestFSMSale): @classmethod def setUpClass(cls): super(TestFSMSaleOrder, cls).setUpClass() cls.test_location = cls.env.ref("fieldservice.test_location") # Setup products that when sold will create some FSM orders cls.setUpFSMProducts() cls.partner_customer_usd = cls.env["res.partner"].create( { "name": "partner_a", "company_id": False, } ) cls.pricelist_usd = cls.env["product.pricelist"].search( [("currency_id.name", "=", "USD")], limit=1 ) # Create some sale orders that will use the above products SaleOrder = cls.env["sale.order"].with_context(tracking_disable=True) # create a generic Sale Order with one product # set to create FSM service per sale order cls.sale_order = SaleOrder.create( { "partner_id": cls.partner_customer_usd.id, "pricelist_id": cls.pricelist_usd.id, } ) cls.sale_order_wo_sol = SaleOrder.create( { "partner_id": cls.partner_customer_usd.id, "pricelist_id": cls.pricelist_usd.id, } ) cls.sale_order_sol = SaleOrder.create( { "partner_id": cls.partner_customer_usd.id, "pricelist_id": cls.pricelist_usd.id, } ) cls.sol_service_per_order = cls.env["sale.order.line"].create( { "name": cls.fsm_per_order_1.name, "product_id": cls.fsm_per_order_1.id, "product_uom_qty": 1, "product_uom": cls.fsm_per_order_1.uom_id.id, "price_unit": cls.fsm_per_order_1.list_price, "order_id": cls.sale_order.id, "tax_id": False, } ) # cls.sol_service_per_order._compute_product_updatable() cls.sale_order_1 = SaleOrder.create( { "partner_id": cls.partner_customer_usd.id, "fsm_location_id": cls.test_location.id, "pricelist_id": cls.pricelist_usd.id, } ) cls.sol_service_per_order_1 = cls.env["sale.order.line"].create( { "name": cls.fsm_per_order_1.name, "product_id": cls.fsm_per_order_1.id, "product_uom_qty": 1, "product_uom": cls.fsm_per_order_1.uom_id.id, "price_unit": cls.fsm_per_order_1.list_price, "order_id": cls.sale_order_1.id, "tax_id": False, } ) # create a generic Sale Order with one product # set to create FSM service per sale order line cls.sale_order_2 = SaleOrder.create( { "partner_id": cls.partner_customer_usd.id, "fsm_location_id": cls.test_location.id, "pricelist_id": cls.pricelist_usd.id, } ) cls.sol_service_per_line_1 = cls.env["sale.order.line"].create( { "name": cls.fsm_per_line_1.name, "product_id": cls.fsm_per_line_1.id, "product_uom_qty": 1, "product_uom": cls.fsm_per_line_1.uom_id.id, "price_unit": cls.fsm_per_line_1.list_price, "order_id": cls.sale_order_2.id, "tax_id": False, } ) # create a generic Sale Order with multiple products # set to create FSM service per sale order line cls.sale_order_3 = SaleOrder.create( { "partner_id": cls.partner_customer_usd.id, "fsm_location_id": cls.test_location.id, "pricelist_id": cls.pricelist_usd.id, } ) cls.sol_service_per_line_2 = cls.env["sale.order.line"].create( { "name": cls.fsm_per_line_1.name, "product_id": cls.fsm_per_line_1.id, "product_uom_qty": 1, "product_uom": cls.fsm_per_line_1.uom_id.id, "price_unit": cls.fsm_per_line_1.list_price, "order_id": cls.sale_order_3.id, "tax_id": False, } ) cls.sol_service_per_line_3 = cls.env["sale.order.line"].create( { "name": cls.fsm_per_line_2.name, "product_id": cls.fsm_per_line_2.id, "product_uom_qty": 1, "product_uom": cls.fsm_per_line_2.uom_id.id, "price_unit": cls.fsm_per_line_2.list_price, "order_id": cls.sale_order_3.id, "tax_id": False, } ) # create a generic Sale Order with mixed products # 2 lines based on service per sale order line # 2 lines based on service per sale order cls.sale_order_4 = SaleOrder.create( { "partner_id": cls.partner_customer_usd.id, "fsm_location_id": cls.test_location.id, "pricelist_id": cls.pricelist_usd.id, } ) cls.sol_service_per_line_4 = cls.env["sale.order.line"].create( { "name": cls.fsm_per_line_1.name, "product_id": cls.fsm_per_line_1.id, "product_uom_qty": 1, "product_uom": cls.fsm_per_line_1.uom_id.id, "price_unit": cls.fsm_per_line_1.list_price, "order_id": cls.sale_order_4.id, "tax_id": False, } ) cls.sol_service_per_line_5 = cls.env["sale.order.line"].create( { "name": cls.fsm_per_line_2.name, "product_id": cls.fsm_per_line_2.id, "product_uom_qty": 1, "product_uom": cls.fsm_per_line_2.uom_id.id, "price_unit": cls.fsm_per_line_2.list_price, "order_id": cls.sale_order_4.id, "tax_id": False, } ) cls.sol_service_per_order_2 = cls.env["sale.order.line"].create( { "name": cls.fsm_per_order_1.name, "product_id": cls.fsm_per_order_1.id, "product_uom_qty": 1, "product_uom": cls.fsm_per_order_1.uom_id.id, "price_unit": cls.fsm_per_order_1.list_price, "order_id": cls.sale_order_4.id, "tax_id": False, } ) cls.sol_service_per_order_3 = cls.env["sale.order.line"].create( { "name": cls.fsm_per_order_2.name, "product_id": cls.fsm_per_order_2.id, "product_uom_qty": 1, "product_uom": cls.fsm_per_order_2.uom_id.id, "price_unit": cls.fsm_per_order_2.list_price, "order_id": cls.sale_order_4.id, "tax_id": False, } ) def _isp_account_installed(self): """Checks if module is installed which will require more logic for the tests. :return Boolean indicating the installed status of the module """ result = False isp_account_module = self.env["ir.module.module"].search( [("name", "=", "fieldservice_isp_account")] ) if isp_account_module and isp_account_module.state == "installed": result = True return result def _fulfill_order(self, order): """Extra logic required to fulfill FSM order status and prevent validation error when attempting to complete the FSM order :return FSM Order with additional fields set """ analytic_account = self.env.ref("analytic.analytic_administratif") self.test_location.analytic_account_id = analytic_account.id timesheet = self.env["account.analytic.line"].create( { "name": "timesheet_line", "unit_amount": 1, "account_id": analytic_account.id, "user_id": self.env.ref("base.partner_admin").id, "product_id": self.env.ref( "fieldservice_isp_account.field_service_regular_time" ).id, } ) order.write( { "employee_timesheet_ids": [(6, 0, timesheet.ids)], } ) return order def test_sale_order_0(self): """Test the sales order 0 flow from sale to invoice. - One FSM order linked to the Sale Order should be created. - One Invoice linked to the FSM Order should be created. """ # Confirm the sale order sol = self.sol_service_per_order with self.assertRaises(ValidationError), self.cr.savepoint(): self.sale_order.action_confirm() sol._compute_product_updatable() # 1 FSM order created def test_sale_order_1(self): """Test the sales order 1 flow from sale to invoice. - One FSM order linked to the Sale Order should be created. - One Invoice linked to the FSM Order should be created. """ # Confirm the sale order self.sale_order_1.action_confirm() # 1 FSM order created self.assertEqual( len(self.sale_order_1.fsm_order_ids.ids), 1, "FSM Sale: Sale Order 1 should create 1 FSM Order", ) FSM_Order = self.env["fsm.order"] fsm_order = FSM_Order.search( [("id", "=", self.sale_order_1.fsm_order_ids[0].id)] ) # Sale Order linked to FSM order self.assertEqual( len(fsm_order.ids), 1, "FSM Sale: Sale Order not linked to FSM Order" ) # Complete the FSM order if self._isp_account_installed(): fsm_order = self._fulfill_order(fsm_order) fsm_order.write( { "date_end": fields.Datetime.today(), "resolution": "Work completed", } ) fsm_order.action_complete() # Invoice the order invoice = self.sale_order_1._create_invoices() # 1 invoices created self.assertEqual( len(invoice.ids), 1, "FSM Sale: Sale Order 1 should create 1 invoice" ) self.assertTrue( fsm_order in invoice.fsm_order_ids, "FSM Sale: Invoice should be linked to FSM Order", ) def test_sale_order_2(self): """Test the sales order 2 flow from sale to invoice. - One FSM order linked to the Sale Order Line should be created. - The FSM Order should update qty_delivered when completed. - One Invoice linked to the FSM Order should be created. """ sol = self.sol_service_per_line_1 # Confirm the sale order self.sale_order_2.action_confirm() # 1 order created self.assertEqual( len(self.sale_order_2.fsm_order_ids.ids), 1, "FSM Sale: Sale Order 2 should create 1 FSM Order", ) FSM_Order = self.env["fsm.order"] fsm_order = FSM_Order.search([("id", "=", sol.fsm_order_id.id)]) # SOL linked to FSM order self.assertTrue( sol.fsm_order_id.id == fsm_order.id, "FSM Sale: Sale Order 2 Line not linked to FSM Order", ) # Complete the FSM order if self._isp_account_installed(): fsm_order = self._fulfill_order(fsm_order) fsm_order.write( { "date_end": fields.Datetime.today(), "resolution": "Work completed", } ) fsm_order.action_complete() # qty delivered should be updated self.assertTrue( sol.qty_delivered == sol.product_uom_qty, "FSM Sale: Sale Order Line qty delivered not equal to qty ordered", ) # Invoice the order invoice = self.sale_order_2._create_invoices() # 1 invoice created self.assertEqual( len(invoice.ids), 1, "FSM Sale: Sale Order 2 should create 1 invoice" ) self.assertTrue( fsm_order in invoice.fsm_order_ids, "FSM Sale: Invoice should be linked to FSM Order", ) def test_sale_order_3(self): """Test sale order 3 flow from sale to invoice. - An FSM order should be created for each Sale Order Line. - The FSM Order should update qty_delivered when completed. - An Invoice linked to each FSM Order should be created. """ sol1 = self.sol_service_per_line_2 sol2 = self.sol_service_per_line_3 # Confirm the sale order self.sale_order_3.action_confirm() # 2 orders created and SOLs linked to FSM orders self.assertEqual( len(self.sale_order_3.fsm_order_ids.ids), 2, "FSM Sale: Sale Order 3 should create 2 FSM Orders", ) FSM_Order = self.env["fsm.order"] fsm_order_1 = FSM_Order.search([("id", "=", sol1.fsm_order_id.id)]) self.assertTrue( sol1.fsm_order_id.id == fsm_order_1.id, "FSM Sale: Sale Order Line 2 not linked to FSM Order", ) fsm_order_2 = FSM_Order.search([("id", "=", sol2.fsm_order_id.id)]) self.assertTrue( sol2.fsm_order_id.id == fsm_order_2.id, "FSM Sale: Sale Order Line 3 not linked to FSM Order", ) # Complete the FSM orders if self._isp_account_installed(): fsm_order_1 = self._fulfill_order(fsm_order_1) fsm_order_1.write( { "date_end": fields.Datetime.today(), "resolution": "Work completed", } ) fsm_order_1.action_complete() self.assertTrue( sol1.qty_delivered == sol1.product_uom_qty, "FSM Sale: Sale Order Line qty delivered not equal to qty ordered", ) if self._isp_account_installed(): fsm_order_2 = self._fulfill_order(fsm_order_2) fsm_order_2.write( { "date_end": fields.Datetime.today(), "resolution": "Work completed", } ) fsm_order_2.action_complete() self.assertTrue( sol2.qty_delivered == sol2.product_uom_qty, "FSM Sale: Sale Order Line qty delivered not equal to qty ordered", ) # Invoice the sale order invoices = self.sale_order_3._create_invoices() # 2 invoices created self.assertEqual( len(invoices.ids), 1, "FSM Sale: Sale Order 3 should create 1 invoices" ) inv_fsm_orders = FSM_Order for inv in invoices: inv_fsm_orders |= inv.fsm_order_ids self.assertTrue( fsm_order_1 in inv_fsm_orders, "FSM Sale: FSM Order 1 should be linked to invoice", ) self.assertTrue( fsm_order_2 in inv_fsm_orders, "FSM Sale: FSM Order 2 should be linked to invoice", ) def test_sale_order_4(self): """Test sale order 4 flow from sale to invoice. - Two FSM orders linked to the Sale Order Lines should be created. - One FSM order linked to the Sale Order should be created. - One Invoices should be created (One for each FSM Order). """ sol1 = self.sol_service_per_line_4 sol2 = self.sol_service_per_line_5 # sol3 = self.sol_service_per_order_2 # sol4 = self.sol_service_per_order_3 # Confirm the sale order self.sale_order_4.action_confirm() # 3 orders created self.assertEqual( len(self.sale_order_4.fsm_order_ids.ids), 3, "FSM Sale: Sale Order 4 should create 3 FSM Orders", ) FSM_Order = self.env["fsm.order"] fsm_order_1 = FSM_Order.search([("id", "=", sol1.fsm_order_id.id)]) self.assertTrue( sol1.fsm_order_id.id == fsm_order_1.id, "FSM Sale: Sale Order Line not linked to FSM Order", ) fsm_order_2 = FSM_Order.search([("id", "=", sol2.fsm_order_id.id)]) self.assertTrue( sol2.fsm_order_id.id == fsm_order_2.id, "FSM Sale: Sale Order Line not linked to FSM Order", ) fsm_order_3 = FSM_Order.search( [ ("id", "in", self.sale_order_4.fsm_order_ids.ids), ("sale_line_id", "=", False), ] ) self.assertEqual( len(fsm_order_3.ids), 1, "FSM Sale: FSM Order not linked to Sale Order" ) # Complete the FSM order if self._isp_account_installed(): fsm_order_1 = self._fulfill_order(fsm_order_1) fsm_order_1.write( { "date_end": fields.Datetime.today(), "resolution": "Work completed", } ) fsm_order_1.action_complete() self.assertTrue( sol1.qty_delivered == sol1.product_uom_qty, "FSM Sale: Sale Order Line qty delivered not equal to qty ordered", ) if self._isp_account_installed(): fsm_order_2 = self._fulfill_order(fsm_order_2) fsm_order_2.write( { "date_end": fields.Datetime.today(), "resolution": "Work completed", } ) fsm_order_2.action_complete() self.assertTrue( sol2.qty_delivered == sol2.product_uom_qty, "FSM Sale: Sale Order Line qty delivered not equal to qty ordered", ) if self._isp_account_installed(): fsm_order_3 = self._fulfill_order(fsm_order_3) fsm_order_3.write( { "date_end": fields.Datetime.today(), "resolution": "Work completed", } ) fsm_order_3.action_complete() # qty_delivered does not update for FSM orders linked only to the sale # Invoice the sale order invoices = self.sale_order_4._create_invoices() # 3 invoices created self.assertEqual( len(invoices.ids), 1, "FSM Sale: Sale Order 4 should create 1 invoice" ) def test_sale_order_5(self): """Test ValidationError isn't raised if order line display_type in ("line_section", "line_note") """ # remove normal order line with display_type=False self.sol_service_per_order.unlink() # add note as order line to sale order self.sol_note = self.env["sale.order.line"].create( { "name": "This is a note", "display_type": "line_note", "product_id": False, "product_uom_qty": 0, "product_uom": False, "price_unit": 0, "order_id": self.sale_order.id, "tax_id": False, } ) # confirm sale order: ValidationError shouldn't be raised self.sale_order.action_confirm() # set sale order to draft self.sale_order.action_cancel() self.sale_order.action_draft() # remove note order line self.sol_note.unlink() # add section as order line to sale order self.sol_section = self.env["sale.order.line"].create( { "name": "This is a section", "display_type": "line_section", "product_id": False, "product_uom_qty": 0, "product_uom": False, "price_unit": 0, "order_id": self.sale_order.id, "tax_id": False, } ) # confirm sale order: ValidationError shouldn't be raised self.sale_order.action_confirm()
38.011299
20,184
4,343
py
PYTHON
15.0
# Copyright (C) 2019 Clément Mombereau (Akretion) # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html) from odoo.tests.common import TransactionCase class FSMSale(TransactionCase): def setUp(self): """Create 3 related partners : a parent company, a child partner and a child shipping partner. For each test, a different partner is a fsm_location. A SO is created with the child partner as customer. The test run the SO's onchange_partner_id and check if the fsm_location_id is the expected one. """ super(FSMSale, self).setUp() # create a parent company self.commercial_partner = self.env["res.partner"].create( { "name": "Company Commercial Partner", "is_company": True, } ) # create a child partner self.partner = self.env["res.partner"].create( { "name": "Child Partner", "parent_id": self.commercial_partner.id, } ) self.partner2 = self.env["res.partner"].create( { "name": "Partner 2", "parent_id": self.commercial_partner.id, } ) # create a child partner shipping address self.shipping_partner = self.env["res.partner"].create( { "name": "Shipping Partner", "parent_id": self.commercial_partner.id, "type": "delivery", } ) # Demo FS location self.location = self.env.ref("fieldservice.location_1") self.partner2.fsm_location = self.location.id def test_autofill_so_fsm_location(self): """First case : - commercial_partner IS NOT a fsm_location - partner IS a fsm_location - shipping_partner IS NOT a fsm_location Test if the SO's fsm_location_id is autofilled with the expected partner_location. """ # Link demo FS location to self.partner self.location.partner_id = self.partner.id # create a Sale Order and run onchange_partner_id self.so = self.env["sale.order"].create({"partner_id": self.partner2.id}) self.so.onchange_partner_id() def test_1_autofill_so_fsm_location(self): """First case : - commercial_partner IS NOT a fsm_location - partner IS a fsm_location - shipping_partner IS NOT a fsm_location Test if the SO's fsm_location_id is autofilled with the expected partner_location. """ # Link demo FS location to self.partner self.location.partner_id = self.partner.id # create a Sale Order and run onchange_partner_id self.so = self.env["sale.order"].create({"partner_id": self.partner.id}) self.so.onchange_partner_id() self.assertEqual(self.so.fsm_location_id.id, self.location.id) def test_2_autofill_so_fsm_location(self): """Second case : - commercial_partner IS NOT a fsm_location - partner IS NOT a fsm_location - shipping_partner IS a fsm_location Test if the SO's fsm_location_id is autofilled with the expected shipping_partner_location. """ # Link demo FS location to self.shipping_partner self.location.partner_id = self.shipping_partner.id # create a Sale Order and run onchange_partner_id self.so = self.env["sale.order"].create({"partner_id": self.partner.id}) self.so.onchange_partner_id() self.assertEqual(self.so.fsm_location_id.id, self.location.id) def test_3_autofill_so_fsm_location(self): """Third case : - commercial_partner IS a fsm_location - partner IS NOT a fsm_location - shipping_partner IS NOT a fsm_location Test if the SO's fsm_location_id is autofilled with the expected commercial_partner_location. """ # Link demo FS location to self.commercial_partner self.location.partner_id = self.commercial_partner.id # create a Sale Order and run onchange_partner_id self.so = self.env["sale.order"].create({"partner_id": self.partner.id}) self.so.onchange_partner_id() self.assertEqual(self.so.fsm_location_id.id, self.location.id)
40.962264
4,342
7,007
py
PYTHON
15.0
# Copyright (C) 2019 Brian McMaster # Copyright (C) 2019 Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import _, api, fields, models from odoo.exceptions import ValidationError class SaleOrder(models.Model): _inherit = "sale.order" fsm_location_id = fields.Many2one( "fsm.location", string="Service Location", help="SO Lines generating a FSM order will be for this location", ) fsm_order_ids = fields.Many2many( "fsm.order", compute="_compute_fsm_order_ids", string="Field Service orders associated to this sale", ) fsm_order_count = fields.Integer( string="FSM Orders", compute="_compute_fsm_order_ids" ) @api.depends("order_line") def _compute_fsm_order_ids(self): for order in self: orders = self.env["fsm.order"] orders |= self.env["fsm.order"].search( [("sale_line_id", "in", order.order_line.ids)] ) orders |= self.env["fsm.order"].search([("sale_id", "=", order.id)]) order.fsm_order_ids = orders order.fsm_order_count = len(order.fsm_order_ids) @api.onchange("partner_id") def onchange_partner_id(self): """ Autofill the Sale Order's FS location with the partner_id, the partner_shipping_id or the partner_id.commercial_partner_id if they are FS locations. """ res = super(SaleOrder, self).onchange_partner_id() domain = [ "|", "|", ("partner_id", "=", self.partner_id.id), ("partner_id", "=", self.partner_shipping_id.id), ("partner_id", "=", self.partner_id.commercial_partner_id.id), ] if self.partner_id.fsm_location: domain = [("partner_id", "=", self.partner_id.id)] location_ids = self.env["fsm.location"].search(domain) self.fsm_location_id = location_ids and location_ids[0] or False return res def _prepare_fsm_values(self, **kwargs): self.ensure_one() template_id = kwargs.get("template_id", False) template_ids = kwargs.get("template_ids", [template_id]) templates = self.env["fsm.template"].search([("id", "in", template_ids)]) note = "" hours = 0.0 categories = self.env["fsm.category"] for template in templates: note += template.instructions or "" hours += template.duration categories |= template.category_ids return { "location_id": self.fsm_location_id.id, "location_directions": self.fsm_location_id.direction, "request_early": self.expected_date, "scheduled_date_start": self.expected_date, "todo": note, "category_ids": [(6, 0, categories.ids)], "scheduled_duration": hours, "sale_id": kwargs.get("so_id", False), "sale_line_id": kwargs.get("sol_id", False), "template_id": template_id, "company_id": self.company_id.id, } def _field_service_generation(self): """ Create Field Service Orders based on the products' configuration. :rtype: list(FSM Orders) :return: list of newly created FSM Orders """ res = [] for sale in self: # Process lines set to FSM Sale new_fsm_sale_lines = sale.order_line.filtered( lambda l: l.product_id.field_service_tracking == "sale" and not l.fsm_order_id ) if new_fsm_sale_lines: fsm_by_sale = self.env["fsm.order"].search( [("sale_id", "=", sale.id), ("sale_line_id", "=", False)] ) if not fsm_by_sale: templates = new_fsm_sale_lines.product_id.fsm_order_template_id vals = sale._prepare_fsm_values( so_id=sale.id, template_ids=templates.ids ) fsm_by_sale = self.env["fsm.order"].sudo().create(vals) res.append(fsm_by_sale) new_fsm_sale_lines.write({"fsm_order_id": fsm_by_sale.id}) # Create new FSM Order for lines set to FSM Line new_fsm_line_lines = sale.order_line.filtered( lambda l: l.product_id.field_service_tracking == "line" and not l.fsm_order_id ) for line in new_fsm_line_lines: vals = sale._prepare_fsm_values( template_id=line.product_id.fsm_order_template_id.id, so_id=self.id, sol_id=line.id, ) fsm_by_line = self.env["fsm.order"].sudo().create(vals) line.write({"fsm_order_id": fsm_by_line.id}) res.append(fsm_by_line) if len(res) > 0: sale._post_fsm_message(res) return res def _post_fsm_message(self, fsm_orders): """ Post messages to the Sale Order and the newly created FSM Orders """ self.ensure_one() msg_fsm_links = "" for fsm_order in fsm_orders: fsm_order.message_post_with_view( "mail.message_origin_link", values={"self": fsm_order, "origin": self}, subtype_id=self.env.ref("mail.mt_note").id, author_id=self.env.user.partner_id.id, ) msg_fsm_links += ( " <a href=# data-oe-model=fsm.order data-oe-id={}>{}</a>,".format( fsm_order.id, fsm_order.name ) ) so_msg_body = _("Field Service Order(s) Created: %s", msg_fsm_links) self.message_post(body=so_msg_body[:-1]) def _action_confirm(self): """On SO confirmation, some lines generate field service orders.""" result = super(SaleOrder, self)._action_confirm() if any( sol.product_id.field_service_tracking != "no" for sol in self.order_line.filtered( lambda x: x.display_type not in ("line_section", "line_note") ) ): if not self.fsm_location_id: raise ValidationError(_("FSM Location must be set")) self._field_service_generation() return result def action_view_fsm_order(self): fsm_orders = self.mapped("fsm_order_ids") action = self.env["ir.actions.act_window"]._for_xml_id( "fieldservice.action_fsm_dash_order" ) if len(fsm_orders) > 1: action["domain"] = [("id", "in", fsm_orders.ids)] elif len(fsm_orders) == 1: action["views"] = [(self.env.ref("fieldservice.fsm_order_form").id, "form")] action["res_id"] = fsm_orders.id else: action = {"type": "ir.actions.act_window_close"} return action
40.50289
7,007
702
py
PYTHON
15.0
# Copyright (C) 2019 Brian McMaster # Copyright (C) 2019 Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import _, fields, models class FSMOrder(models.Model): _inherit = "fsm.order" sale_id = fields.Many2one("sale.order") sale_line_id = fields.Many2one("sale.order.line") def action_view_sales(self): self.ensure_one() return { "type": "ir.actions.act_window", "res_model": "sale.order", "views": [[False, "form"]], "res_id": self.sale_line_id.order_id.id or self.sale_id.id, "context": {"create": False}, "name": _("Sales Orders"), }
31.909091
702
2,392
py
PYTHON
15.0
# Copyright (C) 2019 Brian McMaster # Copyright (C) 2019 Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import api, fields, models class SaleOrderLine(models.Model): _inherit = "sale.order.line" qty_delivered_method = fields.Selection( selection_add=[("field_service", "Field Service Order")], ondelete={"field_service": "cascade"}, ) fsm_order_id = fields.Many2one( "fsm.order", "Order", index=True, copy=False, help="Field Service Order generated by the sales order item", ) @api.depends("product_id.type") def _compute_product_updatable(self): for line in self: if line.product_id.type == "service" and line.state == "sale": line.product_updatable = False else: return super(SaleOrderLine, line)._compute_product_updatable() @api.depends("product_id") def _compute_qty_delivered_method(self): res = super(SaleOrderLine, self)._compute_qty_delivered_method() for line in self: if not line.is_expense and line.product_id.field_service_tracking == "line": line.qty_delivered_method = "field_service" return res @api.depends("fsm_order_id.stage_id") def _compute_qty_delivered(self): res = super(SaleOrderLine, self)._compute_qty_delivered() lines_by_fsm = self.filtered( lambda sol: sol.qty_delivered_method == "field_service" ) complete = self.env.ref("fieldservice.fsm_stage_completed") for line in lines_by_fsm: qty = 0 if line.fsm_order_id.stage_id == complete: qty = line.product_uom_qty line.qty_delivered = qty return res @api.model_create_multi def create(self, vals_list): lines = super(SaleOrderLine, self).create(vals_list) for line in lines: if line.state == "sale": line.order_id._field_service_generation() return line def _prepare_invoice_line(self, **optional_values): res = super()._prepare_invoice_line(**optional_values) if self.fsm_order_id: res.update( { "fsm_order_ids": [(4, self.fsm_order_id.id)], } ) return res
35.176471
2,392
1,388
py
PYTHON
15.0
# Copyright (C) 2019 Brian McMaster # Copyright (C) 2019 Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import api, fields, models class ProductTemplate(models.Model): _inherit = "product.template" service_type = fields.Selection( selection_add=[ ("field", "Field Service Orders"), ], ondelete={"field": "cascade"}, ) field_service_tracking = fields.Selection( [ ("no", "Don't create FSM order"), ("sale", "Create one FSM order per sale order"), ("line", "Create one FSM order per sale order line"), ], default="no", help="""Determines what happens upon sale order confirmation: - None: nothing additional, default behavior. - Per Sale Order: One FSM Order will be created for the sale. - Per Sale Order Line: One FSM Order for each sale order line will be created.""", ) fsm_order_template_id = fields.Many2one( "fsm.template", "Field Service Order Template", help="Select the field service order template to be created", ) @api.onchange("field_service_tracking") def _onchange_field_service_tracking(self): if self.field_service_tracking == "no": self.fsm_order_template_id = False
35.589744
1,388
679
py
PYTHON
15.0
# Copyright (C) 2021 Raphaël Reverdy <[email protected]> # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { "name": "Field Service - Calendar", "summary": "Add calendar to FSM Orders", "author": "Akretion, Odoo Community Association (OCA)", "website": "https://github.com/OCA/field-service", "category": "Field Service", "license": "AGPL-3", "version": "15.0.1.0.0", "depends": [ "calendar", "fieldservice", ], "data": [ "views/fsm_order.xml", "views/fsm_team.xml", ], "installable": True, "development_status": "Beta", "maintainers": [ "hparfr", ], }
28.25
678
3,515
py
PYTHON
15.0
# Copyright (C) 2021 Raphaël Reverdy <[email protected]> # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import fields from odoo.tests.common import TransactionCase class TestFSMOrder(TransactionCase): def setUp(self): super(TestFSMOrder, self).setUp() self.Order = self.env["fsm.order"] self.test_location = self.env.ref("fieldservice.test_location") self.location_1 = self.env.ref("fieldservice.location_1") self.team = self.Order._default_team_id() self.team.calendar_user_id = self.env.ref("base.partner_root").id self.person_id = self.env.ref("fieldservice.person_2") self.person_id3 = self.env.ref("fieldservice.person_3") def test_fsm_order_no_duration(self): new = self.Order.create( { "location_id": self.test_location.id, # no duration = no calendar } ) evt = new.calendar_event_id self.assertFalse(evt.exists()) def test_fsm_order_no_calendar_user(self): self.team.calendar_user_id = False # no calendar user_id = no calendar event new = self.Order.create( { "location_id": self.test_location.id, "scheduled_date_start": fields.Datetime.today(), "scheduled_duration": 2, } ) evt = new.calendar_event_id self.assertFalse(evt.exists()) self.team.calendar_user_id = self.env.ref("base.partner_root").id # update order new.write({"scheduled_duration": 3}) new.write({"location_id": self.location_1.id}) evt = new.calendar_event_id self.assertTrue(evt.exists()) evt.with_context(recurse_order_calendar=False).write({"duration": 5}) # ensure deletion new.scheduled_date_start = False evt = new.calendar_event_id self.assertFalse(evt.exists()) def test_fsm_order_unlink(self): # Create an Orders new = self.Order.create( { "location_id": self.test_location.id, "scheduled_date_start": fields.Datetime.today(), "scheduled_duration": 2, } ) evt = new.calendar_event_id self.assertTrue(evt.exists()) # delete the order new.unlink() # ensure the evt is deleted # this test may fail if another module # archive instead of unlink (like gcalendar) self.assertFalse(evt.exists()) def test_fsm_order_ensure_attendee(self): # Create an Orders new = self.Order.create( { "location_id": self.test_location.id, "scheduled_date_start": fields.Datetime.today(), "scheduled_duration": 2, } ) evt = new.calendar_event_id self.assertTrue( len(evt.partner_ids) == 1, "There should be no other attendees" " because there is no one assigned", ) # organiser is attendee new.person_id = self.person_id evt.with_context(recurse_order_calendar=False).write({"partner_ids": []}) self.assertTrue(self.person_id.partner_id in evt.partner_ids) new.person_id = self.person_id3 self.assertTrue(self.person_id3.partner_id in evt.partner_ids) self.assertTrue( len(evt.partner_ids) == 2, "Not workers should be removed from attendees" )
36.989474
3,514
4,281
py
PYTHON
15.0
# Copyright (C) 2021 Raphaël Reverdy <[email protected]> # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import api, fields, models class FSMOrder(models.Model): _inherit = "fsm.order" calendar_event_id = fields.Many2one( "calendar.event", string="Meeting", readonly=True, ) @api.model_create_multi def create(self, vals_list): res = super().create(vals_list) res._create_calendar_event() return res def _create_calendar_event(self): """Create entry in calendar of the team.""" for order in self._should_have_calendar_event(): order.calendar_event_id = ( self.env["calendar.event"] .with_context(no_mail_to_attendees=True) .create(order._prepare_calendar_event()) ) def _should_have_calendar_event(self): return self.filtered("team_id.calendar_user_id").filtered( "scheduled_date_start" ) def _prepare_calendar_event(self): model_id = self.env.ref("fieldservice.model_fsm_order").id vals = { "name": self.name, "description": self.description, "start": self.scheduled_date_start, "stop": self.scheduled_date_end, "allday": False, "res_model_id": model_id, # link back with "Document" button "res_id": self.id, # link back with "Document" button "location": self._serialize_location(), "user_id": self.team_id.calendar_user_id.id, } vals["partner_ids"] = [(4, self.team_id.calendar_user_id.partner_id.id, False)] # we let calendar_user has a partner_ids in order # to have the meeting in the team's calendar return vals def write(self, vals): old_persons = {} for rec in self: old_persons[rec.id] = rec.person_id res = super().write(vals) to_update = self.create_or_delete_calendar() with_calendar = to_update.filtered("calendar_event_id") if "scheduled_date_start" in vals or "scheduled_date_end" in vals: with_calendar.update_calendar_date(vals) if "location_id" in vals: with_calendar.update_calendar_location() if "person_id" in vals: with_calendar.update_calendar_person(old_persons) return res def unlink(self): self._rm_calendar_event() return super().unlink() def create_or_delete_calendar(self): to_update = self._should_have_calendar_event() to_rm = self - to_update to_create = to_update.filtered(lambda x: x.calendar_event_id.id is False) to_create._create_calendar_event() to_rm._rm_calendar_event() return to_update def _rm_calendar_event(self): # it can be archived instead if desired self.calendar_event_id.unlink() def update_calendar_date(self, vals): if self._context.get("recurse_order_calendar"): # avoid recursion return to_apply = {} to_apply["start"] = self.scheduled_date_start to_apply["stop"] = self.scheduled_date_end # always write start and stop in order to calc duration self.mapped("calendar_event_id").with_context( recurse_order_calendar=True ).write(to_apply) def update_calendar_location(self): for rec in self: rec.calendar_event_id.location = rec._serialize_location() def _serialize_location(self): partner_id = self.location_id.partner_id return f"{partner_id.name} {partner_id._display_address()}" def update_calendar_person(self, old_persons): if self._context.get("recurse_order_calendar"): # avoid recursion return for rec in self: with_ctx = rec.calendar_event_id.with_context(recurse_order_calendar=True) if old_persons.get(rec.id): # remove buddy with_ctx.partner_ids = [(3, old_persons[rec.id].partner_id.id, False)] if rec.person_id: # add the new one with_ctx.partner_ids = [(4, rec.person_id.partner_id.id, False)]
36.896552
4,280
1,733
py
PYTHON
15.0
# Copyright (C) 2021 Raphaël Reverdy <[email protected]> # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import fields, models class Meeting(models.Model): _inherit = "calendar.event" fsm_order_id = fields.One2many( string="Order id", comodel_name="fsm.order", inverse_name="calendar_event_id", ) def _update_fsm_order_date(self): self.ensure_one() if self._context.get("recurse_order_calendar"): # avoid recursion return to_apply = {} to_apply["scheduled_date_start"] = self.start to_apply["scheduled_duration"] = self.duration self.fsm_order_id.with_context(recurse_order_calendar=True).write(to_apply) def _update_fsm_assigned(self): # update back fsm_order when an attenndee is member of a team self.ensure_one() if self._context.get("recurse_order_calendar"): # avoid recursion return person_id = None for partner in self.partner_ids: if partner.fsm_person: person_id = ( self.env["fsm.person"] .search([["partner_id", "=", partner.id]], limit=1) .id ) break self.fsm_order_id.with_context(recurse_order_calendar=True).write( {"person_id": person_id} ) def write(self, values): res = super().write(values) if self.fsm_order_id: if "start" in values or "duration" in values: self._update_fsm_order_date() if "partner_ids" in values: self._update_fsm_assigned() return res
33.307692
1,732
375
py
PYTHON
15.0
# Copyright (C) 2021 Raphaël Reverdy <[email protected]> # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import fields, models class FSMTeam(models.Model): _inherit = "fsm.team" calendar_user_id = fields.Many2one( "res.users", string="Team's calendar", help="Responsible for orders's calendar", )
26.714286
374
867
py
PYTHON
15.0
# Copyright (C) 2018 Brian McMaster # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { "name": "Field Service - Stock", "summary": "Integrate the logistics operations with Field Service", "version": "15.0.1.0.1", "category": "Field Service", "author": "Open Source Integrators, " "Brian McMaster, " "Odoo Community Association (OCA)", "website": "https://github.com/OCA/field-service", "depends": ["fieldservice", "stock"], "data": [ "security/ir.model.access.csv", "data/fsm_stock_data.xml", "views/res_territory.xml", "views/fsm_location.xml", "views/fsm_order.xml", "views/stock.xml", "views/stock_picking.xml", ], "license": "AGPL-3", "development_status": "Beta", "maintainers": ["brian10048", "wolfhall", "max3903", "smangukiya"], }
33.346154
867
569
py
PYTHON
15.0
# Copyright (C) 2021 - TODAY, Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo.tests.common import TransactionCase class FSMWizard(TransactionCase): """ Test used to check that the base functionalities of Field Service Stock. """ def setUp(self): super(FSMWizard, self).setUp() self.Wizard = self.env["fsm.wizard"] self.test_partner = self.env.ref("fieldservice.test_partner") def test_prepare_location(self): self.Wizard._prepare_fsm_location(self.test_partner)
31.611111
569
6,702
py
PYTHON
15.0
# Copyright (C) 2020, Brian McMaster # Copyright (C) 2021 - TODAY, Open Source Integrators # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html) from datetime import timedelta from odoo import fields from odoo.tests.common import TransactionCase class TestFSMStockCommon(TransactionCase): def setUp(self): super(TestFSMStockCommon, self).setUp() self.location = self.env["fsm.location"] self.FSMOrder = self.env["fsm.order"] self.Product = self.env["product.product"].search([], limit=1) self.stock_cust_loc = self.env.ref("stock.stock_location_customers") self.stock_location = self.env.ref("stock.stock_location_stock") self.customer_location = self.env.ref("stock.stock_location_customers") self.test_location = self.env.ref("fieldservice.test_location") self.test_location2 = self.env["fsm.location"].create( { "name": "Test location 2", "partner_id": self.env.ref("fieldservice.location_partner_1").id, "owner_id": self.env.ref("fieldservice.location_partner_1").id, "fsm_parent_id": self.test_location.id, } ) self.partner_1 = ( self.env["res.partner"] .with_context(tracking_disable=True) .create({"name": "Partner 1"}) ) self.customer = self.env["res.partner"].create({"name": "SuperPartner"}) def test_fsm_orders(self): """Test creating new workorders, and test following functions.""" # Create an Orders warehouse = self.env["stock.warehouse"].search([], limit=1) hours_diff = 100 pick_list = [] order_in_pickings = [] order_pick_list2 = [] date_start = fields.Datetime.today() order = self.FSMOrder.create( { "location_id": self.test_location.id, "date_start": date_start, "date_end": date_start + timedelta(hours=hours_diff), "request_early": fields.Datetime.today(), } ) order2 = self.FSMOrder.create( { "location_id": self.test_location2.id, "date_start": date_start, "date_end": date_start + timedelta(hours=50), "request_early": fields.Datetime.today(), } ) order3 = self.FSMOrder.create( { "location_id": self.test_location.id, "date_start": date_start, "date_end": date_start + timedelta(hours=50), "request_early": fields.Datetime.today(), } ) self.picking = self.env["stock.picking"].create( { "location_dest_id": self.stock_location.id, "location_id": self.customer_location.id, "partner_id": self.customer.id, "picking_type_id": self.env.ref("stock.picking_type_in").id, "fsm_order_id": order3.id, } ) self.picking1 = self.env["stock.picking"].create( { "location_dest_id": self.stock_location.id, "location_id": self.customer_location.id, "partner_id": self.customer.id, "picking_type_id": self.env.ref("stock.picking_type_in").id, "fsm_order_id": order3.id, } ) order_in_pickings.append(self.picking.id) order_in_pickings.append(self.picking1.id) self.in_picking = self.env["stock.picking"].create( { "location_dest_id": self.stock_location.id, "location_id": self.customer_location.id, "partner_id": self.customer.id, "picking_type_id": self.env.ref("stock.picking_type_in").id, "fsm_order_id": order.id, } ) order_pick_list2.append(self.in_picking.id) self.out_picking = self.env["stock.picking"].create( { "location_id": self.stock_location.id, "location_dest_id": self.customer_location.id, "partner_id": self.customer.id, "picking_type_id": self.env.ref("stock.picking_type_out").id, } ) order_pick_list2.append(self.out_picking.id) self.out_picking2 = self.env["stock.picking"].create( { "location_id": self.stock_location.id, "location_dest_id": self.customer_location.id, "partner_id": self.customer.id, "picking_type_id": self.env.ref("stock.picking_type_out").id, "fsm_order_id": order2.id, } ) pick_list.append(self.out_picking2.id) self.out_picking3 = self.env["stock.picking"].create( { "location_id": self.stock_location.id, "location_dest_id": self.customer_location.id, "partner_id": self.customer.id, "picking_type_id": self.env.ref("stock.picking_type_out").id, "fsm_order_id": order2.id, } ) rule = self.env["stock.rule"].create( { "name": "Rule Supplier", "route_id": warehouse.reception_route_id.id, "location_id": warehouse.lot_stock_id.id, "location_src_id": self.env.ref("stock.stock_location_suppliers").id, "action": "pull", "delay": 9.0, "procure_method": "make_to_stock", "picking_type_id": warehouse.in_type_id.id, } ) rule._get_stock_move_values( self.Product, 1, self.Product.uom_id, warehouse.lot_stock_id, "name", "origin", self.env.user.company_id, {"date_planned": fields.Datetime.today()}, ) pick_list.append(self.out_picking3.id) order2.picking_ids = [(6, 0, pick_list)] order3.picking_ids = [(6, 0, order_in_pickings)] order.picking_ids = [(6, 0, order_pick_list2)] order._compute_picking_ids() order.location_id._onchange_fsm_parent_id() order2.location_id._onchange_fsm_parent_id() self.assertTrue( order2.location_id.inventory_location_id == order2.location_id.fsm_parent_id.inventory_location_id ) order._default_warehouse_id() order.action_view_delivery() order2.action_view_delivery() order3.action_view_returns() order.action_view_returns()
40.865854
6,702
787
py
PYTHON
15.0
# Copyright (C) 2018 - TODAY, Brian McMaster # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import api, fields, models class FSMLocation(models.Model): _inherit = "fsm.location" inventory_location_id = fields.Many2one( "stock.location", string="Inventory Location", required=True, default=lambda self: self.env.ref("stock.stock_location_customers"), ) shipping_address_id = fields.Many2one("res.partner", string="Shipping Location") @api.onchange("fsm_parent_id") def _onchange_fsm_parent_id(self): res = super(FSMLocation, self)._onchange_fsm_parent_id() if self.fsm_parent_id: self.inventory_location_id = self.fsm_parent_id.inventory_location_id.id return res
34.217391
787
3,597
py
PYTHON
15.0
# Copyright (C) 2018 - TODAY, Brian McMaster # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import api, fields, models class FSMOrder(models.Model): _inherit = "fsm.order" @api.model def _default_warehouse_id(self): company = self.env.user.company_id.id warehouse_ids = self.env["stock.warehouse"].search( [("company_id", "=", company)], limit=1 ) return warehouse_ids and warehouse_ids.id @api.model def _get_move_domain(self): return [("picking_id.picking_type_id.code", "in", ("outgoing", "incoming"))] picking_ids = fields.One2many("stock.picking", "fsm_order_id", string="Transfers") delivery_count = fields.Integer( string="Delivery Orders", compute="_compute_picking_ids" ) procurement_group_id = fields.Many2one( "procurement.group", "Procurement Group", copy=False ) inventory_location_id = fields.Many2one( related="location_id.inventory_location_id", ) warehouse_id = fields.Many2one( "stock.warehouse", string="Warehouse", required=True, default=_default_warehouse_id, help="Warehouse used to ship the materials", ) return_count = fields.Integer( string="Return Orders", compute="_compute_picking_ids" ) move_ids = fields.One2many( "stock.move", "fsm_order_id", string="Operations", domain=_get_move_domain ) @api.depends("picking_ids") def _compute_picking_ids(self): for order in self: outgoing_pickings = order.picking_ids.filtered( lambda p: p.picking_type_id.code == "outgoing" ) order.delivery_count = len(outgoing_pickings.ids) incoming_pickings = order.picking_ids.filtered( lambda p: p.picking_type_id.code == "incoming" ) order.return_count = len(incoming_pickings.ids) def action_view_delivery(self): """ This function returns an action that display existing delivery orders of given fsm order ids. It can either be a in a list or in a form view, if there is only one delivery order to show. """ action = self.env["ir.actions.act_window"]._for_xml_id( "stock.action_picking_tree_all" ) pickings = self.mapped("picking_ids") delivery_ids = self.picking_ids.filtered( lambda p: p.picking_type_id.code == "outgoing" ).ids if len(delivery_ids) > 1: action["domain"] = [("id", "in", delivery_ids)] elif pickings: action["views"] = [(self.env.ref("stock.view_picking_form").id, "form")] action["res_id"] = delivery_ids[0] return action def action_view_returns(self): """ This function returns an action that display existing return orders of given fsm order ids. It can either be a in a list or in a form view, if there is only one return order to show. """ action = self.env["ir.actions.act_window"]._for_xml_id( "stock.action_picking_tree_all" ) pickings = self.mapped("picking_ids") return_ids = self.picking_ids.filtered( lambda p: p.picking_type_id.code == "incoming" ).ids if len(return_ids) > 1: action["domain"] = [("id", "in", return_ids)] elif pickings: action["views"] = [(self.env.ref("stock.view_picking_form").id, "form")] action["res_id"] = return_ids[0] return action
37.46875
3,597
283
py
PYTHON
15.0
# Copyright (C) 2019 Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import fields, models class ResTerritory(models.Model): _inherit = "res.territory" warehouse_id = fields.Many2one("stock.warehouse", string="Warehouse")
31.444444
283
272
py
PYTHON
15.0
# Copyright (C) 2018 Brian McMaster # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import fields, models class StockMove(models.Model): _inherit = "stock.move" fsm_order_id = fields.Many2one("fsm.order", string="Field Service Order")
30.222222
272
324
py
PYTHON
15.0
# Copyright (C) 2018 Brian McMaster # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import fields, models class StockPicking(models.Model): _inherit = "stock.picking" fsm_order_id = fields.Many2one( related="group_id.fsm_order_id", string="Field Service Order", store=True )
29.454545
324
279
py
PYTHON
15.0
# Copyright (C) 2018 Brian McMaster # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import fields, models class ProcurementGroup(models.Model): _inherit = "procurement.group" fsm_order_id = fields.Many2one("fsm.order", "Field Service Order")
31
279
406
py
PYTHON
15.0
# Copyright (C) 2018 - TODAY, Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import models class FSMWizard(models.TransientModel): _inherit = "fsm.wizard" def _prepare_fsm_location(self, partner): res = super()._prepare_fsm_location(partner) res["inventory_location_id"] = partner.property_stock_customer.id return res
31.230769
406