Skip to content

Commit

Permalink
FIX applying pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
FranzPoize committed Aug 17, 2023
1 parent 27a8bc7 commit 0b04a85
Show file tree
Hide file tree
Showing 17 changed files with 137 additions and 85 deletions.
6 changes: 1 addition & 5 deletions mrp_bom_configurable/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@
"demo": [
"demo/mrp_bom_configurable.xml",
],
'assets': {
'web.assets_backend': [
'mrp_bom_variable/static/src/**/*'
]
},
"assets": {"web.assets_backend": ["mrp_bom_variable/static/src/**/*"]},
"installable": True,
}
10 changes: 5 additions & 5 deletions mrp_bom_configurable/demo/mrp_bom_configurable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,17 @@
</record>
<record id="input_config_1" model="input.config">
<field name="name">test</field>
<field name="partner_id" ref="res_partner_1"/>
<field name="partner_id" ref="res_partner_1" />
</record>
<record id="input_config_line_1" model="input.line">
<field name="name">test line</field>
<field name="config_id" ref="input_config_1"/>
<field name="bom_id" ref="mrp_bom_configurable_1"/>
<field name="config_id" ref="input_config_1" />
<field name="bom_id" ref="mrp_bom_configurable_1" />
</record>
<record id="input_config_line_2" model="input.line">
<field name="name">test line</field>
<field name="config_id" ref="input_config_1"/>
<field name="bom_id" ref="mrp_bom_configurable_1"/>
<field name="config_id" ref="input_config_1" />
<field name="bom_id" ref="mrp_bom_configurable_1" />
<field name="test_config">False</field>
</record>
</odoo>
2 changes: 1 addition & 1 deletion mrp_bom_configurable/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@

from odoo.tools import config

if not config["without_demo"]:
if not config["without_demo"] or config["test_enable"]:
from . import demo_input_mixin
25 changes: 17 additions & 8 deletions mrp_bom_configurable/models/demo_input_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ class InputMixin(models.AbstractModel):

test_config = fields.Boolean(default=False, required=True)


class InputConfig(models.Model):
_name = "input.config"
_inherit = ["input.config", "input.mixin"]


CONFIG_ELEMENTS = ["test_config"]


class InputLine(models.Model):
_name = "input.line"
_inherit = ["input.line", "input.mixin"]
Expand All @@ -30,7 +33,7 @@ def create(self, vals_list):
def ui_configure(self):
self.ensure_one()
# TODO
lines, data, elements = [], [], dict()
elements = [], [], dict()
for elm in CONFIG_ELEMENTS:
if self._fields[elm].type == "many2one":
value = self[elm].display_name
Expand All @@ -40,18 +43,24 @@ def ui_configure(self):

bom = self.bom_id
content = bom.check_domain(elements)
self.env["mrp.bom"].create({
self.env["mrp.bom"].create(
{
"product_tmpl_id": bom.product_tmpl_id.id,
"product_id": bom.product_id.id,
"product_qty": self.count,
"product_uom_id": bom.product_uom_id.id,
"configuration_type": "configured",
"bom_line_ids": [
(0, 0, {
"product_id": line.product_id.id,
"product_qty": self.count * line.product_qty,
"product_uom_id": line.product_uom_id.id
})
(
0,
0,
{
"product_id": line.product_id.id,
"product_qty": self.count * line.product_qty,
"product_uom_id": line.product_uom_id.id,
},
)
for line in content
],
})
}
)
4 changes: 3 additions & 1 deletion mrp_bom_configurable/models/input_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ class Inputline(models.Model):
name = fields.Char(required=True)
sequence = fields.Integer()
bom_id = fields.Many2one(
comodel_name="mrp.bom", required=True, domain=lambda s: s.bom_id.configuration_type == "variable"
comodel_name="mrp.bom",
required=True,
domain=lambda s: s.bom_id.configuration_type == "variable",
)
config_id = fields.Many2one(comodel_name="input.config", required=True)
count = fields.Integer(default=1)
Expand Down
13 changes: 9 additions & 4 deletions mrp_bom_configurable/models/mrp_bom.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@
class MrpBom(models.Model):
_inherit = "mrp.bom"

configuration_type = fields.Selection([
('variable', 'Variable BOM'),
('configured', 'BOM from variable BOM'), ('normal', 'Normal BOM')], 'Configuration Type',
default='normal', required=True)
configuration_type = fields.Selection(
selection=[
("variable", "Variable BOM"),
("configured", "BOM from variable BOM"),
("normal", "Normal BOM"),
],
default="normal",
required=True,
)

def check_domain(self, values):
result = []
Expand Down
9 changes: 6 additions & 3 deletions mrp_bom_configurable/models/mrp_bom_line.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from odoo import fields, models
from odoo.tools.safe_eval import safe_eval


class MrpBomLine(models.Model):
Expand Down Expand Up @@ -26,14 +27,16 @@ def execute_domain_element(self, element, values):
param, operator, value = element
code = f"{repr(values[param])} {operator} {repr(value)}"

return eval(code)
return safe_eval(code)

def execute_domain(self, domain, values):
if not isinstance(domain, list):
domain = [domain]

if domain[0] == "OR":
return self.execute_domain(domain[1], values) or execute_domain(domain[2], values)
return self.execute_domain(domain[1], values) or self.execute_domain(
domain[2], values
)
elif len(domain) > 1:
return all(self.execute_domain(domain_elm, values) for domain_elm in domain)
else:
Expand All @@ -44,6 +47,6 @@ def execute(self, values):
if not self.domain:
return True
else:
domain = eval(self.domain)
domain = safe_eval(self.domain)

return self.execute_domain(domain, values)
23 changes: 14 additions & 9 deletions mrp_bom_configurable/report/bom_structure.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
from odoo import api, models
from odoo import fields, models, api


class ReportBomStructure(models.AbstractModel):
_name = 'mrp_bom_variable.report.mrp.report_bom_structure'
_inherit = 'report.mrp.report_bom_structure'
_name = "mrp_bom_variable.report.mrp.report_bom_structure"
_inherit = "report.mrp.report_bom_structure"

@api.model
def _get_bom_data(self, *args, **kwargs):
bom_report_line = super(ReportBomStructure, self)._get_bom_data(*args, **kwargs)
bom_line = kwargs.get('bom_line', False)
bom_line = kwargs.get("bom_line", False)

bom_report_line['domain'] = bom_line.domain if bom_line else False
bom_report_line["domain"] = bom_line.domain if bom_line else False

return bom_report_line

Expand All @@ -30,21 +30,26 @@ def _get_bom_data(self, *args, **kwargs):

@api.model
def _get_byproducts_lines(self, *args, **kwargs):
byproducts = super(ReportBomStructure, self)._get_byproducts_lines(*args, **kwargs)
byproducts = super(ReportBomStructure, self)._get_byproducts_lines(
*args, **kwargs
)
bom = args[1]
product = args[0]

index = 0
for byproduct in bom.byproduct_ids:
if byproduct._skip_byproduct_line(product):
continue
byproducts[index]['domain'] = byproduct.domain
byproducts[index]["domain"] = byproduct.domain

return byproducts

@api.model
def _get_component_data(self, *args, **kwargs):
component_data = super(ReportBomStructure, self)._get_component_data(*args, **kwargs)
component_data = super(ReportBomStructure, self)._get_component_data(
*args, **kwargs
)
bom_line = args[2]

component_data['domain'] = bom_line.domain if bom_line else False
component_data["domain"] = bom_line.domain if bom_line else False
return component_data
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,38 @@ import {BomOverviewComponent} from "@mrp/components/bom_overview/mrp_bom_overvie
import {useService} from "@web/core/utils/hooks";
import {patch} from "@web/core/utils/patch";

const { EventBus, onWillStart, useSubEnv, useState } = owl;

const {EventBus, onWillStart, useSubEnv, useState} = owl;

patch(BomOverviewTable.prototype, "test patch", {
get showDomain() {
return this.props.showOptions.domain;
}
},
});

patch(BomOverviewTable.props.showOptions, "test patch 2", {
shape: {
...BomOverviewTable.props.showOptions.shape,
domain: Boolean,
}
},
});

patch(BomOverviewDisplayFilter.prototype, "test patch 2", {
setup() {
this.displayOptions = {
availabilities: this.env._t('Availabilities'),
domain: this.env._t('Domain'),
leadTimes: this.env._t('Lead Times'),
costs: this.env._t('Costs'),
operations: this.env._t('Operations'),
availabilities: this.env._t("Availabilities"),
domain: this.env._t("Domain"),
leadTimes: this.env._t("Lead Times"),
costs: this.env._t("Costs"),
operations: this.env._t("Operations"),
};
}
},
});

patch(BomOverviewDisplayFilter.props.showOptions, "test patch 2", {
shape: {
...BomOverviewTable.props.showOptions.shape,
domain: Boolean,
}
},
});

patch(BomOverviewLine.prototype, "test patch", {
Expand All @@ -48,15 +47,15 @@ patch(BomOverviewLine.prototype, "test patch", {
},

get hasDomain() {
return this.data.hasOwnProperty('domain');
}
return this.data.hasOwnProperty("domain");
},
});

patch(BomOverviewLine.props.showOptions, "test patch 2", {
shape: {
...BomOverviewTable.props.showOptions.shape,
domain: Boolean,
}
},
});

patch(BomOverviewComponent.prototype, "test patch 3", {
Expand Down Expand Up @@ -103,16 +102,17 @@ patch(BomOverviewComponent.prototype, "test patch 3", {
this.state.bomQuantity,
this.state.currentVariantId,
];
const context = this.state.currentWarehouse ? { warehouse: this.state.currentWarehouse.id } : {};
const context = this.state.currentWarehouse
? {warehouse: this.state.currentWarehouse.id}
: {};
const bomData = await this.orm.call(
"mrp_bom_variable.report.mrp.report_bom_structure",
"get_html",
args,
{ context }
{context}
);
this.state.bomData = bomData["lines"];
this.state.showOptions.attachments = bomData["has_attachments"];
return bomData;
}
},
});

18 changes: 14 additions & 4 deletions mrp_bom_configurable/static/src/components/mrp_templates.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8" ?>
<templates xml:space="preserve">

<t t-name="mrp_bom_variable.BomOverviewTable" t-inherit="mrp.BomOverviewTable" t-inherit-mode="extension" owl="1">
<t
t-name="mrp_bom_variable.BomOverviewTable"
t-inherit="mrp.BomOverviewTable"
t-inherit-mode="extension"
owl="1"
>
<xpath expr="//th[@name='th_mrp_bom_h']" position="after">
<th t-if="showDomain" class="text-end">Domain</th>
</xpath>
</t>

<t t-name="mrp_bom_variable.BomOverviewLine" t-inherit="mrp.BomOverviewLine" t-inherit-mode="extension" owl="1">
<t
t-name="mrp_bom_variable.BomOverviewLine"
t-inherit="mrp.BomOverviewLine"
t-inherit-mode="extension"
owl="1"
>
<xpath expr="//td[@name='td_mrp_bom']" position="after">
<td t-if="showDomain" class="text-end" t-esc="data.domain"/>
<td t-if="showDomain" class="text-end" t-esc="data.domain" />
</xpath>
</t>

Expand Down
Loading

0 comments on commit 0b04a85

Please sign in to comment.