Skip to content

Commit cc77cb3

Browse files
committed
[17.0][ADD] sale_partner_operating_unit
1 parent d0bd1c3 commit cc77cb3

13 files changed

Lines changed: 613 additions & 0 deletions

File tree

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
===========================
2+
Sale Partner Operating Unit
3+
===========================
4+
5+
..
6+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
7+
!! This file is generated by oca-gen-addon-readme !!
8+
!! changes will be overwritten. !!
9+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10+
!! source digest: sha256:78fb292c8f1e1718ad7edc8d1f1199839efe327922a48f467289551d4ab071b9
11+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
12+
13+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
14+
:target: https://odoo-community.org/page/development-status
15+
:alt: Beta
16+
.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png
17+
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
18+
:alt: License: LGPL-3
19+
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Foperating--unit-lightgray.png?logo=github
20+
:target: https://github.com/OCA/operating-unit/tree/17.0/sale_partner_operating_unit
21+
:alt: OCA/operating-unit
22+
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23+
:target: https://translation.odoo-community.org/projects/operating-unit-17-0/operating-unit-17-0-sale_partner_operating_unit
24+
:alt: Translate me on Weblate
25+
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/operating-unit&target_branch=17.0
27+
:alt: Try me on Runboat
28+
29+
|badge1| |badge2| |badge3| |badge4| |badge5|
30+
31+
This module introduces the following features:
32+
33+
- Adds the Operating Unit (OU) to the sale order depending on
34+
customers' Operating Unit.
35+
36+
**Table of contents**
37+
38+
.. contents::
39+
:local:
40+
41+
Usage
42+
=====
43+
44+
Add the operating unit to a sale orders' Customer (partner_id). The
45+
orders' operating unit will be updated accordingly.
46+
47+
Bug Tracker
48+
===========
49+
50+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/operating-unit/issues>`_.
51+
In case of trouble, please check there if your issue has already been reported.
52+
If you spotted it first, help us to smash it by providing a detailed and welcomed
53+
`feedback <https://github.com/OCA/operating-unit/issues/new?body=module:%20sale_partner_operating_unit%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
54+
55+
Do not contact contributors directly about support or help with technical issues.
56+
57+
Credits
58+
=======
59+
60+
Authors
61+
-------
62+
63+
* Camptocamp SA
64+
65+
Contributors
66+
------------
67+
68+
- Maksym Yankin <maksym.yankin@camptocamp.com>
69+
70+
Maintainers
71+
-----------
72+
73+
This module is maintained by the OCA.
74+
75+
.. image:: https://odoo-community.org/logo.png
76+
:alt: Odoo Community Association
77+
:target: https://odoo-community.org
78+
79+
OCA, or the Odoo Community Association, is a nonprofit organization whose
80+
mission is to support the collaborative development of Odoo features and
81+
promote its widespread use.
82+
83+
This module is part of the `OCA/operating-unit <https://github.com/OCA/operating-unit/tree/17.0/sale_partner_operating_unit>`_ project on GitHub.
84+
85+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import models
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Copyright 2025 Camptocamp SA
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
3+
{
4+
"name": "Sale Partner Operating Unit",
5+
"version": "17.0.1.0.0",
6+
"author": "Camptocamp SA, Odoo Community Association (OCA)",
7+
"license": "LGPL-3",
8+
"website": "https://github.com/OCA/operating-unit",
9+
"category": "Product",
10+
"depends": [
11+
# OCA/operating-unit
12+
"res_partner_operating_unit",
13+
"sale_operating_unit",
14+
],
15+
"installable": True,
16+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import sale_order
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Copyright 2025 Camptocamp SA
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
3+
4+
from odoo import api, models
5+
6+
7+
class SaleOrder(models.Model):
8+
_inherit = "sale.order"
9+
10+
@api.depends("partner_id.operating_unit_ids")
11+
def _compute_team_id(self):
12+
# For orders without a team, if the partner's ``operating_unit_ids``
13+
# is set exactly one, we skip the computation of the team.
14+
skip_teams_sales = self.filtered(
15+
lambda order: not order.team_id
16+
and order.partner_id.operating_unit_ids
17+
and (len(order.partner_id.operating_unit_ids) == 1)
18+
)
19+
if skip_teams_sales:
20+
self = self - skip_teams_sales
21+
return super()._compute_team_id()
22+
23+
@api.depends("team_id", "partner_id.operating_unit_ids")
24+
def _compute_operating_unit_id(self):
25+
# For orders without a team, use the partner's ``operating_unit_ids``
26+
# if exactly one is set.
27+
if orders_without_team := self.filtered(lambda order: not order.team_id):
28+
for order in orders_without_team:
29+
if len(order.partner_id.operating_unit_ids) == 1:
30+
order.operating_unit_id = order.partner_id.operating_unit_ids
31+
else:
32+
order.operating_unit_id = False
33+
34+
# For orders with a team, let the super method compute the operating unit.
35+
return super(SaleOrder, self - orders_without_team)._compute_operating_unit_id()
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[build-system]
2+
requires = ["whool"]
3+
build-backend = "whool.buildapi"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Maksym Yankin \<<maksym.yankin@camptocamp.com>\>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This module introduces the following features:
2+
3+
- Adds the Operating Unit (OU) to the sale order depending on customers' Operating Unit.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Add the operating unit to a sale orders' Customer (partner_id).
2+
The orders' operating unit will be updated accordingly.
9.23 KB
Loading

0 commit comments

Comments
 (0)