diff --git a/sale_stock_operating_unit/README.rst b/sale_stock_operating_unit/README.rst index ad0150cc14..435b6d21eb 100644 --- a/sale_stock_operating_unit/README.rst +++ b/sale_stock_operating_unit/README.rst @@ -14,13 +14,13 @@ Operating Unit in Sales Stock :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/15.0/sale_stock_operating_unit + :target: https://github.com/OCA/operating-unit/tree/16.0/sale_stock_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-15-0/operating-unit-15-0-sale_stock_operating_unit + :target: https://translation.odoo-community.org/projects/operating-unit-16-0/operating-unit-16-0-sale_stock_operating_unit :alt: Translate me on Weblate .. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png - :target: https://runbot.odoo-community.org/runbot/213/15.0 + :target: https://runbot.odoo-community.org/runbot/213/16.0 :alt: Try me on Runbot |badge1| |badge2| |badge3| |badge4| |badge5| @@ -59,7 +59,7 @@ Bug Tracker Bugs are tracked on `GitHub Issues `_. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us smashing it by providing a detailed and welcomed -`feedback `_. +`feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -78,6 +78,7 @@ Contributors * Eficent Business and IT Consulting Services S.L. * Serpent Consulting Services Pvt. Ltd. * Alejandro Padrón +* Alan Ramos Maintainers ~~~~~~~~~~~ @@ -92,6 +93,6 @@ 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 `_ project on GitHub. +This module is part of the `OCA/operating-unit `_ project on GitHub. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/sale_stock_operating_unit/__manifest__.py b/sale_stock_operating_unit/__manifest__.py index d85680de17..09d328cbfc 100644 --- a/sale_stock_operating_unit/__manifest__.py +++ b/sale_stock_operating_unit/__manifest__.py @@ -7,7 +7,7 @@ "name": "Operating Unit in Sales Stock", "summary": "An operating unit (OU) is an organizational entity part of a " "company", - "version": "15.0.1.0.0", + "version": "16.0.1.0.0", "author": "Eficent, Serpent Consulting Services Pvt. Ltd., " "Odoo Community Association (OCA)", "license": "LGPL-3", diff --git a/sale_stock_operating_unit/models/__init__.py b/sale_stock_operating_unit/models/__init__.py index 18ebfa1c1e..82374d1641 100644 --- a/sale_stock_operating_unit/models/__init__.py +++ b/sale_stock_operating_unit/models/__init__.py @@ -1,4 +1,5 @@ # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +from . import res_users from . import sale_order from . import stock_move from . import stock_warehouse diff --git a/sale_stock_operating_unit/models/res_users.py b/sale_stock_operating_unit/models/res_users.py new file mode 100644 index 0000000000..cc2ab5f27a --- /dev/null +++ b/sale_stock_operating_unit/models/res_users.py @@ -0,0 +1,20 @@ +# Copyright 2023 Jarsa +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +from odoo import models + + +class ResUsers(models.Model): + _inherit = "res.users" + + def _get_default_warehouse_id(self): + warehouse = self.env["stock.warehouse"].search( + [ + ("company_id", "=", self.env.company.id), + ("operating_unit_id", "=", self.team_id.operating_unit_id.id), + ], + limit=1, + ) + if not warehouse: + return super()._get_default_warehouse_id() + return warehouse diff --git a/sale_stock_operating_unit/models/sale_order.py b/sale_stock_operating_unit/models/sale_order.py index a54dca31a3..d8699951c9 100644 --- a/sale_stock_operating_unit/models/sale_order.py +++ b/sale_stock_operating_unit/models/sale_order.py @@ -2,38 +2,15 @@ # Jordi Ballester Alomar # Copyright 2015-19 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, fields, models +from odoo import _, api, models from odoo.exceptions import ValidationError class SaleOrder(models.Model): _inherit = "sale.order" - @api.model - def _default_warehouse_id(self): - res = super(SaleOrder, self)._default_warehouse_id() - team = self._get_default_team() - warehouses = self.env["stock.warehouse"].search( - [ - ( - "operating_unit_id", - "=", - team.with_user(SUPERUSER_ID).operating_unit_id.id, - ) - ], - limit=1, - ) - if warehouses: - return warehouses - return res - - warehouse_id = fields.Many2one( - comodel_name="stock.warehouse", default=_default_warehouse_id - ) - @api.onchange("team_id") - def onchange_team_id(self): - res = super(SaleOrder, self).onchange_team_id() + def _onchange_team_id(self): if ( self.team_id and self.team_id.operating_unit_id @@ -46,10 +23,8 @@ def onchange_team_id(self): if warehouses: self.warehouse_id = warehouses[0] - return res - @api.onchange("operating_unit_id") - def onchange_operating_unit_id(self): + def _onchange_operating_unit_id(self): if ( self.operating_unit_id and self.operating_unit_id.id != self.warehouse_id.operating_unit_id.id @@ -61,7 +36,7 @@ def onchange_operating_unit_id(self): self.warehouse_id = warehouses[0] @api.onchange("warehouse_id") - def onchange_warehouse_id(self): + def _onchange_warehouse_id(self): if self.warehouse_id: self.operating_unit_id = self.warehouse_id.operating_unit_id if ( diff --git a/sale_stock_operating_unit/models/stock_move.py b/sale_stock_operating_unit/models/stock_move.py index 77747419e2..cd0a93a083 100644 --- a/sale_stock_operating_unit/models/stock_move.py +++ b/sale_stock_operating_unit/models/stock_move.py @@ -12,7 +12,7 @@ def _get_new_picking_values(self): """ Override to add Operating Units to Picking. """ - values = super(StockMove, self)._get_new_picking_values() + values = super()._get_new_picking_values() values.update( { diff --git a/sale_stock_operating_unit/readme/CONTRIBUTORS.rst b/sale_stock_operating_unit/readme/CONTRIBUTORS.rst index 076ca13fda..b6987b7d99 100644 --- a/sale_stock_operating_unit/readme/CONTRIBUTORS.rst +++ b/sale_stock_operating_unit/readme/CONTRIBUTORS.rst @@ -1,3 +1,4 @@ * Eficent Business and IT Consulting Services S.L. * Serpent Consulting Services Pvt. Ltd. * Alejandro Padrón +* Alan Ramos diff --git a/sale_stock_operating_unit/static/description/index.html b/sale_stock_operating_unit/static/description/index.html index f976e79c6b..42bae34865 100644 --- a/sale_stock_operating_unit/static/description/index.html +++ b/sale_stock_operating_unit/static/description/index.html @@ -3,7 +3,7 @@ - + Operating Unit in Sales Stock