Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0] [MIG] sale_operating_unit #600

Open
wants to merge 34 commits into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
3559aae
Migrated sale_operating_unit module and its test cases.
sudhir-serpentcs Feb 9, 2016
d390fb6
Added OU and WH constraints in SO.
sudhir-serpentcs Feb 10, 2016
dd3aec9
migrate code to v9 (wip)
AaronHForgeFlow Aug 23, 2016
704248e
[MIG] sale_operating_unit: Migrated to 10.0
AaronHForgeFlow Jan 31, 2017
d669c15
[FIX] readonly on OU
serpentcs-dev1 Jul 4, 2017
3b87cab
[MIG] sale_operating_unit: Migration to v11
bjeficent Jan 31, 2019
b52bc25
[ADD] icon.png
OCA-git-bot May 21, 2019
8587b75
[UPD] README.rst
OCA-git-bot Jul 29, 2019
b2dc076
[MIG]sale_operating_unit to v12
bjeficent Nov 26, 2019
7adfd3a
[IMP]sale advance payment to include the OU
AaronHForgeFlow Nov 26, 2019
79c991b
[UPD] Update sale_operating_unit.pot
oca-travis Nov 26, 2019
58d962c
[UPD] README.rst
OCA-git-bot Nov 26, 2019
c849612
[FIX] Delete uncalled file
MiquelRForgeFlow Nov 29, 2019
a56ea23
[UPD] Update sale_operating_unit.pot
oca-travis Nov 29, 2019
6a010c9
sale_operating_unit 12.0.1.0.1
OCA-git-bot Nov 29, 2019
bc7058a
[IMP] sale_operating_unit: black, isort
alan196 Feb 12, 2020
9347385
[MIG] sale_operating_unit: Migration to V13
alan196 Feb 12, 2020
a5ba9a7
[UPD] Update sale_operating_unit.pot
oca-travis Apr 16, 2020
cb78e06
[UPD] Eficent -> ForgeFlow
MiquelRForgeFlow Oct 5, 2020
eb57b3f
[UPD] README.rst
OCA-git-bot Oct 5, 2020
b769afb
[MIG] sale_operating_unit: Migration to 14.0
olveracuenca Mar 9, 2022
a1ed7cc
[UPD] README.rst
OCA-git-bot Oct 25, 2022
b5a2215
[UPD] Update sale_operating_unit.pot
Jan 17, 2023
d3bbc75
[FIX] Error sale report to add fiel operating unit
cramosh Jan 27, 2023
2fef895
[FIX] 14.0 sale_operating_unit Error sale report to add field operati…
cramosh Jan 27, 2023
56929b9
[UPD] README.rst
OCA-git-bot Jan 27, 2023
d175f80
sale_operating_unit 14.0.1.0.1
OCA-git-bot Jan 27, 2023
66e2846
[FIX] sale_operating_unit: make operating_unit_id field in sale.order…
alan196 Oct 6, 2022
89f637e
[15.0][MIG] sale_operating_unit: Migration to 15.0
Jun 20, 2022
78a10f4
[UPD] Update sale_operating_unit.pot
Jun 6, 2023
bc9770f
[UPD] README.rst
OCA-git-bot Jun 6, 2023
d78a946
[IMP] sale_operating_unit: pre-commit stuff
Borruso Jun 22, 2023
2f693bd
[MIG] sale_operating_unit: Migration to 16.0
Borruso Jun 22, 2023
80fe82d
[IMP] sale_operating_unit: allowed to hide operating_unit_id in list …
alexeirivera87 Sep 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 105 additions & 0 deletions sale_operating_unit/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
=======================
Operating Unit in Sales
=======================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:dda84076d9ffa732648bf2edae5480a5da3510410a0073b83a213b8bd707c2da
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Foperating--unit-lightgray.png?logo=github
:target: https://github.com/OCA/operating-unit/tree/16.0/sale_operating_unit
:alt: OCA/operating-unit
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/operating-unit-16-0/operating-unit-16-0-sale_operating_unit
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/operating-unit&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module extends the Sales capabilities of Odoo and introduces the operating
unit to the Sales Order. Security rules are defined to ensure that users can
only display the Sales Orders in which they are allowed access to.

**Table of contents**

.. contents::
:local:

Usage
=====

Follow these steps:

#. Create a Sale Order.
#. The Operating Unit of the Sale Team is assigned to the Sale Order.

Known issues / Roadmap
======================

The onchange_team_id method is not working.
If you try to change the team in a sales quotation and the operating unit
is not taken from the sales team, and moreover, I cannot select the operating unit
from the team, only Main OU shows, must have to have your salesperson in the sales team
of the operating unit.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/operating-unit/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/operating-unit/issues/new?body=module:%20sale_operating_unit%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
~~~~~~~

* ForgeFlow
* Serpent Consulting Services Pvt. Ltd.

Contributors
~~~~~~~~~~~~

* Jordi Ballester Alomar <[email protected]>
* Aaron Henriquez <[email protected]>
* Lois Rilo <[email protected]>
* Miquel Raich <[email protected]>
* Sudhir Arya <[email protected]>
* Darshan Patel <[email protected]>
* Alan Ramos <[email protected]>
* Jorge Alberto Olvera Cuenca <[email protected]>
* Alejandro Padrón <[email protected]>
* Alexei Rivera <[email protected]>

Maintainers
~~~~~~~~~~~

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/operating-unit <https://github.com/OCA/operating-unit/tree/16.0/sale_operating_unit>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
5 changes: 5 additions & 0 deletions sale_operating_unit/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).

from . import models
from . import report
from . import wizard
23 changes: 23 additions & 0 deletions sale_operating_unit/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# © 2019 ForgeFlow S.L.
# - Jordi Ballester Alomar
# © 2019 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
{
"name": "Operating Unit in Sales",
"version": "16.0.1.0.0",
"summary": "An operating unit (OU) is an organizational entity part of a "
"company",
"author": "ForgeFlow, "
"Serpent Consulting Services Pvt. Ltd.,"
"Odoo Community Association (OCA)",
"license": "LGPL-3",
"website": "https://github.com/OCA/operating-unit",
"category": "Sales Management",
"depends": ["sale", "account_operating_unit", "sales_team_operating_unit"],
"data": [
"security/sale_security.xml",
"views/sale_view.xml",
"views/sale_report_view.xml",
],
"installable": True,
}
72 changes: 72 additions & 0 deletions sale_operating_unit/i18n/sale_operating_unit.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * sale_operating_unit
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 15.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: sale_operating_unit
#: code:addons/sale_operating_unit/models/crm_team.py:0
#, python-format
msgid ""
"Configuration error. It is not possible to change this team. There are sale "
"orders referencing it in other operating units"
msgstr ""

#. module: sale_operating_unit
#: code:addons/sale_operating_unit/models/sale_order.py:0
#, python-format
msgid ""
"Configuration error. The Company in the Sales Order and in the Operating "
"Unit must be the same."
msgstr ""

#. module: sale_operating_unit
#: code:addons/sale_operating_unit/models/sale_order.py:0
#, python-format
msgid ""
"Configuration error. The Operating Unit of the sales team must match with "
"that of the quote/sales order."
msgstr ""

#. module: sale_operating_unit
#: model:ir.model.fields,field_description:sale_operating_unit.field_sale_order__operating_unit_id
#: model:ir.model.fields,field_description:sale_operating_unit.field_sale_order_line__operating_unit_id
#: model:ir.model.fields,field_description:sale_operating_unit.field_sale_report__operating_unit_id
#: model_terms:ir.ui.view,arch_db:sale_operating_unit.view_sale_report_search
#: model_terms:ir.ui.view,arch_db:sale_operating_unit.view_sales_order_filter
msgid "Operating Unit"
msgstr ""

#. module: sale_operating_unit
#: model:ir.model,name:sale_operating_unit.model_sale_advance_payment_inv
msgid "Sales Advance Payment Invoice"
msgstr ""

#. module: sale_operating_unit
#: model:ir.model,name:sale_operating_unit.model_sale_report
msgid "Sales Analysis Report"
msgstr ""

#. module: sale_operating_unit
#: model:ir.model,name:sale_operating_unit.model_sale_order
msgid "Sales Order"
msgstr ""

#. module: sale_operating_unit
#: model:ir.model,name:sale_operating_unit.model_sale_order_line
msgid "Sales Order Line"
msgstr ""

#. module: sale_operating_unit
#: model:ir.model,name:sale_operating_unit.model_crm_team
msgid "Sales Team"
msgstr ""
4 changes: 4 additions & 0 deletions sale_operating_unit/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).

from . import crm_team
from . import sale_order
34 changes: 34 additions & 0 deletions sale_operating_unit/models/crm_team.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# © 2019 ForgeFlow S.L.
# - Jordi Ballester Alomar
# © 2019 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from odoo import SUPERUSER_ID, _, api, models
from odoo.exceptions import ValidationError


class CrmTeam(models.Model):
_inherit = "crm.team"

@api.constrains("operating_unit_id")
def _check_sales_order_operating_unit(self):
for rec in self:
orders = (
self.with_user(SUPERUSER_ID)
.env["sale.order"]
.search(
[
("team_id", "=", rec.id),
("operating_unit_id", "!=", rec.operating_unit_id.id),
]
)
)
if orders:
raise ValidationError(

Check warning on line 26 in sale_operating_unit/models/crm_team.py

View check run for this annotation

Codecov / codecov/patch

sale_operating_unit/models/crm_team.py#L26

Added line #L26 was not covered by tests
_(
"Configuration error. It is not "
"possible to change this "
"team. There are sale orders "
"referencing it in other operating "
"units"
)
)
83 changes: 83 additions & 0 deletions sale_operating_unit/models/sale_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# © 2019 ForgeFlow S.L.
# - Jordi Ballester Alomar
# © 2019 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from odoo import _, api, fields, models
from odoo.exceptions import ValidationError


class SaleOrder(models.Model):
_inherit = "sale.order"

@api.model
def _default_operating_unit(self):
team = self.env["crm.team"]._get_default_team_id()
if team.operating_unit_id:
return team.operating_unit_id
return self.env.user.default_operating_unit_id

Check warning on line 17 in sale_operating_unit/models/sale_order.py

View check run for this annotation

Codecov / codecov/patch

sale_operating_unit/models/sale_order.py#L17

Added line #L17 was not covered by tests

operating_unit_id = fields.Many2one(
comodel_name="operating.unit",
string="Operating Unit",
default=_default_operating_unit,
readonly=True,
states={"draft": [("readonly", False)], "sent": [("readonly", False)]},
)

@api.onchange("team_id")
def onchange_team_id(self):
if self.team_id:
self.operating_unit_id = self.team_id.operating_unit_id

Check warning on line 30 in sale_operating_unit/models/sale_order.py

View check run for this annotation

Codecov / codecov/patch

sale_operating_unit/models/sale_order.py#L30

Added line #L30 was not covered by tests

@api.onchange("operating_unit_id")
def onchange_operating_unit_id(self):
if self.team_id and self.team_id.operating_unit_id != self.operating_unit_id:
self.team_id = False

Check warning on line 35 in sale_operating_unit/models/sale_order.py

View check run for this annotation

Codecov / codecov/patch

sale_operating_unit/models/sale_order.py#L35

Added line #L35 was not covered by tests

This comment was marked as resolved.

if self.operating_unit_id:
self.team_id = self.env["crm.team"].search(

Check warning on line 37 in sale_operating_unit/models/sale_order.py

View check run for this annotation

Codecov / codecov/patch

sale_operating_unit/models/sale_order.py#L37

Added line #L37 was not covered by tests
[("operating_unit_id", "=", self.operating_unit_id.id)], limit=1
)

@api.constrains("team_id", "operating_unit_id")
def _check_team_operating_unit(self):
for rec in self:
if rec.team_id and rec.team_id.operating_unit_id != rec.operating_unit_id:
raise ValidationError(

Check warning on line 45 in sale_operating_unit/models/sale_order.py

View check run for this annotation

Codecov / codecov/patch

sale_operating_unit/models/sale_order.py#L45

Added line #L45 was not covered by tests
_(
"Configuration error. The Operating "
"Unit of the sales team must match "
"with that of the quote/sales order."
)
)

@api.constrains("operating_unit_id", "company_id")
def _check_company_operating_unit(self):
for rec in self:
if (
rec.company_id
and rec.operating_unit_id
and rec.company_id != rec.operating_unit_id.company_id
):
raise ValidationError(

Check warning on line 61 in sale_operating_unit/models/sale_order.py

View check run for this annotation

Codecov / codecov/patch

sale_operating_unit/models/sale_order.py#L61

Added line #L61 was not covered by tests
_(
"Configuration error. The Company in "
"the Sales Order and in the Operating "
"Unit must be the same."
)
)

def _prepare_invoice(self):
self.ensure_one()
invoice_vals = super(SaleOrder, self)._prepare_invoice()
invoice_vals["operating_unit_id"] = self.operating_unit_id.id
return invoice_vals


class SaleOrderLine(models.Model):
_inherit = "sale.order.line"

operating_unit_id = fields.Many2one(
related="order_id.operating_unit_id",
string="Operating Unit",
store=True,
)
10 changes: 10 additions & 0 deletions sale_operating_unit/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
* Jordi Ballester Alomar <[email protected]>
* Aaron Henriquez <[email protected]>
* Lois Rilo <[email protected]>
* Miquel Raich <[email protected]>
* Sudhir Arya <[email protected]>
* Darshan Patel <[email protected]>
* Alan Ramos <[email protected]>
* Jorge Alberto Olvera Cuenca <[email protected]>
* Alejandro Padrón <[email protected]>
* Alexei Rivera <[email protected]>
3 changes: 3 additions & 0 deletions sale_operating_unit/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This module extends the Sales capabilities of Odoo and introduces the operating
unit to the Sales Order. Security rules are defined to ensure that users can
only display the Sales Orders in which they are allowed access to.
5 changes: 5 additions & 0 deletions sale_operating_unit/readme/ROADMAP.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
The onchange_team_id method is not working.
If you try to change the team in a sales quotation and the operating unit
is not taken from the sales team, and moreover, I cannot select the operating unit
from the team, only Main OU shows, must have to have your salesperson in the sales team
of the operating unit.
4 changes: 4 additions & 0 deletions sale_operating_unit/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Follow these steps:

#. Create a Sale Order.
#. The Operating Unit of the Sale Team is assigned to the Sale Order.
3 changes: 3 additions & 0 deletions sale_operating_unit/report/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from . import sale_report
19 changes: 19 additions & 0 deletions sale_operating_unit/report/sale_report.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl-3.0).

from odoo import fields, models


class SaleReport(models.Model):
_inherit = "sale.report"

operating_unit_id = fields.Many2one("operating.unit", "Operating Unit")

def _group_by_sale(self):
res = super()._group_by_sale()
res += """, s.operating_unit_id"""
return res

def _select_additional_fields(self):
res = super()._select_additional_fields()
res["operating_unit_id"] = "s.operating_unit_id"
return res
Loading
Loading