-
-
Notifications
You must be signed in to change notification settings - Fork 265
Open
Labels
Description
Origin: #600
I'm not sure if this should be a separate module like website_sale_operating_unit or it should be handled here
To reproduce:
- Install website_sale;
- create a product and publish it;
- make sure the sales team is set to "Website" on the website (this is by default)
- create a OU "Online Orders" or whatever and change the operating unit on the sales team to it
- go to /shop and click "Add to Cart"
- This error occurs:
- Configuration error. The Operating Unit of the sales team must match with that of the quote/sales order.
I fixed it by replacing it with compute and inverse but keeping the onchanges for ux
operating_unit_id = fields.Many2one(
comodel_name="operating.unit",
string="Operating Unit",
compute="_compute_operating_unit_id",
default=_default_operating_unit,
store=True,
readonly=True,
states={"draft": [("readonly", False)], "sent": [("readonly", False)]},
)
@api.onchange("team_id")
@api.depends("team_id", "team_id.operating_unit_id")
def _compute_operating_unit_id(self):
for sale in self.filtered(lambda s: s.state in ("draft", "sent") and s.team_id.operating_unit_id):
sale.operating_unit_id = sale.team_id.operating_unit_id
@api.onchange("operating_unit_id")
def _onchange_operating_unit_id(self):
for sale in self.filtered(
lambda s: s.state in ("draft", "sent")
and s.operating_unit_id != s.team_id.operating_unit_id
):
sale.team_id = self.env["crm.team"].search(
[("operating_unit_id", "=", sale.operating_unit_id.id)], limit=1
)This will also need a pre_init_hook, because the root user is assigned to an operating unit, which causes the sales team to be assigned an operating unit as well when the sales_team_operating_unit module is installed.
https://github.com/OCA/operating-unit/blob/16.0/operating_unit/data/operating_unit_data.xml
operating-unit/sales_team_operating_unit/models/crm_team.py
Lines 13 to 16 in 77d307a
| operating_unit_id = fields.Many2one( | |
| "operating.unit", | |
| default=lambda self: self.env["res.users"].operating_unit_default_get(), | |
| ) |