Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
f11da75
Added Purchase Operating Unit module.
sudhir-serpentcs Dec 31, 2015
5e10dc9
Improved the unit test case for Purchase OU.
sudhir-serpentcs Jan 2, 2016
67e39ee
Improved the code of unit test cases and of constraint.
sudhir-serpentcs Jan 8, 2016
9232c82
Migrated the module with test cases.
sudhir-serpentcs Feb 22, 2016
b27782b
create PO from procurement
JordiBForgeFlow Oct 6, 2016
45235a2
[MIG] purchase_operating_unit: Migrated to 10.0
AaronHForgeFlow Jan 31, 2017
2eb37ab
[FIX] readonly on OU
serpentcs-dev1 Jul 4, 2017
2bc4486
[FIX] when the procurement location is not internal the PO may belong…
AaronHForgeFlow Nov 22, 2017
8d06ee0
[FIX]PYLINT mainly
AaronHForgeFlow Jun 11, 2018
53aeda9
[MIG] purchase_operating_unit: Migration to v12.0
bjeficent Dec 18, 2018
00d1fc2
[UPD] Update purchase_operating_unit.pot
oca-travis Oct 30, 2019
81d7c02
[UPD] README.rst
OCA-git-bot Oct 30, 2019
1b4d175
[IMP] purchase_operating_unit: black, isort, prettier
BT-nstuder Jan 7, 2020
22b10f3
[MIG] purchase_operating_unit: Migration to 13.0
BT-nstuder Jan 8, 2020
f0b2d1a
[UPD] Update purchase_operating_unit.pot
oca-travis Apr 30, 2020
bcb3466
[UPD] README.rst
OCA-git-bot Apr 30, 2020
7b3501f
[FIX] Fixed Issue #291
nikul-serpentcs Oct 1, 2020
3f6150a
[UPD] README.rst
OCA-git-bot Oct 1, 2020
6313409
purchase_operating_unit 13.0.1.0.1
OCA-git-bot Oct 1, 2020
5619ba0
[UPD] Eficent -> ForgeFlow
MiquelRForgeFlow Oct 5, 2020
16e0d59
[UPD] README.rst
OCA-git-bot Oct 5, 2020
840bc59
[IMP] : black, isort, prettier
kittiu Dec 4, 2020
8b982f6
[14.0][MIG] purchase_operating_unit
kittiu Dec 4, 2020
8a1d35a
[UPD] Update purchase_operating_unit.pot
oca-travis May 30, 2021
d109bf3
[UPD] README.rst
OCA-git-bot May 30, 2021
32356ad
[14.0][FIX] purchase_operating_unit, add OU when create invoice
kittiu Jun 15, 2021
ab128ba
purchase_operating_unit 14.0.1.0.1
OCA-git-bot Aug 3, 2021
56264c6
[14.0][FIX] purchase_operating_unit
kittiu Oct 19, 2021
7f37ce5
purchase_operating_unit 14.0.1.0.2
OCA-git-bot Oct 19, 2021
c0dd769
[IMP] purchase_operating_unit: black, isort, prettier
alan196 Jan 13, 2022
92cdeb3
[MIG] purchase_operating_unit: Migration to 15.0
alan196 Jan 13, 2022
1f45d4b
[UPD] Update purchase_operating_unit.pot
Mar 8, 2023
03f55ad
[UPD] README.rst
OCA-git-bot Mar 8, 2023
d68ce8b
[UPD] README.rst
OCA-git-bot Sep 3, 2023
fc876ab
[ENH] purchase_operating_unit: add OU to Purchase Analysis Report
ps-tubtim Oct 10, 2023
660382e
[UPD] Update purchase_operating_unit.pot
Oct 10, 2023
26aa084
[BOT] post-merge updates
OCA-git-bot Oct 10, 2023
db73e5e
[FIX] purchase_operating_unit: Fix warning from an onchange function …
May 15, 2024
f47b56b
[UPD] Update purchase_operating_unit.pot
May 24, 2024
cc7f928
[BOT] post-merge updates
OCA-git-bot May 24, 2024
725aaf9
[IMP] purchase_operating_unit: pre-commit stuff
nopparuts Oct 2, 2024
0cad4eb
[MIG] purchase_operating_unit: Migration to 16.0
nopparuts Oct 2, 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
97 changes: 97 additions & 0 deletions purchase_operating_unit/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
=================================
Operating Unit in Purchase Orders
=================================

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

.. |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/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-16-0/operating-unit-16-0-purchase_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 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 to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/operating-unit/issues/new?body=module:%20purchase_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 <jordi.ballester@forgeflow.com>
* Aaron Henriquez <ahforgeflow@forgeflow.com>
* Sudhir Arya <sudhir.arya@serpentcs.com>
* Nicola Studer <nicola.studer@braintec-group.com>
* Nikul Chaudhary <nikul.chaudhary.serpentcs@gmail.com>
* Kitti U. <kittiu@ecosoft.co.th>
* Alan Ramos <alan.ramos@jarsa.com>
* Nopparit S. <nopparut.s@aginix.tech>

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/purchase_operating_unit>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
3 changes: 3 additions & 0 deletions purchase_operating_unit/__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 models
from . import report
27 changes: 27 additions & 0 deletions purchase_operating_unit/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# © 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",
"report/purchase_report_view.xml",
"views/purchase_order_view.xml",
"views/purchase_order_line_view.xml",
"views/account_move_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>
77 changes: 77 additions & 0 deletions purchase_operating_unit/i18n/purchase_operating_unit.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * purchase_operating_unit
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.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:ir.model.fields,field_description:purchase_operating_unit.field_purchase_report__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
#: model_terms:ir.ui.view,arch_db:purchase_operating_unit.view_purchase_order_search
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_account_bank_statement_line__purchase_ou_domain
#: model:ir.model.fields,field_description:purchase_operating_unit.field_account_move__purchase_ou_domain
#: model:ir.model.fields,field_description:purchase_operating_unit.field_account_payment__purchase_ou_domain
msgid "Purchase Ou Domain"
msgstr ""

#. module: purchase_operating_unit
#: model:ir.model,name:purchase_operating_unit.model_purchase_report
msgid "Purchase Report"
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
55 changes: 55 additions & 0 deletions purchase_operating_unit/models/account_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# 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 AccountMove(models.Model):
_inherit = "account.move"

purchase_ou_domain = fields.Many2many(
comodel_name="purchase.order", compute="_compute_purchase_ou_domain"
)

# 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.depends("operating_unit_id")
def _compute_purchase_ou_domain(self):
for rec in self:
rec.purchase_ou_domain = (
self.env["purchase.order"]
.sudo()
.search([("operating_unit_id", "=", rec.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"
)
8 changes: 8 additions & 0 deletions purchase_operating_unit/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
* Jordi Ballester Alomar <jordi.ballester@forgeflow.com>
* Aaron Henriquez <ahforgeflow@forgeflow.com>
* Sudhir Arya <sudhir.arya@serpentcs.com>
* Nicola Studer <nicola.studer@braintec-group.com>
* Nikul Chaudhary <nikul.chaudhary.serpentcs@gmail.com>
* Kitti U. <kittiu@ecosoft.co.th>
* Alan Ramos <alan.ramos@jarsa.com>
* Nopparit S. <nopparut.s@aginix.tech>
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.
2 changes: 2 additions & 0 deletions purchase_operating_unit/report/__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 purchase_report
Loading