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

[MIG] purchase_operating_unit: Migration to 16.0 #593

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
93 changes: 93 additions & 0 deletions purchase_operating_unit/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
=================================
Operating Unit in Purchase Orders
=================================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |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/15.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-15-0/operating-unit-15-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/15.0
:alt: Try me on Runbot

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

This module introduces the following features:

- It introduces the operating unit to the purchase order.
- The operating unit is copied to the invoice.
- It implements user's security rules.

**Table of contents**

.. contents::
:local:

Usage
=====

#. Create a PO: the Default Operating Unit is assigned to the PO. If you want,
you can change to another Operating Unit.
#. Validate the PO: the Operating Unit is propagated to the Invoices.
#. From the invoice, it is not possible to change the Operating Unit, it has to
be the same as the one of the PO.

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:%2015.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]>
* Sudhir Arya <[email protected]>
* Nicola Studer <[email protected]>
* Nikul Chaudhary <[email protected]>
* Kitti U. <[email protected]>
* Alan Ramos <[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/15.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: 2 additions & 0 deletions purchase_operating_unit/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from . import models
25 changes: 25 additions & 0 deletions purchase_operating_unit/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# © 2015-17 ForgeFlow S.L.
# - Jordi Ballester Alomar
# © 2015-17 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).

{
"name": "Operating Unit in Purchase Orders",
"summary": "Adds the concecpt of operating unit (OU) in purchase order "
"management",
"version": "16.0.1.0.0",
"author": "ForgeFlow, "
"Serpent Consulting Services Pvt. Ltd.,"
"Odoo Community Association (OCA)",
"website": "https://github.com/OCA/operating-unit",
"category": "Purchase Management",
"depends": ["purchase", "account_operating_unit"],
"license": "LGPL-3",
"data": [
"security/purchase_security.xml",
"views/purchase_order_view.xml",
"views/purchase_order_line_view.xml",
],
"demo": ["demo/purchase_order_demo.xml"],
"installable": True,
}
28 changes: 28 additions & 0 deletions purchase_operating_unit/demo/purchase_order_demo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8" ?>
<!--Copyright 2015-17 ForgeFlow S.L.-->
<!-- - Jordi Ballester Alomar-->
<!--Copyright 2015-17 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya-->
<!--License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).-->
<odoo>
<record id="purchase.purchase_order_1" model="purchase.order">
<field name="operating_unit_id" ref="operating_unit.main_operating_unit" />
</record>
<record id="purchase.purchase_order_2" model="purchase.order">
<field name="operating_unit_id" ref="operating_unit.main_operating_unit" />
</record>
<record id="purchase.purchase_order_3" model="purchase.order">
<field name="operating_unit_id" ref="operating_unit.main_operating_unit" />
</record>
<record id="purchase.purchase_order_4" model="purchase.order">
<field name="operating_unit_id" ref="operating_unit.main_operating_unit" />
</record>
<record id="purchase.purchase_order_5" model="purchase.order">
<field name="operating_unit_id" ref="operating_unit.main_operating_unit" />
</record>
<record id="purchase.purchase_order_6" model="purchase.order">
<field name="operating_unit_id" ref="operating_unit.main_operating_unit" />
</record>
<record id="purchase.purchase_order_7" model="purchase.order">
<field name="operating_unit_id" ref="operating_unit.main_operating_unit" />
</record>
</odoo>
63 changes: 63 additions & 0 deletions purchase_operating_unit/i18n/purchase_operating_unit.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * purchase_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: purchase_operating_unit
#: 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."
msgstr ""

#. module: purchase_operating_unit
#: model:ir.model,name:purchase_operating_unit.model_account_move
msgid "Journal Entry"
msgstr ""

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

#. module: purchase_operating_unit
#: model:ir.model.fields,field_description:purchase_operating_unit.field_purchase_order__operating_unit_id
#: model:ir.model.fields,field_description:purchase_operating_unit.field_purchase_order_line__operating_unit_id
#: model_terms:ir.ui.view,arch_db:purchase_operating_unit.purchase_order_line_search
#: model_terms:ir.ui.view,arch_db:purchase_operating_unit.view_purchase_order_filter
msgid "Operating Unit"
msgstr ""

#. module: purchase_operating_unit
#: model:ir.model,name:purchase_operating_unit.model_purchase_order
msgid "Purchase Order"
msgstr ""

#. module: purchase_operating_unit
#: model:ir.model,name:purchase_operating_unit.model_purchase_order_line
msgid "Purchase Order Line"
msgstr ""

#. module: purchase_operating_unit
#: model:ir.model.fields,field_description:purchase_operating_unit.field_purchase_order__requesting_operating_unit_id
msgid "Requesting Operating Unit"
msgstr ""

#. module: purchase_operating_unit
#: code:addons/purchase_operating_unit/models/account_move.py:0
#, python-format
msgid ""
"The operating unit of the purchase order must be the same as in the "
"associated invoices."
msgstr ""
3 changes: 3 additions & 0 deletions purchase_operating_unit/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from . import purchase_order
from . import account_move
53 changes: 53 additions & 0 deletions purchase_operating_unit/models/account_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Copyright 2015-17 ForgeFlow S.L.
# - Jordi Ballester Alomar
# Copyright 2015-17 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from odoo import _, api, models
from odoo.exceptions import ValidationError


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

# Load all unsold PO lines
@api.onchange("purchase_vendor_bill_id", "purchase_id")
def _onchange_purchase_auto_complete(self):
"""
Override to add Operating Unit from Purchase Order to Invoice.
"""
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 = purchase_id.operating_unit_id.id
return super()._onchange_purchase_auto_complete()

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


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

@api.constrains("operating_unit_id", "purchase_line_id")
def _check_invoice_ou(self):
for line in self:
if (
line.purchase_line_id
and line.operating_unit_id != line.purchase_line_id.operating_unit_id
):
raise ValidationError(
_(
"The operating unit of the purchase order must "
"be the same as in the associated invoices."
)
)
62 changes: 62 additions & 0 deletions purchase_operating_unit/models/purchase_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Copyright 2015-17 ForgeFlow S.L.
# - Jordi Ballester Alomar
# Copyright 2015-17 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 PurchaseOrder(models.Model):
_inherit = "purchase.order"

READONLY_STATES = {
"purchase": [("readonly", True)],
"done": [("readonly", True)],
"cancel": [("readonly", True)],
}

operating_unit_id = fields.Many2one(
comodel_name="operating.unit",
string="Operating Unit",
states=READONLY_STATES,
default=lambda self: (
self.env["res.users"].operating_unit_default_get(self.env.uid)
),
)

requesting_operating_unit_id = fields.Many2one(
comodel_name="operating.unit",
string="Requesting Operating Unit",
states=READONLY_STATES,
default=lambda self: (
self.env["res.users"].operating_unit_default_get(self.env.uid)
),
)

@api.constrains("operating_unit_id", "company_id")
def _check_company_operating_unit(self):
for record in self:
if (
record.company_id
and record.operating_unit_id
and record.company_id != record.operating_unit_id.company_id
):
raise ValidationError(
_(
"Configuration error. The Company in the Purchase Order "
"and in the Operating Unit must be the same."
)
)

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


class PurchaseOrderLine(models.Model):
_inherit = "purchase.order.line"

operating_unit_id = fields.Many2one(
related="order_id.operating_unit_id", string="Operating Unit"
)
7 changes: 7 additions & 0 deletions purchase_operating_unit/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
* Jordi Ballester Alomar <[email protected]>
* Aaron Henriquez <[email protected]>
* Sudhir Arya <[email protected]>
* Nicola Studer <[email protected]>
* Nikul Chaudhary <[email protected]>
* Kitti U. <[email protected]>
* Alan Ramos <[email protected]>
5 changes: 5 additions & 0 deletions purchase_operating_unit/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
This module introduces the following features:

- It introduces the operating unit to the purchase order.
- The operating unit is copied to the invoice.
- It implements user's security rules.
5 changes: 5 additions & 0 deletions purchase_operating_unit/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#. Create a PO: the Default Operating Unit is assigned to the PO. If you want,
you can change to another Operating Unit.
#. Validate the PO: the Operating Unit is propagated to the Invoices.
#. From the invoice, it is not possible to change the Operating Unit, it has to
be the same as the one of the PO.
31 changes: 31 additions & 0 deletions purchase_operating_unit/security/purchase_security.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8" ?>
<!--Copyright 2015-17 ForgeFlow S.L.-->
<!-- - Jordi Ballester Alomar-->
<!--Copyright 2015-17 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya-->
<!--License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).-->
<odoo noupdate="1">
<record id="ir_rule_purchase_order_allowed_operating_units" model="ir.rule">
<field name="model_id" ref="purchase.model_purchase_order" />
<field
name="domain_force"
>['|',('operating_unit_id','=',False),('operating_unit_id','in', user.operating_unit_ids.ids)]</field>
<field name="name">PO's from allowed operating units</field>
<field name="global" eval="True" />
<field eval="0" name="perm_unlink" />
<field eval="0" name="perm_write" />
<field eval="1" name="perm_read" />
<field eval="0" name="perm_create" />
</record>
<record id="ir_rule_purchase_order_line_allowed_operating_units" model="ir.rule">
<field name="model_id" ref="purchase.model_purchase_order_line" />
<field
name="domain_force"
>['|',('operating_unit_id','=',False),('operating_unit_id','in', user.operating_unit_ids.ids)]</field>
<field name="name">PO lines from allowed operating units</field>
<field name="global" eval="True" />
<field eval="0" name="perm_unlink" />
<field eval="0" name="perm_write" />
<field eval="1" name="perm_read" />
<field eval="0" name="perm_create" />
</record>
</odoo>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading