Skip to content

Commit

Permalink
[IMP] Improved a Migrated js file and onchnage specification.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ammar-OSI committed Feb 22, 2024
1 parent a4f6b67 commit 27d0ee3
Show file tree
Hide file tree
Showing 8 changed files with 154 additions and 178 deletions.
19 changes: 9 additions & 10 deletions product_configurator_mrp/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,16 @@
"security/configurator_security.xml",
"security/ir.model.access.csv",
],
# "assets": {
# "web.assets_backend": [
# "/product_configurator_mrp/static/src/js/list_controller.js",
# "/product_configurator_mrp/static/src/js/kanban_controller.js",
# "/product_configurator_mrp/static/src/js/form_controller.js",
# "/product_configurator_mrp/static/src/scss/mrp_config.scss",
# "/product_configurator_mrp/static/src/xml/mrp_production_views.xml",
# ],
# },
"assets": {
"web.assets_backend": [
"/product_configurator_mrp/static/src/js/list_controller.js",
"/product_configurator_mrp/static/src/js/kanban_controller.js",
"/product_configurator_mrp/static/src/js/form_controller.js",
"/product_configurator_mrp/static/src/scss/mrp_config.scss",
"/product_configurator_mrp/static/src/xml/mrp_production_views.xml"
],
},
"demo": ["demo/product_template.xml"],
# "qweb": ["static/src/xml/mrp_production_views.xml"],
"installable": True,
"auto_install": False,
"development_status": "Beta",
Expand Down
3 changes: 2 additions & 1 deletion product_configurator_mrp/models/mrp.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (C) 2021 Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import fields, models
from odoo import fields, models, api


class MrpProduction(models.Model):
Expand All @@ -23,6 +23,7 @@ class MrpProduction(models.Model):
string="Custom Values",
)

@api.model
def action_config_start(self):
"""Return action to start configuration wizard"""
configurator_obj = self.env["product.configurator.mrp"]
Expand Down
39 changes: 23 additions & 16 deletions product_configurator_mrp/models/product_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ def create_get_bom(self, variant, product_tmpl_id=None, values=None):
for product in attr_products:
bom_line_vals = {"product_id": product.id, "product_qty": 1}
specs = self.get_onchange_specifications(model="mrp.bom.line")
for key, val in specs.items():
if val is None:
specs[key] = {}
updates = mrpBomLine.onchange(
bom_line_vals, ["product_id", "product_qty"], specs
)
Expand All @@ -76,6 +79,9 @@ def create_get_bom(self, variant, product_tmpl_id=None, values=None):
specs = self.get_onchange_specifications(
model="mrp.bom.line"
)
for key, val in specs.items():
if val is None:
specs[key] = {}
updates = mrpBomLine.onchange(
parent_bom_line_vals,
["product_id", "product_qty"],
Expand All @@ -86,7 +92,7 @@ def create_get_bom(self, variant, product_tmpl_id=None, values=None):
values=values, model="mrp.bom.line"
)
values.update(parent_bom_line_vals)
bom_lines.append((0, 0, values))
bom_lines.append((0, 0, parent_bom_line_vals))
else:
parent_bom_line_vals = {
"product_id": parent_bom_line.product_id.id,
Expand All @@ -96,33 +102,34 @@ def create_get_bom(self, variant, product_tmpl_id=None, values=None):
for key, val in specs.items():
if val is None:
specs[key] = {}

updates = mrpBomLine.onchange(
parent_bom_line_vals, ["product_id", "product_qty"], specs
)
values2 = updates.get("value", {})
values2 = self.get_vals_to_write(
values = updates.get("value", {})
values = self.get_vals_to_write(
values=values, model="mrp.bom.line"
)
values2.update(parent_bom_line_vals)
bom_lines.append((0, 0, values2))
values.update(parent_bom_line_vals)
bom_lines.append((0, 0, values))
if bom_lines:
bom_values = {
"product_tmpl_id": self.product_tmpl_id.id,
"product_id": variant.id,
"bom_line_ids": bom_lines,
}
specs = self.get_onchange_specifications(model="mrp.bom")

# updates = mrpBom.onchange(
# bom_values,
# ["product_id", "product_tmpl_id", "bom_line_ids"],
# specs,
# )
# values = updates.get("value", {})
# values = self.get_vals_to_write(values=values, model="mrp.bom")
# values.update(bom_values)
mrp_bom_id = mrpBom.create(bom_values)
for key, val in specs.items():
if val is None:
specs[key] = {}
updates = mrpBom.onchange(
bom_values,
["product_id", "product_configurator_sale_mrproduct_tmpl_id", "bom_line_ids"],
specs,
)
values = updates.get("value", {})
values = self.get_vals_to_write(values=values, model="mrp.bom")
values.update(bom_values)
mrp_bom_id = mrpBom.create(values)
if mrp_bom_id and parent_bom:
for operation_line in parent_bom.operation_ids:
operation_line.copy(default={"bom_id": mrp_bom_id.id})
Expand Down
81 changes: 27 additions & 54 deletions product_configurator_mrp/static/src/js/form_controller.js
Original file line number Diff line number Diff line change
@@ -1,60 +1,33 @@
odoo.define("product_configurator_mrp.FormController", function (require) {
"use strict";
/** @odoo-module **/

var core = require("web.core");
var FormController = require("web.FormController");
var FormView = require("web.FormView");
var viewRegistry = require("web.view_registry");
import { _t } from "@web/core/l10n/translation";
import { registry } from "@web/core/registry";
import { useService } from "@web/core/utils/hooks";
import { formView } from "@web/views/form/form_view";
import { FormController } from "@web/views/form/form_controller";

var qweb = core.qweb;
export class ProductConfiguratorFormController extends FormController {
setup() {
super.setup();
this.action = useService("action");
this.rpc = useService("rpc");
this.orm = useService("orm");
}

var ConfigFormController = FormController.extend({
buttons_template: "ConfigFormView.buttons",
events: _.extend({}, FormController.prototype.events, {
"click .o_form_button_create_config": "_onConfigure",
}),
async _onConfigure() {
let action = await this.orm.call("mrp.production", 'action_config_start', [])
this.action.doAction(action)
}
}
ProductConfiguratorFormController.components = {
...FormController.components,
};

renderButtons: function () {
var self = this;
var $footer = this.footerToButtons ? this.renderer.$("footer") : null;
var mustRenderFooterButtons = $footer && $footer.length;
self._super.apply(this, arguments);
if (mustRenderFooterButtons);
else if (
this.$buttons &&
self.modelName === "mrp.production" &&
self.initialState.context.custom_create_variant
) {
var button_create = this.$buttons.find(".o_form_button_create");
button_create.after(
qweb.render("ConfigFormView.buttons", {
widget: this,
})
);
this.$buttons
.find(".o_form_button_create_config")
.css("display", "inline");
}
},

_onConfigure: function () {
var self = this;
return this._rpc({
model: "mrp.production",
method: "action_config_start",
args: [""],
context: this.initialState.context,
}).then(function (result) {
self.do_action(result);
});
},
});
export const ProductConfiguratorFormView = {
...formView,
Controller: ProductConfiguratorFormController,
buttonTemplate: "product_configurator_mrp.FormButtons",
};

var ConfigFormView = FormView.extend({
config: _.extend({}, FormView.prototype.config, {
Controller: ConfigFormController,
}),
});

viewRegistry.add("product_configurator_mrp_form", ConfigFormView);
});
registry.category("views").add("product_configurator_mrp_form", ProductConfiguratorFormView);
69 changes: 27 additions & 42 deletions product_configurator_mrp/static/src/js/kanban_controller.js
Original file line number Diff line number Diff line change
@@ -1,48 +1,33 @@
odoo.define("product_configurator_mrp.KanbanController", function (require) {
"use strict";
/** @odoo-module **/

var KanbanController = require("web.KanbanController");
var KanbanView = require("web.KanbanView");
var viewRegistry = require("web.view_registry");
import { _t } from "@web/core/l10n/translation";
import { registry } from "@web/core/registry";
import { useService } from "@web/core/utils/hooks";
import { kanbanView } from "@web/views/kanban/kanban_view";
import { KanbanController } from "@web/views/kanban/kanban_controller";

var ConfigKanbanController = KanbanController.extend({
buttons_template: "ConfigKanbanView.buttons",
events: _.extend({}, KanbanController.prototype.events, {
"click .o-kanban-button-new_config": "_onConfigure",
}),
export class ProductConfiguratorKanbanController extends KanbanController {
setup() {
super.setup();
this.action = useService("action");
this.rpc = useService("rpc");
this.orm = useService("orm");

renderButtons: function () {
var self = this;
self._super.apply(this, arguments);
if (
this.$buttons &&
self.modelName === "mrp.production" &&
self.initialState.context.custom_create_variant
) {
this.$buttons
.find(".o-kanban-button-new_config")
.css("display", "inline");
}
},
}

_onConfigure: function () {
var self = this;
return this._rpc({
model: "mrp.production",
method: "action_config_start",
args: [""],
context: this.initialState.context,
}).then(function (result) {
self.do_action(result);
});
},
});
async _onConfigure() {
let action = await this.orm.call("mrp.production", 'action_config_start', [])
this.action.doAction(action)
}
}
ProductConfiguratorKanbanController.components = {
...KanbanController.components,
};

var ConfigKanbanView = KanbanView.extend({
config: _.extend({}, KanbanView.prototype.config, {
Controller: ConfigKanbanController,
}),
});

viewRegistry.add("product_configurator_mrp_kanban", ConfigKanbanView);
});
export const ProductConfiguratorKanbanView = {
...kanbanView,
Controller: ProductConfiguratorKanbanController,
buttonTemplate: "product_configurator_mrp.KanbanButtons",
};
registry.category("views").add("product_configurator_mrp_kanban", ProductConfiguratorKanbanView);
82 changes: 35 additions & 47 deletions product_configurator_mrp/static/src/js/list_controller.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,35 @@
odoo.define("product_configurator_mrp.ListController", function (require) {
"use strict";
var ListController = require("web.ListController");
var ListView = require("web.ListView");
var viewRegistry = require("web.view_registry");

var ConfigListController = ListController.extend({
buttons_template: "ConfigListView.buttons",
events: _.extend({}, ListController.prototype.events, {
"click .o_list_button_add_config": "_onConfigure",
}),

renderButtons: function () {
var self = this;
self._super.apply(this, arguments);
if (
this.$buttons &&
self.modelName === "mrp.production" &&
self.initialState.context.custom_create_variant
) {
this.$buttons
.find(".o_list_button_add_config")
.css("display", "inline");
}
},

_onConfigure: function () {
var self = this;
return this._rpc({
model: "mrp.production",
method: "action_config_start",
args: [""],
context: this.initialState.context,
}).then(function (result) {
self.do_action(result);
});
},
});

var ConfigListView = ListView.extend({
config: _.extend({}, ListView.prototype.config, {
Controller: ConfigListController,
}),
});

viewRegistry.add("product_configurator_mrp_tree", ConfigListView);
});
/** @odoo-module **/

import { _t } from "@web/core/l10n/translation";
import { registry } from "@web/core/registry";
import { listView } from "@web/views/list/list_view";
import { ListController } from "@web/views/list/list_controller";
import { useService } from "@web/core/utils/hooks";

export class ProductConfiguratorController extends ListController {
setup() {
super.setup();
this.action = useService("action");
this.rpc = useService("rpc");
this.orm = useService("orm");

}

async _onConfigure() {
let action = await this.orm.call("mrp.production", 'action_config_start', [])
this.action.doAction(action)
}
};

ProductConfiguratorController.components = {
...ListController.components,
};

export const ProductConfiguratorListView = {
...listView,
Controller: ProductConfiguratorController,
buttonTemplate: "product_configurator_mrp.ListButtons",
};


registry.category("views").add("product_configurator_mrp_tree", ProductConfiguratorListView);
Loading

0 comments on commit 27d0ee3

Please sign in to comment.