Skip to content

Commit

Permalink
[ADD] purchase_requisition_filter_date: Add fields filter_date_from a…
Browse files Browse the repository at this point in the history
…nd filter_date_to
  • Loading branch information
unaiberis committed Jan 30, 2025
1 parent 3c9b478 commit e79ed1d
Show file tree
Hide file tree
Showing 9 changed files with 138 additions and 0 deletions.
50 changes: 50 additions & 0 deletions purchase_requisition_filter_date/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
.. image:: https://img.shields.io/badge/license-LGPL--3-blue.svg
:target: https://opensource.org/licenses/LGPL-3.0
:alt: License: LGPL-3

===================================
Purchase Requisition Filter by Date
===================================

Overview
========

The **Purchase Requisition Filter by Date** module allows users to filter purchase requisition lines by a date range. This is particularly helpful in managing large purchase requisitions by focusing on specific scheduled dates.

Features
========

- **Date Range Filters**:

- Add fields for "From Date" and "To Date" on the purchase requisition form.

- Filter purchase requisition lines based on the provided date range.

- **Enhanced Workflow**:

- Update the wizard for creating purchase orders to respect the filtered date range.

- **Automatic Grouping**:

- Group requisition lines by scheduled date and create purchase orders with the appropriate planned dates.

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

If you encounter any issues, please report them on the GitHub repository at `GitHub Issues <https://github.com/avanzosc/odoo-addons/issues>`_.

Credits
=======

Contributors
------------

* Ana Juaristi <[email protected]>
* Unai Beristain <[email protected]>

For specific questions or support, please contact the contributors.

License
=======

This project is licensed under the LGPL-3 License. For more details, refer to the LICENSE file or visit <https://opensource.org/licenses/LGPL-3.0>.
3 changes: 3 additions & 0 deletions purchase_requisition_filter_date/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import models

# from . import wizard
14 changes: 14 additions & 0 deletions purchase_requisition_filter_date/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "Purchase Requisition Filter by Date",
"version": "16.0.1.0.0",
"category": "Purchases",
"author": "Avanzosc",
"license": "LGPL-3",
"depends": ["purchase_requisition"],
"data": [
"views/purchase_requisition_views.xml",
],
"installable": True,
"application": False,
"website": "https://github.com/avanzosc/odoo-addons",
}
2 changes: 2 additions & 0 deletions purchase_requisition_filter_date/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import purchase_order
from . import purchase_requisition
38 changes: 38 additions & 0 deletions purchase_requisition_filter_date/models/purchase_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from odoo import api, models


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

@api.onchange("requisition_id")
def _onchange_requisition_id(self):
if self.requisition_id:
valid_lines = self.requisition_id.line_ids.filtered(
lambda line: self.requisition_id.date_from
<= line.schedule_date
<= self.requisition_id.date_to
)

result = super()._onchange_requisition_id()

for sale_order_line in self.order_line:
matching_requisition_line = valid_lines.filtered(
lambda line: line.product_id == sale_order_line.product_id
)

if matching_requisition_line:
sale_order_line.date_planned = (
matching_requisition_line.schedule_date
)

self.order_line = self.order_line - sale_order_line

self.order_line |= sale_order_line

else:
self.order_line = self.order_line - sale_order_line

for sale_order_line in self.order_line:
print(sale_order_line.date_planned)

return result
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from odoo import fields, models


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

date_from = fields.Date(string="From")
date_to = fields.Date(string="To")
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<odoo>
<record id="view_purchase_requisition_form_inherit" model="ir.ui.view">
<field name="name">purchase.requisition.form.inherit.filter.date</field>
<field name="model">purchase.requisition</field>
<field
name="inherit_id"
ref="purchase_requisition.view_purchase_requisition_form"
/>
<field name="arch" type="xml">
<xpath expr="//group/group" position="inside">
<field name="date_from" />
<field name="date_to" />
</xpath>
</field>
</record>
</odoo>
6 changes: 6 additions & 0 deletions setup/purchase_requisition_filter_date/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 e79ed1d

Please sign in to comment.