Skip to content

Commit

Permalink
[MIG] purchase_operating_unit: Migration to 13.0
Browse files Browse the repository at this point in the history
  • Loading branch information
BT-nstuder authored and BT-aleonard committed May 11, 2023
1 parent 78c8444 commit ad413f1
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 64 deletions.
11 changes: 6 additions & 5 deletions purchase_operating_unit/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ Operating Unit in Purchase Orders
: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/12.0/purchase_operating_unit
:target: https://github.com/OCA/operating-unit/tree/13.0/purchase_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-12-0/operating-unit-12-0-purchase_operating_unit
:target: https://translation.odoo-community.org/projects/operating-unit-13-0/operating-unit-13-0-purchase_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/12.0
:target: https://runbot.odoo-community.org/runbot/213/13.0
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand Down Expand Up @@ -60,7 +60,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:%20purchase_operating_unit%0Aversion:%2012.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:%20purchase_operating_unit%0Aversion:%2013.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 @@ -79,6 +79,7 @@ Contributors
* Jordi Ballester Alomar <[email protected]>
* Aaron Henriquez <[email protected]>
* Sudhir Arya <[email protected]>
* Nicola Studer <[email protected]>

Maintainers
~~~~~~~~~~~
Expand All @@ -93,6 +94,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/12.0/purchase_operating_unit>`_ project on GitHub.
This module is part of the `OCA/operating-unit <https://github.com/OCA/operating-unit/tree/13.0/purchase_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 purchase_operating_unit/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"name": "Operating Unit in Purchase Orders",
"summary": "Adds the concecpt of operating unit (OU) in purchase order "
"management",
"version": "12.0.1.0.0",
"version": "13.0.1.0.0",
"author": "Eficent, "
"Serpent Consulting Services Pvt. Ltd.,"
"Odoo Community Association (OCA)",
Expand Down
40 changes: 23 additions & 17 deletions purchase_operating_unit/i18n/purchase_operating_unit.pot
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * purchase_operating_unit
# * purchase_operating_unit
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 12.0\n"
"Project-Id-Version: Odoo Server 13.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: <>\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: purchase_operating_unit
#: code:addons/purchase_operating_unit/models/purchase_order.py:82
#: code:addons/purchase_operating_unit/models/purchase_order.py:0
#, python-format
msgid "Configuration error. The Company in the Purchase Order and in the Operating Unit must be the same."
msgid ""
"Configuration error. The Company in the Purchase Order and in the Operating "
"Unit must be the same."
msgstr ""

#. module: purchase_operating_unit
#: code:addons/purchase_operating_unit/models/purchase_order.py:71
#: code:addons/purchase_operating_unit/models/purchase_order.py:0
#, python-format
msgid "Configuration error. The Quotation / Purchase Order and the Warehouse of picking type must belong to the same Operating Unit."
msgid ""
"Configuration error. The Quotation / Purchase Order and the Warehouse of "
"picking type must belong to the same Operating Unit."
msgstr ""

#. module: purchase_operating_unit
Expand All @@ -31,19 +35,20 @@ msgid "Deliver To"
msgstr ""

#. module: purchase_operating_unit
#: model:ir.model,name:purchase_operating_unit.model_account_invoice
msgid "Invoice"
#: model:ir.model,name:purchase_operating_unit.model_account_move
msgid "Journal Entries"
msgstr ""

#. module: purchase_operating_unit
#: model:ir.model,name:purchase_operating_unit.model_account_invoice_line
msgid "Invoice Line"
#: model:ir.model,name:purchase_operating_unit.model_account_move_line
msgid "Journal Item"
msgstr ""

#. module: purchase_operating_unit
#: code:addons/purchase_operating_unit/models/purchase_order.py:97
#: code:addons/purchase_operating_unit/models/purchase_order.py:0
#, python-format
msgid "No Warehouse found with the Operating Unit indicated in the Purchase Order"
msgid ""
"No Warehouse found with the Operating Unit indicated in the Purchase Order"
msgstr ""

#. module: purchase_operating_unit
Expand All @@ -70,13 +75,14 @@ msgid "Requesting Operating Unit"
msgstr ""

#. module: purchase_operating_unit
#: code:addons/purchase_operating_unit/models/account_invoice.py:43
#: code:addons/purchase_operating_unit/models/account_invoice.py:0
#, python-format
msgid "The operating unit of the purchase order must be the same as in the associated invoices."
msgid ""
"The operating unit of the purchase order must be the same as in the "
"associated invoices."
msgstr ""

#. module: purchase_operating_unit
#: model:ir.model.fields,help:purchase_operating_unit.field_purchase_order__picking_type_id
msgid "This will determine picking type of incoming shipment"
msgid "This will determine operation type of incoming shipment"
msgstr ""

34 changes: 18 additions & 16 deletions purchase_operating_unit/models/account_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,37 @@
from odoo import _, api, exceptions, models


class AccountInvoice(models.Model):
_inherit = "account.invoice"
class AccountMove(models.Model):
_inherit = "account.move"

# Load all unsold PO lines
@api.onchange("purchase_id")
def purchase_order_change(self):
@api.onchange("purchase_vendor_bill_id", "purchase_id")
def _onchange_purchase_auto_complete(self):
"""
Override to add Operating Unit from Purchase Order to Invoice.
"""
if self.purchase_id and self.purchase_id.operating_unit_id:
purchase_id = self.purchase_id
if self.purchase_vendor_bill_id.purchase_order_id:
purchase_id = self.purchase_vendor_bill_id.purchase_order_id
if purchase_id and purchase_id.operating_unit_id:
# Assign OU from PO to Invoice
self.operating_unit_id = self.purchase_id.operating_unit_id.id
return super(AccountInvoice, self).purchase_order_change()
self.operating_unit_id = purchase_id.operating_unit_id.id
return super()._onchange_purchase_auto_complete()

@api.onchange("operating_unit_id")
def _onchange_allowed_purchase_ids(self):
def _onchange_operating_unit_id(self):
"""
Show only the purchase orders that have the same operating unit
"""
result = super(AccountInvoice, self)._onchange_allowed_purchase_ids()
return {
"domain": {
"purchase_id": [("operating_unit_id", "=", self.operating_unit_id.id)]
}
}

result["domain"]["purchase_id"] += [
("operating_unit_id", "=", self.operating_unit_id.id)
]
return result


class AccountInvoiceLines(models.Model):
_inherit = "account.invoice.line"
class AccountMoveLine(models.Model):
_inherit = "account.move.line"

@api.constrains("operating_unit_id", "purchase_line_id")
def _check_invoice_ou(self):
Expand Down
6 changes: 1 addition & 5 deletions purchase_operating_unit/models/purchase_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,12 @@ def _default_picking_type(self):
)

picking_type_id = fields.Many2one(
comodel_name="stock.picking.type",
string="Deliver To",
help="This will determine picking type of incoming shipment",
required=True,
states={
"confirmed": [("readonly", True)],
"approved": [("readonly", True)],
"done": [("readonly", True)],
},
default=lambda self: self._default_picking_type(),
default=_default_picking_type,
)

@api.constrains("operating_unit_id", "picking_type_id")
Expand Down
1 change: 1 addition & 0 deletions purchase_operating_unit/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
* Jordi Ballester Alomar <[email protected]>
* Aaron Henriquez <[email protected]>
* Sudhir Arya <[email protected]>
* Nicola Studer <[email protected]>
7 changes: 4 additions & 3 deletions purchase_operating_unit/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ <h1 class="title">Operating Unit in Purchase Orders</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/12.0/purchase_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-12-0/operating-unit-12-0-purchase_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/12.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/13.0/purchase_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-13-0/operating-unit-13-0-purchase_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/13.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p>This module introduces the following features:</p>
<ul class="simple">
<li>It introduces the operating unit to the purchase order.</li>
Expand Down Expand Up @@ -411,7 +411,7 @@ <h1><a class="toc-backref" href="#id3">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:%20purchase_operating_unit%0Aversion:%2012.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:%20purchase_operating_unit%0Aversion:%2013.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 @@ -429,6 +429,7 @@ <h2><a class="toc-backref" href="#id6">Contributors</a></h2>
<li>Jordi Ballester Alomar &lt;<a class="reference external" href="mailto:jordi.ballester&#64;eficent.com">jordi.ballester&#64;eficent.com</a>&gt;</li>
<li>Aaron Henriquez &lt;<a class="reference external" href="mailto:aheficent&#64;eficent.com">aheficent&#64;eficent.com</a>&gt;</li>
<li>Sudhir Arya &lt;<a class="reference external" href="mailto:sudhir.arya&#64;serpentcs.com">sudhir.arya&#64;serpentcs.com</a>&gt;</li>
<li>Nicola Studer &lt;<a class="reference external" href="mailto:nicola.studer&#64;braintec-group.com">nicola.studer&#64;braintec-group.com</a>&gt;</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand All @@ -438,7 +439,7 @@ <h2><a class="toc-backref" href="#id7">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/12.0/purchase_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/13.0/purchase_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
18 changes: 9 additions & 9 deletions purchase_operating_unit/tests/test_po_security.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,44 +11,44 @@ def test_po_ou_security(self):
# User 2 is only assigned to Operating Unit 2, and cannot list
# purchase orders from Operating Unit 1.
po_ids = (
self.PurchaseOrder.sudo(self.user2_id)
self.PurchaseOrder.with_user(self.user2_id)
.search([("operating_unit_id", "=", self.ou1.id)])
.ids
)
self.assertEqual(po_ids, [])
# User 2 cannot list the picking that was created from PO 1
picking_ids = (
self.StockPicking.sudo(self.user2_id)
self.StockPicking.with_user(self.user2_id)
.search([("id", "in", self.purchase1.picking_ids.ids)])
.ids
)
self.assertEqual(picking_ids, [])
# User 2 cannot list the invoice that was created from PO 1
invoice_ids = (
self.AccountInvoice.sudo(self.user2_id)
.search([("purchase_id", "=", self.purchase1.id)])
self.AccountInvoice.with_user(self.user2_id)
.search([("id", "=", self.invoice.id)])
.ids
)
self.assertEqual(invoice_ids, [])
# User 1 is assigned to Operating Unit 1, and can list
# the purchase order 1 from Operating Unit 1.
po_ids = (
self.PurchaseOrder.sudo(self.user1_id)
self.PurchaseOrder.with_user(self.user1_id)
.search([("operating_unit_id", "=", self.ou1.id)])
.ids
)
self.assertNotEqual(po_ids, [])
# User 1 can list the picking that was created from PO 1
picking_ids = (
self.StockPicking.sudo(self.user1_id)
self.StockPicking.with_user(self.user1_id)
.search([("id", "in", self.purchase1.picking_ids.ids)])
.ids
)
self.assertNotEqual(picking_ids, [])
# # User 1 can list the invoice that was created from PO 2
# User 1 can list the invoice that was created from PO 2
invoice_ids = (
self.AccountInvoice.sudo(self.user1_id)
.search([("purchase_id", "=", self.purchase1.id)])
self.AccountInvoice.with_user(self.user1_id)
.search([("id", "=", self.invoice.id)])
.ids
)
self.assertNotEqual(invoice_ids, [])
18 changes: 10 additions & 8 deletions purchase_operating_unit/tests/test_purchase_operating_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def setUp(self):
self.ResUsers = self.env["res.users"]
self.StockPicking = self.env["stock.picking"]
self.PurchaseOrder = self.env["purchase.order"]
self.AccountInvoice = self.env["account.invoice"]
self.AccountInvoice = self.env["account.move"]
# company
self.company1 = self.env.ref("base.main_company")
self.company2 = self.env.ref("stock.res_company_1")
Expand All @@ -32,7 +32,7 @@ def setUp(self):
self.product2 = self.env.ref("product.product_product_9")
self.product3 = self.env.ref("product.product_product_11")
# Account
self.account = self.env.ref("l10n_generic_coa.conf_a_pay")
self.account = self.env.ref("l10n_generic_coa.payable")
# Create users
self.user1_id = self._create_user(
"user_1",
Expand All @@ -50,8 +50,8 @@ def setUp(self):
self.user1_id,
[(self.product1, 1000), (self.product2, 500), (self.product3, 800)],
)
self.purchase1.sudo(self.user1_id).button_confirm()
self._create_invoice(self.purchase1, self.partner1, self.account)
self.purchase1.with_user(self.user1_id).button_confirm()
self.invoice = self._create_invoice(self.purchase1, self.partner1, self.account)

def _create_user(self, login, groups, company, operating_units):
""" Create a user."""
Expand Down Expand Up @@ -85,7 +85,7 @@ def _create_purchase(self, user_id, line_products):
"date_planned": time.strftime(DEFAULT_SERVER_DATETIME_FORMAT),
}
lines.append((0, 0, line_values))
purchase = self.PurchaseOrder.sudo(user_id).create(
purchase = self.PurchaseOrder.with_user(user_id).create(
{
"operating_unit_id": self.ou1.id,
"requesting_operating_unit_id": self.ou1.id,
Expand All @@ -101,13 +101,15 @@ def _create_invoice(self, purchase, partner, account):
invoice_vals = {
"purchase_id": purchase.id,
"partner_id": partner.id,
"account_id": account.id,
# "account_id": account.id,
"type": "in_invoice",
}
purchase_context = {
"active_id": purchase.id,
"active_ids": purchase.ids,
"active_model": "purchase.order",
}
self.env["account.invoice"].with_context(purchase_context).create(invoice_vals)
return True
res = (
self.env["account.move"].with_context(purchase_context).create(invoice_vals)
)
return res

0 comments on commit ad413f1

Please sign in to comment.