-
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
12 changed files
with
205 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,15 @@ | ||
{ | ||
"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", | ||
# "wizard/purchase_requisition_wizard_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,2 @@ | ||
from . import purchase_order_line | ||
from . import purchase_requisition |
15 changes: 15 additions & 0 deletions
15
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,15 @@ | ||
from odoo import api, models | ||
|
||
|
||
class PurchaseOrderLine(models.Model): | ||
_inherit = "purchase.order.line" | ||
|
||
@api.model_create_multi | ||
def create(self, vals_list): | ||
if "purchase_requisition_date" in self.env.context: | ||
for i in range(len(vals_list) - 1, -1, -1): | ||
if "date_planned" not in vals_list[i]: | ||
del vals_list[i] | ||
if "purchase_requisition_date" in self.env.context and not vals_list: | ||
return self.env["purchase.order.line"] | ||
return super().create(vals_list) |
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> |
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 @@ | ||
from . import purchase_requisition_wizard |
74 changes: 74 additions & 0 deletions
74
purchase_requisition_filter_date/wizard/purchase_requisition_wizard.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,74 @@ | ||
from odoo import _, api, fields, models | ||
|
||
|
||
class PurchaseRequisitionAlternativeWarning(models.TransientModel): | ||
_inherit = "purchase.requisition.alternative.warning" | ||
|
||
@api.model | ||
def _default_alternatives_filter_date(self): | ||
po_obj = self.env["purchase.order"] | ||
alternatives = self._default_alternative_po_ids() | ||
filtered_alternatives = [] | ||
for alternative in alternatives: | ||
po_info = alternative[2] | ||
po = po_obj.browse(po_info.get("po_id")) | ||
valid = True | ||
if ( | ||
po.date_order and po.date_planned and po.date_planned < po.date_order | ||
) or ( | ||
po.date_deadline | ||
and po.date_planned | ||
and po.date_planned > po.date_deadline | ||
): | ||
valid = False | ||
if valid: | ||
filtered_alternatives.append(alternative) | ||
return filtered_alternatives | ||
|
||
alternative_po_ids = fields.Many2many( | ||
default=_default_alternatives_filter_date, | ||
) | ||
|
||
def action_group_by_date(self): | ||
dates = set(self.alternative_po_ids.mapped("date_planned")) | ||
grouped_alternatives = [] | ||
for date in dates: | ||
result = self.with_context( | ||
purchase_requisition_date=date | ||
)._group_alternatives() | ||
if "domain" in result: | ||
domain = result.get("domain") | ||
grouped_alternatives += domain[0][2] | ||
return { | ||
"domain": [("id", "in", grouped_alternatives)], | ||
"name": _("Grouped Alternatives"), | ||
"view_type": "form", | ||
"view_mode": "tree,form", | ||
"res_model": "purchase.order", | ||
"context": {"from_grouped_alternatives": True}, | ||
"type": "ir.actions.act_window", | ||
} | ||
|
||
def _group_alternatives(self): | ||
# Implementa la lógica para agrupar alternativas por fecha o cualquier otro criterio necesario. | ||
# Retorna un resultado con el dominio de las alternativas agrupadas. | ||
return { | ||
"domain": [("id", "in", self.alternative_po_ids.ids)], | ||
} | ||
|
||
def _prepare_po_vals(self, supplier, currency_id, alternative_lines_by_supplier): | ||
vals = super()._prepare_po_vals( | ||
supplier, currency_id, alternative_lines_by_supplier | ||
) | ||
if "purchase_requisition_date" in self.env.context: | ||
vals["date_planned"] = self.env.context.get("purchase_requisition_date") | ||
return vals | ||
|
||
def _prepare_po_line_vals(self, line): | ||
vals = super()._prepare_po_line_vals(line) | ||
if ( | ||
"purchase_requisition_date" in self.env.context | ||
and line.date_planned == self.env.context.get("purchase_requisition_date") | ||
): | ||
vals["date_planned"] = self.env.context.get("purchase_requisition_date") | ||
return vals |
14 changes: 14 additions & 0 deletions
14
purchase_requisition_filter_date/wizard/purchase_requisition_wizard_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,14 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<odoo> | ||
<record id="purchase_requisition_alternative_warning_form_inherit" model="ir.ui.view"> | ||
<field name="name">Alternative Warning Inherited</field> | ||
<field name="model">purchase.requisition.alternative.warning</field> | ||
<field name="inherit_id" ref="purchase_requisition.purchase_requisition_alternative_warning_form" /> | ||
<field name="arch" type="xml"> | ||
<xpath expr="//tree" position="inside"> | ||
<field name="filter_date_from" /> | ||
<field name="filter_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, | ||
) |