Initial commit: OCA Technical packages (595 packages)

This commit is contained in:
Ernad Husremovic 2025-08-29 15:43:03 +02:00
commit 2cc02aac6e
24950 changed files with 2318079 additions and 0 deletions

View file

@ -0,0 +1 @@
from . import ddmrp_adjustment_sheet

View file

@ -0,0 +1,138 @@
# Copyright 2017-20 ForgeFlow S.L. (https://www.forgeflow.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import _, api, fields, models
from odoo.exceptions import ValidationError
from ..models.ddmrp_adjustment import DAF_string, LTAF_string
class DdmrpAdjustmentSheet(models.TransientModel):
_name = "ddmrp.adjustment.sheet"
_description = "Buffer Adjustment Sheet"
def _get_factors(self):
factors = []
if self.apply_daf:
factors.append(DAF_string)
if self.apply_ltaf:
factors.append(LTAF_string)
return factors
def _prepare_line(self, period, factor):
vals = {
"sheet_id": self.id,
"date_range_id": period.id,
"factor": factor,
"value": 0.0,
}
return vals
def _prepare_lines(self):
self.ensure_one()
periods = self.env["date.range"].search(
[
("type_id", "=", self.date_range_type_id.id),
"|",
"&",
("date_start", ">=", self.date_start),
("date_start", "<=", self.date_end),
"&",
("date_end", ">=", self.date_start),
("date_end", "<=", self.date_end),
]
)
# TODO: re-check
domain = [
("type_id", "=", self.date_range_type_id.id),
("date_start", "<=", self.date_start),
("date_end", ">=", self.date_start),
]
periods |= self.env["date.range"].search(domain)
factors = self._get_factors()
items = []
for period in periods:
for factor in factors:
vals = self._prepare_line(period, factor)
items.append((0, 0, vals))
return items
@api.constrains("date_start", "date_end")
def _check_start_end_dates(self):
for rec in self:
if rec.date_start > rec.date_end:
raise ValidationError(
_("The start date cannot be later than the end date.")
)
date_start = fields.Date(string="Date From", required=True)
date_end = fields.Date(string="Date To", required=True)
date_range_type_id = fields.Many2one(
string="Date Range Type", comodel_name="date.range.type", required=True
)
buffer_ids = fields.Many2many(comodel_name="stock.buffer", string="DDMRP Buffers")
line_ids = fields.Many2many(
string="Adjustments", comodel_name="ddmrp.adjustment.sheet.line"
)
apply_daf = fields.Boolean(string="Demand Adjustment Factor")
apply_ltaf = fields.Boolean(string="Lead Time Adjustment Factor")
@api.onchange(
"date_range_type_id", "date_start", "date_end", "apply_daf", "apply_ltaf"
)
def _onchange_sheet(self):
self.line_ids = [(6, 0, [])]
if not (
self.date_range_type_id
and self.date_start
and self.date_end
and len(self.buffer_ids) > 0
):
return
if self.apply_daf or self.apply_ltaf:
lines = self._prepare_lines()
self.line_ids = lines
def button_validate(self):
self.ensure_one()
if not self.buffer_ids:
raise ValidationError(_("You must select at least one buffer."))
if not self.line_ids.mapped("factor"):
raise ValidationError(_("You must apply at least one factor"))
res = []
for b in self.buffer_ids:
for line in self.line_ids:
data = line._prepare_adjustment_data(b)
estimate = self.env["ddmrp.adjustment"].create(data)
res.append(estimate.id)
action = {
"domain": [("id", "in", res)],
"name": _("DDMRP Buffer Adjustment"),
"src_model": "ddmrp.adjustment.sheet",
"view_mode": "tree",
"res_model": "ddmrp.adjustment",
"type": "ir.actions.act_window",
}
return action
class DdmrpAdjustmentSheetLine(models.TransientModel):
_name = "ddmrp.adjustment.sheet.line"
_description = "Buffer Adjustment Sheet Line"
sheet_id = fields.Many2one(comodel_name="ddmrp.adjustment.sheet")
date_range_id = fields.Many2one(comodel_name="date.range", string="Period")
factor = fields.Char(string="Factors")
value = fields.Float()
@api.model
def _prepare_adjustment_data(self, buf):
data = {
"date_range_id": self.date_range_id.id,
"buffer_id": buf.id,
"value": self.value,
"adjustment_type": self.factor,
}
return data

View file

@ -0,0 +1,76 @@
<?xml version="1.0" ?>
<odoo>
<record id="view_ddmrp_adjustment_sheet_wizard_form" model="ir.ui.view">
<field name="name">ddmrp.adjustment.sheet.form1</field>
<field name="model">ddmrp.adjustment.sheet</field>
<field name="arch" type="xml">
<form string="Buffer Adjustments Wizard">
<group name="dates" string="Periods">
<label for="date_start" string="Period" />
<div><field name="date_start" class="oe_inline" /> to <field
name="date_end"
class="oe_inline"
/></div>
<field name="date_range_type_id" />
</group>
<group name="buffers" string="Buffers">
<field name="buffer_ids" nolabel="1" colspan="2">
<tree name="buffer_tree">
<field name="name" />
<field name="product_id" />
<field name="location_id" />
<field name="buffer_profile_id" />
</tree>
</field>
</group>
<group name="factor" string="Factors to Apply">
<field name="apply_daf" />
<field name="apply_ltaf" />
</group>
<group name="factor_sheet" string="Sheet">
<p colspan="2">Fill the factors to apply in each period for all the
selected Buffers.</p>
<br />
<field
name="line_ids"
nolabel="1"
colspan="2"
widget="x2many_2d_matrix"
field_x_axis="date_range_id"
field_y_axis="factor"
field_value="value"
>
<tree editable="True" nolabel="1" create="false">
<field name="date_range_id" />
<field name="factor" />
<field name="value" />
</tree>
</field>
</group>
<footer>
<button
name="button_validate"
string="Validate"
type="object"
class="oe_highlight"
/>
<button string="Cancel" class="oe_link" special="cancel" />
</footer>
</form>
</field>
</record>
<record id="action_ddmrp_adjustment_sheet_wizard" model="ir.actions.act_window">
<field name="name">Create Buffer Adjustments</field>
<field name="res_model">ddmrp.adjustment.sheet</field>
<field name="type">ir.actions.act_window</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
<menuitem
id="menu_ddmrp_adjustment_sheet_wizard"
parent="stock_demand_estimate.stock_demand_planning_menu"
action="action_ddmrp_adjustment_sheet_wizard"
groups="ddmrp.group_stock_buffer_maintainer"
sequence="51"
/>
</odoo>