diff --git a/purchase_requisition_section_and_note/README.rst b/purchase_requisition_section_and_note/README.rst new file mode 100644 index 00000000000..65174c6c0f3 --- /dev/null +++ b/purchase_requisition_section_and_note/README.rst @@ -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 `_ + +**Table of contents** + +.. contents:: + :local: + +Bug Tracker +=========== + +Bugs are tracked on `GitHub 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 `_. + +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 `__: + +|maintainer-bealdav| + +This module is part of the `OCA/purchase-workflow `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/purchase_requisition_section_and_note/__init__.py b/purchase_requisition_section_and_note/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/purchase_requisition_section_and_note/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/purchase_requisition_section_and_note/__manifest__.py b/purchase_requisition_section_and_note/__manifest__.py new file mode 100644 index 00000000000..3e338cdc0b1 --- /dev/null +++ b/purchase_requisition_section_and_note/__manifest__.py @@ -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, +} diff --git a/purchase_requisition_section_and_note/data/demo.xml b/purchase_requisition_section_and_note/data/demo.xml new file mode 100644 index 00000000000..fe2a05d12ed --- /dev/null +++ b/purchase_requisition_section_and_note/data/demo.xml @@ -0,0 +1,75 @@ + + + + + purchase_template + my template + + + + + line_section + 2 + 0 + Section 1 + + + + 4 + + 1 + + + + 6 + + 1 + + + + 8 + + 1 + + + + line_section + 10 + 0 + Section 2 + + + + 12 + + 1 + + + + 14 + line_note + 0 + --> Nice flipover + + + + 16 + + 1 + + + + + + + + + + + + + diff --git a/purchase_requisition_section_and_note/models/__init__.py b/purchase_requisition_section_and_note/models/__init__.py new file mode 100644 index 00000000000..4e07a9ad187 --- /dev/null +++ b/purchase_requisition_section_and_note/models/__init__.py @@ -0,0 +1,5 @@ +from . import ( + purchase, + purchase_requisition, + purchase_requisition_line, +) diff --git a/purchase_requisition_section_and_note/models/purchase.py b/purchase_requisition_section_and_note/models/purchase.py new file mode 100644 index 00000000000..36b926fadb0 --- /dev/null +++ b/purchase_requisition_section_and_note/models/purchase.py @@ -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 diff --git a/purchase_requisition_section_and_note/models/purchase_requisition.py b/purchase_requisition_section_and_note/models/purchase_requisition.py new file mode 100644 index 00000000000..e90416870da --- /dev/null +++ b/purchase_requisition_section_and_note/models/purchase_requisition.py @@ -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, + ) diff --git a/purchase_requisition_section_and_note/models/purchase_requisition_line.py b/purchase_requisition_section_and_note/models/purchase_requisition_line.py new file mode 100644 index 00000000000..5886c40f25c --- /dev/null +++ b/purchase_requisition_section_and_note/models/purchase_requisition_line.py @@ -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 diff --git a/purchase_requisition_section_and_note/pyproject.toml b/purchase_requisition_section_and_note/pyproject.toml new file mode 100644 index 00000000000..4231d0cccb3 --- /dev/null +++ b/purchase_requisition_section_and_note/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/purchase_requisition_section_and_note/readme/CONTIBUTORS.md b/purchase_requisition_section_and_note/readme/CONTIBUTORS.md new file mode 100644 index 00000000000..b70290a250a --- /dev/null +++ b/purchase_requisition_section_and_note/readme/CONTIBUTORS.md @@ -0,0 +1,3 @@ +- David BEAL +- BADEP +- Quentin Dupont () diff --git a/purchase_requisition_section_and_note/readme/DESCRIPTION.md b/purchase_requisition_section_and_note/readme/DESCRIPTION.md new file mode 100644 index 00000000000..ae4204d08ed --- /dev/null +++ b/purchase_requisition_section_and_note/readme/DESCRIPTION.md @@ -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 + diff --git a/purchase_requisition_section_and_note/static/description/agreement.png b/purchase_requisition_section_and_note/static/description/agreement.png new file mode 100644 index 00000000000..3e22addbded Binary files /dev/null and b/purchase_requisition_section_and_note/static/description/agreement.png differ diff --git a/purchase_requisition_section_and_note/static/description/index.html b/purchase_requisition_section_and_note/static/description/index.html new file mode 100644 index 00000000000..b89cc111a72 --- /dev/null +++ b/purchase_requisition_section_and_note/static/description/index.html @@ -0,0 +1,432 @@ + + + + + +Purchase Requisition Section and Note + + + +
+

Purchase Requisition Section and Note

+ + +

Alpha License: AGPL-3 OCA/purchase-workflow Translate me on Weblate Try me on Runboat

+

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

+
+https://raw.githubusercontent.com/OCA/purchase-workflow/18.0/purchase_requisition_section_and_note/static/description/agreement.png +
+
+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

+
+

Table of contents

+ +
+

Bug Tracker

+

Bugs are tracked on GitHub 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.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Akretion
  • +
+
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

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.

+

Current maintainer:

+

bealdav

+

This module is part of the OCA/purchase-workflow project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/purchase_requisition_section_and_note/static/description/po.png b/purchase_requisition_section_and_note/static/description/po.png new file mode 100644 index 00000000000..ef6998ae37f Binary files /dev/null and b/purchase_requisition_section_and_note/static/description/po.png differ diff --git a/purchase_requisition_section_and_note/tests/__init__.py b/purchase_requisition_section_and_note/tests/__init__.py new file mode 100644 index 00000000000..d9b96c4fa5a --- /dev/null +++ b/purchase_requisition_section_and_note/tests/__init__.py @@ -0,0 +1 @@ +from . import test_module diff --git a/purchase_requisition_section_and_note/tests/test_module.py b/purchase_requisition_section_and_note/tests/test_module.py new file mode 100644 index 00000000000..613f71a4615 --- /dev/null +++ b/purchase_requisition_section_and_note/tests/test_module.py @@ -0,0 +1,18 @@ +from odoo.tests.common import TransactionCase + + +class TestModule(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True)) + + def test_compare_lines_order_between_purchase_and_requistion(self): + po = self.env.ref("purchase_requisition_section_and_note.po1") + po._onchange_requisition_id() + po_lines_order = [x.name for x in po.order_line.sorted("sequence")] + requisition_lines_order = [ + x.name or x.product_id.display_name + for x in po.requisition_id.line_with_sectionnote_ids.sorted("sequence") + ] + self.assertEqual(po_lines_order, requisition_lines_order) diff --git a/purchase_requisition_section_and_note/views/purchase.xml b/purchase_requisition_section_and_note/views/purchase.xml new file mode 100644 index 00000000000..9ef3b8e1e16 --- /dev/null +++ b/purchase_requisition_section_and_note/views/purchase.xml @@ -0,0 +1,18 @@ + + + purchase.order + + + +