Skip to content

Commit

Permalink
[MIG] sale_stock_operating_unit: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
alan196 committed Jul 27, 2023
1 parent e20e217 commit 4ce1da7
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 71 deletions.
11 changes: 6 additions & 5 deletions sale_stock_operating_unit/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down Expand Up @@ -59,7 +59,7 @@ 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 smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/operating-unit/issues/new?body=module:%20sale_stock_operating_unit%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/operating-unit/issues/new?body=module:%20sale_stock_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.

Expand All @@ -78,6 +78,7 @@ Contributors
* Eficent Business and IT Consulting Services S.L. <[email protected]>
* Serpent Consulting Services Pvt. Ltd. <[email protected]>
* Alejandro Padrón <[email protected]>
* Alan Ramos <[email protected]>

Maintainers
~~~~~~~~~~~
Expand All @@ -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 <https://github.com/OCA/operating-unit/tree/15.0/sale_stock_operating_unit>`_ project on GitHub.
This module is part of the `OCA/operating-unit <https://github.com/OCA/operating-unit/tree/16.0/sale_stock_operating_unit>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 1 addition & 1 deletion sale_stock_operating_unit/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
15 changes: 6 additions & 9 deletions sale_stock_operating_unit/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# 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, fields, models
from odoo.exceptions import ValidationError


Expand All @@ -11,14 +11,14 @@ class SaleOrder(models.Model):

@api.model
def _default_warehouse_id(self):
res = super(SaleOrder, self)._default_warehouse_id()
res = super()._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,
team.sudo().operating_unit_id.id,
)
],
limit=1,
Expand All @@ -32,8 +32,7 @@ def _default_warehouse_id(self):
)

@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
Expand All @@ -46,10 +45,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
Expand All @@ -61,7 +58,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 (
Expand Down
2 changes: 1 addition & 1 deletion sale_stock_operating_unit/models/stock_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
{
Expand Down
1 change: 1 addition & 0 deletions sale_stock_operating_unit/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
* Eficent Business and IT Consulting Services S.L. <[email protected]>
* Serpent Consulting Services Pvt. Ltd. <[email protected]>
* Alejandro Padrón <[email protected]>
* Alan Ramos <[email protected]>
9 changes: 5 additions & 4 deletions sale_stock_operating_unit/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.15.1: http://docutils.sourceforge.net/" />
<meta name="generator" content="Docutils: http://docutils.sourceforge.net/" />
<title>Operating Unit in Sales Stock</title>
<style type="text/css">

Expand Down Expand Up @@ -367,7 +367,7 @@ <h1 class="title">Operating Unit in Sales Stock</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/operating-unit/tree/15.0/sale_stock_operating_unit"><img alt="OCA/operating-unit" src="https://img.shields.io/badge/github-OCA%2Foperating--unit-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/operating-unit-15-0/operating-unit-15-0-sale_stock_operating_unit"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/213/15.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/operating-unit/tree/16.0/sale_stock_operating_unit"><img alt="OCA/operating-unit" src="https://img.shields.io/badge/github-OCA%2Foperating--unit-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/operating-unit-16-0/operating-unit-16-0-sale_stock_operating_unit"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/213/16.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p>This module was written to extend the Sales and the Stock capabilities of Odoo.
This module introduces some new operating unit (OU) capabilities in order to
enhance the performance of already existing OU features for Sales and Stock.</p>
Expand Down Expand Up @@ -408,7 +408,7 @@ <h1><a class="toc-backref" href="#id2">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/operating-unit/issues">GitHub Issues</a>.
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
<a class="reference external" href="https://github.com/OCA/operating-unit/issues/new?body=module:%20sale_stock_operating_unit%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/operating-unit/issues/new?body=module:%20sale_stock_operating_unit%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
Expand All @@ -426,6 +426,7 @@ <h2><a class="toc-backref" href="#id5">Contributors</a></h2>
<li>Eficent Business and IT Consulting Services S.L. &lt;<a class="reference external" href="mailto:contact&#64;eficent.com">contact&#64;eficent.com</a>&gt;</li>
<li>Serpent Consulting Services Pvt. Ltd. &lt;<a class="reference external" href="mailto:support&#64;serpentcs.com">support&#64;serpentcs.com</a>&gt;</li>
<li>Alejandro Padrón &lt;<a class="reference external" href="mailto:alejandro.padron&#64;bt-group.com">alejandro.padron&#64;bt-group.com</a>&gt;</li>
<li>Alan Ramos &lt;<a class="reference external" href="mailto:alan.ramos&#64;jarsa.com">alan.ramos&#64;jarsa.com</a>&gt;</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand All @@ -435,7 +436,7 @@ <h2><a class="toc-backref" href="#id6">Maintainers</a></h2>
<p>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.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/operating-unit/tree/15.0/sale_stock_operating_unit">OCA/operating-unit</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/operating-unit/tree/16.0/sale_stock_operating_unit">OCA/operating-unit</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
Expand Down
107 changes: 56 additions & 51 deletions sale_stock_operating_unit/tests/test_sale_stock_operating_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,79 +7,81 @@


class TestSaleStockOperatingUnit(common.TransactionCase):
def setUp(self):
super(TestSaleStockOperatingUnit, self).setUp()
self.res_groups = self.env["res.groups"]
self.res_users_model = self.env["res.users"]
self.warehouse_model = self.env["stock.warehouse"]
self.sale_model = self.env["sale.order"]
self.sale_line_model = self.env["sale.order.line"]
self.sale_team_model = self.env["crm.team"]
@classmethod
def setUpClass(cls):
super().setUp()
cls.res_groups = cls.env["res.groups"]
cls.res_users_model = cls.env["res.users"]
cls.warehouse_model = cls.env["stock.warehouse"]
cls.sale_model = cls.env["sale.order"]
cls.sale_line_model = cls.env["sale.order.line"]
cls.sale_team_model = cls.env["crm.team"]
# Company
self.company = self.env.ref("base.main_company")
cls.company = cls.env.ref("base.main_company")
# Groups
self.grp_sale_user = self.env.ref("sales_team.group_sale_manager")
self.grp_acc_user = self.env.ref("account.group_account_invoice")
cls.grp_sale_user = cls.env.ref("sales_team.group_sale_manager")
cls.grp_acc_user = cls.env.ref("account.group_account_invoice")
# Main Operating Unit
self.ou1 = self.env.ref("operating_unit.main_operating_unit")
cls.ou1 = cls.env.ref("operating_unit.main_operating_unit")
# B2C Operating Unit
self.b2c = self.env.ref("operating_unit.b2c_operating_unit")
cls.b2c = cls.env.ref("operating_unit.b2c_operating_unit")
# Customer
self.customer = self.env.ref("base.res_partner_2")
cls.customer = cls.env.ref("base.res_partner_2")
# Price list
self.pricelist = self.env.ref("product.list0")
cls.pricelist = cls.env.ref("product.list0")
# Products
self.product1 = self.env.ref("product.product_product_7")
self.product1.write({"invoice_policy": "order"})
cls.product1 = cls.env.ref("product.product_product_7")
cls.product1.write({"invoice_policy": "order"})
# Create user1
self.user1 = self._create_user(
cls.user1 = cls._create_user(
"user_1",
[self.grp_sale_user, self.grp_acc_user],
self.company,
[self.ou1, self.b2c],
[cls.grp_sale_user, cls.grp_acc_user],
cls.company,
[cls.ou1, cls.b2c],
)
# Create user2
self.user2 = self._create_user(
"user_2", [self.grp_sale_user, self.grp_acc_user], self.company, [self.b2c]
cls.user2 = cls._create_user(
"user_2", [cls.grp_sale_user, cls.grp_acc_user], cls.company, [cls.b2c]
)

# Create sales team OU1
self.sale_team_ou1 = self._create_sale_team(self.user1.id, self.ou1)
cls.sale_team_ou1 = cls._create_sale_team(cls.user1.id, cls.ou1)

# Create sales team OU2
self.sale_team_b2c = self._create_sale_team(self.user2.id, self.b2c)
cls.sale_team_b2c = cls._create_sale_team(cls.user2.id, cls.b2c)

# Warehouses
self.ou1_wh = self.env.ref("stock.warehouse0")
self.b2c_wh = self.env.ref("stock_operating_unit.stock_warehouse_b2c")
cls.ou1_wh = cls.env.ref("stock.warehouse0")
cls.b2c_wh = cls.env.ref("stock_operating_unit.stock_warehouse_b2c")
# Locations
self.b2c_wh.lot_stock_id.write(
{"company_id": self.company.id, "operating_unit_id": self.b2c.id}
cls.b2c_wh.lot_stock_id.write(
{"company_id": cls.company.id, "operating_unit_id": cls.b2c.id}
)

# Create Sale Order1
self.sale1 = self._create_sale_order(
self.user1.id,
self.customer,
self.product1,
self.pricelist,
self.sale_team_ou1,
self.ou1_wh,
cls.sale1 = cls._create_sale_order(
cls.user1.id,
cls.customer,
cls.product1,
cls.pricelist,
cls.sale_team_ou1,
cls.ou1_wh,
)
# Create Sale Order2
self.sale2 = self._create_sale_order(
self.user2.id,
self.customer,
self.product1,
self.pricelist,
self.sale_team_b2c,
self.b2c_wh,
cls.sale2 = cls._create_sale_order(
cls.user2.id,
cls.customer,
cls.product1,
cls.pricelist,
cls.sale_team_b2c,
cls.b2c_wh,
)

def _create_user(self, login, groups, company, operating_units):
@classmethod
def _create_user(cls, login, groups, company, operating_units):
"""Create a user."""
group_ids = [group.id for group in groups]
user = self.res_users_model.create(
user = cls.res_users_model.create(
{
"name": "Test Sales User",
"login": login,
Expand All @@ -93,20 +95,22 @@ def _create_user(self, login, groups, company, operating_units):
)
return user

def _create_sale_team(self, uid, operating_unit):
@classmethod
def _create_sale_team(cls, uid, operating_unit):
"""Create a sale team."""
team = (
self.sale_team_model.with_user(uid)
cls.sale_team_model.with_user(uid)
.with_context(mail_create_nosubscribe=True)
.create(
{"name": operating_unit.name, "operating_unit_id": operating_unit.id}
)
)
return team

def _create_sale_order(self, uid, customer, product, pricelist, team, wh):
@classmethod
def _create_sale_order(cls, uid, customer, product, pricelist, team, wh):
"""Create a sale order."""
sale = self.sale_model.with_user(uid).create(
sale = cls.sale_model.with_user(uid).create(
{
"partner_id": customer.id,
"partner_invoice_id": customer.id,
Expand All @@ -117,12 +121,13 @@ def _create_sale_order(self, uid, customer, product, pricelist, team, wh):
"warehouse_id": wh.id,
}
)
self.sale_line_model.with_user(uid).create(
cls.sale_line_model.with_user(uid).create(
{"order_id": sale.id, "product_id": product.id, "name": "Sale Order Line"}
)
return sale

def _confirm_sale(self, sale):
@classmethod
def _confirm_sale(cls, sale):
sale.action_confirm()
return True

Expand Down

0 comments on commit 4ce1da7

Please sign in to comment.