Skip to content
Draft
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
91 changes: 91 additions & 0 deletions purchase_requisition_section_and_note/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
=====================================
Purchase Requisition Section and Note
=====================================

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

.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png
:target: https://odoo-community.org/page/development-status
:alt: Alpha
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fpurchase--workflow-lightgray.png?logo=github
:target: https://github.com/OCA/purchase-workflow/tree/18.0/purchase_requisition_section_and_note
:alt: OCA/purchase-workflow
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/purchase-workflow-18-0/purchase-workflow-18-0-purchase_requisition_section_and_note
: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/purchase-workflow&target_branch=18.0
:alt: Try me on Runboat

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

This module adds the possibility to add sections ands notes in Purchase
Requisition. It adds a page in form view.

.. figure:: https://raw.githubusercontent.com/OCA/purchase-workflow/18.0/purchase_requisition_section_and_note/static/description/agreement.png

.. figure:: https://raw.githubusercontent.com/OCA/purchase-workflow/18.0/purchase_requisition_section_and_note/static/description/po.png

Copy paste from mrp_bom_widget_section_and_note_one2many

.. IMPORTANT::
This is an alpha version, the data model and design can change at any time without warning.
Only for development or testing purpose, do not use in production.
`More details on development status <https://odoo-community.org/page/development-status>`_

**Table of contents**

.. contents::
:local:

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/purchase-workflow/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/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**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
-------

* Akretion

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.

.. |maintainer-bealdav| image:: https://github.com/bealdav.png?size=40px
:target: https://github.com/bealdav
:alt: bealdav

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-bealdav|

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.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions purchase_requisition_section_and_note/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
21 changes: 21 additions & 0 deletions purchase_requisition_section_and_note/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2025 Akretion
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "Purchase Requisition Section and Note",
"summary": "Add section and note to purchase requisition",
"version": "18.0.1.0.0",
"website": "https://github.com/OCA/purchase-workflow",
"author": "Akretion, Odoo Community Association (OCA)",
"maintainers": ["bealdav"],
"development_status": "Alpha",
"license": "AGPL-3",
"depends": [
"purchase_requisition",
],
"data": [
"views/requisition.xml",
"views/purchase.xml",
],
"demo": ["data/demo.xml"],
"installable": True,
}
75 changes: 75 additions & 0 deletions purchase_requisition_section_and_note/data/demo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<odoo noupdate="0">
<record id="purchase_template" model="purchase.requisition">
<field name="user_id" ref="base.user_admin" />
<field name="vendor_id" ref="base.res_partner_1" />
<field name="requisition_type">purchase_template</field>
<field name="reference">my template</field>
</record>

<record id="purchase_template_line_section1" model="purchase.requisition.line">
<field name="requisition_id" ref="purchase_template" />
<field name="display_type">line_section</field>
<field name="sequence">2</field>
<field name="product_qty">0</field>
<field name="name">Section 1</field>
</record>
<record id="purchase_template_line1" model="purchase.requisition.line">
<field name="requisition_id" ref="purchase_template" />
<field name="sequence">4</field>
<field name="product_id" ref="product.product_delivery_02" />
<field name="product_qty">1</field>
</record>
<record id="purchase_template_line2" model="purchase.requisition.line">
<field name="requisition_id" ref="purchase_template" />
<field name="sequence">6</field>
<field name="product_id" ref="product.product_delivery_01" />
<field name="product_qty">1</field>
</record>
<record id="purchase_template_line3" model="purchase.requisition.line">
<field name="requisition_id" ref="purchase_template" />
<field name="sequence">8</field>
<field name="product_id" ref="product.consu_delivery_01" />
<field name="product_qty">1</field>
</record>
<record id="purchase_template_line_section2" model="purchase.requisition.line">
<field name="requisition_id" ref="purchase_template" />
<field name="display_type">line_section</field>
<field name="sequence">10</field>
<field name="product_qty">0</field>
<field name="name">Section 2</field>
</record>
<record id="purchase_template_line5" model="purchase.requisition.line">
<field name="requisition_id" ref="purchase_template" />
<field name="sequence">12</field>
<field name="product_id" ref="product.product_product_25" />
<field name="product_qty">1</field>
</record>
<record id="purchase_template_line_note" model="purchase.requisition.line">
<field name="requisition_id" ref="purchase_template" />
<field name="sequence">14</field>
<field name="display_type">line_note</field>
<field name="product_qty">0</field>
<field name="name"> --> Nice flipover</field>
</record>
<record id="purchase_template_line6" model="purchase.requisition.line">
<field name="requisition_id" ref="purchase_template" />
<field name="sequence">16</field>
<field name="product_id" ref="product.product_product_20" />
<field name="product_qty">1</field>
</record>

<function
model="purchase.requisition"
name="action_confirm"
eval="[[ref('purchase_template')]]"
/>

<!--Resource: purchase.order-->
<record id="po1" model="purchase.order">
<field name="partner_id" ref="base.res_partner_1" />
<field name="user_id" ref="base.user_admin" />
<field name="requisition_id" ref="purchase_template" />
</record>

<function model="purchase.order" name="reorder_lines" eval="[[ref('po1')]]" />
</odoo>
5 changes: 5 additions & 0 deletions purchase_requisition_section_and_note/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from . import (
purchase,
purchase_requisition,
purchase_requisition_line,
)
76 changes: 76 additions & 0 deletions purchase_requisition_section_and_note/models/purchase.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
from collections import defaultdict

from odoo import Command, api, fields, models


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


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

sequence_to_update = fields.Boolean(
readonly=True,
help="Technical field to flag orders that have to be sequenced again",
)

@api.onchange("requisition_id")
def _onchange_requisition_id(self):
# Add company_id and partner_id to context for tax computation
# on purchase requisitions without a company_id
self = self.with_context(
order_company_id=self.company_id.id,
order_partner_id=self.partner_id.id,
)
res = super()._onchange_requisition_id()
if self and self.requisition_id:
lines = []
for line in self.requisition_id.line_with_sectionnote_ids:
if line.display_type:
lines.append(
Command.create(
{
"product_qty": 0,
"display_type": line.display_type,
"name": line.name,
}
)
)
if lines:
self.order_line = lines
self._set_sequence_based_on_requisition()
self.sequence_to_update = True
return res

def reorder_lines(self):
for rec in self:
rec.sequence_to_update = False

def _set_sequence_based_on_requisition(self):
self.ensure_one()
if self.requisition_id:
# we apply sequence define in requisition
data = defaultdict(dict)
for line in self.requisition_id.line_with_sectionnote_ids:
data[line.display_type or "no"][line.product_id.name or line.name] = (
line.sequence
)
# data content is:
# {"no": {"my product description": 30},
# "line_note": {"my note": 35, "my note2": 37},
# "line_section": {"my section": 45}}
# we need to aggregate already created records
# with new lines provided by onchange
for line in self._origin.order_line | self.order_line:
display = line.display_type or "no"
sequence = (
data.get(display)
and data[display].get(
line.product_id and line.product_id.name or line.name
)
or False
)
if sequence:
line.sequence = sequence
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from odoo import fields, models


class PurchaseRequisition(models.Model):
_inherit = "purchase.requisition"

# Split requisition_line_ids in two fields handled thanks to domain
# Keep original field line_ids to keep all the native functionnalities
line_ids = fields.One2many(domain=[("display_type", "=", False)])

line_with_sectionnote_ids = fields.One2many(
comodel_name="purchase.requisition.line",
inverse_name="requisition_id",
string="Requisition Lines With Sections & Notes",
copy=False,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
from odoo import fields, models


class PurchaseRequisitionLine(models.Model):
_inherit = "purchase.requisition.line"

# Returns mandatory for classic line thanks to _sql_constraints and view
product_id = fields.Many2one(required=False)

# New fields to handle section & note
name = fields.Text()
sequence = fields.Integer()

display_type = fields.Selection(
[("line_section", "Section"), ("line_note", "Note")],
default=False,
help="Technical field for UX purpose.",
)

_sql_constraints = [
(
"bom_required_fields_product_qty",
"CHECK(display_type IS NOT NULL OR"
"(product_id IS NOT NULL AND product_qty IS NOT NULL))",
"Missing required fields on purchase requisition: product and quantity.",
),
]

def _prepare_purchase_order_line(
self,
name,
product_qty=0.0,
price_unit=0.0,
taxes_ids=False,
):
values = super()._prepare_purchase_order_line(
name=name,
product_qty=product_qty,
price_unit=price_unit,
taxes_ids=taxes_ids,
)
# tax computation
# on purchase requisitions without a company_id
company_id = self.env.context.get("order_company_id")
partner_id = self.env.context.get("order_partner_id")
if company_id:
company = self.env["res.company"].browse(company_id)
partner = self.env["res.partner"].browse(partner_id)
if not partner:
partner = self.requisition_id.vendor_id
fpos = (
self.env["account.fiscal.position"]
.with_company(company)
._get_fiscal_position(partner)
)
taxes = self.product_id.supplier_taxes_id.filtered(
lambda tax: tax.company_id in company
)
if not taxes:
taxes = self.product_id.supplier_taxes_id.filtered(
lambda tax: tax.company_id in company.parent_ids
)
values["taxes_id"] = [(6, 0, fpos.map_tax(taxes).ids)]
return values
3 changes: 3 additions & 0 deletions purchase_requisition_section_and_note/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
3 changes: 3 additions & 0 deletions purchase_requisition_section_and_note/readme/CONTIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- David BEAL <david.beal@akretion.com>
- BADEP
- Quentin Dupont (<quentin.dupont@grap.coop>)
10 changes: 10 additions & 0 deletions purchase_requisition_section_and_note/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
This module adds the possibility to add sections ands notes in Purchase Requisition. It adds a page in form view.

.. figure:: static/description/agreement.png


.. figure:: static/description/po.png


Copy paste from mrp_bom_widget_section_and_note_one2many

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading