forked from OCA/operating-unit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] purchase_operating_unit_sequence
- Loading branch information
njojic
committed
Jun 28, 2024
1 parent
ec1246a
commit 85d05d3
Showing
12 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* `Ametras intelligence GmbH <https://www.ametras.com>`_: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
13
purchase_operating_unit_sequence/views/operating_unit_view.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
1 change: 1 addition & 0 deletions
1
setup/purchase_operating_unit_sequence/odoo/addons/purchase_operating_unit_sequence
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../purchase_operating_unit_sequence |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) |