Skip to content

Commit

Permalink
[IMP] stock_buffer_route: Add alternative item type in buffer
Browse files Browse the repository at this point in the history
Considering that the 'Route' field will be used to define a different way to procure, a field called 'Alternative Item Type' is added in the Stock Buffer to simplify the search with the filters.
  • Loading branch information
BernatPForgeFlow committed Aug 1, 2023
1 parent 390db0c commit 90f6300
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 13 deletions.
30 changes: 29 additions & 1 deletion stock_buffer_route/models/stock_buffer.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# Copyright 2019-20 ForgeFlow S.L. (https://www.forgeflow.com)
# Copyright 2019-23 ForgeFlow S.L. (https://www.forgeflow.com)
# Copyright 2019-20 Camptocamp SA
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).

from odoo import api, fields, models

_ITEM_TYPES = [
("manufactured", "Manufactured"),
("purchased", "Purchased"),
("distributed", "Distributed"),
]


class StockBuffer(models.Model):
_inherit = "stock.buffer"
Expand All @@ -19,6 +25,12 @@ class StockBuffer(models.Model):
domain="[('id', 'in', route_ids)]",
ondelete="restrict",
)
item_type_alternative = fields.Selection(
string="Alternative Item Type",
selection=_ITEM_TYPES,
compute="_compute_item_type_alternative",
store=True,
)

@api.depends("product_id", "warehouse_id", "warehouse_id.route_ids", "location_id")
def _compute_route_ids(self):
Expand All @@ -35,6 +47,22 @@ def _compute_route_ids(self):
parents = record.get_parents()
record.route_ids = self._get_location_routes_of_parents(routes, parents)

@api.depends(
"product_id", "route_id", "route_id.rule_ids", "route_id.rule_ids.action"
)
def _compute_item_type_alternative(self):
for rec in self:
rec.item_type_alternative = ""
if rec.route_id:
if "buy" in rec.route_id.mapped("rule_ids.action"):
rec.item_type_alternative = "purchased"

Check warning on line 58 in stock_buffer_route/models/stock_buffer.py

View check run for this annotation

Codecov / codecov/patch

stock_buffer_route/models/stock_buffer.py#L58

Added line #L58 was not covered by tests
elif "manufacture" in rec.route_id.mapped("rule_ids.action"):
rec.item_type_alternative = "manufactured"

Check warning on line 60 in stock_buffer_route/models/stock_buffer.py

View check run for this annotation

Codecov / codecov/patch

stock_buffer_route/models/stock_buffer.py#L60

Added line #L60 was not covered by tests
elif "pull" in rec.route_id.mapped(
"rule_ids.action"
) or "pull_push" in rec.route_id.mapped("rule_ids.action"):
rec.item_type_alternative = "distributed"

def _get_location_routes_of_parents(self, routes, parents):
return routes.filtered(
lambda route: (
Expand Down
30 changes: 29 additions & 1 deletion stock_buffer_route/views/stock_buffer_views.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2019-20 ForgeFlow S.L. (https://www.forgeflow.com)
<!-- Copyright 2019-23 ForgeFlow S.L. (https://www.forgeflow.com)
License LGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo>
<record id="stock_buffer_view_tree" model="ir.ui.view">
<field name="name">stock.buffer.tree</field>
<field name="model">stock.buffer</field>
<field name="inherit_id" ref="ddmrp.stock_buffer_view_tree" />
<field name="arch" type="xml">
<field name="item_type" position="after">
<field name="item_type_alternative" optional="hide" />
</field>
</field>
</record>
<record id="stock_buffer_view_form" model="ir.ui.view">
<field name="name">stock.buffer.form</field>
<field name="model">stock.buffer</field>
Expand All @@ -22,6 +32,24 @@
<field name="model">stock.buffer</field>
<field name="inherit_id" ref="ddmrp.stock_buffer_search" />
<field name="arch" type="xml">
<xpath
expr="//filter[@name='item_type_manufactured']"
position="attributes"
>
<attribute
name="domain"
>['|', ('item_type', '=', 'manufactured'), ('item_type_alternative', '=', 'manufactured')]</attribute>
</xpath>
<xpath expr="//filter[@name='item_type_purchased']" position="attributes">
<attribute
name="domain"
>['|', ('item_type', '=', 'purchased'), ('item_type_alternative', '=', 'purchased')]</attribute>
</xpath>
<xpath expr="//filter[@name='item_type_distributed']" position="attributes">
<attribute
name="domain"
>['|', ('item_type', '=', 'distributed'), ('item_type_alternative', '=', 'distributed')]</attribute>
</xpath>
<xpath
expr="//filter[@name='main_supplier_group_filter']"
position="before"
Expand Down
11 changes: 0 additions & 11 deletions stock_buffer_route/wizards/make_procurement_buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,6 @@
class MakeProcurementBuffer(models.TransientModel):
_inherit = "make.procurement.buffer"

partner_id = fields.Many2one(
comodel_name="res.partner",
string="Vendor",
help="If set, will be used as preferred vendor for purchase routes.",
)
item_ids = fields.One2many(
comodel_name="make.procurement.buffer.item",
inverse_name="wiz_id",
string="Items",
)

@api.model
def _prepare_item(self, buffer, qty_override=None):
res = super(MakeProcurementBuffer, self)._prepare_item(buffer, qty_override)
Expand Down

0 comments on commit 90f6300

Please sign in to comment.