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 a76c454
Show file tree
Hide file tree
Showing 10 changed files with 156 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",
}
3 changes: 3 additions & 0 deletions purchase_requisition_filter_date/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import purchase_order_line
from . import purchase_order
from . import purchase_requisition
36 changes: 36 additions & 0 deletions purchase_requisition_filter_date/models/purchase_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from datetime import datetime, time

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:
schedule_datetime = datetime.combine(
matching_requisition_line.schedule_date, time.min
)

sale_order_line.date_planned = schedule_datetime

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
return result
19 changes: 19 additions & 0 deletions purchase_requisition_filter_date/models/purchase_order_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from odoo import models


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

def _compute_price_unit_and_date_planned_and_name(self):
for pol in self:
if pol.product_id.id in pol.order_id.requisition_id.line_ids.product_id.ids:
matching_requisition_line = (
pol.order_id.requisition_id.line_ids.filtered(
lambda line: line.product_id == pol.product_id
)
)

if matching_requisition_line:
pol.date_planned = matching_requisition_line.schedule_date

return super()._compute_price_unit_and_date_planned_and_name()
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 a76c454

Please sign in to comment.