-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] purchase_requisition_filter_date: Add fields filter_date_from a…
…nd filter_date_to
- Loading branch information
Showing
10 changed files
with
156 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from . import models | ||
|
||
# from . import wizard |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
19
purchase_requisition_filter_date/models/purchase_order_line.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
8 changes: 8 additions & 0 deletions
8
purchase_requisition_filter_date/models/purchase_requisition.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
16 changes: 16 additions & 0 deletions
16
purchase_requisition_filter_date/views/purchase_requisition_views.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
1 change: 1 addition & 0 deletions
1
setup/purchase_requisition_filter_date/odoo/addons/purchase_requisition_filter_date
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../purchase_requisition_filter_date |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) |