-
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
9 changed files
with
244 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 @@ | ||
from . import models |
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,2 @@ | ||
from . import purchase_requisition | ||
from . import purchase_requisition_create_alternative |
65 changes: 65 additions & 0 deletions
65
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,65 @@ | ||
import logging | ||
|
||
from odoo import fields, models | ||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
|
||
class PurchaseRequisition(models.Model): | ||
_inherit = "purchase.requisition" | ||
|
||
filter_date_from = fields.Date(string="From") | ||
filter_date_to = fields.Date(string="To") | ||
|
||
def CREATE_PO(self): | ||
_logger.info( | ||
"CREATE_PO: Starting wizard creation for requisition ID %s", self.id | ||
) | ||
self.ensure_one() | ||
|
||
wizard = self.env["purchase.requisition.create.po.wizard"].create( | ||
{"requisition_id": self.id} | ||
) | ||
_logger.info( | ||
"CREATE_PO: Created wizard ID %s for requisition ID %s", | ||
wizard.id, | ||
self.id, | ||
) | ||
|
||
lines = self.line_ids.filtered( | ||
lambda line: not line.schedule_date | ||
or (self.filter_date_from and line.schedule_date >= self.filter_date_from) | ||
or (self.filter_date_to and line.schedule_date <= self.filter_date_to) | ||
) | ||
_logger.info( | ||
"CREATE_PO: Found %d lines matching filters for requisition ID %s", | ||
len(lines), | ||
self.id, | ||
) | ||
if lines: | ||
_logger.debug( | ||
"CREATE_PO: Matching line IDs: %s", | ||
[line.id for line in lines], | ||
) | ||
|
||
wizard.line_ids = [(6, 0, lines.ids)] | ||
_logger.info( | ||
"CREATE_PO: Assigned %d lines to wizard ID %s", | ||
len(lines), | ||
wizard.id, | ||
) | ||
|
||
action = { | ||
"name": "Crear Pedido", | ||
"type": "ir.actions.act_window", | ||
"res_model": "purchase.requisition.create.po.wizard", | ||
"view_mode": "form", | ||
"target": "new", | ||
"res_id": wizard.id, | ||
} | ||
_logger.info( | ||
"CREATE_PO: Returning action to open wizard ID %s for requisition ID %s", | ||
wizard.id, | ||
self.id, | ||
) | ||
return action |
64 changes: 64 additions & 0 deletions
64
purchase_requisition_filter_date/models/purchase_requisition_create_alternative.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,64 @@ | ||
import logging | ||
from collections import defaultdict | ||
|
||
from odoo import fields, models | ||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
class PurchaseRequisitionCreateAlternative(models.TransientModel): | ||
_inherit = "purchase.requisition.create.alternative" | ||
|
||
filter_date_from = fields.Date(string="Desde") | ||
filter_date_to = fields.Date(string="Hasta") | ||
|
||
def action_create_alternative(self): | ||
# Llamamos a la función original utilizando super() | ||
_logger.info( | ||
"ACTION_CREATE_ALTERNATIVE: Starting custom creation for requisition", | ||
) | ||
# Obtener las líneas de la requisición para crear los pedidos | ||
requisition_lines_by_date = defaultdict(list) | ||
|
||
for line in self.line_ids: | ||
# Filtrar según las fechas 'Desde' y 'Hasta' | ||
if self.filter_date_from and line.schedule_date and line.schedule_date < self.filter_date_from: | ||
continue | ||
if self.filter_date_to and line.schedule_date and line.schedule_date > self.filter_date_to: | ||
continue | ||
# Agrupar las líneas por fecha de programación | ||
requisition_lines_by_date[line.schedule_date].append(line) | ||
_logger.info( | ||
"ACTION_CREATE_ALTERNATIVE: Line ID %s grouped by date %s", line.id, line.schedule_date | ||
) | ||
|
||
orders = [] | ||
for date, lines in requisition_lines_by_date.items(): | ||
_logger.info( | ||
"ACTION_CREATE_ALTERNATIVE: Preparing purchase order for date %s with %d lines", | ||
date, | ||
len(lines), | ||
) | ||
|
||
# Llamar al método original de creación de órdenes de compra | ||
po_vals = self._prepare_purchase_order() # Usar el método de la clase base | ||
po = self.env["purchase.order"].create(po_vals) | ||
_logger.info( | ||
"ACTION_CREATE_ALTERNATIVE: Created purchase order ID %s for date %s", po.id, date | ||
) | ||
|
||
# Crear las líneas del pedido para cada línea agrupada | ||
for line in lines: | ||
po_line_vals = line._prepare_purchase_order_line(po) | ||
po_line_vals["date_planned"] = date # Asignar la fecha de entrega | ||
self.env["purchase.order.line"].create(po_line_vals) | ||
_logger.info( | ||
"ACTION_CREATE_ALTERNATIVE_LINE: Created line for purchase order ID %s with values: %s", | ||
po.id, | ||
po_line_vals, | ||
) | ||
orders.append(po) | ||
|
||
# Llamar al método original para finalizar el estado de la requisición (no se usa requisition_id directamente) | ||
super(PurchaseRequisitionCreateAlternative, self).action_create_alternative() | ||
|
||
return orders |
41 changes: 41 additions & 0 deletions
41
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,41 @@ | ||
<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="filter_date_from" /> | ||
<field name="filter_date_to" /> | ||
</xpath> | ||
</field> | ||
</record> | ||
|
||
<record | ||
id="purchase_requisition_create_alternative_form_inherit" | ||
model="ir.ui.view" | ||
> | ||
<field name="name">Create Alternative Inherited</field> | ||
<field name="model">purchase.requisition.create.alternative</field> | ||
<field | ||
name="inherit_id" | ||
ref="purchase_requisition.purchase_requisition_create_alternative_form" | ||
/> | ||
<field name="arch" type="xml"> | ||
<xpath expr="//group" position="before"> | ||
<group> | ||
<group> | ||
<field name="filter_date_from" /> | ||
</group> | ||
<group> | ||
<field name="filter_date_to" /> | ||
</group> | ||
</group> | ||
</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, | ||
) |