Skip to content

Commit bfcd73c

Browse files
committed
[18.0][ADD] purchase_requisition_section_and_note module
1 parent 4953955 commit bfcd73c

File tree

18 files changed

+913
-0
lines changed

18 files changed

+913
-0
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
=====================================
2+
Purchase Requisition Section and Note
3+
=====================================
4+
5+
..
6+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
7+
!! This file is generated by oca-gen-addon-readme !!
8+
!! changes will be overwritten. !!
9+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10+
!! source digest: sha256:e7be337b9a755bf038b7906ab514d458aa241fc4afec4619f88fdd12a63516e5
11+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
12+
13+
.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png
14+
:target: https://odoo-community.org/page/development-status
15+
:alt: Alpha
16+
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
17+
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
18+
:alt: License: AGPL-3
19+
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fpurchase--workflow-lightgray.png?logo=github
20+
:target: https://github.com/OCA/purchase-workflow/tree/18.0/purchase_requisition_section_and_note
21+
:alt: OCA/purchase-workflow
22+
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23+
:target: https://translation.odoo-community.org/projects/purchase-workflow-18-0/purchase-workflow-18-0-purchase_requisition_section_and_note
24+
:alt: Translate me on Weblate
25+
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/purchase-workflow&target_branch=18.0
27+
:alt: Try me on Runboat
28+
29+
|badge1| |badge2| |badge3| |badge4| |badge5|
30+
31+
This module adds the possibility to add sections ands notes in Purchase
32+
Requisition. It adds a page in form view.
33+
34+
.. figure:: https://raw.githubusercontent.com/OCA/purchase-workflow/18.0/purchase_requisition_section_and_note/static/description/agreement.png
35+
36+
.. figure:: https://raw.githubusercontent.com/OCA/purchase-workflow/18.0/purchase_requisition_section_and_note/static/description/po.png
37+
38+
Copy paste from mrp_bom_widget_section_and_note_one2many
39+
40+
.. IMPORTANT::
41+
This is an alpha version, the data model and design can change at any time without warning.
42+
Only for development or testing purpose, do not use in production.
43+
`More details on development status <https://odoo-community.org/page/development-status>`_
44+
45+
**Table of contents**
46+
47+
.. contents::
48+
:local:
49+
50+
Bug Tracker
51+
===========
52+
53+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/purchase-workflow/issues>`_.
54+
In case of trouble, please check there if your issue has already been reported.
55+
If you spotted it first, help us to smash it by providing a detailed and welcomed
56+
`feedback <https://github.com/OCA/purchase-workflow/issues/new?body=module:%20purchase_requisition_section_and_note%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
57+
58+
Do not contact contributors directly about support or help with technical issues.
59+
60+
Credits
61+
=======
62+
63+
Authors
64+
-------
65+
66+
* Akretion
67+
68+
Maintainers
69+
-----------
70+
71+
This module is maintained by the OCA.
72+
73+
.. image:: https://odoo-community.org/logo.png
74+
:alt: Odoo Community Association
75+
:target: https://odoo-community.org
76+
77+
OCA, or the Odoo Community Association, is a nonprofit organization whose
78+
mission is to support the collaborative development of Odoo features and
79+
promote its widespread use.
80+
81+
.. |maintainer-bealdav| image:: https://github.com/bealdav.png?size=40px
82+
:target: https://github.com/bealdav
83+
:alt: bealdav
84+
85+
Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:
86+
87+
|maintainer-bealdav|
88+
89+
This module is part of the `OCA/purchase-workflow <https://github.com/OCA/purchase-workflow/tree/18.0/purchase_requisition_section_and_note>`_ project on GitHub.
90+
91+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import models
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright 2025 Akretion
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
3+
{
4+
"name": "Purchase Requisition Section and Note",
5+
"summary": "Add section and note to purchase requisition",
6+
"version": "18.0.1.0.0",
7+
"website": "https://github.com/OCA/purchase-workflow",
8+
"author": "Akretion, Odoo Community Association (OCA)",
9+
"maintainers": ["bealdav"],
10+
"development_status": "Alpha",
11+
"license": "AGPL-3",
12+
"depends": [
13+
"purchase_requisition",
14+
],
15+
"data": [
16+
"views/requisition.xml",
17+
"views/purchase.xml",
18+
],
19+
"demo": ["data/demo.xml"],
20+
"installable": True,
21+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<odoo noupdate="0">
2+
<record id="purchase_template" model="purchase.requisition">
3+
<field name="user_id" ref="base.user_admin" />
4+
<field name="vendor_id" ref="base.res_partner_1" />
5+
<field name="requisition_type">purchase_template</field>
6+
<field name="reference">my template</field>
7+
</record>
8+
9+
<record id="purchase_template_line_section1" model="purchase.requisition.line">
10+
<field name="requisition_id" ref="purchase_template" />
11+
<field name="display_type">line_section</field>
12+
<field name="sequence">2</field>
13+
<field name="product_qty">0</field>
14+
<field name="name">Section 1</field>
15+
</record>
16+
<record id="purchase_template_line1" model="purchase.requisition.line">
17+
<field name="requisition_id" ref="purchase_template" />
18+
<field name="sequence">4</field>
19+
<field name="product_id" ref="product.product_delivery_02" />
20+
<field name="product_qty">1</field>
21+
</record>
22+
<record id="purchase_template_line2" model="purchase.requisition.line">
23+
<field name="requisition_id" ref="purchase_template" />
24+
<field name="sequence">6</field>
25+
<field name="product_id" ref="product.product_delivery_01" />
26+
<field name="product_qty">1</field>
27+
</record>
28+
<record id="purchase_template_line3" model="purchase.requisition.line">
29+
<field name="requisition_id" ref="purchase_template" />
30+
<field name="sequence">8</field>
31+
<field name="product_id" ref="product.consu_delivery_01" />
32+
<field name="product_qty">1</field>
33+
</record>
34+
<record id="purchase_template_line_section2" model="purchase.requisition.line">
35+
<field name="requisition_id" ref="purchase_template" />
36+
<field name="display_type">line_section</field>
37+
<field name="sequence">10</field>
38+
<field name="product_qty">0</field>
39+
<field name="name">Section 2</field>
40+
</record>
41+
<record id="purchase_template_line5" model="purchase.requisition.line">
42+
<field name="requisition_id" ref="purchase_template" />
43+
<field name="sequence">12</field>
44+
<field name="product_id" ref="product.product_product_25" />
45+
<field name="product_qty">1</field>
46+
</record>
47+
<record id="purchase_template_line_note" model="purchase.requisition.line">
48+
<field name="requisition_id" ref="purchase_template" />
49+
<field name="sequence">14</field>
50+
<field name="display_type">line_note</field>
51+
<field name="product_qty">0</field>
52+
<field name="name"> --> Nice flipover</field>
53+
</record>
54+
<record id="purchase_template_line6" model="purchase.requisition.line">
55+
<field name="requisition_id" ref="purchase_template" />
56+
<field name="sequence">16</field>
57+
<field name="product_id" ref="product.product_product_20" />
58+
<field name="product_qty">1</field>
59+
</record>
60+
61+
<function
62+
model="purchase.requisition"
63+
name="action_confirm"
64+
eval="[[ref('purchase_template')]]"
65+
/>
66+
67+
<!--Resource: purchase.order-->
68+
<record id="po1" model="purchase.order">
69+
<field name="partner_id" ref="base.res_partner_1" />
70+
<field name="user_id" ref="base.user_admin" />
71+
<field name="requisition_id" ref="purchase_template" />
72+
</record>
73+
74+
<function model="purchase.order" name="reorder_lines" eval="[[ref('po1')]]" />
75+
</odoo>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from . import (
2+
purchase,
3+
purchase_requisition,
4+
purchase_requisition_line,
5+
)
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
from collections import defaultdict
2+
3+
from odoo import Command, api, fields, models
4+
5+
6+
class PurchaseOrderLine(models.Model):
7+
_inherit = "purchase.order.line"
8+
_order = "sequence asc"
9+
10+
11+
class PurchaseOrder(models.Model):
12+
_inherit = "purchase.order"
13+
14+
sequence_to_update = fields.Boolean(
15+
readonly=True,
16+
help="Technical field to flag orders that have to be sequenced again",
17+
)
18+
19+
@api.onchange("requisition_id")
20+
def _onchange_requisition_id(self):
21+
res = super()._onchange_requisition_id()
22+
if self and self.requisition_id:
23+
lines = []
24+
for line in self.requisition_id.line_with_sectionnote_ids:
25+
if line.display_type:
26+
lines.append(
27+
Command.create(
28+
{
29+
"product_qty": 0,
30+
"display_type": line.display_type,
31+
"name": line.name,
32+
}
33+
)
34+
)
35+
if lines:
36+
self.order_line = lines
37+
self._set_sequence_based_on_requisition()
38+
self.sequence_to_update = True
39+
return res
40+
41+
def reorder_lines(self):
42+
for rec in self:
43+
rec.sequence_to_update = False
44+
45+
def _set_sequence_based_on_requisition(self):
46+
self.ensure_one()
47+
if self.requisition_id:
48+
# we apply sequence define in requisition
49+
data = defaultdict(dict)
50+
for line in self.requisition_id.line_with_sectionnote_ids:
51+
data[line.display_type or "no"][line.product_id.name or line.name] = (
52+
line.sequence
53+
)
54+
# data content is:
55+
# {"no": {"my product description": 30},
56+
# "line_note": {"my note": 35, "my note2": 37},
57+
# "line_section": {"my section": 45}}
58+
# we need to aggregate already created records
59+
# with new lines provided by onchange
60+
for line in self._origin.order_line | self.order_line:
61+
display = line.display_type or "no"
62+
sequence = (
63+
data.get(display)
64+
and data[display].get(
65+
line.product_id and line.product_id.name or line.name
66+
)
67+
or False
68+
)
69+
if sequence:
70+
line.sequence = sequence
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from odoo import fields, models
2+
3+
4+
class PurchaseRequisition(models.Model):
5+
_inherit = "purchase.requisition"
6+
7+
# Split requisition_line_ids in two fields handled thanks to domain
8+
# Keep original field line_ids to keep all the native functionnalities
9+
line_ids = fields.One2many(domain=[("display_type", "=", False)])
10+
11+
line_with_sectionnote_ids = fields.One2many(
12+
comodel_name="purchase.requisition.line",
13+
inverse_name="requisition_id",
14+
string="Requisition Lines With Sections & Notes",
15+
copy=False,
16+
)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from odoo import fields, models
2+
3+
4+
class PurchaseRequisitionLine(models.Model):
5+
_inherit = "purchase.requisition.line"
6+
7+
# Returns mandatory for classic line thanks to _sql_constraints and view
8+
product_id = fields.Many2one(required=False)
9+
10+
# New fields to handle section & note
11+
name = fields.Text()
12+
sequence = fields.Integer()
13+
14+
display_type = fields.Selection(
15+
[("line_section", "Section"), ("line_note", "Note")],
16+
default=False,
17+
help="Technical field for UX purpose.",
18+
)
19+
20+
_sql_constraints = [
21+
(
22+
"bom_required_fields_product_qty",
23+
"CHECK(display_type IS NOT NULL OR"
24+
"(product_id IS NOT NULL AND product_qty IS NOT NULL))",
25+
"Missing required fields on purchase requisition: product and quantity.",
26+
),
27+
]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[build-system]
2+
requires = ["whool"]
3+
build-backend = "whool.buildapi"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
- David BEAL <[email protected]>
2+
- BADEP
3+
- Quentin Dupont (<[email protected]>)

0 commit comments

Comments
 (0)