Skip to content

Commit

Permalink
[ADD] purchase_operating_unit_sequence
Browse files Browse the repository at this point in the history
  • Loading branch information
njojic committed Jun 28, 2024
1 parent ec1246a commit e17f336
Show file tree
Hide file tree
Showing 14 changed files with 97 additions and 0 deletions.
Empty file.
4 changes: 4 additions & 0 deletions purchase_operating_unit_sequence/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)

from . import models
from .hooks import assign_ou_sequences
17 changes: 17 additions & 0 deletions purchase_operating_unit_sequence/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2024 Ametras
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html)

{
"name": "Purchase Order Sequence by Operating Unit",
"version": "13.0.1.0.0",
"license": "AGPL-3",
"category": "Sales",
"author": "Ametras intelligence GmbH, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/operating-unit",
"maintainer": "Ametras intelligence GmbH",
"summary": "Custom Purchase Order Sequence by Operating Unit",
"depends": ["purchase", "operating_unit"],
"data": ["views/operating_unit_view.xml"],
"installable": True,
"post_init_hook": "assign_ou_sequences",
}
19 changes: 19 additions & 0 deletions purchase_operating_unit_sequence/hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from odoo import SUPERUSER_ID, api


def assign_ou_sequences(cr, registry):
with api.Environment.manage():
env = api.Environment(cr, SUPERUSER_ID, {})
operating_unit_obj = env["operating.unit"]
sequence_obj = env["ir.sequence"]
for operating_unit in operating_unit_obj.search([]):
purchase_sequence_id = sequence_obj.create(
{
"name": "Purchase Order of {}".format(operating_unit.name),
"code": "purchase.order.{}".format(operating_unit.code),
"prefix": "{}-PO".format(operating_unit.code),
"padding": 5,
"company_id": operating_unit.company_id.id,
}
)
operating_unit.write({"purchase_sequence_id": purchase_sequence_id.id})
4 changes: 4 additions & 0 deletions purchase_operating_unit_sequence/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)

from . import operating_unit
from . import purchase_order
11 changes: 11 additions & 0 deletions purchase_operating_unit_sequence/models/operating_unit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from odoo import fields, models


class OperatingUnit(models.Model):
_inherit = "operating.unit"

purchase_sequence_id = fields.Many2one(
comodel_name="ir.sequence",
string="Purchase Order Sequence",
help="Sequence of purchase order with this operating unit",
)
13 changes: 13 additions & 0 deletions purchase_operating_unit_sequence/models/purchase_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from odoo import api, models


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

@api.model
def create(self, vals):
if vals.get("operating_unit_id", False):
ou_id = self.env["operating.unit"].browse(vals["operating_unit_id"])
if ou_id.purchase_sequence_id:
vals["name"] = ou_id.purchase_sequence_id.next_by_id()
return super().create(vals)
1 change: 1 addition & 0 deletions purchase_operating_unit_sequence/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* `Ametras intelligence GmbH <https://www.ametras.com>`_:
1 change: 1 addition & 0 deletions purchase_operating_unit_sequence/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This module use to define sequence of Purchase Orders by Operating Unit.
13 changes: 13 additions & 0 deletions purchase_operating_unit_sequence/views/operating_unit_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="view_purchase_order_operating_unit_form" model="ir.ui.view">
<field name="name">operating.unit.form</field>
<field name="model">operating.unit</field>
<field name="inherit_id" ref="operating_unit.view_operating_unit_form" />
<field name="arch" type="xml">
<xpath expr="//group[@name='main_group']" position="inside">
<field name="purchase_sequence_id" />
</xpath>
</field>
</record>
</odoo>
6 changes: 6 additions & 0 deletions setup/pos_operating_unit_sequence/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
6 changes: 6 additions & 0 deletions setup/purchase_operating_unit_sequence/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

0 comments on commit e17f336

Please sign in to comment.