Skip to content

Commit

Permalink
[17.0][MIG]ddmrp
Browse files Browse the repository at this point in the history
  • Loading branch information
Vandan-OSI committed May 10, 2024
1 parent d7db326 commit d18744a
Show file tree
Hide file tree
Showing 24 changed files with 220 additions and 311 deletions.
17 changes: 7 additions & 10 deletions ddmrp/models/mrp_bom.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ class MrpBom(models.Model):
string="Stock Location",
compute="_compute_context_location",
)
# This is a legacy field that can be removed in v17
location_id = fields.Many2one(related="context_location_id")

def _get_search_buffer_domain(self):
product = self.product_id
Expand Down Expand Up @@ -61,12 +59,12 @@ def _compute_is_buffered(self):
for bom in self:
bom.is_buffered = True if bom.buffer_id else False

@api.depends_context("location_id")
@api.depends_context("context_location_id")
def _compute_context_location(self):
warehouse_model = self.env["stock.warehouse"]
for rec in self:
if self.env.context.get("location_id", None):
rec.context_location_id = self.env.context.get("location_id")
if self.env.context.get("context_location_id", None):
rec.context_location_id = self.env.context.get("context_location_id")
elif self.env.context.get("warehouse", None):
warehouse_id = self.env.context.get("warehouse")
rec.context_location_id = warehouse_model.browse(
Expand All @@ -81,7 +79,8 @@ def _compute_context_location(self):

def _get_produce_delay(self):
self.ensure_one()
return self.product_id.produce_delay or self.product_tmpl_id.produce_delay
# return self.product_id.produce_delay or self.product_tmpl_id.produce_delay
return self.produce_delay

def _get_longest_path(self):
if not self.bom_line_ids:
Expand Down Expand Up @@ -128,7 +127,7 @@ def _get_manufactured_dlt(self):
return dlt

@api.depends("context_location_id")
@api.depends_context("location_id")
@api.depends_context("context_location_id")
def _compute_dlt(self):
for rec in self:
rec.dlt = rec._get_manufactured_dlt()
Expand Down Expand Up @@ -161,8 +160,6 @@ class MrpBomLine(models.Model):
compute="_compute_dlt",
)
context_location_id = fields.Many2one(related="bom_id.context_location_id")
# This is a legacy field that can be removed in v17
location_id = fields.Many2one(related="context_location_id")

def _get_search_buffer_domain(self):
product = self.product_id
Expand All @@ -177,7 +174,7 @@ def _get_search_buffer_domain(self):
return domain

@api.depends("context_location_id")
@api.depends_context("location_id")
@api.depends_context("context_location_id")
def _compute_is_buffered(self):
for line in self:
domain = line._get_search_buffer_domain()
Expand Down
25 changes: 6 additions & 19 deletions ddmrp/models/stock_buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def default_get(self, fields):
name = fields.Char(
copy=False,
required=True,
default=lambda self: self.env["ir.sequence"].next_by_code("stock.buffer"),
# default=lambda self: self.env["ir.sequence"].next_by_code("stock.buffer"),
)
active = fields.Boolean(default=True)
warehouse_id = fields.Many2one(
Expand Down Expand Up @@ -149,8 +149,7 @@ def default_get(self, fields):
(
"stock_buffer_uniq",
"unique(product_id, location_id)",
"The product/location combination must be unique."
"Remember that the buffer could be archived.",
"The product/location combination must be unique. Remember that the buffer could be archived.",
),
]

Expand Down Expand Up @@ -371,7 +370,7 @@ def _get_outgoing_reservation_qty(self):
lambda line: line.location_id.is_sublocation_of(self.location_id)
and not line.location_dest_id.is_sublocation_of(self.location_id)
)
return sum(lines.mapped("reserved_qty"))
return sum(lines.mapped("quantity"))

def _update_quantities_dict(self, product):
self.ensure_one()
Expand Down Expand Up @@ -960,7 +959,6 @@ def _compute_order_spike_threshold(self):
def _get_manufactured_bom(self, limit=1):
return self.env["mrp.bom"].search(
[
("type", "=", "normal"),
"|",
("product_id", "=", self.product_id.id),
("product_tmpl_id", "=", self.product_id.product_tmpl_id.id),
Expand Down Expand Up @@ -1242,10 +1240,10 @@ def _compute_product_vendor_code(self):
)
ddmrp_chart = fields.Text(
string="DDMRP Chart",
compute=_compute_ddmrp_chart_planning,
compute="_compute_ddmrp_chart_planning",
)
ddmrp_chart_execution = fields.Text(
string="DDMRP Execution Chart", compute=_compute_ddmrp_chart_execution
string="DDMRP Execution Chart", compute="_compute_ddmrp_chart_execution"
)
show_execution_chart = fields.Boolean()
ddmrp_demand_chart = fields.Text(
Expand Down Expand Up @@ -1619,7 +1617,7 @@ def _get_demand_by_days(self, moves):
demand_by_days[
date
] += move.product_qty - move.product_uom._compute_quantity(
move.reserved_availability, move.product_id.uom_id
move.product_uom_qty, move.product_id.uom_id
)
return demand_by_days

Expand Down Expand Up @@ -1781,7 +1779,6 @@ def write(self, vals):
def _procure_qty_to_order(self):
qty_to_order = self.procure_recommended_qty
rounding = self.procure_uom_id.rounding or self.product_uom.rounding
qty_in_progress = self._quantity_in_progress()[self._origin.id]
if (
self.item_type == "distributed"
and self.buffer_profile_id.replenish_distributed_limit_to_free_qty
Expand All @@ -1802,16 +1799,6 @@ def _procure_qty_to_order(self):
else:
# move only what we have in stock
return min(qty_to_order, self.distributed_source_location_qty)
elif (
float_compare(qty_in_progress, 0, precision_rounding=rounding) > 0
and float_compare(
qty_to_order, self.green_zone_qty, precision_rounding=rounding
)
< 0
):
# When there is qty in progress (e.g. RfQ sent), do not keep
# auto-procuring small quantities, wait for the qty to be at least GZ.
return 0
return qty_to_order

def do_auto_procure(self):
Expand Down
5 changes: 4 additions & 1 deletion ddmrp/report/mrp_report_bom_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def _get_bom_data(
def _get_component_data(
self,
parent_bom,
parent_product,
warehouse,
bom_line,
line_quantity,
Expand All @@ -58,6 +59,7 @@ def _get_component_data(
):
res = super(BomStructureReport, self)._get_component_data(
parent_bom,
parent_product,
warehouse,
bom_line,
line_quantity,
Expand All @@ -67,7 +69,8 @@ def _get_component_data(
ignore_stock=ignore_stock,
)
if bom_line.product_id.bom_ids:
lead_time = bom_line.product_id.produce_delay
# lead_time = bom_line.product_id.produce_delay
lead_time = bom_line.bom_id.produce_delay
else:
lead_time = (
bom_line.product_id.seller_ids
Expand Down
19 changes: 8 additions & 11 deletions ddmrp/static/src/components/bom_overview/mrp_bom_overview.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,24 @@
import {BomOverviewComponent} from "@mrp/components/bom_overview/mrp_bom_overview";
import {patch} from "@web/core/utils/patch";

patch(BomOverviewComponent.prototype, "ddmrp", {
patch(BomOverviewComponent.prototype, {
setup() {
this._super.apply();
super.setup();
this.state.showOptions.is_buffered = true;
this.state.showOptions.dlt = true;
},

async getWarehouses() {
await this._super.apply();
await super.getWarehouses();
if (this.props.action.context.warehouse_id) {
this.state.currentWarehouse = this.warehouses.filter(
(warehouse) => warehouse.id === this.props.action.context.warehouse_id
)[0];
}
},

getReportName() {
return (
this._super.apply(this, arguments) +
"&show_buffered=" +
this.state.showOptions.is_buffered
);
},
});

getReportName(printAll) {
return super.getReportName(...arguments) + "&show_buffered=" + this.state.showOptions.is_buffered;
}
});
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
/** @odoo-module **/

import { _t } from "@web/core/l10n/translation";
import {BomOverviewDisplayFilter} from "@mrp/components/bom_overview_display_filter/mrp_bom_overview_display_filter";

import {patch} from "@web/core/utils/patch";

patch(BomOverviewDisplayFilter.prototype, "ddmrp", {
patch(BomOverviewDisplayFilter.prototype,{
setup() {
this._super.apply();
this.displayOptions.is_buffered = this.env._t("Buffered");
super.setup();
this.displayOptions.is_buffered = _t("Buffered");
},
});

patch(BomOverviewDisplayFilter, "ddmrp", {
patch(BomOverviewDisplayFilter,{
props: {
...BomOverviewDisplayFilter.props,
showOptions: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import {BomOverviewLine} from "@mrp/components/bom_overview_line/mrp_bom_overview_line";
import {patch} from "@web/core/utils/patch";

patch(BomOverviewLine, "ddmrp", {
patch(BomOverviewLine,{
props: {
...BomOverviewLine.props,
showOptions: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
t-name="ddmrp.BomOverviewLine"
t-inherit="mrp.BomOverviewLine"
t-inherit-mode="extension"
owl="1"
>
<xpath expr="//td[@name='td_mrp_bom']" position="before">
<td
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import {BomOverviewSpecialLine} from "@mrp/components/bom_overview_special_line/mrp_bom_overview_special_line";
import {patch} from "@web/core/utils/patch";

patch(BomOverviewSpecialLine, "ddmrp", {
patch(BomOverviewSpecialLine,{
props: {
...BomOverviewSpecialLine.props,
showOptions: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
t-name="ddmrp.BomOverviewSpecialLine"
t-inherit="mrp.BomOverviewSpecialLine"
t-inherit-mode="extension"
owl="1"
>
<xpath expr="//td[@name='td_mrp_bom']" position="before">
<td t-if="showBuffered" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
import {BomOverviewTable} from "@mrp/components/bom_overview_table/mrp_bom_overview_table";
import {patch} from "@web/core/utils/patch";

patch(BomOverviewTable.prototype, "ddmrp", {
patch(BomOverviewTable.prototype,{
// ---- Getters ----

get showBuffered() {
return this.props.showOptions.is_buffered;
},
});

patch(BomOverviewTable, "ddmrp", {
patch(BomOverviewTable,{
props: {
...BomOverviewTable.props,
showOptions: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
t-name="ddmrp.BomOverviewTable"
t-inherit="mrp.BomOverviewTable"
t-inherit-mode="extension"
owl="1"
>
<xpath expr="//th[@name='th_mrp_bom_h']" position="before">
<th t-if="showBuffered" class="text-center">Buffered</th>
Expand Down
65 changes: 34 additions & 31 deletions ddmrp/static/src/widgets/stock_buffer_info.esm.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
/** @odoo-module **/

import {FloatField} from "@web/views/fields/float/float_field";
import {FloatField , floatField} from "@web/views/fields/float/float_field";
import {loadBundle} from "@web/core/assets";
import {registry} from "@web/core/registry";
import {useService} from "@web/core/utils/hooks";
import {useUniquePopover} from "@web/core/model_field_selector/unique_popover_hook";

const {Component, markup, onWillStart} = owl;
import { usePopover } from "@web/core/popover/popover_hook";
import { Component, markup, onWillStart } from "@odoo/owl";

export class StockBufferPopover extends Component {
setup() {
Expand Down Expand Up @@ -69,7 +68,7 @@ StockBufferPopover.template = "ddmrp.StockBufferPopover";
export class StockBufferInfoWidget extends FloatField {
setup() {
super.setup();
this.popover = useUniquePopover();
this.popover = usePopover(StockBufferPopover);
}

get classFromDecoration() {
Expand All @@ -84,43 +83,47 @@ export class StockBufferInfoWidget extends FloatField {
showPopup(ev) {
ev.stopPropagation();
ev.preventDefault();
this.popover.add(
ev.currentTarget,
this.constructor.components.Popover,
{
bus: this.bus,
record: this.props.record,
field: this.props.field,
color_from: this.props.color_from,
buffer_id: this.props.buffer_id,
},
{
position: "right",
}
);
this.popover.open(ev.currentTarget, {
bus: this.bus,
record: this.props.record,
field: this.props.field,
color_from: this.props.color_from,
buffer_id: this.props.buffer_id,
},
{
position: "right",
});
}
}

StockBufferInfoWidget.components = {
...StockBufferInfoWidget.components,
StockBufferInfoWidget.template = "ddmrp.StockBufferInfoWidget";
export const stockBufferInfoWidget = {
...floatField,
component: StockBufferInfoWidget,
};

stockBufferInfoWidget.components = {
...stockBufferInfoWidget.components,
Popover: StockBufferPopover,
};
StockBufferInfoWidget.template = "ddmrp.StockBufferInfoWidget";

StockBufferInfoWidget.props = {
...StockBufferInfoWidget.props,


stockBufferInfoWidget.props = {
...stockBufferInfoWidget.props,
color_from: {type: String, optional: true},
field: {type: String, optional: true},
buffer_id: {type: String, optional: true},
};

const StockBufferInfoWidgetExtractProps = StockBufferInfoWidget.extractProps;
StockBufferInfoWidget.extractProps = ({attrs, field}) => {
return Object.assign(StockBufferInfoWidgetExtractProps({attrs, field}), {
color_from: attrs.options.color_from,
field: attrs.options.field,
buffer_id: attrs.options.buffer_id,
const StockBufferInfoWidgetExtractProps = stockBufferInfoWidget.extractProps;

stockBufferInfoWidget.extractProps = ({attrs, options}) => {
return Object.assign(StockBufferInfoWidgetExtractProps({attrs, options}), {
color_from: options.color_from,
field: options.field,
buffer_id: options.buffer_id,
});
};

registry.category("fields").add("stock_buffer_info", StockBufferInfoWidget);
registry.category("fields").add("stock_buffer_info", stockBufferInfoWidget);
Loading

0 comments on commit d18744a

Please sign in to comment.