|
1 | 1 | # Copyright (C) 2018 - TODAY, Open Source Integrators
|
2 | 2 | # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
3 | 3 |
|
4 |
| -from odoo import fields, models |
| 4 | +from odoo import api, fields, models |
5 | 5 |
|
6 | 6 |
|
7 | 7 | class ResPartner(models.Model):
|
@@ -52,21 +52,22 @@ def action_open_owned_locations(self):
|
52 | 52 | return action
|
53 | 53 |
|
54 | 54 | def _convert_fsm_location(self):
|
55 |
| - wiz = self.env["fsm.wizard"] |
56 |
| - partners_with_loc_ids = ( |
57 |
| - self.env["fsm.location"] |
58 |
| - .sudo() |
59 |
| - .search([("active", "in", [False, True]), ("partner_id", "in", self.ids)]) |
60 |
| - .mapped("partner_id") |
61 |
| - ).ids |
| 55 | + """Build service location when adding child partner with type=fsm_location.""" |
| 56 | + if self.env.context.get("creating_fsm_location"): |
| 57 | + return # partner created by inheritance from fsm.location |
| 58 | + for partner in self: |
| 59 | + if partner.type == "fsm_location" and not partner.fsm_location_id: |
| 60 | + self.env["fsm.wizard"].action_convert_location(partner) |
62 | 61 |
|
63 |
| - partners_to_convert = self.filtered( |
64 |
| - lambda p: p.type == "fsm_location" and p.id not in partners_with_loc_ids |
65 |
| - ) |
66 |
| - for partner_to_convert in partners_to_convert: |
67 |
| - wiz.action_convert_location(partner_to_convert) |
| 62 | + @api.model_create_multi |
| 63 | + def create(self, vals_list): |
| 64 | + partners = super().create(vals_list) |
| 65 | + if any(vals.get("type") == "fsm_location" for vals in vals_list): |
| 66 | + partners._convert_fsm_location() |
| 67 | + return partners |
68 | 68 |
|
69 |
| - def write(self, value): |
70 |
| - res = super().write(value) |
71 |
| - self._convert_fsm_location() |
| 69 | + def write(self, vals): |
| 70 | + res = super().write(vals) |
| 71 | + if vals.get("type") == "fsm_location": |
| 72 | + self._convert_fsm_location() |
72 | 73 | return res
|
0 commit comments